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