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/poll.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/poll.2')
| -rw-r--r-- | man/man2/poll.2 | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/man/man2/poll.2 b/man/man2/poll.2 index 85856bb34d..e3e5119d2e 100644 --- a/man/man2/poll.2 +++ b/man/man2/poll.2 @@ -555,6 +555,7 @@ at which point the file descriptor was closed and the program terminated. \& Licensed under GNU General Public License v2 or later. */ +#include <err.h> #include <fcntl.h> #include <poll.h> #include <stdio.h> @@ -562,9 +563,6 @@ at which point the file descriptor was closed and the program terminated. #include <sys/types.h> #include <unistd.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -582,14 +580,14 @@ main(int argc, char *argv[]) num_open_fds = nfds = argc \- 1; pfds = calloc(nfds, sizeof(struct pollfd)); if (pfds == NULL) - errExit("malloc"); + err(EXIT_FAILURE, "malloc"); \& /* Open each file on command line, and add it to \[aq]pfds\[aq] array. */ \& for (nfds_t j = 0; j < nfds; j++) { pfds[j].fd = open(argv[j + 1], O_RDONLY); if (pfds[j].fd == \-1) - errExit("open"); + err(EXIT_FAILURE, "open"); \& printf("Opened \[rs]"%s\[rs]" on fd %d\[rs]n", argv[j + 1], pfds[j].fd); \& @@ -603,7 +601,7 @@ main(int argc, char *argv[]) printf("About to poll()\[rs]n"); ready = poll(pfds, nfds, \-1); if (ready == \-1) - errExit("poll"); + err(EXIT_FAILURE, "poll"); \& printf("Ready: %d\[rs]n", ready); \& @@ -619,13 +617,13 @@ main(int argc, char *argv[]) if (pfds[j].revents & POLLIN) { s = read(pfds[j].fd, buf, sizeof(buf)); if (s == \-1) - errExit("read"); + err(EXIT_FAILURE, "read"); printf(" read %zd bytes: %.*s\[rs]n", s, (int) s, buf); } else { /* POLLERR | POLLHUP */ printf(" closing fd %d\[rs]n", pfds[j].fd); if (close(pfds[j].fd) == \-1) - errExit("close"); + err(EXIT_FAILURE, "close"); num_open_fds\-\-; } } |
