linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] getaddrinfo.3: Fix includes
@ 2021-05-14 13:11 Alejandro Colomar
  2021-05-14 13:21 ` Alejandro Colomar (man-pages)
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2021-05-14 13:11 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, jwakely

- 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@gmail.com>
---

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@gmail.com/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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] getaddrinfo.3: Fix includes
  2021-05-14 13:11 [PATCH] getaddrinfo.3: Fix includes Alejandro Colomar
@ 2021-05-14 13:21 ` Alejandro Colomar (man-pages)
  2021-05-14 13:26   ` [PATCH v2] " Alejandro Colomar
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-05-14 13:21 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, jwakely

On 5/14/21 3:11 PM, Alejandro Colomar wrote:
> - 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 */

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.

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

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] getaddrinfo.3: Fix includes
  2021-05-14 13:21 ` Alejandro Colomar (man-pages)
@ 2021-05-14 13:26   ` Alejandro Colomar
  0 siblings, 0 replies; 3+ messages in thread
From: Alejandro Colomar @ 2021-05-14 13:26 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, jwakely

- 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@gmail.com>
---

 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-14 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 13:11 [PATCH] getaddrinfo.3: Fix includes Alejandro Colomar
2021-05-14 13:21 ` Alejandro Colomar (man-pages)
2021-05-14 13:26   ` [PATCH v2] " Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).