diff options
| author | Alejandro Colomar <alx@kernel.org> | 2025-08-19 17:48:50 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2025-08-20 18:14:03 +0200 |
| commit | 0e7a39804a3c017a209117fc2243c6cbb543dede (patch) | |
| tree | 91e0b287d8b826d668c3d8118347f07cc8b8964a /man/man3/makecontext.3 | |
| parent | e2d3f14fe40ad90a1fedf0fcd27e6cc896c49a7a (diff) | |
| download | man-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/makecontext.3')
| -rw-r--r-- | man/man3/makecontext.3 | 14 |
1 files changed, 6 insertions, 8 deletions
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); |
