aboutsummaryrefslogtreecommitdiffstats
path: root/man/man2/mprotect.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/mprotect.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/mprotect.2')
-rw-r--r--man/man2/mprotect.212
1 files changed, 5 insertions, 7 deletions
diff --git a/man/man2/mprotect.2 b/man/man2/mprotect.2
index 773d93dc9c..269ae204d6 100644
--- a/man/man2/mprotect.2
+++ b/man/man2/mprotect.2
@@ -293,6 +293,7 @@ Got SIGSEGV at address: 0x804e000
\&
.\" SRC BEGIN (mprotect.c)
.EX
+#include <err.h>
#include <malloc.h>
#include <signal.h>
#include <stdio.h>
@@ -300,9 +301,6 @@ Got SIGSEGV at address: 0x804e000
#include <sys/mman.h>
#include <unistd.h>
\&
-#define handle_error(msg) \[rs]
- do { perror(msg); exit(EXIT_FAILURE); } while (0)
-\&
static char *buffer;
\&
static void
@@ -328,24 +326,24 @@ main(void)
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
if (sigaction(SIGSEGV, &sa, NULL) == \-1)
- handle_error("sigaction");
+ err(EXIT_FAILURE, "sigaction");
\&
pagesize = sysconf(_SC_PAGE_SIZE);
if (pagesize == \-1)
- handle_error("sysconf");
+ err(EXIT_FAILURE, "sysconf");
\&
/* Allocate a buffer aligned on a page boundary;
initial protection is PROT_READ | PROT_WRITE. */
\&
buffer = memalign(pagesize, 4 * pagesize);
if (buffer == NULL)
- handle_error("memalign");
+ err(EXIT_FAILURE, "memalign");
\&
printf("Start of region: %p\[rs]n", buffer);
\&
if (mprotect(buffer + pagesize * 2, pagesize,
PROT_READ) == \-1)
- handle_error("mprotect");
+ err(EXIT_FAILURE, "mprotect");
\&
for (char *p = buffer ; ; )
*(p++) = \[aq]a\[aq];