[PATCH v4] getaddrinfo.3: Fix includes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---

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(-)

diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 35071b733..b51a634b3 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>      /* 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
 
-- 
2.31.1




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux