diff options
| author | Alejandro Colomar <alx@kernel.org> | 2025-08-19 17:48:50 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2025-08-20 18:14:03 +0200 |
| commit | 0e7a39804a3c017a209117fc2243c6cbb543dede (patch) | |
| tree | 91e0b287d8b826d668c3d8118347f07cc8b8964a /man/man2/bind.2 | |
| parent | e2d3f14fe40ad90a1fedf0fcd27e6cc896c49a7a (diff) | |
| download | man-pages-0e7a39804a3c.tar.gz | |
man/: EXAMPLES: Use err(3) and errc(3bsd) instead of similar macros
These functions are quite portable. And if one doesn't have them for
some reason (but libbsd has been ported to many systems), one can write
them easily as macros, anyway.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'man/man2/bind.2')
| -rw-r--r-- | man/man2/bind.2 | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/man/man2/bind.2 b/man/man2/bind.2 index 5d44c152a6..309f6d9d7c 100644 --- a/man/man2/bind.2 +++ b/man/man2/bind.2 @@ -209,6 +209,7 @@ domain, and accept connections: .P .\" SRC BEGIN (bind.c) .EX +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -219,9 +220,6 @@ domain, and accept connections: #define MY_SOCK_PATH "/somepath" #define LISTEN_BACKLOG 50 \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& int main(void) { @@ -231,7 +229,7 @@ main(void) \& sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == \-1) - handle_error("socket"); + err(EXIT_FAILURE, "socket"); \& memset(&my_addr, 0, sizeof(my_addr)); my_addr.sun_family = AF_UNIX; @@ -240,10 +238,10 @@ main(void) \& if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(my_addr)) == \-1) - handle_error("bind"); + err(EXIT_FAILURE, "bind"); \& if (listen(sfd, LISTEN_BACKLOG) == \-1) - handle_error("listen"); + err(EXIT_FAILURE, "listen"); \& /* Now we can accept incoming connections one at a time using accept(2). */ @@ -252,15 +250,15 @@ main(void) cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size); if (cfd == \-1) - handle_error("accept"); + err(EXIT_FAILURE, "accept"); \& /* Code to deal with incoming connection(s)... */ \& if (close(sfd) == \-1) - handle_error("close"); + err(EXIT_FAILURE, "close"); \& if (unlink(MY_SOCK_PATH) == \-1) - handle_error("unlink"); + err(EXIT_FAILURE, "unlink"); } .EE .\" SRC END |
