diff options
| -rw-r--r-- | man/man2/bind.2 | 16 | ||||
| -rw-r--r-- | man/man2/mmap.2 | 12 | ||||
| -rw-r--r-- | man/man2/mprotect.2 | 12 | ||||
| -rw-r--r-- | man/man2/poll.2 | 14 | ||||
| -rw-r--r-- | man/man2/shmop.2 | 22 | ||||
| -rw-r--r-- | man/man2/timer_create.2 | 20 | ||||
| -rw-r--r-- | man/man3/duplocale.3 | 8 | ||||
| -rw-r--r-- | man/man3/inet_net_pton.3 | 8 | ||||
| -rw-r--r-- | man/man3/makecontext.3 | 14 | ||||
| -rw-r--r-- | man/man3/mq_getattr.3 | 10 | ||||
| -rw-r--r-- | man/man3/mq_notify.3 | 14 | ||||
| -rw-r--r-- | man/man3/newlocale.3 | 12 | ||||
| -rw-r--r-- | man/man3/posix_spawn.3 | 26 | ||||
| -rw-r--r-- | man/man3/pthread_cancel.3 | 14 | ||||
| -rw-r--r-- | man/man3/pthread_cleanup_push.3 | 10 | ||||
| -rw-r--r-- | man/man3/pthread_create.3 | 21 | ||||
| -rw-r--r-- | man/man3/pthread_getcpuclockid.3 | 15 | ||||
| -rw-r--r-- | man/man3/pthread_mutexattr_setrobust.3 | 10 | ||||
| -rw-r--r-- | man/man3/pthread_setschedparam.3 | 26 | ||||
| -rw-r--r-- | man/man3/pthread_sigmask.3 | 10 | ||||
| -rw-r--r-- | man/man3/sem_wait.3 | 10 | ||||
| -rw-r--r-- | man/man3/shm_open.3 | 30 | ||||
| -rw-r--r-- | man/man4/loop.4 | 14 | ||||
| -rw-r--r-- | man/man7/aio.7 | 17 |
24 files changed, 154 insertions, 211 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 diff --git a/man/man2/mmap.2 b/man/man2/mmap.2 index 28ad07198a..23ffcd758c 100644 --- a/man/man2/mmap.2 +++ b/man/man2/mmap.2 @@ -948,6 +948,7 @@ to output the desired bytes. .SS Program source .\" SRC BEGIN (mmap.c) .EX +#include <err.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -956,9 +957,6 @@ to output the desired bytes. #include <sys/types.h> #include <unistd.h> \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& int main(int argc, char *argv[]) { @@ -976,10 +974,10 @@ main(int argc, char *argv[]) \& fd = open(argv[1], O_RDONLY); if (fd == \-1) - handle_error("open"); + err(EXIT_FAILURE, "open"); \& if (fstat(fd, &sb) == \-1) /* To obtain file size */ - handle_error("fstat"); + err(EXIT_FAILURE, "fstat"); \& offset = atoi(argv[2]); pa_offset = offset & \[ti](sysconf(_SC_PAGE_SIZE) \- 1); @@ -1003,12 +1001,12 @@ main(int argc, char *argv[]) addr = mmap(NULL, length + offset \- pa_offset, PROT_READ, MAP_PRIVATE, fd, pa_offset); if (addr == MAP_FAILED) - handle_error("mmap"); + err(EXIT_FAILURE, "mmap"); \& s = write(STDOUT_FILENO, addr + offset \- pa_offset, length); if (s != length) { if (s == \-1) - handle_error("write"); + err(EXIT_FAILURE, "write"); \& fprintf(stderr, "partial write"); exit(EXIT_FAILURE); diff --git a/man/man2/mprotect.2 b/man/man2/mprotect.2 index 773d93dc9c..269ae204d6 100644 --- a/man/man2/mprotect.2 +++ b/man/man2/mprotect.2 @@ -293,6 +293,7 @@ Got SIGSEGV at address: 0x804e000 \& .\" SRC BEGIN (mprotect.c) .EX +#include <err.h> #include <malloc.h> #include <signal.h> #include <stdio.h> @@ -300,9 +301,6 @@ Got SIGSEGV at address: 0x804e000 #include <sys/mman.h> #include <unistd.h> \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& static char *buffer; \& static void @@ -328,24 +326,24 @@ main(void) sigemptyset(&sa.sa_mask); sa.sa_sigaction = handler; if (sigaction(SIGSEGV, &sa, NULL) == \-1) - handle_error("sigaction"); + err(EXIT_FAILURE, "sigaction"); \& pagesize = sysconf(_SC_PAGE_SIZE); if (pagesize == \-1) - handle_error("sysconf"); + err(EXIT_FAILURE, "sysconf"); \& /* Allocate a buffer aligned on a page boundary; initial protection is PROT_READ | PROT_WRITE. */ \& buffer = memalign(pagesize, 4 * pagesize); if (buffer == NULL) - handle_error("memalign"); + err(EXIT_FAILURE, "memalign"); \& printf("Start of region: %p\[rs]n", buffer); \& if (mprotect(buffer + pagesize * 2, pagesize, PROT_READ) == \-1) - handle_error("mprotect"); + err(EXIT_FAILURE, "mprotect"); \& for (char *p = buffer ; ; ) *(p++) = \[aq]a\[aq]; 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\-\-; } } diff --git a/man/man2/shmop.2 b/man/man2/shmop.2 index 12e7bd763f..660d9615ea 100644 --- a/man/man2/shmop.2 +++ b/man/man2/shmop.2 @@ -312,13 +312,11 @@ The following header file is included by the "reader" and "writer" programs: #ifndef SVSHM_STRING_H #define SVSHM_STRING_H \& +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <sys/sem.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& union semun { /* Used in calls to semctl() */ int val; struct semid_ds *buf; @@ -372,23 +370,23 @@ main(void) \& shmid = shmget(IPC_PRIVATE, MEM_SIZE, IPC_CREAT | 0600); if (shmid == \-1) - errExit("shmget"); + err(EXIT_FAILURE, "shmget"); \& semid = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600); if (semid == \-1) - errExit("semget"); + err(EXIT_FAILURE, "semget"); \& /* Attach shared memory into our address space. */ \& addr = shmat(shmid, NULL, SHM_RDONLY); if (addr == (void *) \-1) - errExit("shmat"); + err(EXIT_FAILURE, "shmat"); \& /* Initialize semaphore 0 in set with value 1. */ \& arg.val = 1; if (semctl(semid, 0, SETVAL, arg) == \-1) - errExit("semctl"); + err(EXIT_FAILURE, "semctl"); \& printf("shmid = %d; semid = %d\[rs]n", shmid, semid); \& @@ -399,7 +397,7 @@ main(void) sop.sem_flg = 0; \& if (semop(semid, &sop, 1) == \-1) - errExit("semop"); + err(EXIT_FAILURE, "semop"); \& /* Print the string from shared memory. */ \& @@ -408,9 +406,9 @@ main(void) /* Remove shared memory and semaphore set. */ \& if (shmctl(shmid, IPC_RMID, NULL) == \-1) - errExit("shmctl"); + err(EXIT_FAILURE, "shmctl"); if (semctl(semid, 0, IPC_RMID, dummy) == \-1) - errExit("semctl"); + err(EXIT_FAILURE, "semctl"); \& exit(EXIT_SUCCESS); } @@ -470,7 +468,7 @@ main(int argc, char *argv[]) \& addr = shmat(shmid, NULL, 0); if (addr == (void *) \-1) - errExit("shmat"); + err(EXIT_FAILURE, "shmat"); \& memcpy(addr, argv[3], size); \& @@ -481,7 +479,7 @@ main(int argc, char *argv[]) sop.sem_flg = 0; \& if (semop(semid, &sop, 1) == \-1) - errExit("semop"); + err(EXIT_FAILURE, "semop"); \& exit(EXIT_SUCCESS); } diff --git a/man/man2/timer_create.2 b/man/man2/timer_create.2 index 287d7bda4a..90ed35ef85 100644 --- a/man/man2/timer_create.2 +++ b/man/man2/timer_create.2 @@ -353,6 +353,7 @@ Caught signal 34 \& .\" SRC BEGIN (timer_create.c) .EX +#include <err.h> #include <signal.h> #include <stdint.h> #include <stdio.h> @@ -363,9 +364,6 @@ Caught signal 34 #define CLOCKID CLOCK_REALTIME #define SIG SIGRTMIN \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& static void print_siginfo(siginfo_t *si) { @@ -379,9 +377,9 @@ print_siginfo(siginfo_t *si) \& or = timer_getoverrun(*tidp); if (or == \-1) - errExit("timer_getoverrun"); - else - printf(" overrun count = %d\[rs]n", or); + err(EXIT_FAILURE, "timer_getoverrun"); +\& + printf(" overrun count = %d\[rs]n", or); } \& static void @@ -421,7 +419,7 @@ main(int argc, char *argv[]) sa.sa_sigaction = handler; sigemptyset(&sa.sa_mask); if (sigaction(SIG, &sa, NULL) == \-1) - errExit("sigaction"); + err(EXIT_FAILURE, "sigaction"); \& /* Block timer signal temporarily. */ \& @@ -429,7 +427,7 @@ main(int argc, char *argv[]) sigemptyset(&mask); sigaddset(&mask, SIG); if (sigprocmask(SIG_SETMASK, &mask, NULL) == \-1) - errExit("sigprocmask"); + err(EXIT_FAILURE, "sigprocmask"); \& /* Create the timer. */ \& @@ -437,7 +435,7 @@ main(int argc, char *argv[]) sev.sigev_signo = SIG; sev.sigev_value.sival_ptr = &timerid; if (timer_create(CLOCKID, &sev, &timerid) == \-1) - errExit("timer_create"); + err(EXIT_FAILURE, "timer_create"); \& printf("timer ID is %#jx\[rs]n", (uintmax_t) timerid); \& @@ -450,7 +448,7 @@ main(int argc, char *argv[]) its.it_interval.tv_nsec = its.it_value.tv_nsec; \& if (timer_settime(timerid, 0, &its, NULL) == \-1) - errExit("timer_settime"); + err(EXIT_FAILURE, "timer_settime"); \& /* Sleep for a while; meanwhile, the timer may expire multiple times. */ @@ -463,7 +461,7 @@ main(int argc, char *argv[]) \& printf("Unblocking signal %d\[rs]n", SIG); if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == \-1) - errExit("sigprocmask"); + err(EXIT_FAILURE, "sigprocmask"); \& exit(EXIT_SUCCESS); } diff --git a/man/man3/duplocale.3 b/man/man3/duplocale.3 index dfaaddd557..7f66c743bb 100644 --- a/man/man3/duplocale.3 +++ b/man/man3/duplocale.3 @@ -119,13 +119,11 @@ ABC .EX #define _XOPEN_SOURCE 700 #include <ctype.h> +#include <err.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -142,11 +140,11 @@ main(int argc, char *argv[]) \& loc = uselocale((locale_t) 0); if (loc == (locale_t) 0) - errExit("uselocale"); + err(EXIT_FAILURE, "uselocale"); \& nloc = duplocale(loc); if (nloc == (locale_t) 0) - errExit("duplocale"); + err(EXIT_FAILURE, "duplocale"); \& for (char *p = argv[1]; *p; p++) putchar(toupper_l(*p, nloc)); diff --git a/man/man3/inet_net_pton.3 b/man/man3/inet_net_pton.3 index 78c43f153a..2e8a33e069 100644 --- a/man/man3/inet_net_pton.3 +++ b/man/man3/inet_net_pton.3 @@ -311,12 +311,10 @@ Raw address: c1a80180 /* Link with "\-lresolv" */ \& #include <arpa/inet.h> +#include <err.h> #include <stdio.h> #include <stdlib.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -343,7 +341,7 @@ main(int argc, char *argv[]) \& bits = inet_net_pton(AF_INET, argv[1], &addr, sizeof(addr)); if (bits == \-1) - errExit("inet_net_ntop"); + err(EXIT_FAILURE, "inet_net_ntop"); \& printf("inet_net_pton() returned: %d\[rs]n", bits); \& @@ -351,7 +349,7 @@ main(int argc, char *argv[]) returned by inet_net_pton(). */ \& if (inet_net_ntop(AF_INET, &addr, bits, buf, sizeof(buf)) == NULL) - errExit("inet_net_ntop"); + err(EXIT_FAILURE, "inet_net_ntop"); \& printf("inet_net_ntop() yielded: %s\[rs]n", buf); \& diff --git a/man/man3/makecontext.3 b/man/man3/makecontext.3 index 1af4828ad5..f213cc3158 100644 --- a/man/man3/makecontext.3 +++ b/man/man3/makecontext.3 @@ -179,22 +179,20 @@ main: exiting \& .\" SRC BEGIN (makecontext.c) .EX +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <ucontext.h> \& static ucontext_t uctx_main, uctx_func1, uctx_func2; \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& static void func1(void) { printf("%s: started\[rs]n", __func__); printf("%s: swapcontext(&uctx_func1, &uctx_func2)\[rs]n", __func__); if (swapcontext(&uctx_func1, &uctx_func2) == \-1) - handle_error("swapcontext"); + err(EXIT_FAILURE, "swapcontext"); printf("%s: returning\[rs]n", __func__); } \& @@ -204,7 +202,7 @@ func2(void) printf("%s: started\[rs]n", __func__); printf("%s: swapcontext(&uctx_func2, &uctx_func1)\[rs]n", __func__); if (swapcontext(&uctx_func2, &uctx_func1) == \-1) - handle_error("swapcontext"); + err(EXIT_FAILURE, "swapcontext"); printf("%s: returning\[rs]n", __func__); } \& @@ -215,14 +213,14 @@ main(int argc, char *argv[]) char func2_stack[16384]; \& if (getcontext(&uctx_func1) == \-1) - handle_error("getcontext"); + err(EXIT_FAILURE, "getcontext"); uctx_func1.uc_stack.ss_sp = func1_stack; uctx_func1.uc_stack.ss_size = sizeof(func1_stack); uctx_func1.uc_link = &uctx_main; makecontext(&uctx_func1, func1, 0); \& if (getcontext(&uctx_func2) == \-1) - handle_error("getcontext"); + err(EXIT_FAILURE, "getcontext"); uctx_func2.uc_stack.ss_sp = func2_stack; uctx_func2.uc_stack.ss_size = sizeof(func2_stack); /* Successor context is f1(), unless argc > 1 */ @@ -231,7 +229,7 @@ main(int argc, char *argv[]) \& printf("%s: swapcontext(&uctx_main, &uctx_func2)\[rs]n", __func__); if (swapcontext(&uctx_main, &uctx_func2) == \-1) - handle_error("swapcontext"); + err(EXIT_FAILURE, "swapcontext"); \& printf("%s: exiting\[rs]n", __func__); exit(EXIT_SUCCESS); diff --git a/man/man3/mq_getattr.3 b/man/man3/mq_getattr.3 index 644c83a3a9..9c327477e9 100644 --- a/man/man3/mq_getattr.3 +++ b/man/man3/mq_getattr.3 @@ -181,6 +181,7 @@ Linux 3.8.0 \& .\" SRC BEGIN (mq_getattr.c) .EX +#include <err.h> #include <fcntl.h> #include <mqueue.h> #include <stdio.h> @@ -188,9 +189,6 @@ Linux 3.8.0 #include <sys/stat.h> #include <unistd.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -204,16 +202,16 @@ main(int argc, char *argv[]) \& mqd = mq_open(argv[1], O_CREAT | O_EXCL, 0600, NULL); if (mqd == (mqd_t) \-1) - errExit("mq_open"); + err(EXIT_FAILURE, "mq_open"); \& if (mq_getattr(mqd, &attr) == \-1) - errExit("mq_getattr"); + err(EXIT_FAILURE, "mq_getattr"); \& printf("Maximum # of messages on queue: %ld\[rs]n", attr.mq_maxmsg); printf("Maximum message size: %ld\[rs]n", attr.mq_msgsize); \& if (mq_unlink(argv[1]) == \-1) - errExit("mq_unlink"); + err(EXIT_FAILURE, "mq_unlink"); \& exit(EXIT_SUCCESS); } diff --git a/man/man3/mq_notify.3 b/man/man3/mq_notify.3 index 87e5cfe341..cb375a0db0 100644 --- a/man/man3/mq_notify.3 +++ b/man/man3/mq_notify.3 @@ -201,6 +201,7 @@ queue and then terminates the process. .SS Program source .\" SRC BEGIN (mq_notify.c) .EX +#include <err.h> #include <mqueue.h> #include <pthread.h> #include <signal.h> @@ -208,9 +209,6 @@ queue and then terminates the process. #include <stdlib.h> #include <unistd.h> \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& static void /* Thread start function */ tfunc(union sigval sv) { @@ -222,14 +220,14 @@ tfunc(union sigval sv) /* Determine max. msg size; allocate buffer to receive msg */ \& if (mq_getattr(mqdes, &attr) == \-1) - handle_error("mq_getattr"); + err(EXIT_FAILURE, "mq_getattr"); buf = malloc(attr.mq_msgsize); if (buf == NULL) - handle_error("malloc"); + err(EXIT_FAILURE, "malloc"); \& nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL); if (nr == \-1) - handle_error("mq_receive"); + err(EXIT_FAILURE, "mq_receive"); \& printf("Read %zd bytes from MQ\[rs]n", nr); free(buf); @@ -249,14 +247,14 @@ main(int argc, char *argv[]) \& mqdes = mq_open(argv[1], O_RDONLY); if (mqdes == (mqd_t) \-1) - handle_error("mq_open"); + err(EXIT_FAILURE, "mq_open"); \& sev.sigev_notify = SIGEV_THREAD; sev.sigev_notify_function = tfunc; sev.sigev_notify_attributes = NULL; sev.sigev_value.sival_ptr = &mqdes; /* Arg. to thread func. */ if (mq_notify(mqdes, &sev) == \-1) - handle_error("mq_notify"); + err(EXIT_FAILURE, "mq_notify"); \& pause(); /* Process will be terminated by thread function */ } diff --git a/man/man3/newlocale.3 b/man/man3/newlocale.3 index de23c96a58..fbf8a1d4d9 100644 --- a/man/man3/newlocale.3 +++ b/man/man3/newlocale.3 @@ -275,14 +275,12 @@ Te Paraire, te 07 o PoutÅ«\-te\-rangi, 2014 00:38:44 CET .\" SRC BEGIN (newlocale.c) .EX #define _XOPEN_SOURCE 700 +#include <err.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> #include <time.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -302,7 +300,7 @@ main(int argc, char *argv[]) \& loc = newlocale(LC_NUMERIC_MASK, argv[1], (locale_t) 0); if (loc == (locale_t) 0) - errExit("newlocale"); + err(EXIT_FAILURE, "newlocale"); \& /* If a second command\-line argument was specified, modify the locale object to take the LC_TIME settings from the locale @@ -313,7 +311,7 @@ main(int argc, char *argv[]) if (argc > 2) { nloc = newlocale(LC_TIME_MASK, argv[2], loc); if (nloc == (locale_t) 0) - errExit("newlocale"); + err(EXIT_FAILURE, "newlocale"); loc = nloc; } \& @@ -330,11 +328,11 @@ main(int argc, char *argv[]) t = time(NULL); tm = localtime(&t); if (tm == NULL) - errExit("time"); + err(EXIT_FAILURE, "time"); \& s = strftime(buf, sizeof(buf), "%c", tm); if (s == 0) - errExit("strftime"); + err(EXIT_FAILURE, "strftime"); \& printf("%s\[rs]n", buf); \& diff --git a/man/man3/posix_spawn.3 b/man/man3/posix_spawn.3 index c4c5b3c96a..852cb58616 100644 --- a/man/man3/posix_spawn.3 +++ b/man/man3/posix_spawn.3 @@ -655,6 +655,7 @@ Child status: exited, status=127 \& .\" SRC BEGIN (posix_spawn.c) .EX +#include <err.h> #include <errno.h> #include <spawn.h> #include <stdint.h> @@ -664,13 +665,6 @@ Child status: exited, status=127 #include <unistd.h> #include <wait.h> \& -#define errExit(msg) do { perror(msg); \[rs] - exit(EXIT_FAILURE); } while (0) -\& -#define errExitEN(en, msg) \[rs] - do { errno = en; perror(msg); \[rs] - exit(EXIT_FAILURE); } while (0) -\& char **environ; \& int @@ -699,12 +693,12 @@ main(int argc, char *argv[]) \& s = posix_spawn_file_actions_init(&file_actions); if (s != 0) - errExitEN(s, "posix_spawn_file_actions_init"); + errc(EXIT_FAILURE, s, "posix_spawn_file_actions_init"); \& s = posix_spawn_file_actions_addclose(&file_actions, STDOUT_FILENO); if (s != 0) - errExitEN(s, "posix_spawn_file_actions_addclose"); + errc(EXIT_FAILURE, s, "posix_spawn_file_actions_addclose"); \& file_actionsp = &file_actions; break; @@ -716,15 +710,15 @@ main(int argc, char *argv[]) \& s = posix_spawnattr_init(&attr); if (s != 0) - errExitEN(s, "posix_spawnattr_init"); + errc(EXIT_FAILURE, s, "posix_spawnattr_init"); s = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK); if (s != 0) - errExitEN(s, "posix_spawnattr_setflags"); + errc(EXIT_FAILURE, s, "posix_spawnattr_setflags"); \& sigfillset(&mask); s = posix_spawnattr_setsigmask(&attr, &mask); if (s != 0) - errExitEN(s, "posix_spawnattr_setsigmask"); + errc(EXIT_FAILURE, s, "posix_spawnattr_setsigmask"); \& attrp = &attr; break; @@ -744,20 +738,20 @@ main(int argc, char *argv[]) s = posix_spawnp(&child_pid, argv[optind], file_actionsp, attrp, &argv[optind], environ); if (s != 0) - errExitEN(s, "posix_spawn"); + errc(EXIT_FAILURE, s, "posix_spawn"); \& /* Destroy any objects that we created earlier. */ \& if (attrp != NULL) { s = posix_spawnattr_destroy(attrp); if (s != 0) - errExitEN(s, "posix_spawnattr_destroy"); + errc(EXIT_FAILURE, s, "posix_spawnattr_destroy"); } \& if (file_actionsp != NULL) { s = posix_spawn_file_actions_destroy(file_actionsp); if (s != 0) - errExitEN(s, "posix_spawn_file_actions_destroy"); + errc(EXIT_FAILURE, s, "posix_spawn_file_actions_destroy"); } \& printf("PID of child: %jd\[rs]n", (intmax_t) child_pid); @@ -767,7 +761,7 @@ main(int argc, char *argv[]) do { s = waitpid(child_pid, &status, WUNTRACED | WCONTINUED); if (s == \-1) - errExit("waitpid"); + err(EXIT_FAILURE, "waitpid"); \& printf("Child status: "); if (WIFEXITED(status)) { diff --git a/man/man3/pthread_cancel.3 b/man/man3/pthread_cancel.3 index d14a305954..c89c8ca483 100644 --- a/man/man3/pthread_cancel.3 +++ b/man/man3/pthread_cancel.3 @@ -148,15 +148,13 @@ main(): thread was canceled \& .\" SRC BEGIN (pthread_cancel.c) .EX +#include <err.h> #include <errno.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> \& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& static void * thread_func(void *ignored_argument) { @@ -167,7 +165,7 @@ thread_func(void *ignored_argument) \& s = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); if (s != 0) - handle_error_en(s, "pthread_setcancelstate"); + errc(EXIT_FAILURE, s, "pthread_setcancelstate"); \& printf("%s(): started; cancelation disabled\[rs]n", __func__); sleep(5); @@ -175,7 +173,7 @@ thread_func(void *ignored_argument) \& s = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if (s != 0) - handle_error_en(s, "pthread_setcancelstate"); + errc(EXIT_FAILURE, s, "pthread_setcancelstate"); \& /* sleep() is a cancelation point. */ \& @@ -198,20 +196,20 @@ main(void) \& s = pthread_create(&thr, NULL, &thread_func, NULL); if (s != 0) - handle_error_en(s, "pthread_create"); + errc(EXIT_FAILURE, s, "pthread_create"); \& sleep(2); /* Give thread a chance to get started */ \& printf("%s(): sending cancelation request\[rs]n", __func__); s = pthread_cancel(thr); if (s != 0) - handle_error_en(s, "pthread_cancel"); + errc(EXIT_FAILURE, s, "pthread_cancel"); \& /* Join with thread to see what its exit status was. */ \& s = pthread_join(thr, &res); if (s != 0) - handle_error_en(s, "pthread_join"); + errc(EXIT_FAILURE, s, "pthread_join"); \& if (res == PTHREAD_CANCELED) printf("%s(): thread was canceled\[rs]n", __func__); diff --git a/man/man3/pthread_cleanup_push.3 b/man/man3/pthread_cleanup_push.3 index 8553ec7bc4..0f5137986b 100644 --- a/man/man3/pthread_cleanup_push.3 +++ b/man/man3/pthread_cleanup_push.3 @@ -236,6 +236,7 @@ was nonzero. \& .\" SRC BEGIN (pthread_cleanup_push.c) .EX +#include <err.h> #include <errno.h> #include <pthread.h> #include <stdio.h> @@ -243,9 +244,6 @@ was nonzero. #include <sys/types.h> #include <unistd.h> \& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& static int done = 0; static int cleanup_pop_arg = 0; static int cnt = 0; @@ -290,7 +288,7 @@ main(int argc, char *argv[]) \& s = pthread_create(&thr, NULL, thread_start, NULL); if (s != 0) - handle_error_en(s, "pthread_create"); + errc(EXIT_FAILURE, s, "pthread_create"); \& sleep(2); /* Allow new thread to run a while */ \& @@ -303,12 +301,12 @@ main(int argc, char *argv[]) printf("Canceling thread\[rs]n"); s = pthread_cancel(thr); if (s != 0) - handle_error_en(s, "pthread_cancel"); + errc(EXIT_FAILURE, s, "pthread_cancel"); } \& s = pthread_join(thr, &res); if (s != 0) - handle_error_en(s, "pthread_join"); + errc(EXIT_FAILURE, s, "pthread_join"); \& if (res == PTHREAD_CANCELED) printf("Thread was canceled; cnt = %d\[rs]n", cnt); diff --git a/man/man3/pthread_create.3 b/man/man3/pthread_create.3 index 1aee9c06fa..8c9f58edd1 100644 --- a/man/man3/pthread_create.3 +++ b/man/man3/pthread_create.3 @@ -251,6 +251,7 @@ Joined with thread 3; returned value was SERVUS .\" SRC BEGIN (pthread_create.c) .EX #include <ctype.h> +#include <err.h> #include <errno.h> #include <pthread.h> #include <stdio.h> @@ -259,12 +260,6 @@ Joined with thread 3; returned value was SERVUS #include <sys/types.h> #include <unistd.h> \& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& struct thread_info { /* Used as argument to thread_start() */ pthread_t thread_id; /* ID returned by pthread_create() */ int thread_num; /* Application\-defined thread # */ @@ -285,7 +280,7 @@ thread_start(void *arg) \& uargv = strdup(tinfo\->argv_string); if (uargv == NULL) - handle_error("strdup"); + err(EXIT_FAILURE, "strdup"); \& for (char *p = uargv; *p != \[aq]\[rs]0\[aq]; p++) *p = toupper(*p); @@ -325,19 +320,19 @@ main(int argc, char *argv[]) \& s = pthread_attr_init(&attr); if (s != 0) - handle_error_en(s, "pthread_attr_init"); + errc(EXIT_FAILURE, s, "pthread_attr_init"); \& if (stack_size > 0) { s = pthread_attr_setstacksize(&attr, stack_size); if (s != 0) - handle_error_en(s, "pthread_attr_setstacksize"); + errc(EXIT_FAILURE, s, "pthread_attr_setstacksize"); } \& /* Allocate memory for pthread_create() arguments. */ \& tinfo = calloc(num_threads, sizeof(*tinfo)); if (tinfo == NULL) - handle_error("calloc"); + err(EXIT_FAILURE, "calloc"); \& /* Create one thread for each command\-line argument. */ \& @@ -351,7 +346,7 @@ main(int argc, char *argv[]) s = pthread_create(&tinfo[tnum].thread_id, &attr, &thread_start, &tinfo[tnum]); if (s != 0) - handle_error_en(s, "pthread_create"); + errc(EXIT_FAILURE, s, "pthread_create"); } \& /* Destroy the thread attributes object, since it is no @@ -359,14 +354,14 @@ main(int argc, char *argv[]) \& s = pthread_attr_destroy(&attr); if (s != 0) - handle_error_en(s, "pthread_attr_destroy"); + errc(EXIT_FAILURE, s, "pthread_attr_destroy"); \& /* Now join with each thread, and display its returned value. */ \& for (size_t tnum = 0; tnum < num_threads; tnum++) { s = pthread_join(tinfo[tnum].thread_id, &res); if (s != 0) - handle_error_en(s, "pthread_join"); + errc(EXIT_FAILURE, s, "pthread_join"); \& printf("Joined with thread %d; returned value was %s\[rs]n", tinfo[tnum].thread_num, (char *) res); diff --git a/man/man3/pthread_getcpuclockid.3 b/man/man3/pthread_getcpuclockid.3 index 9de7dfb413..5a4785ef46 100644 --- a/man/man3/pthread_getcpuclockid.3 +++ b/man/man3/pthread_getcpuclockid.3 @@ -98,6 +98,7 @@ Subthread CPU time: 0.992 .EX /* Link with "\-lrt" */ \& +#include <err.h> #include <errno.h> #include <pthread.h> #include <stdint.h> @@ -108,12 +109,6 @@ Subthread CPU time: 0.992 #include <time.h> #include <unistd.h> \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& static void * thread_start(void *arg) { @@ -129,7 +124,7 @@ pclock(char *msg, clockid_t cid) \& printf("%s", msg); if (clock_gettime(cid, &ts) == \-1) - handle_error("clock_gettime"); + err(EXIT_FAILURE, "clock_gettime"); printf("%4jd.%03ld\[rs]n", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); } \& @@ -142,7 +137,7 @@ main(void) \& s = pthread_create(&thread, NULL, thread_start, NULL); if (s != 0) - handle_error_en(s, "pthread_create"); + errc(EXIT_FAILURE, s, "pthread_create"); \& printf("Main thread sleeping\[rs]n"); sleep(1); @@ -155,7 +150,7 @@ main(void) \& s = pthread_getcpuclockid(pthread_self(), &cid); if (s != 0) - handle_error_en(s, "pthread_getcpuclockid"); + errc(EXIT_FAILURE, s, "pthread_getcpuclockid"); pclock("Main thread CPU time: ", cid); \& /* The preceding 4 lines of code could have been replaced by: @@ -163,7 +158,7 @@ main(void) \& s = pthread_getcpuclockid(thread, &cid); if (s != 0) - handle_error_en(s, "pthread_getcpuclockid"); + errc(EXIT_FAILURE, s, "pthread_getcpuclockid"); pclock("Subthread CPU time: 1 ", cid); \& exit(EXIT_SUCCESS); /* Terminates both threads */ diff --git a/man/man3/pthread_mutexattr_setrobust.3 b/man/man3/pthread_mutexattr_setrobust.3 index 6110b54c75..3dfbb357b1 100644 --- a/man/man3/pthread_mutexattr_setrobust.3 +++ b/man/man3/pthread_mutexattr_setrobust.3 @@ -189,15 +189,13 @@ The following shell session shows what we see when running this program: .SS Program source .\" SRC BEGIN (pthread_mutexattr_setrobust.c) .EX +#include <err.h> #include <errno.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> \& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& static pthread_mutex_t mtx; \& static void * @@ -235,11 +233,11 @@ main(void) printf("[main] Now make the mutex consistent\[rs]n"); s = pthread_mutex_consistent(&mtx); if (s != 0) - handle_error_en(s, "pthread_mutex_consistent"); + errc(EXIT_FAILURE, s, "pthread_mutex_consistent"); printf("[main] Mutex is now consistent; unlocking\[rs]n"); s = pthread_mutex_unlock(&mtx); if (s != 0) - handle_error_en(s, "pthread_mutex_unlock"); + errc(EXIT_FAILURE, s, "pthread_mutex_unlock"); \& exit(EXIT_SUCCESS); } else if (s == 0) { @@ -247,7 +245,7 @@ main(void) exit(EXIT_FAILURE); } else { printf("[main] pthread_mutex_lock() unexpectedly failed\[rs]n"); - handle_error_en(s, "pthread_mutex_lock"); + errc(EXIT_FAILURE, s, "pthread_mutex_lock"); } } .EE diff --git a/man/man3/pthread_setschedparam.3 b/man/man3/pthread_setschedparam.3 index 37c8cb081c..c16560e7ba 100644 --- a/man/man3/pthread_setschedparam.3 +++ b/man/man3/pthread_setschedparam.3 @@ -224,15 +224,13 @@ is the default for the inherit scheduler attribute. .EX /* pthreads_sched_test.c */ \& +#include <err.h> #include <errno.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> \& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& [[noreturn]] static void usage(char *prog_name, char *msg) @@ -287,7 +285,7 @@ display_thread_sched_attr(char *msg) \& s = pthread_getschedparam(pthread_self(), &policy, ¶m); if (s != 0) - handle_error_en(s, "pthread_getschedparam"); + errc(EXIT_FAILURE, s, "pthread_getschedparam"); \& printf("%s\[rs]n", msg); display_sched_attr(policy, ¶m); @@ -344,7 +342,7 @@ main(int argc, char *argv[]) \& s = pthread_setschedparam(pthread_self(), policy, ¶m); if (s != 0) - handle_error_en(s, "pthread_setschedparam"); + errc(EXIT_FAILURE, s, "pthread_setschedparam"); } \& display_thread_sched_attr("Scheduler settings of main thread"); @@ -357,7 +355,7 @@ main(int argc, char *argv[]) if (!use_null_attrib) { s = pthread_attr_init(&attr); if (s != 0) - handle_error_en(s, "pthread_attr_init"); + errc(EXIT_FAILURE, s, "pthread_attr_init"); attrp = &attr; } \& @@ -371,7 +369,7 @@ main(int argc, char *argv[]) \& s = pthread_attr_setinheritsched(&attr, inheritsched); if (s != 0) - handle_error_en(s, "pthread_attr_setinheritsched"); + errc(EXIT_FAILURE, s, "pthread_attr_setinheritsched"); } \& if (attr_sched_str != NULL) { @@ -381,10 +379,10 @@ main(int argc, char *argv[]) \& s = pthread_attr_setschedpolicy(&attr, policy); if (s != 0) - handle_error_en(s, "pthread_attr_setschedpolicy"); + errc(EXIT_FAILURE, s, "pthread_attr_setschedpolicy"); s = pthread_attr_setschedparam(&attr, ¶m); if (s != 0) - handle_error_en(s, "pthread_attr_setschedparam"); + errc(EXIT_FAILURE, s, "pthread_attr_setschedparam"); } \& /* If we initialized a thread attributes object, display @@ -393,10 +391,10 @@ main(int argc, char *argv[]) if (attrp != NULL) { s = pthread_attr_getschedparam(&attr, ¶m); if (s != 0) - handle_error_en(s, "pthread_attr_getschedparam"); + errc(EXIT_FAILURE, s, "pthread_attr_getschedparam"); s = pthread_attr_getschedpolicy(&attr, &policy); if (s != 0) - handle_error_en(s, "pthread_attr_getschedpolicy"); + errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy"); \& printf("Scheduler settings in \[aq]attr\[aq]\[rs]n"); display_sched_attr(policy, ¶m); @@ -413,19 +411,19 @@ main(int argc, char *argv[]) \& s = pthread_create(&thread, attrp, &thread_start, NULL); if (s != 0) - handle_error_en(s, "pthread_create"); + errc(EXIT_FAILURE, s, "pthread_create"); \& /* Destroy unneeded thread attributes object. */ \& if (!use_null_attrib) { s = pthread_attr_destroy(&attr); if (s != 0) - handle_error_en(s, "pthread_attr_destroy"); + errc(EXIT_FAILURE, s, "pthread_attr_destroy"); } \& s = pthread_join(thread, NULL); if (s != 0) - handle_error_en(s, "pthread_join"); + errc(EXIT_FAILURE, s, "pthread_join"); \& exit(EXIT_SUCCESS); } diff --git a/man/man3/pthread_sigmask.3 b/man/man3/pthread_sigmask.3 index 2175e3a97d..bf9ad38008 100644 --- a/man/man3/pthread_sigmask.3 +++ b/man/man3/pthread_sigmask.3 @@ -95,6 +95,7 @@ Signal handling thread got signal 10 \& .\" SRC BEGIN (pthread_sigmask.c) .EX +#include <err.h> #include <errno.h> #include <pthread.h> #include <signal.h> @@ -104,9 +105,6 @@ Signal handling thread got signal 10 \& /* Simple error handling functions */ \& -#define handle_error_en(en, msg) \[rs] - do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -\& static void * sig_thread(void *arg) { @@ -116,7 +114,7 @@ sig_thread(void *arg) for (;;) { s = sigwait(set, &sig); if (s != 0) - handle_error_en(s, "sigwait"); + errc(EXIT_FAILURE, s, "sigwait"); printf("Signal handling thread got signal %d\[rs]n", sig); } } @@ -136,11 +134,11 @@ main(void) sigaddset(&set, SIGUSR1); s = pthread_sigmask(SIG_BLOCK, &set, NULL); if (s != 0) - handle_error_en(s, "pthread_sigmask"); + errc(EXIT_FAILURE, s, "pthread_sigmask"); \& s = pthread_create(&thread, NULL, &sig_thread, &set); if (s != 0) - handle_error_en(s, "pthread_create"); + errc(EXIT_FAILURE, s, "pthread_create"); \& /* Main thread carries on to create other threads and/or do other work. */ diff --git a/man/man3/sem_wait.3 b/man/man3/sem_wait.3 index 2aa68eb345..8b75ea59a6 100644 --- a/man/man3/sem_wait.3 +++ b/man/man3/sem_wait.3 @@ -165,6 +165,7 @@ sem_timedwait() timed out \& .\" SRC BEGIN (sem_wait.c) .EX +#include <err.h> #include <errno.h> #include <semaphore.h> #include <signal.h> @@ -177,9 +178,6 @@ sem_timedwait() timed out \& sem_t sem; \& -#define handle_error(msg) \[rs] - do { perror(msg); exit(EXIT_FAILURE); } while (0) -\& static void handler(int sig) { @@ -204,7 +202,7 @@ main(int argc, char *argv[]) } \& if (sem_init(&sem, 0, 0) == \-1) - handle_error("sem_init"); + err(EXIT_FAILURE, "sem_init"); \& /* Establish SIGALRM handler; set alarm timer using argv[1]. */ \& @@ -212,7 +210,7 @@ main(int argc, char *argv[]) sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGALRM, &sa, NULL) == \-1) - handle_error("sigaction"); + err(EXIT_FAILURE, "sigaction"); \& alarm(atoi(argv[1])); \& @@ -220,7 +218,7 @@ main(int argc, char *argv[]) number of seconds given argv[2]. */ \& if (clock_gettime(CLOCK_REALTIME, &ts) == \-1) - handle_error("clock_gettime"); + err(EXIT_FAILURE, "clock_gettime"); \& ts.tv_sec += atoi(argv[2]); \& diff --git a/man/man3/shm_open.3 b/man/man3/shm_open.3 index db703e1e4e..0ba63c870e 100644 --- a/man/man3/shm_open.3 +++ b/man/man3/shm_open.3 @@ -293,14 +293,12 @@ on the memory object that is shared between the two programs. #ifndef PSHM_UCASE_H #define PSHM_UCASE_H \& +#include <err.h> #include <semaphore.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& #define BUF_SIZE 1024 /* Maximum size for exchanged string */ \& /* Define a structure that will be imposed on the shared @@ -367,30 +365,30 @@ main(int argc, char *argv[]) \& fd = shm_open(shmpath, O_CREAT | O_EXCL | O_RDWR, 0600); if (fd == \-1) - errExit("shm_open"); + err(EXIT_FAILURE, "shm_open"); \& if (ftruncate(fd, sizeof(struct shmbuf)) == \-1) - errExit("ftruncate"); + err(EXIT_FAILURE, "ftruncate"); \& /* Map the object into the caller\[aq]s address space. */ \& shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shmp == MAP_FAILED) - errExit("mmap"); + err(EXIT_FAILURE, "mmap"); \& /* Initialize semaphores as process\-shared, with value 0. */ \& if (sem_init(&shmp\->sem1, 1, 0) == \-1) - errExit("sem_init\-sem1"); + err(EXIT_FAILURE, "sem_init\-sem1"); if (sem_init(&shmp\->sem2, 1, 0) == \-1) - errExit("sem_init\-sem2"); + err(EXIT_FAILURE, "sem_init\-sem2"); \& /* Wait for \[aq]sem1\[aq] to be posted by peer before touching shared memory. */ \& if (sem_wait(&shmp\->sem1) == \-1) - errExit("sem_wait"); + err(EXIT_FAILURE, "sem_wait"); \& /* Convert data in shared memory into upper case. */ \& @@ -401,7 +399,7 @@ main(int argc, char *argv[]) access the modified data in shared memory. */ \& if (sem_post(&shmp\->sem2) == \-1) - errExit("sem_post"); + err(EXIT_FAILURE, "sem_post"); \& /* Unlink the shared memory object. Even if the peer process is still using the object, this is okay. The object will @@ -474,12 +472,12 @@ main(int argc, char *argv[]) \& fd = shm_open(shmpath, O_RDWR, 0); if (fd == \-1) - errExit("shm_open"); + err(EXIT_FAILURE, "shm_open"); \& shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shmp == MAP_FAILED) - errExit("mmap"); + err(EXIT_FAILURE, "mmap"); \& /* Copy data into the shared memory object. */ \& @@ -489,20 +487,20 @@ main(int argc, char *argv[]) /* Tell peer that it can now access shared memory. */ \& if (sem_post(&shmp\->sem1) == \-1) - errExit("sem_post"); + err(EXIT_FAILURE, "sem_post"); \& /* Wait until peer says that it has finished accessing the shared memory. */ \& if (sem_wait(&shmp\->sem2) == \-1) - errExit("sem_wait"); + err(EXIT_FAILURE, "sem_wait"); \& /* Write modified data in shared memory to standard output. */ \& if (write(STDOUT_FILENO, &shmp\->buf, len) == \-1) - errExit("write"); + err(EXIT_FAILURE, "write"); if (write(STDOUT_FILENO, "\[rs]n", 1) == \-1) - errExit("write"); + err(EXIT_FAILURE, "write"); \& exit(EXIT_SUCCESS); } diff --git a/man/man4/loop.4 b/man/man4/loop.4 index 8997a9aca0..a497ab0399 100644 --- a/man/man4/loop.4 +++ b/man/man4/loop.4 @@ -308,6 +308,7 @@ loopname = /dev/loop5 .SS Program source \& .EX +#include <err.h> #include <fcntl.h> #include <linux/loop.h> #include <sys/ioctl.h> @@ -315,9 +316,6 @@ loopname = /dev/loop5 #include <stdlib.h> #include <unistd.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -332,25 +330,25 @@ main(int argc, char *argv[]) \& loopctlfd = open("/dev/loop\-control", O_RDWR); if (loopctlfd == \-1) - errExit("open: /dev/loop\-control"); + err(EXIT_FAILURE, "open: /dev/loop\-control"); \& devnr = ioctl(loopctlfd, LOOP_CTL_GET_FREE); if (devnr == \-1) - errExit("ioctl\-LOOP_CTL_GET_FREE"); + err(EXIT_FAILURE, "ioctl\-LOOP_CTL_GET_FREE"); \& sprintf(loopname, "/dev/loop%ld", devnr); printf("loopname = %s\[rs]n", loopname); \& loopfd = open(loopname, O_RDWR); if (loopfd == \-1) - errExit("open: loopname"); + err(EXIT_FAILURE, "open: loopname"); \& backingfile = open(argv[1], O_RDWR); if (backingfile == \-1) - errExit("open: backing\-file"); + err(EXIT_FAILURE, "open: backing\-file"); \& if (ioctl(loopfd, LOOP_SET_FD, backingfile) == \-1) - errExit("ioctl\-LOOP_SET_FD"); + err(EXIT_FAILURE, "ioctl\-LOOP_SET_FD"); \& exit(EXIT_SUCCESS); } 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; |
