aboutsummaryrefslogtreecommitdiffstats
path: root/man/man3
diff options
context:
space:
mode:
Diffstat (limited to 'man/man3')
-rw-r--r--man/man3/duplocale.38
-rw-r--r--man/man3/inet_net_pton.38
-rw-r--r--man/man3/makecontext.314
-rw-r--r--man/man3/mq_getattr.310
-rw-r--r--man/man3/mq_notify.314
-rw-r--r--man/man3/newlocale.312
-rw-r--r--man/man3/posix_spawn.326
-rw-r--r--man/man3/pthread_cancel.314
-rw-r--r--man/man3/pthread_cleanup_push.310
-rw-r--r--man/man3/pthread_create.321
-rw-r--r--man/man3/pthread_getcpuclockid.315
-rw-r--r--man/man3/pthread_mutexattr_setrobust.310
-rw-r--r--man/man3/pthread_setschedparam.326
-rw-r--r--man/man3/pthread_sigmask.310
-rw-r--r--man/man3/sem_wait.310
-rw-r--r--man/man3/shm_open.330
16 files changed, 98 insertions, 140 deletions
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, &param);
if (s != 0)
- handle_error_en(s, "pthread_getschedparam");
+ errc(EXIT_FAILURE, s, "pthread_getschedparam");
\&
printf("%s\[rs]n", msg);
display_sched_attr(policy, &param);
@@ -344,7 +342,7 @@ main(int argc, char *argv[])
\&
s = pthread_setschedparam(pthread_self(), policy, &param);
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, &param);
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, &param);
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, &param);
@@ -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);
}