aboutsummaryrefslogtreecommitdiffstats
path: root/man/man2/mmap.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/mmap.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/mmap.2')
-rw-r--r--man/man2/mmap.212
1 files changed, 5 insertions, 7 deletions
diff --git a/man/man2/mmap.2 b/man/man2/mmap.2
index 28ad07198a..23ffcd758c 100644
--- a/man/man2/mmap.2
+++ b/man/man2/mmap.2
@@ -948,6 +948,7 @@ to output the desired bytes.
.SS Program source
.\" SRC BEGIN (mmap.c)
.EX
+#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -956,9 +957,6 @@ to output the desired bytes.
#include <sys/types.h>
#include <unistd.h>
\&
-#define handle_error(msg) \[rs]
- do { perror(msg); exit(EXIT_FAILURE); } while (0)
-\&
int
main(int argc, char *argv[])
{
@@ -976,10 +974,10 @@ main(int argc, char *argv[])
\&
fd = open(argv[1], O_RDONLY);
if (fd == \-1)
- handle_error("open");
+ err(EXIT_FAILURE, "open");
\&
if (fstat(fd, &sb) == \-1) /* To obtain file size */
- handle_error("fstat");
+ err(EXIT_FAILURE, "fstat");
\&
offset = atoi(argv[2]);
pa_offset = offset & \[ti](sysconf(_SC_PAGE_SIZE) \- 1);
@@ -1003,12 +1001,12 @@ main(int argc, char *argv[])
addr = mmap(NULL, length + offset \- pa_offset, PROT_READ,
MAP_PRIVATE, fd, pa_offset);
if (addr == MAP_FAILED)
- handle_error("mmap");
+ err(EXIT_FAILURE, "mmap");
\&
s = write(STDOUT_FILENO, addr + offset \- pa_offset, length);
if (s != length) {
if (s == \-1)
- handle_error("write");
+ err(EXIT_FAILURE, "write");
\&
fprintf(stderr, "partial write");
exit(EXIT_FAILURE);