Skip to contentSkip to conversation

getaddrinfo.3: Fix includes

PATCH Superseded Alejandro Colomar 1 participant 2 messages May 14, 2021 – May 15, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH v3 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 */

$

---

v2: fix commit msg
v3: ffix commit msg (lines starting with # may be removed by git)

 man3/getaddrinfo.3 | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
man3/getaddrinfo.3 +12 -14
index 35071b733..aa3b81165 100644
@@ -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
#1 lore raw

PATCH v4 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 */
$

---

v2: fix commit msg
v3: ffix commit msg (starting # may be removed by git)
v4: ffix (fit into 80-col right margin)

 man3/getaddrinfo.3 | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
man3/getaddrinfo.3 +12 -14
index 35071b733..b51a634b3 100644
@@ -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>      /* addrinfo, gai_strerror, freeaddrinfo, ... */
+#include <stdio.h>      /* fprintf, NULL, stderr, printf */
+#include <stdlib.h>     /* exit, EXIT_FAILURE */
+#include <string.h>     /* memset */
+#include <sys/socket.h> /* bind, recvfrom, sendto, socket, ... */
+#include <unistd.h>     /* 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>      /* addrinfo, freeaddrinfo, gai_strerror, ... */
+#include <stdio.h>      /* fprintf, stderr, perror, printf, ... */
+#include <stdlib.h>     /* exit, EXIT_FAILURE, EXIT_SUCCESS */
+#include <string.h>     /* memset, strlen */
+#include <sys/socket.h> /* connect, socket, AF_UNSPEC, SOCK_DGRAM */
+#include <unistd.h>     /* close, read, write, ssize_t */
 
 #define BUF_SIZE 500
 
Signature · 1 line
2.31.1