aboutsummaryrefslogtreecommitdiffstats
path: root/man/man2/shmop.2
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/man2/shmop.2
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/man2/shmop.2')
-rw-r--r--man/man2/shmop.222
1 files changed, 10 insertions, 12 deletions
diff --git a/man/man2/shmop.2 b/man/man2/shmop.2
index 12e7bd763f..660d9615ea 100644
--- a/man/man2/shmop.2
+++ b/man/man2/shmop.2
@@ -312,13 +312,11 @@ The following header file is included by the "reader" and "writer" programs:
#ifndef SVSHM_STRING_H
#define SVSHM_STRING_H
\&
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sem.h>
\&
-#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs]
- } while (0)
-\&
union semun { /* Used in calls to semctl() */
int val;
struct semid_ds *buf;
@@ -372,23 +370,23 @@ main(void)
\&
shmid = shmget(IPC_PRIVATE, MEM_SIZE, IPC_CREAT | 0600);
if (shmid == \-1)
- errExit("shmget");
+ err(EXIT_FAILURE, "shmget");
\&
semid = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
if (semid == \-1)
- errExit("semget");
+ err(EXIT_FAILURE, "semget");
\&
/* Attach shared memory into our address space. */
\&
addr = shmat(shmid, NULL, SHM_RDONLY);
if (addr == (void *) \-1)
- errExit("shmat");
+ err(EXIT_FAILURE, "shmat");
\&
/* Initialize semaphore 0 in set with value 1. */
\&
arg.val = 1;
if (semctl(semid, 0, SETVAL, arg) == \-1)
- errExit("semctl");
+ err(EXIT_FAILURE, "semctl");
\&
printf("shmid = %d; semid = %d\[rs]n", shmid, semid);
\&
@@ -399,7 +397,7 @@ main(void)
sop.sem_flg = 0;
\&
if (semop(semid, &sop, 1) == \-1)
- errExit("semop");
+ err(EXIT_FAILURE, "semop");
\&
/* Print the string from shared memory. */
\&
@@ -408,9 +406,9 @@ main(void)
/* Remove shared memory and semaphore set. */
\&
if (shmctl(shmid, IPC_RMID, NULL) == \-1)
- errExit("shmctl");
+ err(EXIT_FAILURE, "shmctl");
if (semctl(semid, 0, IPC_RMID, dummy) == \-1)
- errExit("semctl");
+ err(EXIT_FAILURE, "semctl");
\&
exit(EXIT_SUCCESS);
}
@@ -470,7 +468,7 @@ main(int argc, char *argv[])
\&
addr = shmat(shmid, NULL, 0);
if (addr == (void *) \-1)
- errExit("shmat");
+ err(EXIT_FAILURE, "shmat");
\&
memcpy(addr, argv[3], size);
\&
@@ -481,7 +479,7 @@ main(int argc, char *argv[])
sop.sem_flg = 0;
\&
if (semop(semid, &sop, 1) == \-1)
- errExit("semop");
+ err(EXIT_FAILURE, "semop");
\&
exit(EXIT_SUCCESS);
}