aboutsummaryrefslogtreecommitdiffstats
path: root/man/man3/pthread_getcpuclockid.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_getcpuclockid.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_getcpuclockid.3')
-rw-r--r--man/man3/pthread_getcpuclockid.315
1 files changed, 5 insertions, 10 deletions
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 */