diff options
| author | Alejandro Colomar <alx@kernel.org> | 2025-08-19 17:48:50 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2025-08-20 18:14:03 +0200 |
| commit | 0e7a39804a3c017a209117fc2243c6cbb543dede (patch) | |
| tree | 91e0b287d8b826d668c3d8118347f07cc8b8964a /man/man4 | |
| parent | e2d3f14fe40ad90a1fedf0fcd27e6cc896c49a7a (diff) | |
| download | man-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/man4')
| -rw-r--r-- | man/man4/loop.4 | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/man/man4/loop.4 b/man/man4/loop.4 index 8997a9aca0..a497ab0399 100644 --- a/man/man4/loop.4 +++ b/man/man4/loop.4 @@ -308,6 +308,7 @@ loopname = /dev/loop5 .SS Program source \& .EX +#include <err.h> #include <fcntl.h> #include <linux/loop.h> #include <sys/ioctl.h> @@ -315,9 +316,6 @@ loopname = /dev/loop5 #include <stdlib.h> #include <unistd.h> \& -#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \[rs] - } while (0) -\& int main(int argc, char *argv[]) { @@ -332,25 +330,25 @@ main(int argc, char *argv[]) \& loopctlfd = open("/dev/loop\-control", O_RDWR); if (loopctlfd == \-1) - errExit("open: /dev/loop\-control"); + err(EXIT_FAILURE, "open: /dev/loop\-control"); \& devnr = ioctl(loopctlfd, LOOP_CTL_GET_FREE); if (devnr == \-1) - errExit("ioctl\-LOOP_CTL_GET_FREE"); + err(EXIT_FAILURE, "ioctl\-LOOP_CTL_GET_FREE"); \& sprintf(loopname, "/dev/loop%ld", devnr); printf("loopname = %s\[rs]n", loopname); \& loopfd = open(loopname, O_RDWR); if (loopfd == \-1) - errExit("open: loopname"); + err(EXIT_FAILURE, "open: loopname"); \& backingfile = open(argv[1], O_RDWR); if (backingfile == \-1) - errExit("open: backing\-file"); + err(EXIT_FAILURE, "open: backing\-file"); \& if (ioctl(loopfd, LOOP_SET_FD, backingfile) == \-1) - errExit("ioctl\-LOOP_SET_FD"); + err(EXIT_FAILURE, "ioctl\-LOOP_SET_FD"); \& exit(EXIT_SUCCESS); } |
