aboutsummaryrefslogtreecommitdiffstats
path: root/man/man7
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2025-08-19 17:48:50 +0200
committerAlejandro Colomar <alx@kernel.org>2025-08-20 18:14:03 +0200
commit0e7a39804a3c017a209117fc2243c6cbb543dede (patch)
tree91e0b287d8b826d668c3d8118347f07cc8b8964a /man/man7
parente2d3f14fe40ad90a1fedf0fcd27e6cc896c49a7a (diff)
downloadman-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/man7')
-rw-r--r--man/man7/aio.717
1 files changed, 8 insertions, 9 deletions
diff --git a/man/man7/aio.7 b/man/man7/aio.7
index 931247a580..a3937206bf 100644
--- a/man/man7/aio.7
+++ b/man/man7/aio.7
@@ -226,6 +226,7 @@ aio_return():
.SS Program source
\&
.EX
+#include <err.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
@@ -236,8 +237,6 @@ aio_return():
\&
#define BUF_SIZE 20 /* Size of buffers for read operations */
\&
-#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)
-\&
struct ioRequest { /* Application\-defined structure for tracking
I/O requests */
int reqNum;
@@ -290,11 +289,11 @@ main(int argc, char *argv[])
\&
struct ioRequest *ioList = calloc(numReqs, sizeof(*ioList));
if (ioList == NULL)
- errExit("calloc");
+ err(EXIT_FAILURE, "calloc");
\&
struct aiocb *aiocbList = calloc(numReqs, sizeof(*aiocbList));
if (aiocbList == NULL)
- errExit("calloc");
+ err(EXIT_FAILURE, "calloc");
\&
/* Establish handlers for SIGQUIT and the I/O completion signal. */
\&
@@ -303,12 +302,12 @@ main(int argc, char *argv[])
\&
sa.sa_handler = quitHandler;
if (sigaction(SIGQUIT, &sa, NULL) == \-1)
- errExit("sigaction");
+ err(EXIT_FAILURE, "sigaction");
\&
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = aioSigHandler;
if (sigaction(IO_SIGNAL, &sa, NULL) == \-1)
- errExit("sigaction");
+ err(EXIT_FAILURE, "sigaction");
\&
/* Open each file specified on the command line, and queue
a read request on the resulting file descriptor. */
@@ -320,13 +319,13 @@ main(int argc, char *argv[])
\&
ioList[j].aiocbp\->aio_fildes = open(argv[j + 1], O_RDONLY);
if (ioList[j].aiocbp\->aio_fildes == \-1)
- errExit("open");
+ err(EXIT_FAILURE, "open");
printf("opened %s on descriptor %d\[rs]n", argv[j + 1],
ioList[j].aiocbp\->aio_fildes);
\&
ioList[j].aiocbp\->aio_buf = malloc(BUF_SIZE);
if (ioList[j].aiocbp\->aio_buf == NULL)
- errExit("malloc");
+ err(EXIT_FAILURE, "malloc");
\&
ioList[j].aiocbp\->aio_nbytes = BUF_SIZE;
ioList[j].aiocbp\->aio_reqprio = 0;
@@ -338,7 +337,7 @@ main(int argc, char *argv[])
\&
s = aio_read(ioList[j].aiocbp);
if (s == \-1)
- errExit("aio_read");
+ err(EXIT_FAILURE, "aio_read");
}
\&
openReqs = numReqs;