- Remove unnecessary includes - Add a comment about why each include is needed - Sort alphabetically All this has been done using iwyu(1): $ iwyu getaddrinfo_server.c 2>&1 \ | sed -e '\,^#,s,//,/*,' -e '\,^#,s,$, */,' \ | sed '/^#/s/\w*\.\.\./.../'; getaddrinfo_client.c should add these lines: getaddrinfo_client.c should remove these lines: - #include <sys/types.h> // lines 1-1 The full include-list for getaddrinfo_client.c: #include <netdb.h> /* for addrinfo, freeaddrinfo, gai_strerror, ... */ #include <stdio.h> /* for fprintf, stderr, perror, printf, NULL, size_t */ #include <stdlib.h> /* for exit, EXIT_FAILURE, EXIT_SUCCESS */ #include <string.h> /* for memset, strlen */ #include <sys/socket.h> /* for connect, socket, AF_UNSPEC, SOCK_DGRAM */ #include <unistd.h> /* for close, read, write, ssize_t */ $ iwyu getaddrinfo_client.c 2>&1 \ | sed -e '\,^#,s,//,/*,' -e '\,^#,s,$, */,' \ | sed '/^#/s/\w*\.\.\./.../'; getaddrinfo_client.c should add these lines: getaddrinfo_client.c should remove these lines: - #include <sys/types.h> // lines 1-1 The full include-list for getaddrinfo_client.c: #include <netdb.h> /* for addrinfo, freeaddrinfo, gai_strerror, ... */ #include <stdio.h> /* for fprintf, stderr, perror, printf, NULL, size_t */ #include <stdlib.h> /* for exit, EXIT_FAILURE, EXIT_SUCCESS */ #include <string.h> /* for memset, strlen */ #include <sys/socket.h> /* for connect, socket, AF_UNSPEC, SOCK_DGRAM */ #include <unistd.h> /* for close, read, write, ssize_t */ $ Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx> --- Hi Michael, Today I met this tool for checking the includes. I like its output very much, so I used it directly (with a few tweaks) to update the includes in our EXAMPLES. I kept the comments about why each one is needed, because I think that info might be useful, but id you prefer, we can remove it and keep it only in the commit msg. When we update an example, it will be easier to see if we should remove an include or add a new one (ideally we would rerun iwyu(1)). Hi Jonathan, I CCd you because of the recent discussion in <https://lore.kernel.org/linux-man/cb10752b-3036-67d3-41c5-b9ef0954f7f9@xxxxxxxxx/T/>. You might find this tool useful :) Cheers, Alex man3/getaddrinfo.3 | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3 index 35071b733..aa3b81165 100644 --- a/man3/getaddrinfo.3 +++ b/man3/getaddrinfo.3 @@ -660,13 +660,12 @@ The programs are an echo server and client for UDP datagrams. .SS Server program \& .EX -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <sys/socket.h> -#include <netdb.h> +#include <netdb.h> /* for addrinfo, gai_strerror, freeaddrinfo, ... */ +#include <stdio.h> /* for fprintf, NULL, stderr, printf */ +#include <stdlib.h> /* for exit, EXIT_FAILURE */ +#include <string.h> /* for memset */ +#include <sys/socket.h> /* for bind, recvfrom, sendto, socket, ... */ +#include <unistd.h> /* for close, ssize_t */ #define BUF_SIZE 500 @@ -755,13 +754,12 @@ main(int argc, char *argv[]) .SS Client program \& .EX -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> +#include <netdb.h> /* for addrinfo, freeaddrinfo, gai_strerror, ... */ +#include <stdio.h> /* for fprintf, stderr, perror, printf, NULL, size_t */ +#include <stdlib.h> /* for exit, EXIT_FAILURE, EXIT_SUCCESS */ +#include <string.h> /* for memset, strlen */ +#include <sys/socket.h> /* for connect, socket, AF_UNSPEC, SOCK_DGRAM */ +#include <unistd.h> /* for close, read, write, ssize_t */ #define BUF_SIZE 500 -- 2.31.1