aboutsummaryrefslogtreecommitdiffstats
path: root/man/man3/pthread_cancel.3
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/man3/pthread_cancel.3
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/man3/pthread_cancel.3')
-rw-r--r--man/man3/pthread_cancel.314
1 files changed, 6 insertions, 8 deletions
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__);