getaddrinfo.3: Fix includes
PATCH 1/1 getaddrinfo.3: Fix includes
- 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 */
$
---
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/[email protected]/T/>.
You might find this tool useful :)
Cheers,
Alex
man3/getaddrinfo.3 | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
man3/getaddrinfo.3 +12 -14
@@ -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
Signature · 1 line
2.31.1
Quoted 15 lines · Alejandro Colomar
- Remove unnecessary includes
- Add a comment about why each include is needed
- Sort alphabeticallyAll this has been done using iwyu(1):
$ iwyu getaddrinfo_server.c 2>&1 \ | sed -e '\,^#,s,//,/*,' -e '\,^#,s,$, */,' \ | sed '/^#/s/\w*\.\.\./.../';
getaddrinfo_client.cshould add these lines:
getaddrinfo_client.cshould remove these lines:
- #include <sys/types.h> // lines 1-1
Quoted 7 lines
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 */
Oops, the above should be:
getaddrinfo_server.c should add these lines:
getaddrinfo_server.c should remove these lines:
- #include <sys/types.h> // lines 1-1
The full include-list for getaddrinfo_server.c:
#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 */
The code contents are correct.
Quoted 18 lines
$ iwyu getaddrinfo_client.c 2>&1 \ | sed -e '\,^#,s,//,/*,' -e '\,^#,s,$, */,' \ | sed '/^#/s/\w*\.\.\./.../';
getaddrinfo_client.cshould add these lines:
getaddrinfo_client.cshould remove these lines:
- #include <sys/types.h> // lines 1-1The 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 */$
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
PATCH v2 1/1 getaddrinfo.3: Fix includes
- 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_server.c should add these lines:
getaddrinfo_server.c should remove these lines:
- #include <sys/types.h> // lines 1-1
The full include-list for getaddrinfo_server.c:
#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 */ $ 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 */
$
---
man3/getaddrinfo.3 | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
man3/getaddrinfo.3 +12 -14
@@ -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
Signature · 1 line
2.31.1