diff options
Diffstat (limited to 'man/man3/shm_open.3')
| -rw-r--r-- | man/man3/shm_open.3 | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/man/man3/shm_open.3 b/man/man3/shm_open.3 index db703e1e4e..0ba63c870e 100644 --- a/man/man3/shm_open.3 +++ b/man/man3/shm_open.3 @@ -293,14 +293,12 @@ on the memory object that is shared between the two programs. #ifndef PSHM_UCASE_H #define PSHM_UCASE_H \& +#include <err.h> #include <semaphore.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& #define BUF_SIZE 1024 /* Maximum size for exchanged string */ \& /* Define a structure that will be imposed on the shared @@ -367,30 +365,30 @@ main(int argc, char *argv[]) \& fd = shm_open(shmpath, O_CREAT | O_EXCL | O_RDWR, 0600); if (fd == \-1) - errExit("shm_open"); + err(EXIT_FAILURE, "shm_open"); \& if (ftruncate(fd, sizeof(struct shmbuf)) == \-1) - errExit("ftruncate"); + err(EXIT_FAILURE, "ftruncate"); \& /* Map the object into the caller\[aq]s address space. */ \& shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shmp == MAP_FAILED) - errExit("mmap"); + err(EXIT_FAILURE, "mmap"); \& /* Initialize semaphores as process\-shared, with value 0. */ \& if (sem_init(&shmp\->sem1, 1, 0) == \-1) - errExit("sem_init\-sem1"); + err(EXIT_FAILURE, "sem_init\-sem1"); if (sem_init(&shmp\->sem2, 1, 0) == \-1) - errExit("sem_init\-sem2"); + err(EXIT_FAILURE, "sem_init\-sem2"); \& /* Wait for \[aq]sem1\[aq] to be posted by peer before touching shared memory. */ \& if (sem_wait(&shmp\->sem1) == \-1) - errExit("sem_wait"); + err(EXIT_FAILURE, "sem_wait"); \& /* Convert data in shared memory into upper case. */ \& @@ -401,7 +399,7 @@ main(int argc, char *argv[]) access the modified data in shared memory. */ \& if (sem_post(&shmp\->sem2) == \-1) - errExit("sem_post"); + err(EXIT_FAILURE, "sem_post"); \& /* Unlink the shared memory object. Even if the peer process is still using the object, this is okay. The object will @@ -474,12 +472,12 @@ main(int argc, char *argv[]) \& fd = shm_open(shmpath, O_RDWR, 0); if (fd == \-1) - errExit("shm_open"); + err(EXIT_FAILURE, "shm_open"); \& shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shmp == MAP_FAILED) - errExit("mmap"); + err(EXIT_FAILURE, "mmap"); \& /* Copy data into the shared memory object. */ \& @@ -489,20 +487,20 @@ main(int argc, char *argv[]) /* Tell peer that it can now access shared memory. */ \& if (sem_post(&shmp\->sem1) == \-1) - errExit("sem_post"); + err(EXIT_FAILURE, "sem_post"); \& /* Wait until peer says that it has finished accessing the shared memory. */ \& if (sem_wait(&shmp\->sem2) == \-1) - errExit("sem_wait"); + err(EXIT_FAILURE, "sem_wait"); \& /* Write modified data in shared memory to standard output. */ \& if (write(STDOUT_FILENO, &shmp\->buf, len) == \-1) - errExit("write"); + err(EXIT_FAILURE, "write"); if (write(STDOUT_FILENO, "\[rs]n", 1) == \-1) - errExit("write"); + err(EXIT_FAILURE, "write"); \& exit(EXIT_SUCCESS); } |
