summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-05-03 00:48:14 +0200
committerAlejandro Colomar <alx@kernel.org>2023-05-03 00:48:22 +0200
commitfe5dba139dc089eae4061fdc17f087e71f48b198 (patch)
tree54af56b1b0138bde9a21e99372ab68ce4d64564a
parent5a0d9ed151e6449d978fabdd654cacc17b20a235 (diff)
man*/, man.ignore.grep: srcfix; warn about blank lines
- Use the dummy character to avoid warnings in examples. - Re-enable the warning. Suggested-by: "G. Branden Robinson" <g.branden.robinson@gmail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man1/intro.12
-rw-r--r--man1/locale.110
-rw-r--r--man1/memusage.114
-rw-r--r--man1/sprof.118
-rw-r--r--man2/_syscall.26
-rw-r--r--man2/add_key.210
-rw-r--r--man2/bind.224
-rw-r--r--man2/bpf.232
-rw-r--r--man2/capget.28
-rw-r--r--man2/chown.214
-rw-r--r--man2/clock_getres.226
-rw-r--r--man2/clone.248
-rw-r--r--man2/close_range.226
-rw-r--r--man2/copy_file_range.218
-rw-r--r--man2/dup.210
-rw-r--r--man2/epoll_wait.22
-rw-r--r--man2/eventfd.218
-rw-r--r--man2/execve.216
-rw-r--r--man2/fork.24
-rw-r--r--man2/futex.264
-rw-r--r--man2/getdents.216
-rw-r--r--man2/getitimer.22
-rw-r--r--man2/getrlimit.218
-rw-r--r--man2/io_submit.22
-rw-r--r--man2/ioctl_fat.260
-rw-r--r--man2/ioctl_getfsmap.24
-rw-r--r--man2/ioctl_iflags.22
-rw-r--r--man2/ioctl_ns.232
-rw-r--r--man2/ioctl_pipe.22
-rw-r--r--man2/ioctl_tty.228
-rw-r--r--man2/ioctl_userfaultfd.22
-rw-r--r--man2/kcmp.230
-rw-r--r--man2/keyctl.248
-rw-r--r--man2/listxattr.230
-rw-r--r--man2/membarrier.250
-rw-r--r--man2/memfd_create.246
-rw-r--r--man2/mmap.228
-rw-r--r--man2/mount_setattr.242
-rw-r--r--man2/mprotect.226
-rw-r--r--man2/msgop.234
-rw-r--r--man2/nfsservctl.24
-rw-r--r--man2/open.28
-rw-r--r--man2/open_by_handle_at.288
-rw-r--r--man2/perf_event_open.252
-rw-r--r--man2/pidfd_open.216
-rw-r--r--man2/pidfd_send_signal.224
-rw-r--r--man2/pipe.216
-rw-r--r--man2/pivot_root.250
-rw-r--r--man2/poll.236
-rw-r--r--man2/process_vm_readv.28
-rw-r--r--man2/quotactl.236
-rw-r--r--man2/readlink.226
-rw-r--r--man2/readv.24
-rw-r--r--man2/recv.24
-rw-r--r--man2/recvmmsg.214
-rw-r--r--man2/request_key.212
-rw-r--r--man2/sched_setaffinity.226
-rw-r--r--man2/seccomp.236
-rw-r--r--man2/seccomp_unotify.2318
-rw-r--r--man2/select.218
-rw-r--r--man2/select_tut.2100
-rw-r--r--man2/semget.222
-rw-r--r--man2/semop.28
-rw-r--r--man2/sendmmsg.218
-rw-r--r--man2/setns.212
-rw-r--r--man2/shmop.274
-rw-r--r--man2/sigaction.210
-rw-r--r--man2/sigaltstack.26
-rw-r--r--man2/signalfd.214
-rw-r--r--man2/spu_run.216
-rw-r--r--man2/stat.224
-rw-r--r--man2/statx.210
-rw-r--r--man2/syscall.24
-rw-r--r--man2/sysctl.216
-rw-r--r--man2/tee.212
-rw-r--r--man2/timer_create.250
-rw-r--r--man2/timerfd_create.230
-rw-r--r--man2/unshare.216
-rw-r--r--man2/userfaultfd.296
-rw-r--r--man2/wait.210
-rw-r--r--man3/CPU_SET.318
-rw-r--r--man3/MAX.38
-rw-r--r--man3/_Generic.38
-rw-r--r--man3/__ppc_get_timebase.318
-rw-r--r--man3/atexit.310
-rw-r--r--man3/backtrace.322
-rw-r--r--man3/basename.32
-rw-r--r--man3/bsearch.314
-rw-r--r--man3/bswap.38
-rw-r--r--man3/cacos.318
-rw-r--r--man3/cacosh.314
-rw-r--r--man3/catan.314
-rw-r--r--man3/catanh.314
-rw-r--r--man3/circleq.320
-rw-r--r--man3/clock_getcpuclockid.310
-rw-r--r--man3/cmsg.38
-rw-r--r--man3/confstr.32
-rw-r--r--man3/dl_iterate_phdr.318
-rw-r--r--man3/dladdr.32
-rw-r--r--man3/dlinfo.330
-rw-r--r--man3/dlopen.320
-rw-r--r--man3/duplocale.320
-rw-r--r--man3/encrypt.310
-rw-r--r--man3/end.36
-rw-r--r--man3/endian.38
-rw-r--r--man3/envz_add.36
-rw-r--r--man3/fmemopen.318
-rw-r--r--man3/fmtmsg.34
-rw-r--r--man3/fopencookie.364
-rw-r--r--man3/fread.318
-rw-r--r--man3/frexp.36
-rw-r--r--man3/ftw.316
-rw-r--r--man3/get_nprocs.32
-rw-r--r--man3/get_phys_pages.32
-rw-r--r--man3/getaddrinfo.370
-rw-r--r--man3/getaddrinfo_a.372
-rw-r--r--man3/getdate.310
-rw-r--r--man3/getgrent_r.34
-rw-r--r--man3/getgrouplist.322
-rw-r--r--man3/getifaddrs.326
-rw-r--r--man3/getline.310
-rw-r--r--man3/getnameinfo.34
-rw-r--r--man3/getopt.340
-rw-r--r--man3/getprotoent_r.326
-rw-r--r--man3/getpwent_r.36
-rw-r--r--man3/getpwnam.312
-rw-r--r--man3/getservent_r.328
-rw-r--r--man3/getsubopt.326
-rw-r--r--man3/getutent.314
-rw-r--r--man3/glob.32
-rw-r--r--man3/gnu_get_libc_version.34
-rw-r--r--man3/hsearch.310
-rw-r--r--man3/if_nameindex.310
-rw-r--r--man3/inet.310
-rw-r--r--man3/inet_net_pton.330
-rw-r--r--man3/inet_pton.314
-rw-r--r--man3/insque.338
-rw-r--r--man3/list.320
-rw-r--r--man3/makecontext.318
-rw-r--r--man3/mallinfo.330
-rw-r--r--man3/malloc.312
-rw-r--r--man3/malloc_hook.322
-rw-r--r--man3/malloc_info.340
-rw-r--r--man3/mallopt.312
-rw-r--r--man3/matherr.320
-rw-r--r--man3/mbstowcs.342
-rw-r--r--man3/mcheck.314
-rw-r--r--man3/mq_getattr.316
-rw-r--r--man3/mq_notify.322
-rw-r--r--man3/mtrace.36
-rw-r--r--man3/newlocale.336
-rw-r--r--man3/nl_langinfo.36
-rw-r--r--man3/ntp_gettime.32
-rw-r--r--man3/offsetof.38
-rw-r--r--man3/posix_spawn.354
-rw-r--r--man3/printf.316
-rw-r--r--man3/pthread_attr_init.356
-rw-r--r--man3/pthread_cancel.336
-rw-r--r--man3/pthread_cleanup_push.332
-rw-r--r--man3/pthread_cleanup_push_defer_np.32
-rw-r--r--man3/pthread_create.358
-rw-r--r--man3/pthread_getattr_default_np.322
-rw-r--r--man3/pthread_getattr_np.358
-rw-r--r--man3/pthread_getcpuclockid.330
-rw-r--r--man3/pthread_mutexattr_setrobust.324
-rw-r--r--man3/pthread_setaffinity_np.318
-rw-r--r--man3/pthread_setname_np.320
-rw-r--r--man3/pthread_setschedparam.382
-rw-r--r--man3/pthread_sigmask.320
-rw-r--r--man3/pthread_tryjoin_np.38
-rw-r--r--man3/qsort.310
-rw-r--r--man3/rand.316
-rw-r--r--man3/regex.318
-rw-r--r--man3/rpmatch.34
-rw-r--r--man3/rtime.312
-rw-r--r--man3/rtnetlink.310
-rw-r--r--man3/scandir.38
-rw-r--r--man3/sem_wait.334
-rw-r--r--man3/setaliasent.36
-rw-r--r--man3/setbuf.34
-rw-r--r--man3/shm_open.386
-rw-r--r--man3/slist.324
-rw-r--r--man3/sockatmark.38
-rw-r--r--man3/sscanf.32
-rw-r--r--man3/stailq.322
-rw-r--r--man3/static_assert.318
-rw-r--r--man3/stdarg.36
-rw-r--r--man3/stpncpy.314
-rw-r--r--man3/strcmp.312
-rw-r--r--man3/strcpy.322
-rw-r--r--man3/strftime.38
-rw-r--r--man3/strncat.318
-rw-r--r--man3/strptime.34
-rw-r--r--man3/strsep.310
-rw-r--r--man3/strtok.310
-rw-r--r--man3/strtol.322
-rw-r--r--man3/strverscmp.310
-rw-r--r--man3/system.32
-rw-r--r--man3/tailq.320
-rw-r--r--man3/tsearch.316
-rw-r--r--man3/wordexp.34
-rw-r--r--man3const/EXIT_SUCCESS.3const10
-rw-r--r--man3head/printf.h.3head100
-rw-r--r--man3type/epoll_event.3type2
-rw-r--r--man3type/stat.3type6
-rw-r--r--man4/cciss.44
-rw-r--r--man4/fuse.42
-rw-r--r--man4/lirc.42
-rw-r--r--man4/loop.420
-rw-r--r--man4/vcs.44
-rw-r--r--man5/acct.56
-rw-r--r--man5/core.524
-rw-r--r--man5/elf.512
-rw-r--r--man5/hosts.54
-rw-r--r--man5/nsswitch.conf.52
-rw-r--r--man5/utmp.514
-rw-r--r--man7/aio.792
-rw-r--r--man7/capabilities.710
-rw-r--r--man7/complex.72
-rw-r--r--man7/ddp.72
-rw-r--r--man7/epoll.710
-rw-r--r--man7/fanotify.7165
-rw-r--r--man7/feature_test_macros.738
-rw-r--r--man7/inotify.794
-rw-r--r--man7/ip.78
-rw-r--r--man7/ipv6.72
-rw-r--r--man7/landlock.710
-rw-r--r--man7/locale.78
-rw-r--r--man7/math_error.74
-rw-r--r--man7/mount_namespaces.72
-rw-r--r--man7/netlink.716
-rw-r--r--man7/pkeys.720
-rw-r--r--man7/rtld-audit.732
-rw-r--r--man7/rtnetlink.74
-rw-r--r--man7/sock_diag.764
-rw-r--r--man7/socket.72
-rw-r--r--man7/string_copying.724
-rw-r--r--man7/system_data_types.724
-rw-r--r--man7/unix.7124
-rw-r--r--man7/user_namespaces.7106
-rw-r--r--man7/vdso.72
-rw-r--r--share/lint/groff/man.ignore.grep1
242 files changed, 2779 insertions, 2783 deletions
diff --git a/man1/intro.1 b/man1/intro.1
index 5c60aa520..78cd46610 100644
--- a/man1/intro.1
+++ b/man1/intro.1
@@ -69,7 +69,7 @@ Su Mo Tu We Th Fr Sa
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
-
+\&
.RB "$ " ls
bin tel
.RB "$ " "ls \-l"
diff --git a/man1/locale.1 b/man1/locale.1
index 4e257eb7b..6754aa1f0 100644
--- a/man1/locale.1
+++ b/man1/locale.1
@@ -139,24 +139,24 @@ LC_TELEPHONE="en_US.UTF\-8"
LC_MEASUREMENT="en_US.UTF\-8"
LC_IDENTIFICATION="en_US.UTF\-8"
LC_ALL=
-
+.PP
$ \fBlocale date_fmt\fP
%a %b %e %H:%M:%S %Z %Y
-
+.PP
$ \fBlocale \-k date_fmt\fP
date_fmt="%a %b %e %H:%M:%S %Z %Y"
-
+.PP
$ \fBlocale \-ck date_fmt\fP
LC_TIME
date_fmt="%a %b %e %H:%M:%S %Z %Y"
-
+.PP
$ \fBlocale LC_TELEPHONE\fP
+%c (%a) %l
(%a) %l
11
1
UTF\-8
-
+.PP
$ \fBlocale \-k LC_TELEPHONE\fP
tel_int_fmt="+%c (%a) %l"
tel_dom_fmt="(%a) %l"
diff --git a/man1/memusage.1 b/man1/memusage.1
index e9c656825..aeca54bb0 100644
--- a/man1/memusage.1
+++ b/man1/memusage.1
@@ -223,35 +223,35 @@ $ \fBmemusagestat memusage.dat memusage.png\fP
.EX
#include <stdio.h>
#include <stdlib.h>
-
+\&
#define CYCLES 20
-
+\&
int
main(int argc, char *argv[])
{
int i, j;
size_t size;
int *p;
-
+\&
size = sizeof(*p) * 100;
printf("malloc: %zu\en", size);
p = malloc(size);
-
+\&
for (i = 0; i < CYCLES; i++) {
if (i < CYCLES / 2)
j = i;
else
j\-\-;
-
+\&
size = sizeof(*p) * (j * 50 + 110);
printf("realloc: %zu\en", size);
p = realloc(p, size);
-
+\&
size = sizeof(*p) * ((j + 1) * 150 + 110);
printf("realloc: %zu\en", size);
p = realloc(p, size);
}
-
+\&
free(p);
exit(EXIT_SUCCESS);
}
diff --git a/man1/sprof.1 b/man1/sprof.1
index 04903d6e9..0807ee5bd 100644
--- a/man1/sprof.1
+++ b/man1/sprof.1
@@ -65,10 +65,10 @@ First, the code of the main program:
.EX
$ \fBcat prog.c\fP
#include <stdlib.h>
-
+\&
void x1(void);
void x2(void);
-
+\&
int
main(int argc, char *argv[])
{
@@ -90,27 +90,27 @@ construct the shared object:
.EX
$ \fBcat libdemo.c\fP
#include <unistd.h>
-
+\&
void
consumeCpu1(int lim)
{
for (unsigned int j = 0; j < lim; j++)
getppid();
}
-
+\&
void
x1(void) {
for (unsigned int j = 0; j < 100; j++)
consumeCpu1(200000);
}
-
+\&
void
consumeCpu2(int lim)
{
for (unsigned int j = 0; j < lim; j++)
getppid();
}
-
+\&
void
x2(void)
{
@@ -211,7 +211,7 @@ option to generate a flat profile with counts and ticks:
.EX
$ \fBsprof \-p libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
Flat profile:
-
+\&
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls us/call us/call name
@@ -229,9 +229,9 @@ option generates a call graph:
.in +4n
.EX
$ \fBsprof \-q libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
-
+\&
index % time self children called name
-
+\&
0.00 0.00 100/100 x1 [1]
[0] 100.0 0.00 0.00 100 consumeCpu1 [0]
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
diff --git a/man2/_syscall.2 b/man2/_syscall.2
index cd9ebb614..e29ee1e64 100644
--- a/man2/_syscall.2
+++ b/man2/_syscall.2
@@ -130,15 +130,15 @@ passed by-value or by-pointer (for aggregates like structs).
#include <errno.h>
#include <linux/unistd.h> /* for _syscallX macros/related stuff */
#include <linux/kernel.h> /* for struct sysinfo */
-
+\&
_syscall1(int, sysinfo, struct sysinfo *, info);
-
+\&
int
main(void)
{
struct sysinfo s_info;
int error;
-
+\&
error = sysinfo(&s_info);
printf("code error = %d\en", error);
printf("Uptime = %lds\enLoad: 1 min %lu / 5 min %lu / 15 min %lu\en"
diff --git a/man2/add_key.2 b/man2/add_key.2
index 10120c941..9f502c964 100644
--- a/man2/add_key.2
+++ b/man2/add_key.2
@@ -245,27 +245,27 @@ $ \fBgrep \[aq]64a4dca\[aq] /proc/keys\fP
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
key_serial_t key;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage: %s type description payload\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
key = add_key(argv[1], argv[2], argv[3], strlen(argv[3]),
KEY_SPEC_SESSION_KEYRING);
if (key == \-1) {
perror("add_key");
exit(EXIT_FAILURE);
}
-
+\&
printf("Key ID is %jx\en", (uintmax_t) key);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/bind.2 b/man2/bind.2
index 1f635cb83..a9627b7ad 100644
--- a/man2/bind.2
+++ b/man2/bind.2
@@ -222,50 +222,50 @@ domain, and accept connections:
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
-
+\&
#define MY_SOCK_PATH "/somepath"
#define LISTEN_BACKLOG 50
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
int
main(void)
{
int sfd, cfd;
socklen_t peer_addr_size;
struct sockaddr_un my_addr, peer_addr;
-
+\&
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sfd == \-1)
handle_error("socket");
-
+\&
memset(&my_addr, 0, sizeof(my_addr));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH,
sizeof(my_addr.sun_path) \- 1);
-
+\&
if (bind(sfd, (struct sockaddr *) &my_addr,
sizeof(my_addr)) == \-1)
handle_error("bind");
-
+\&
if (listen(sfd, LISTEN_BACKLOG) == \-1)
handle_error("listen");
-
+\&
/* Now we can accept incoming connections one
at a time using accept(2). */
-
+\&
peer_addr_size = sizeof(peer_addr);
cfd = accept(sfd, (struct sockaddr *) &peer_addr,
&peer_addr_size);
if (cfd == \-1)
handle_error("accept");
-
+\&
/* Code to deal with incoming connection(s)... */
-
+\&
if (close(sfd) == \-1)
handle_error("close");
-
+\&
if (unlink(MY_SOCK_PATH) == \-1)
handle_error("unlink");
}
diff --git a/man2/bpf.2 b/man2/bpf.2
index a5d08703a..d32435a1d 100644
--- a/man2/bpf.2
+++ b/man2/bpf.2
@@ -175,7 +175,7 @@ union bpf_attr {
__u32 max_entries; /* maximum number of entries
in a map */
};
-
+\&
struct { /* Used by BPF_MAP_*_ELEM and BPF_MAP_GET_NEXT_KEY
commands */
__u32 map_fd;
@@ -186,7 +186,7 @@ union bpf_attr {
};
__u64 flags;
};
-
+\&
struct { /* Used by BPF_PROG_LOAD */
__u32 prog_type;
__u32 insn_cnt;
@@ -247,7 +247,7 @@ bpf_create_map(enum bpf_map_type map_type,
.value_size = value_size,
.max_entries = max_entries
};
-
+\&
return bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
}
.EE
@@ -392,7 +392,7 @@ bpf_lookup_elem(int fd, const void *key, void *value)
.key = ptr_to_u64(key),
.value = ptr_to_u64(value),
};
-
+\&
return bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
}
.EE
@@ -431,7 +431,7 @@ bpf_update_elem(int fd, const void *key, const void *value,
.value = ptr_to_u64(value),
.flags = flags,
};
-
+\&
return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
}
.EE
@@ -500,7 +500,7 @@ bpf_delete_elem(int fd, const void *key)
.map_fd = fd,
.key = ptr_to_u64(key),
};
-
+\&
return bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
}
.EE
@@ -533,7 +533,7 @@ bpf_get_next_key(int fd, const void *key, void *next_key)
.key = ptr_to_u64(key),
.next_key = ptr_to_u64(next_key),
};
-
+\&
return bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr));
}
.EE
@@ -714,7 +714,7 @@ with this eBPF program.
.in +4n
.EX
char bpf_log_buf[LOG_BUF_SIZE];
-
+\&
int
bpf_prog_load(enum bpf_prog_type type,
const struct bpf_insn *insns, int insn_cnt,
@@ -729,7 +729,7 @@ bpf_prog_load(enum bpf_prog_type type,
.log_size = LOG_BUF_SIZE,
.log_level = 1,
};
-
+\&
return bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
}
.EE
@@ -1197,7 +1197,7 @@ main(int argc, char *argv[])
{
int sock, map_fd, prog_fd, key;
long long value = 0, tcp_cnt, udp_cnt;
-
+\&
map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(key),
sizeof(value), 256);
if (map_fd < 0) {
@@ -1205,7 +1205,7 @@ main(int argc, char *argv[])
/* likely not run as root */
return 1;
}
-
+\&
struct bpf_insn prog[] = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), /* r6 = r1 */
BPF_LD_ABS(BPF_B, ETH_HLEN + offsetof(struct iphdr, protocol)),
@@ -1226,15 +1226,15 @@ main(int argc, char *argv[])
BPF_MOV64_IMM(BPF_REG_0, 0), /* r0 = 0 */
BPF_EXIT_INSN(), /* return r0 */
};
-
+\&
prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, prog,
sizeof(prog) / sizeof(prog[0]), "GPL");
-
+\&
sock = open_raw_sock("lo");
-
+\&
assert(setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd,
sizeof(prog_fd)) == 0);
-
+\&
for (;;) {
key = IPPROTO_TCP;
assert(bpf_lookup_elem(map_fd, &key, &tcp_cnt) == 0);
@@ -1243,7 +1243,7 @@ main(int argc, char *argv[])
printf("TCP %lld UDP %lld packets\en", tcp_cnt, udp_cnt);
sleep(1);
}
-
+\&
return 0;
}
.EE
diff --git a/man2/capget.2 b/man2/capget.2
index 68d0ab672..7327071e8 100644
--- a/man2/capget.2
+++ b/man2/capget.2
@@ -58,23 +58,23 @@ The structures are defined as follows.
.EX
#define _LINUX_CAPABILITY_VERSION_1 0x19980330
#define _LINUX_CAPABILITY_U32S_1 1
-
+\&
/* V2 added in Linux 2.6.25; deprecated */
#define _LINUX_CAPABILITY_VERSION_2 0x20071026
.\" commit e338d263a76af78fe8f38a72131188b58fceb591
.\" Added 64 bit capability support
#define _LINUX_CAPABILITY_U32S_2 2
-
+\&
/* V3 added in Linux 2.6.26 */
#define _LINUX_CAPABILITY_VERSION_3 0x20080522
.\" commit ca05a99a54db1db5bca72eccb5866d2a86f8517f
#define _LINUX_CAPABILITY_U32S_3 2
-
+\&
typedef struct __user_cap_header_struct {
__u32 version;
int pid;
} *cap_user_header_t;
-
+\&
typedef struct __user_cap_data_struct {
__u32 effective;
__u32 permitted;
diff --git a/man2/chown.2 b/man2/chown.2
index fe1906b7d..32b17fbdc 100644
--- a/man2/chown.2
+++ b/man2/chown.2
@@ -428,36 +428,36 @@ to perform a lookup in the system password file).
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
char *endptr;
uid_t uid;
struct passwd *pwd;
-
+\&
if (argc != 3 || argv[1][0] == \[aq]\e0\[aq]) {
fprintf(stderr, "%s <owner> <file>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
uid = strtol(argv[1], &endptr, 10); /* Allow a numeric string */
-
+\&
if (*endptr != \[aq]\e0\[aq]) { /* Was not pure numeric string */
pwd = getpwnam(argv[1]); /* Try getting UID for username */
if (pwd == NULL) {
perror("getpwnam");
exit(EXIT_FAILURE);
}
-
+\&
uid = pwd\->pw_uid;
}
-
+\&
if (chown(argv[2], uid, \-1) == \-1) {
perror("chown");
exit(EXIT_FAILURE);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/clock_getres.2 b/man2/clock_getres.2
index e744bc7ff..9fb7ef14d 100644
--- a/man2/clock_getres.2
+++ b/man2/clock_getres.2
@@ -226,11 +226,11 @@ dynamic clock ID.
#define CLOCKFD 3
#define FD_TO_CLOCKID(fd) ((\[ti](clockid_t) (fd) << 3) | CLOCKFD)
#define CLOCKID_TO_FD(clk) ((unsigned int) \[ti]((clk) >> 3))
-
+\&
struct timespec ts;
clockid_t clkid;
int fd;
-
+\&
fd = open("/dev/ptp0", O_RDWR);
clkid = FD_TO_CLOCKID(fd);
clock_gettime(clkid, &ts);
@@ -445,7 +445,7 @@ CLOCK_BOOTTIME : 72691.019 (20h 11m 31s)
.\" SRC BEGIN (clock_getres.c)
.EX
/* clock_times.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#define _XOPEN_SOURCE 600
@@ -454,48 +454,48 @@ CLOCK_BOOTTIME : 72691.019 (20h 11m 31s)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-
+\&
#define SECS_IN_DAY (24 * 60 * 60)
-
+\&
static void
displayClock(clockid_t clock, const char *name, bool showRes)
{
long days;
struct timespec ts;
-
+\&
if (clock_gettime(clock, &ts) == \-1) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
-
+\&
printf("%\-15s: %10jd.%03ld (", name,
(intmax_t) ts.tv_sec, ts.tv_nsec / 1000000);
-
+\&
days = ts.tv_sec / SECS_IN_DAY;
if (days > 0)
printf("%ld days + ", days);
-
+\&
printf("%2dh %2dm %2ds",
(int) (ts.tv_sec % SECS_IN_DAY) / 3600,
(int) (ts.tv_sec % 3600) / 60,
(int) ts.tv_sec % 60);
printf(")\en");
-
+\&
if (clock_getres(clock, &ts) == \-1) {
perror("clock_getres");
exit(EXIT_FAILURE);
}
-
+\&
if (showRes)
printf(" resolution: %10jd.%09ld\en",
(intmax_t) ts.tv_sec, ts.tv_nsec);
}
-
+\&
int
main(int argc, char *argv[])
{
bool showRes = argc > 1;
-
+\&
displayClock(CLOCK_REALTIME, "CLOCK_REALTIME", showRes);
#ifdef CLOCK_TAI
displayClock(CLOCK_TAI, "CLOCK_TAI", showRes);
diff --git a/man2/clone.2 b/man2/clone.2
index ec43841eb..4c5b4ac6b 100644
--- a/man2/clone.2
+++ b/man2/clone.2
@@ -1788,9 +1788,9 @@ To get the truth, it was sometimes necessary to use code such as the following:
.in +4n
.EX
#include <syscall.h>
-
+\&
pid_t mypid;
-
+\&
mypid = syscall(SYS_getpid);
.EE
.in
@@ -1848,34 +1848,34 @@ so we should include it for portability.
#include <sys/utsname.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
static int /* Start function for cloned child */
childFunc(void *arg)
{
struct utsname uts;
-
+\&
/* Change hostname in UTS namespace of child. */
-
+\&
if (sethostname(arg, strlen(arg)) == \-1)
err(EXIT_FAILURE, "sethostname");
-
+\&
/* Retrieve and display hostname. */
-
+\&
if (uname(&uts) == \-1)
err(EXIT_FAILURE, "uname");
printf("uts.nodename in child: %s\en", uts.nodename);
-
+\&
/* Keep the namespace open for a while, by sleeping.
This allows some experimentation\-\-for example, another
process might join the namespace. */
-
+\&
sleep(200);
-
+\&
return 0; /* Child terminates now */
}
-
+\&
#define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */
-
+\&
int
main(int argc, char *argv[])
{
@@ -1883,44 +1883,44 @@ main(int argc, char *argv[])
char *stackTop; /* End of stack buffer */
pid_t pid;
struct utsname uts;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s <child\-hostname>\en", argv[0]);
exit(EXIT_SUCCESS);
}
-
+\&
/* Allocate memory to be used for the stack of the child. */
-
+\&
stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, \-1, 0);
if (stack == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
-
+\&
stackTop = stack + STACK_SIZE; /* Assume stack grows downward */
-
+\&
/* Create child that has its own UTS namespace;
child commences execution in childFunc(). */
-
+\&
pid = clone(childFunc, stackTop, CLONE_NEWUTS | SIGCHLD, argv[1]);
if (pid == \-1)
err(EXIT_FAILURE, "clone");
printf("clone() returned %jd\en", (intmax_t) pid);
-
+\&
/* Parent falls through to here */
-
+\&
sleep(1); /* Give child time to change its hostname */
-
+\&
/* Display hostname in parent\[aq]s UTS namespace. This will be
different from hostname in child\[aq]s UTS namespace. */
-
+\&
if (uname(&uts) == \-1)
err(EXIT_FAILURE, "uname");
printf("uts.nodename in parent: %s\en", uts.nodename);
-
+\&
if (waitpid(pid, NULL, 0) == \-1) /* Wait for child */
err(EXIT_FAILURE, "waitpid");
printf("child has terminated\en");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/close_range.2 b/man2/close_range.2
index 782719de0..1df68c91d 100644
--- a/man2/close_range.2
+++ b/man2/close_range.2
@@ -207,9 +207,9 @@ result from the calls to
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
/* Show the contents of the symbolic links in /proc/self/fd */
-
+\&
static void
show_fds(void)
{
@@ -217,35 +217,35 @@ show_fds(void)
char path[PATH_MAX], target[PATH_MAX];
ssize_t len;
struct dirent *dp;
-
+\&
dirp = opendir("/proc/self/fd");
if (dirp == NULL) {
perror("opendir");
exit(EXIT_FAILURE);
}
-
+\&
for (;;) {
dp = readdir(dirp);
if (dp == NULL)
break;
-
+\&
if (dp\->d_type == DT_LNK) {
snprintf(path, sizeof(path), "/proc/self/fd/%s",
dp\->d_name);
-
+\&
len = readlink(path, target, sizeof(target));
printf("%s ==> %.*s\en", path, (int) len, target);
}
}
-
+\&
closedir(dirp);
}
-
+\&
int
main(int argc, char *argv[])
{
int fd;
-
+\&
for (size_t j = 1; j < argc; j++) {
fd = open(argv[j], O_RDONLY);
if (fd == \-1) {
@@ -254,16 +254,16 @@ main(int argc, char *argv[])
}
printf("%s opened as FD %d\en", argv[j], fd);
}
-
+\&
show_fds();
-
+\&
printf("========= About to call close_range() =======\en");
-
+\&
if (syscall(SYS_close_range, 3, \[ti]0U, 0) == \-1) {
perror("close_range");
exit(EXIT_FAILURE);
}
-
+\&
show_fds();
exit(EXIT_FAILURE);
}
diff --git a/man2/copy_file_range.2 b/man2/copy_file_range.2
index 1bade7bf7..6f3aa4971 100644
--- a/man2/copy_file_range.2
+++ b/man2/copy_file_range.2
@@ -239,48 +239,48 @@ the call failed to copy, while still reporting success.
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd_in, fd_out;
off64_t len, ret;
struct stat stat;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <source> <destination>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd_in = open(argv[1], O_RDONLY);
if (fd_in == \-1) {
perror("open (argv[1])");
exit(EXIT_FAILURE);
}
-
+\&
if (fstat(fd_in, &stat) == \-1) {
perror("fstat");
exit(EXIT_FAILURE);
}
-
+\&
len = stat.st_size;
-
+\&
fd_out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd_out == \-1) {
perror("open (argv[2])");
exit(EXIT_FAILURE);
}
-
+\&
do {
ret = copy_file_range(fd_in, NULL, fd_out, NULL, len, 0);
if (ret == \-1) {
perror("copy_file_range");
exit(EXIT_FAILURE);
}
-
+\&
len \-= ret;
} while (len > 0 && ret > 0);
-
+\&
close(fd_in);
close(fd_out);
exit(EXIT_SUCCESS);
diff --git a/man2/dup.2 b/man2/dup.2
index f69922be4..b38e4dd08 100644
--- a/man2/dup.2
+++ b/man2/dup.2
@@ -255,21 +255,21 @@ Instead, code something like the following could be used:
/* Obtain a duplicate of \[aq]newfd\[aq] that can subsequently
be used to check for close() errors; an EBADF error
means that \[aq]newfd\[aq] was not open. */
-
+\&
tmpfd = dup(newfd);
if (tmpfd == \-1 && errno != EBADF) {
/* Handle unexpected dup() error. */
}
-
+\&
/* Atomically duplicate \[aq]oldfd\[aq] on \[aq]newfd\[aq]. */
-
+\&
if (dup2(oldfd, newfd) == \-1) {
/* Handle dup2() error. */
}
-
+\&
/* Now check for close() errors on the file originally
referred to by \[aq]newfd\[aq]. */
-
+\&
if (tmpfd != \-1) {
if (close(tmpfd) == \-1) {
/* Handle errors from close. */
diff --git a/man2/epoll_wait.2 b/man2/epoll_wait.2
index 7c79afdfa..6e91af7f8 100644
--- a/man2/epoll_wait.2
+++ b/man2/epoll_wait.2
@@ -136,7 +136,7 @@ executing the following calls:
.in +4n
.EX
sigset_t origmask;
-
+\&
pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
ready = epoll_wait(epfd, &events, maxevents, timeout);
pthread_sigmask(SIG_SETMASK, &origmask, NULL);
diff --git a/man2/eventfd.2 b/man2/eventfd.2
index 9b7ab22b3..e540e3b43 100644
--- a/man2/eventfd.2
+++ b/man2/eventfd.2
@@ -286,7 +286,7 @@ reading and writing on an eventfd file descriptor:
.in +4n
.EX
typedef uint64_t eventfd_t;
-
+\&
int eventfd_read(int fd, eventfd_t *value);
int eventfd_write(int fd, eventfd_t value);
.EE
@@ -385,23 +385,23 @@ Parent read 28 (0x1c) from efd
#include <stdlib.h>
#include <sys/eventfd.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int efd;
uint64_t u;
ssize_t s;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s <num>...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
efd = eventfd(0, 0);
if (efd == \-1)
err(EXIT_FAILURE, "eventfd");
-
+\&
switch (fork()) {
case 0:
for (size_t j = 1; j < argc; j++) {
@@ -413,19 +413,19 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "write");
}
printf("Child completed write loop\en");
-
+\&
exit(EXIT_SUCCESS);
-
+\&
default:
sleep(2);
-
+\&
printf("Parent about to read\en");
s = read(efd, &u, sizeof(uint64_t));
if (s != sizeof(uint64_t))
err(EXIT_FAILURE, "read");
printf("Parent read %"PRIu64" (%#"PRIx64") from efd\en", u, u);
exit(EXIT_SUCCESS);
-
+\&
case \-1:
err(EXIT_FAILURE, "fork");
}
diff --git a/man2/execve.2 b/man2/execve.2
index 20804ead7..538ebb90c 100644
--- a/man2/execve.2
+++ b/man2/execve.2
@@ -777,16 +777,16 @@ It just echoes its command-line arguments, one per line.
.\" SRC BEGIN (myecho.c)
.EX
/* myecho.c */
-
+\&
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
for (size_t j = 0; j < argc; j++)
printf("argv[%zu]: %s\en", j, argv[j]);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -800,24 +800,24 @@ argument:
.\" SRC BEGIN (execve.c)
.EX
/* execve.c */
-
+\&
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
static char *newargv[] = { NULL, "hello", "world", NULL };
static char *newenviron[] = { NULL };
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <file\-to\-exec>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
newargv[0] = argv[1];
-
+\&
execve(argv[1], newargv, newenviron);
perror("execve"); /* execve() returns only on error */
exit(EXIT_FAILURE);
diff --git a/man2/fork.2 b/man2/fork.2
index 15d23fef5..4b779e42b 100644
--- a/man2/fork.2
+++ b/man2/fork.2
@@ -308,12 +308,12 @@ for more examples.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(void)
{
pid_t pid;
-
+\&
if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
perror("signal");
exit(EXIT_FAILURE);
diff --git a/man2/futex.2 b/man2/futex.2
index eb4abac9e..559990e27 100644
--- a/man2/futex.2
+++ b/man2/futex.2
@@ -1781,10 +1781,10 @@ Child (18535) 4
.\" SRC BEGIN (futex.c)
.EX
/* futex_demo.c
-
+\&
Usage: futex_demo [nloops]
(Default: 5)
-
+\&
Demonstrate the use of futexes in a program where parent and child
use a pair of futexes located inside a shared anonymous mapping to
synchronize access to a shared resource: the terminal. The two
@@ -1805,9 +1805,9 @@ Child (18535) 4
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
static uint32_t *futex1, *futex2, *iaddr;
-
+\&
static int
futex(uint32_t *uaddr, int futex_op, uint32_t val,
const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)
@@ -1815,111 +1815,111 @@ futex(uint32_t *uaddr, int futex_op, uint32_t val,
return syscall(SYS_futex, uaddr, futex_op, val,
timeout, uaddr2, val3);
}
-
+\&
/* Acquire the futex pointed to by \[aq]futexp\[aq]: wait for its value to
become 1, and then set the value to 0. */
-
+\&
static void
fwait(uint32_t *futexp)
{
long s;
const uint32_t one = 1;
-
+\&
/* atomic_compare_exchange_strong(ptr, oldval, newval)
atomically performs the equivalent of:
-
+\&
if (*ptr == *oldval)
*ptr = newval;
-
+\&
It returns true if the test yielded true and *ptr was updated. */
-
+\&
while (1) {
-
+\&
/* Is the futex available? */
if (atomic_compare_exchange_strong(futexp, &one, 0))
break; /* Yes */
-
+\&
/* Futex is not available; wait. */
-
+\&
s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
if (s == \-1 && errno != EAGAIN)
err(EXIT_FAILURE, "futex\-FUTEX_WAIT");
}
}
-
+\&
/* Release the futex pointed to by \[aq]futexp\[aq]: if the futex currently
has the value 0, set its value to 1 and then wake any futex waiters,
so that if the peer is blocked in fwait(), it can proceed. */
-
+\&
static void
fpost(uint32_t *futexp)
{
long s;
const uint32_t zero = 0;
-
+\&
/* atomic_compare_exchange_strong() was described
in comments above. */
-
+\&
if (atomic_compare_exchange_strong(futexp, &zero, 1)) {
s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);
if (s == \-1)
err(EXIT_FAILURE, "futex\-FUTEX_WAKE");
}
}
-
+\&
int
main(int argc, char *argv[])
{
pid_t childPid;
unsigned int nloops;
-
+\&
setbuf(stdout, NULL);
-
+\&
nloops = (argc > 1) ? atoi(argv[1]) : 5;
-
+\&
/* Create a shared anonymous mapping that will hold the futexes.
Since the futexes are being shared between processes, we
subsequently use the "shared" futex operations (i.e., not the
ones suffixed "_PRIVATE"). */
-
+\&
iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
if (iaddr == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
-
+\&
futex1 = &iaddr[0];
futex2 = &iaddr[1];
-
+\&
*futex1 = 0; /* State: unavailable */
*futex2 = 1; /* State: available */
-
+\&
/* Create a child process that inherits the shared anonymous
mapping. */
-
+\&
childPid = fork();
if (childPid == \-1)
err(EXIT_FAILURE, "fork");
-
+\&
if (childPid == 0) { /* Child */
for (unsigned int j = 0; j < nloops; j++) {
fwait(futex1);
printf("Child (%jd) %u\en", (intmax_t) getpid(), j);
fpost(futex2);
}
-
+\&
exit(EXIT_SUCCESS);
}
-
+\&
/* Parent falls through to here. */
-
+\&
for (unsigned int j = 0; j < nloops; j++) {
fwait(futex2);
printf("Parent (%jd) %u\en", (intmax_t) getpid(), j);
fpost(futex1);
}
-
+\&
wait(NULL);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/getdents.2 b/man2/getdents.2
index 38024c33a..5d373d916 100644
--- a/man2/getdents.2
+++ b/man2/getdents.2
@@ -259,16 +259,16 @@ inode# file type d_reclen d_off d_name
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
struct linux_dirent {
unsigned long d_ino;
off_t d_off;
unsigned short d_reclen;
char d_name[];
};
-
+\&
#define BUF_SIZE 1024
-
+\&
int
main(int argc, char *argv[])
{
@@ -277,19 +277,19 @@ main(int argc, char *argv[])
char buf[BUF_SIZE];
long nread;
struct linux_dirent *d;
-
+\&
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
if (fd == \-1)
err(EXIT_FAILURE, "open");
-
+\&
for (;;) {
nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
if (nread == \-1)
err(EXIT_FAILURE, "getdents");
-
+\&
if (nread == 0)
break;
-
+\&
printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%ld \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
printf("inode# file type d_reclen d_off d_name\en");
for (size_t bpos = 0; bpos < nread;) {
@@ -308,7 +308,7 @@ main(int argc, char *argv[])
bpos += d\->d_reclen;
}
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/getitimer.2 b/man2/getitimer.2
index 3af439efa..7740eab9f 100644
--- a/man2/getitimer.2
+++ b/man2/getitimer.2
@@ -74,7 +74,7 @@ struct itimerval {
struct timeval it_interval; /* Interval for periodic timer */
struct timeval it_value; /* Time until next expiration */
};
-
+\&
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
diff --git a/man2/getrlimit.2 b/man2/getrlimit.2
index 3b923ca2a..21f919fdc 100644
--- a/man2/getrlimit.2
+++ b/man2/getrlimit.2
@@ -792,44 +792,44 @@ The program below demonstrates the use of
#include <stdlib.h>
#include <sys/resource.h>
#include <time.h>
-
+\&
int
main(int argc, char *argv[])
{
pid_t pid;
struct rlimit old, new;
struct rlimit *newp;
-
+\&
if (!(argc == 2 || argc == 4)) {
fprintf(stderr, "Usage: %s <pid> [<new\-soft\-limit> "
"<new\-hard\-limit>]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
pid = atoi(argv[1]); /* PID of target process */
-
+\&
newp = NULL;
if (argc == 4) {
new.rlim_cur = atoi(argv[2]);
new.rlim_max = atoi(argv[3]);
newp = &new;
}
-
+\&
/* Set CPU time limit of target process; retrieve and display
previous limit */
-
+\&
if (prlimit(pid, RLIMIT_CPU, newp, &old) == \-1)
err(EXIT_FAILURE, "prlimit\-1");
printf("Previous limits: soft=%jd; hard=%jd\en",
(intmax_t) old.rlim_cur, (intmax_t) old.rlim_max);
-
+\&
/* Retrieve and display new CPU time limit */
-
+\&
if (prlimit(pid, RLIMIT_CPU, NULL, &old) == \-1)
err(EXIT_FAILURE, "prlimit\-2");
printf("New limits: soft=%jd; hard=%jd\en",
(intmax_t) old.rlim_cur, (intmax_t) old.rlim_max);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/io_submit.2 b/man2/io_submit.2
index 879ae9d4c..1030bb6cd 100644
--- a/man2/io_submit.2
+++ b/man2/io_submit.2
@@ -52,7 +52,7 @@ defines the parameters that control the I/O operation.
.in +4n
.EX
#include <linux/aio_abi.h>
-
+\&
struct iocb {
__u64 aio_data;
__u32 PADDED(aio_key, aio_rw_flags);
diff --git a/man2/ioctl_fat.2 b/man2/ioctl_fat.2
index d00855095..64cde8e2c 100644
--- a/man2/ioctl_fat.2
+++ b/man2/ioctl_fat.2
@@ -257,7 +257,7 @@ Archive flag is not set
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
-
+\&
/*
* Read file attributes of a file on a FAT filesystem.
* Output the state of the archive flag.
@@ -267,50 +267,50 @@ readattr(int fd)
{
int ret;
uint32_t attr;
-
+\&
ret = ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
if (ret == \-1) {
perror("ioctl");
exit(EXIT_FAILURE);
}
-
+\&
if (attr & ATTR_ARCH)
printf("Archive flag is set\en");
else
printf("Archive flag is not set\en");
-
+\&
return attr;
}
-
+\&
int
main(int argc, char *argv[])
{
int fd;
int ret;
uint32_t attr;
-
+\&
if (argc != 2) {
printf("Usage: %s FILENAME\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_RDONLY);
if (fd == \-1) {
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Read and display the FAT file attributes.
*/
attr = readattr(fd);
-
+\&
/*
* Invert archive attribute.
*/
printf("Toggling archive flag\en");
attr \[ha]= ATTR_ARCH;
-
+\&
/*
* Write the changed FAT file attributes.
*/
@@ -319,14 +319,14 @@ main(int argc, char *argv[])
perror("ioctl");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Read and display the FAT file attributes.
*/
readattr(fd);
-
+\&
close(fd);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -357,25 +357,25 @@ Volume ID 6443\-6241
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd;
int ret;
uint32_t id;
-
+\&
if (argc != 2) {
printf("Usage: %s FILENAME\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_RDONLY);
if (fd == \-1) {
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Read volume ID.
*/
@@ -384,14 +384,14 @@ main(int argc, char *argv[])
perror("ioctl");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Format the output as two groups of 16 bits each.
*/
printf("Volume ID %04x\-%04x\en", id >> 16, id & 0xFFFF);
-
+\&
close(fd);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -425,19 +425,19 @@ LOWER.TXT \-> \[aq]lower.txt\[aq]
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd;
int ret;
struct __fat_dirent entry[2];
-
+\&
if (argc != 2) {
printf("Usage: %s DIRECTORY\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/*
* Open file descriptor for the directory.
*/
@@ -446,14 +446,14 @@ main(int argc, char *argv[])
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
for (;;) {
-
+\&
/*
* Read next directory entry.
*/
ret = ioctl(fd, VFAT_IOCTL_READDIR_BOTH, entry);
-
+\&
/*
* If an error occurs, the return value is \-1.
* If the end of the directory list has been reached,
@@ -463,23 +463,23 @@ main(int argc, char *argv[])
*/
if (ret < 1)
break;
-
+\&
/*
* Write both the short name and the long name.
*/
printf("%s \-> \[aq]%s\[aq]\en", entry[0].d_name, entry[1].d_name);
}
-
+\&
if (ret == \-1) {
perror("VFAT_IOCTL_READDIR_BOTH");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Close the file descriptor.
*/
close(fd);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/ioctl_getfsmap.2 b/man2/ioctl_getfsmap.2
index 093f20691..d995ad524 100644
--- a/man2/ioctl_getfsmap.2
+++ b/man2/ioctl_getfsmap.2
@@ -36,14 +36,14 @@ struct fsmap {
__u64 fmr_length; /* Length of segment */
__u64 fmr_reserved[3]; /* Must be zero */
};
-
+\&
struct fsmap_head {
__u32 fmh_iflags; /* Control flags */
__u32 fmh_oflags; /* Output flags */
__u32 fmh_count; /* # of entries in array incl. input */
__u32 fmh_entries; /* # of entries filled in (output) */
__u64 fmh_reserved[6]; /* Must be zero */
-
+\&
struct fsmap fmh_keys[2]; /* Low and high keys for
the mapping search */
struct fsmap fmh_recs[]; /* Returned records */
diff --git a/man2/ioctl_iflags.2 b/man2/ioctl_iflags.2
index 19d246147..cf4962829 100644
--- a/man2/ioctl_iflags.2
+++ b/man2/ioctl_iflags.2
@@ -18,7 +18,7 @@ operations:
.EX
int attr;
fd = open("pathname", ...);
-
+\&
ioctl(fd, FS_IOC_GETFLAGS, &attr); /* Place current flags
in \[aq]attr\[aq] */
attr |= FS_NOATIME_FL; /* Tweak returned bit mask */
diff --git a/man2/ioctl_ns.2 b/man2/ioctl_ns.2
index 859fab4ad..19fa3b1fe 100644
--- a/man2/ioctl_ns.2
+++ b/man2/ioctl_ns.2
@@ -232,7 +232,7 @@ The owning user namespace is outside your namespace scope
.\" SRC BEGIN (ns_show.c)
.EX
/* ns_show.c
-
+\&
Licensed under the GNU General Public License v2 or later.
*/
#include <errno.h>
@@ -246,13 +246,13 @@ The owning user namespace is outside your namespace scope
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd, userns_fd, parent_fd;
struct stat sb;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s /proc/[pid]/ns/[file] [p|u]\en",
argv[0]);
@@ -263,22 +263,22 @@ main(int argc, char *argv[])
"NS_GET_USERNS is the default.\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Obtain a file descriptor for the \[aq]ns\[aq] file specified
in argv[1]. */
-
+\&
fd = open(argv[1], O_RDONLY);
if (fd == \-1) {
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
/* Obtain a file descriptor for the owning user namespace and
then obtain and display the inode number of that namespace. */
-
+\&
if (argc < 3 || strchr(argv[2], \[aq]u\[aq])) {
userns_fd = ioctl(fd, NS_GET_USERNS);
-
+\&
if (userns_fd == \-1) {
if (errno == EPERM)
printf("The owning user namespace is outside "
@@ -287,7 +287,7 @@ main(int argc, char *argv[])
perror("ioctl\-NS_GET_USERNS");
exit(EXIT_FAILURE);
}
-
+\&
if (fstat(userns_fd, &sb) == \-1) {
perror("fstat\-userns");
exit(EXIT_FAILURE);
@@ -297,16 +297,16 @@ main(int argc, char *argv[])
major(sb.st_dev),
minor(sb.st_dev),
(uintmax_t) sb.st_ino);
-
+\&
close(userns_fd);
}
-
+\&
/* Obtain a file descriptor for the parent namespace and
then obtain and display the inode number of that namespace. */
-
+\&
if (argc > 2 && strchr(argv[2], \[aq]p\[aq])) {
parent_fd = ioctl(fd, NS_GET_PARENT);
-
+\&
if (parent_fd == \-1) {
if (errno == EINVAL)
printf("Can\[aq] get parent namespace of a "
@@ -318,7 +318,7 @@ main(int argc, char *argv[])
perror("ioctl\-NS_GET_PARENT");
exit(EXIT_FAILURE);
}
-
+\&
if (fstat(parent_fd, &sb) == \-1) {
perror("fstat\-parentns");
exit(EXIT_FAILURE);
@@ -327,10 +327,10 @@ main(int argc, char *argv[])
major(sb.st_dev),
minor(sb.st_dev),
(uintmax_t) sb.st_ino);
-
+\&
close(parent_fd);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/ioctl_pipe.2 b/man2/ioctl_pipe.2
index 5c3c86664..995e896de 100644
--- a/man2/ioctl_pipe.2
+++ b/man2/ioctl_pipe.2
@@ -50,7 +50,7 @@ struct watch_notification_filter {
__u32 __reserved;
struct watch_notification_type_filter filters[];
};
-
+\&
struct watch_notification_type_filter {
__u32 type;
__u32 info_filter;
diff --git a/man2/ioctl_tty.2 b/man2/ioctl_tty.2
index bd13f0e2a..85577f80f 100644
--- a/man2/ioctl_tty.2
+++ b/man2/ioctl_tty.2
@@ -775,12 +775,12 @@ Check the condition of DTR on the serial port.
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
-
+\&
int
main(void)
{
int fd, serial;
-
+\&
fd = open("/dev/ttyS0", O_RDONLY);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR)
@@ -797,14 +797,14 @@ Get or set arbitrary baudrate on the serial port.
.\" SRC BEGIN (tcgets.c)
.EX
/* SPDX-License-Identifier: GPL-2.0-or-later */
-
+\&
#include <asm/termbits.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -820,18 +820,18 @@ main(int argc, char *argv[])
struct termios tio;
# endif
int fd, rc;
-
+\&
if (argc != 2 && argc != 3 && argc != 4) {
fprintf(stderr, "Usage: %s device [output [input] ]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY);
if (fd < 0) {
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
/* Get the current serial port settings via supported ioctl */
# if defined TCGETS2
rc = ioctl(fd, TCGETS2, &tio);
@@ -843,20 +843,20 @@ main(int argc, char *argv[])
close(fd);
exit(EXIT_FAILURE);
}
-
+\&
/* Change baud rate when more arguments were provided */
if (argc == 3 || argc == 4) {
/* Clear the current output baud rate and fill a new value */
tio.c_cflag &= \[ti]CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ospeed = atoi(argv[2]);
-
+\&
/* Clear the current input baud rate and fill a new value */
tio.c_cflag &= \[ti](CBAUD << IBSHIFT);
tio.c_cflag |= BOTHER << IBSHIFT;
/* When 4th argument is not provided reuse output baud rate */
tio.c_ispeed = (argc == 4) ? atoi(argv[3]) : atoi(argv[2]);
-
+\&
/* Set new serial port settings via supported ioctl */
# if defined TCSETS2
rc = ioctl(fd, TCSETS2, &tio);
@@ -868,7 +868,7 @@ main(int argc, char *argv[])
close(fd);
exit(EXIT_FAILURE);
}
-
+\&
/* And get new values which were really configured */
# if defined TCGETS2
rc = ioctl(fd, TCGETS2, &tio);
@@ -881,12 +881,12 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
-
+\&
close(fd);
-
+\&
printf("output baud rate: %u\en", tio.c_ospeed);
printf("input baud rate: %u\en", tio.c_ispeed);
-
+\&
exit(EXIT_SUCCESS);
#endif
}
diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2
index 3f851f51b..b5281ec4c 100644
--- a/man2/ioctl_userfaultfd.2
+++ b/man2/ioctl_userfaultfd.2
@@ -289,7 +289,7 @@ struct uffdio_range {
__u64 start; /* Start of range */
__u64 len; /* Length of range (bytes) */
};
-
+\&
struct uffdio_register {
struct uffdio_range range;
__u64 mode; /* Desired mode of operation (input) */
diff --git a/man2/kcmp.2 b/man2/kcmp.2
index 7c02b5c44..d1c24130c 100644
--- a/man2/kcmp.2
+++ b/man2/kcmp.2
@@ -323,7 +323,7 @@ An example run of the program is as follows:
$ \fB./a.out\fP
Parent PID is 1144
Parent opened file on FD 3
-
+\&
PID of child of fork() is 1145
Compare duplicate FDs from different processes:
kcmp(1145, 1144, KCMP_FILE, 3, 3) ==> same
@@ -349,14 +349,14 @@ Child duplicated FD 3 to create FD 5
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
static int
kcmp(pid_t pid1, pid_t pid2, int type,
unsigned long idx1, unsigned long idx2)
{
return syscall(SYS_kcmp, pid1, pid2, type, idx1, idx2);
}
-
+\&
static void
test_kcmp(char *msg, pid_t pid1, pid_t pid2, int fd_a, int fd_b)
{
@@ -366,51 +366,51 @@ test_kcmp(char *msg, pid_t pid1, pid_t pid2, int fd_a, int fd_b)
(kcmp(pid1, pid2, KCMP_FILE, fd_a, fd_b) == 0) ?
"same" : "different");
}
-
+\&
int
main(void)
{
int fd1, fd2, fd3;
static const char pathname[] = "/tmp/kcmp.test";
-
+\&
fd1 = open(pathname, O_CREAT | O_RDWR, 0600);
if (fd1 == \-1)
err(EXIT_FAILURE, "open");
-
+\&
printf("Parent PID is %jd\en", (intmax_t) getpid());
printf("Parent opened file on FD %d\en\en", fd1);
-
+\&
switch (fork()) {
case \-1:
err(EXIT_FAILURE, "fork");
-
+\&
case 0:
printf("PID of child of fork() is %jd\en", (intmax_t) getpid());
-
+\&
test_kcmp("Compare duplicate FDs from different processes:",
getpid(), getppid(), fd1, fd1);
-
+\&
fd2 = open(pathname, O_CREAT | O_RDWR, 0600);
if (fd2 == \-1)
err(EXIT_FAILURE, "open");
printf("Child opened file on FD %d\en", fd2);
-
+\&
test_kcmp("Compare FDs from distinct open()s in same process:",
getpid(), getpid(), fd1, fd2);
-
+\&
fd3 = dup(fd1);
if (fd3 == \-1)
err(EXIT_FAILURE, "dup");
printf("Child duplicated FD %d to create FD %d\en", fd1, fd3);
-
+\&
test_kcmp("Compare duplicated FDs in same process:",
getpid(), getpid(), fd1, fd3);
break;
-
+\&
default:
wait(NULL);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/keyctl.2 b/man2/keyctl.2
index ef0729de6..e6972cb03 100644
--- a/man2/keyctl.2
+++ b/man2/keyctl.2
@@ -2010,7 +2010,7 @@ we can see the command-line arguments supplied to our example program:
.EX
$ \fBcat /tmp/key_instantiate.log\fP
Time: Mon Nov 7 13:06:47 2016
-
+\&
Command line arguments:
argv[0]: /sbin/request\-key
operation: create
@@ -2020,7 +2020,7 @@ Command line arguments:
thread_keyring: 0
process_keyring: 0
session_keyring: 256e6a6
-
+\&
Key description: user;1000;1000;3f010000;mykey
Auth key payload: somepayloaddata
Destination keyring: 256e6a6
@@ -2075,7 +2075,7 @@ $ \fBcat /proc/keys | egrep \[aq]mykey|256e6a6\[aq]\fP
.\" SRC BEGIN (key_instantiate.c)
.EX
/* key_instantiate.c */
-
+\&
#include <errno.h>
#include <keyutils.h>
#include <stdint.h>
@@ -2084,11 +2084,11 @@ $ \fBcat /proc/keys | egrep \[aq]mykey|256e6a6\[aq]\fP
#include <string.h>
#include <sys/types.h>
#include <time.h>
-
+\&
#ifndef KEY_SPEC_REQUESTOR_KEYRING
#define KEY_SPEC_REQUESTOR_KEYRING (\-8)
#endif
-
+\&
int
main(int argc, char *argv[])
{
@@ -2103,22 +2103,22 @@ main(int argc, char *argv[])
time_t t;
key_serial_t key_to_instantiate, dest_keyring;
key_serial_t thread_keyring, process_keyring, session_keyring;
-
+\&
if (argc != 8) {
fprintf(stderr, "Usage: %s op key uid gid thread_keyring "
"process_keyring session_keyring\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fp = fopen("/tmp/key_instantiate.log", "w");
if (fp == NULL)
exit(EXIT_FAILURE);
-
+\&
setbuf(fp, NULL);
-
+\&
t = time(NULL);
fprintf(fp, "Time: %s\en", ctime(&t));
-
+\&
/*
* The kernel passes a fixed set of arguments to the program
* that it execs; fetch them.
@@ -2130,7 +2130,7 @@ main(int argc, char *argv[])
thread_keyring = atoi(argv[5]);
process_keyring = atoi(argv[6]);
session_keyring = atoi(argv[7]);
-
+\&
fprintf(fp, "Command line arguments:\en");
fprintf(fp, " argv[0]: %s\en", argv[0]);
fprintf(fp, " operation: %s\en", operation);
@@ -2145,7 +2145,7 @@ main(int argc, char *argv[])
fprintf(fp, " session_keyring: %jx\en",
(uintmax_t) session_keyring);
fprintf(fp, "\en");
-
+\&
/*
* Assume the authority to instantiate the key named in argv[2].
*/
@@ -2154,7 +2154,7 @@ main(int argc, char *argv[])
strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
/*
* Fetch the description of the key that is to be instantiated.
*/
@@ -2163,9 +2163,9 @@ main(int argc, char *argv[])
fprintf(fp, "KEYCTL_DESCRIBE failed: %s\en", strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
fprintf(fp, "Key description: %s\en", dbuf);
-
+\&
/*
* Fetch the payload of the authorization key, which is
* actually the callout data given to request_key().
@@ -2176,10 +2176,10 @@ main(int argc, char *argv[])
fprintf(fp, "KEYCTL_READ failed: %s\en", strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
auth_key_payload[akp_size] = \[aq]\e0\[aq];
fprintf(fp, "Auth key payload: %s\en", auth_key_payload);
-
+\&
/*
* For interest, get the ID of the authorization key and
* display it.
@@ -2191,9 +2191,9 @@ main(int argc, char *argv[])
strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
fprintf(fp, "Auth key ID: %jx\en", (uintmax_t) auth_key);
-
+\&
/*
* Fetch key ID for the request_key(2) destination keyring.
*/
@@ -2204,9 +2204,9 @@ main(int argc, char *argv[])
strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
fprintf(fp, "Destination keyring: %jx\en", (uintmax_t) dest_keyring);
-
+\&
/*
* Fetch the description of the authorization key. This
* allows us to see the key type, UID, GID, permissions,
@@ -2220,9 +2220,9 @@ main(int argc, char *argv[])
fprintf(fp, "KEYCTL_DESCRIBE failed: %s\en", strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
fprintf(fp, "Auth key description: %s\en", dbuf);
-
+\&
/*
* Instantiate the key using the callout data that was supplied
* in the payload of the authorization key.
@@ -2234,7 +2234,7 @@ main(int argc, char *argv[])
strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/listxattr.2 b/man2/listxattr.2
index 3387c6493..30a4d8230 100644
--- a/man2/listxattr.2
+++ b/man2/listxattr.2
@@ -201,18 +201,18 @@ user.empty: <no value>
#include <stdlib.h>
#include <string.h>
#include <sys/xattr.h>
-
+\&
int
main(int argc, char *argv[])
{
char *buf, *key, *val;
ssize_t buflen, keylen, vallen;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s path\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/*
* Determine the length of the buffer needed.
*/
@@ -225,7 +225,7 @@ main(int argc, char *argv[])
printf("%s has no attributes.\en", argv[1]);
exit(EXIT_SUCCESS);
}
-
+\&
/*
* Allocate the buffer.
*/
@@ -234,7 +234,7 @@ main(int argc, char *argv[])
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Copy the list of attribute keys to the buffer.
*/
@@ -243,7 +243,7 @@ main(int argc, char *argv[])
perror("listxattr");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Loop over the list of zero terminated strings with the
* attribute keys. Use the remaining buffer length to determine
@@ -251,21 +251,21 @@ main(int argc, char *argv[])
*/
key = buf;
while (buflen > 0) {
-
+\&
/*
* Output attribute key.
*/
printf("%s: ", key);
-
+\&
/*
* Determine length of the value.
*/
vallen = getxattr(argv[1], key, NULL, 0);
if (vallen == \-1)
perror("getxattr");
-
+\&
if (vallen > 0) {
-
+\&
/*
* Allocate value buffer.
* One extra byte is needed to append 0x00.
@@ -275,7 +275,7 @@ main(int argc, char *argv[])
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Copy value to buffer.
*/
@@ -289,14 +289,14 @@ main(int argc, char *argv[])
val[vallen] = 0;
printf("%s", val);
}
-
+\&
free(val);
} else if (vallen == 0) {
printf("<no value>");
}
-
+\&
printf("\en");
-
+\&
/*
* Forward to next attribute key.
*/
@@ -304,7 +304,7 @@ main(int argc, char *argv[])
buflen \-= keylen;
key += keylen;
}
-
+\&
free(buf);
exit(EXIT_SUCCESS);
}
diff --git a/man2/membarrier.2 b/man2/membarrier.2
index 1df4249b5..eeb52f6de 100644
--- a/man2/membarrier.2
+++ b/man2/membarrier.2
@@ -319,9 +319,9 @@ following code (x86) can be transformed using
.\" SRC BEGIN (membarrier.c)
.EX
#include <stdlib.h>
-
+\&
static volatile int a, b;
-
+\&
static void
fast_path(int *read_b)
{
@@ -329,7 +329,7 @@ fast_path(int *read_b)
asm volatile ("mfence" : : : "memory");
*read_b = b;
}
-
+\&
static void
slow_path(int *read_a)
{
@@ -337,29 +337,29 @@ slow_path(int *read_a)
asm volatile ("mfence" : : : "memory");
*read_a = a;
}
-
+\&
int
main(void)
{
int read_a, read_b;
-
+\&
/*
* Real applications would call fast_path() and slow_path()
* from different threads. Call those from main() to keep
* this example short.
*/
-
+\&
slow_path(&read_a);
fast_path(&read_b);
-
+\&
/*
* read_b == 0 implies read_a == 1 and
* read_a == 0 implies read_b == 1.
*/
-
+\&
if (read_b == 0 && read_a == 0)
abort();
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -378,37 +378,37 @@ becomes:
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/membarrier.h>
-
+\&
static volatile int a, b;
-
+\&
static int
membarrier(int cmd, unsigned int flags, int cpu_id)
{
return syscall(__NR_membarrier, cmd, flags, cpu_id);
}
-
+\&
static int
init_membarrier(void)
{
int ret;
-
+\&
/* Check that membarrier() is supported. */
-
+\&
ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0);
if (ret < 0) {
perror("membarrier");
return \-1;
}
-
+\&
if (!(ret & MEMBARRIER_CMD_GLOBAL)) {
fprintf(stderr,
"membarrier does not support MEMBARRIER_CMD_GLOBAL\en");
return \-1;
}
-
+\&
return 0;
}
-
+\&
static void
fast_path(int *read_b)
{
@@ -416,7 +416,7 @@ fast_path(int *read_b)
asm volatile ("" : : : "memory");
*read_b = b;
}
-
+\&
static void
slow_path(int *read_a)
{
@@ -424,32 +424,32 @@ slow_path(int *read_a)
membarrier(MEMBARRIER_CMD_GLOBAL, 0, 0);
*read_a = a;
}
-
+\&
int
main(int argc, char *argv[])
{
int read_a, read_b;
-
+\&
if (init_membarrier())
exit(EXIT_FAILURE);
-
+\&
/*
* Real applications would call fast_path() and slow_path()
* from different threads. Call those from main() to keep
* this example short.
*/
-
+\&
slow_path(&read_a);
fast_path(&read_b);
-
+\&
/*
* read_b == 0 implies read_a == 1 and
* read_a == 0 implies read_b == 1.
*/
-
+\&
if (read_b == 0 && read_a == 0)
abort();
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/memfd_create.2 b/man2/memfd_create.2
index 3274b3983..873163719 100644
--- a/man2/memfd_create.2
+++ b/man2/memfd_create.2
@@ -414,7 +414,7 @@ Existing seals: WRITE SHRINK
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -422,7 +422,7 @@ main(int argc, char *argv[])
char *name, *seals_arg;
ssize_t len;
unsigned int seals;
-
+\&
if (argc < 3) {
fprintf(stderr, "%s name size [seals]\en", argv[0]);
fprintf(stderr, "\et\[aq]seals\[aq] can contain any of the "
@@ -434,35 +434,35 @@ main(int argc, char *argv[])
fprintf(stderr, "\et\etS \- F_SEAL_SEAL\en");
exit(EXIT_FAILURE);
}
-
+\&
name = argv[1];
len = atoi(argv[2]);
seals_arg = argv[3];
-
+\&
/* Create an anonymous file in tmpfs; allow seals to be
placed on the file. */
-
+\&
fd = memfd_create(name, MFD_ALLOW_SEALING);
if (fd == \-1)
err(EXIT_FAILURE, "memfd_create");
-
+\&
/* Size the file as specified on the command line. */
-
+\&
if (ftruncate(fd, len) == \-1)
err(EXIT_FAILURE, "truncate");
-
+\&
printf("PID: %jd; fd: %d; /proc/%jd/fd/%d\en",
(intmax_t) getpid(), fd, (intmax_t) getpid(), fd);
-
+\&
/* Code to map the file and populate the mapping with data
omitted. */
-
+\&
/* If a \[aq]seals\[aq] command\-line argument was supplied, set some
seals on the file. */
-
+\&
if (seals_arg != NULL) {
seals = 0;
-
+\&
if (strchr(seals_arg, \[aq]g\[aq]) != NULL)
seals |= F_SEAL_GROW;
if (strchr(seals_arg, \[aq]s\[aq]) != NULL)
@@ -473,16 +473,16 @@ main(int argc, char *argv[])
seals |= F_SEAL_FUTURE_WRITE;
if (strchr(seals_arg, \[aq]S\[aq]) != NULL)
seals |= F_SEAL_SEAL;
-
+\&
if (fcntl(fd, F_ADD_SEALS, seals) == \-1)
err(EXIT_FAILURE, "fcntl");
}
-
+\&
/* Keep running, so that the file created by memfd_create()
continues to exist. */
-
+\&
pause();
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -496,26 +496,26 @@ main(int argc, char *argv[])
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd;
unsigned int seals;
-
+\&
if (argc != 2) {
fprintf(stderr, "%s /proc/PID/fd/FD\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_RDWR);
if (fd == \-1)
err(EXIT_FAILURE, "open");
-
+\&
seals = fcntl(fd, F_GET_SEALS);
if (seals == \-1)
err(EXIT_FAILURE, "fcntl");
-
+\&
printf("Existing seals:");
if (seals & F_SEAL_SEAL)
printf(" SEAL");
@@ -528,10 +528,10 @@ main(int argc, char *argv[])
if (seals & F_SEAL_SHRINK)
printf(" SHRINK");
printf("\en");
-
+\&
/* Code to map the file and access the contents of the
resulting mapping omitted. */
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/mmap.2 b/man2/mmap.2
index 8b8e11b1a..3d8181ebb 100644
--- a/man2/mmap.2
+++ b/man2/mmap.2
@@ -941,10 +941,10 @@ to output the desired bytes.
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
int
main(int argc, char *argv[])
{
@@ -954,55 +954,55 @@ main(int argc, char *argv[])
size_t length;
ssize_t s;
struct stat sb;
-
+\&
if (argc < 3 || argc > 4) {
fprintf(stderr, "%s file offset [length]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_RDONLY);
if (fd == \-1)
handle_error("open");
-
+\&
if (fstat(fd, &sb) == \-1) /* To obtain file size */
handle_error("fstat");
-
+\&
offset = atoi(argv[2]);
pa_offset = offset & \[ti](sysconf(_SC_PAGE_SIZE) \- 1);
/* offset for mmap() must be page aligned */
-
+\&
if (offset >= sb.st_size) {
fprintf(stderr, "offset is past end of file\en");
exit(EXIT_FAILURE);
}
-
+\&
if (argc == 4) {
length = atoi(argv[3]);
if (offset + length > sb.st_size)
length = sb.st_size \- offset;
/* Can\[aq]t display bytes past end of file */
-
+\&
} else { /* No length arg ==> display to end of file */
length = sb.st_size \- offset;
}
-
+\&
addr = mmap(NULL, length + offset \- pa_offset, PROT_READ,
MAP_PRIVATE, fd, pa_offset);
if (addr == MAP_FAILED)
handle_error("mmap");
-
+\&
s = write(STDOUT_FILENO, addr + offset \- pa_offset, length);
if (s != length) {
if (s == \-1)
handle_error("write");
-
+\&
fprintf(stderr, "partial write");
exit(EXIT_FAILURE);
}
-
+\&
munmap(addr, length + offset \- pa_offset);
close(fd);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/mount_setattr.2 b/man2/mount_setattr.2
index 8df02641a..efccd5b53 100644
--- a/man2/mount_setattr.2
+++ b/man2/mount_setattr.2
@@ -10,8 +10,6 @@ Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
-
-.PP
.BR "#include <linux/fcntl.h>" " /* Definition of " AT_* " constants */"
.BR "#include <linux/mount.h>" " /* Definition of " MOUNT_ATTR_* " constants */"
.BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
@@ -175,19 +173,19 @@ are equivalent to the following steps:
.in +4n
.EX
unsigned int current_mnt_flags = mnt\->mnt_flags;
-
+\&
/*
* Clear all flags set in .attr_clr,
* clearing MOUNT_ATTR_NOEXEC and MOUNT_ATTR_NODEV.
*/
current_mnt_flags &= \(tiattr\->attr_clr;
-
+\&
/*
* Now set all flags set in .attr_set,
* applying MOUNT_ATTR_RDONLY and MOUNT_ATTR_NOSUID.
*/
current_mnt_flags |= attr\->attr_set;
-
+\&
mnt\->mnt_flags = current_mnt_flags;
.EE
.in
@@ -912,7 +910,7 @@ with a structure which has every byte nonzero
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
static inline int
mount_setattr(int dirfd, const char *pathname, unsigned int flags,
struct mount_attr *attr, size_t size)
@@ -920,13 +918,13 @@ mount_setattr(int dirfd, const char *pathname, unsigned int flags,
return syscall(SYS_mount_setattr, dirfd, pathname, flags,
attr, size);
}
-
+\&
static inline int
open_tree(int dirfd, const char *filename, unsigned int flags)
{
return syscall(SYS_open_tree, dirfd, filename, flags);
}
-
+\&
static inline int
move_mount(int from_dirfd, const char *from_pathname,
int to_dirfd, const char *to_pathname, unsigned int flags)
@@ -934,7 +932,7 @@ move_mount(int from_dirfd, const char *from_pathname,
return syscall(SYS_move_mount, from_dirfd, from_pathname,
to_dirfd, to_pathname, flags);
}
-
+\&
static const struct option longopts[] = {
{"map\-mount", required_argument, NULL, \[aq]a\[aq]},
{"recursive", no_argument, NULL, \[aq]b\[aq]},
@@ -945,7 +943,7 @@ static const struct option longopts[] = {
{"no\-access\-time", no_argument, NULL, \[aq]g\[aq]},
{ NULL, 0, NULL, 0 },
};
-
+\&
int
main(int argc, char *argv[])
{
@@ -957,7 +955,7 @@ main(int argc, char *argv[])
const char *source;
const char *target;
struct mount_attr *attr = &(struct mount_attr){};
-
+\&
while ((ret = getopt_long_only(argc, argv, "",
longopts, &index)) != \-1) {
switch (ret) {
@@ -989,13 +987,13 @@ main(int argc, char *argv[])
errx(EXIT_FAILURE, "Invalid argument specified");
}
}
-
+\&
if ((argc \- optind) < 2)
errx(EXIT_FAILURE, "Missing source or target mount point");
-
+\&
source = argv[optind];
target = argv[optind + 1];
-
+\&
/* In the following, \-1 as the \[aq]dirfd\[aq] argument ensures that
open_tree() fails if \[aq]source\[aq] is not an absolute pathname. */
.\" Christian Brauner
@@ -1010,36 +1008,36 @@ main(int argc, char *argv[])
.\" resolve-flag space have made this **chef's kiss**.
.\" If I can't operate based on a well-known dirfd I use absolute paths
.\" with a -EBADF dirfd passed to *at() functions.
-
+\&
fd_tree = open_tree(\-1, source,
OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC |
AT_EMPTY_PATH | (recursive ? AT_RECURSIVE : 0));
if (fd_tree == \-1)
err(EXIT_FAILURE, "open(%s)", source);
-
+\&
if (fd_userns >= 0) {
attr\->attr_set |= MOUNT_ATTR_IDMAP;
attr\->userns_fd = fd_userns;
}
-
+\&
ret = mount_setattr(fd_tree, "",
AT_EMPTY_PATH | (recursive ? AT_RECURSIVE : 0),
attr, sizeof(struct mount_attr));
if (ret == \-1)
err(EXIT_FAILURE, "mount_setattr");
-
+\&
close(fd_userns);
-
+\&
/* In the following, \-1 as the \[aq]to_dirfd\[aq] argument ensures that
open_tree() fails if \[aq]target\[aq] is not an absolute pathname. */
-
+\&
ret = move_mount(fd_tree, "", \-1, target,
MOVE_MOUNT_F_EMPTY_PATH);
if (ret == \-1)
err(EXIT_FAILURE, "move_mount() to %s", target);
-
+\&
close(fd_tree);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/mprotect.2 b/man2/mprotect.2
index 5a829dafe..1fe3e6a13 100644
--- a/man2/mprotect.2
+++ b/man2/mprotect.2
@@ -301,12 +301,12 @@ Got SIGSEGV at address: 0x804e000
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static char *buffer;
-
+\&
static void
handler(int sig, siginfo_t *si, void *unused)
{
@@ -315,43 +315,43 @@ handler(int sig, siginfo_t *si, void *unused)
printf() is not async\-signal\-safe; see signal\-safety(7).
Nevertheless, we use printf() here as a simple way of
showing that the handler was called. */
-
+\&
printf("Got SIGSEGV at address: %p\en", si\->si_addr);
exit(EXIT_FAILURE);
}
-
+\&
int
main(void)
{
int pagesize;
struct sigaction sa;
-
+\&
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
if (sigaction(SIGSEGV, &sa, NULL) == \-1)
handle_error("sigaction");
-
+\&
pagesize = sysconf(_SC_PAGE_SIZE);
if (pagesize == \-1)
handle_error("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");
-
+\&
printf("Start of region: %p\en", buffer);
-
+\&
if (mprotect(buffer + pagesize * 2, pagesize,
PROT_READ) == \-1)
handle_error("mprotect");
-
+\&
for (char *p = buffer ; ; )
*(p++) = \[aq]a\[aq];
-
+\&
printf("Loop completed\en"); /* Should never happen */
exit(EXIT_SUCCESS);
}
diff --git a/man2/msgop.2 b/man2/msgop.2
index ee4f11419..55e78ddc2 100644
--- a/man2/msgop.2
+++ b/man2/msgop.2
@@ -553,7 +553,7 @@ The following shell session shows a sample run of the program:
.EX
.RB "$" " ./a.out \-s"
sent: a message at Wed Mar 4 16:25:45 2015
-
+.PP
.RB "$" " ./a.out \-r"
message received: a message at Wed Mar 4 16:25:45 2015
.EE
@@ -569,18 +569,18 @@ message received: a message at Wed Mar 4 16:25:45 2015
#include <sys/msg.h>
#include <time.h>
#include <unistd.h>
-
+\&
struct msgbuf {
long mtype;
char mtext[80];
};
-
+\&
static void
usage(char *prog_name, char *msg)
{
if (msg != NULL)
fputs(msg, stderr);
-
+\&
fprintf(stderr, "Usage: %s [options]\en", prog_name);
fprintf(stderr, "Options are:\en");
fprintf(stderr, "\-s send message using msgsnd()\en");
@@ -589,19 +589,19 @@ usage(char *prog_name, char *msg)
fprintf(stderr, "\-k message queue key (default is 1234)\en");
exit(EXIT_FAILURE);
}
-
+\&
static void
send_msg(int qid, int msgtype)
{
time_t t;
struct msgbuf msg;
-
+\&
msg.mtype = msgtype;
-
+\&
time(&t);
snprintf(msg.mtext, sizeof(msg.mtext), "a message at %s",
ctime(&t));
-
+\&
if (msgsnd(qid, &msg, sizeof(msg.mtext),
IPC_NOWAIT) == \-1)
{
@@ -610,12 +610,12 @@ send_msg(int qid, int msgtype)
}
printf("sent: %s\en", msg.mtext);
}
-
+\&
static void
get_msg(int qid, int msgtype)
{
struct msgbuf msg;
-
+\&
if (msgrcv(qid, &msg, sizeof(msg.mtext), msgtype,
MSG_NOERROR | IPC_NOWAIT) == \-1) {
if (errno != ENOMSG) {
@@ -627,7 +627,7 @@ get_msg(int qid, int msgtype)
printf("message received: %s\en", msg.mtext);
}
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -635,7 +635,7 @@ main(int argc, char *argv[])
int mode = 0; /* 1 = send, 2 = receive */
int msgtype = 1;
int msgkey = 1234;
-
+\&
while ((opt = getopt(argc, argv, "srt:k:")) != \-1) {
switch (opt) {
case \[aq]s\[aq]:
@@ -656,22 +656,22 @@ main(int argc, char *argv[])
usage(argv[0], "Unrecognized option\en");
}
}
-
+\&
if (mode == 0)
usage(argv[0], "must use either \-s or \-r option\en");
-
+\&
qid = msgget(msgkey, IPC_CREAT | 0666);
-
+\&
if (qid == \-1) {
perror("msgget");
exit(EXIT_FAILURE);
}
-
+\&
if (mode == 2)
get_msg(qid, msgtype);
else
send_msg(qid, msgtype);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/nfsservctl.2 b/man2/nfsservctl.2
index 7e0996f33..846c88595 100644
--- a/man2/nfsservctl.2
+++ b/man2/nfsservctl.2
@@ -37,7 +37,7 @@ filesystem; see
(only in Linux 2.4.x and earlier). */
#define NFSCTL_GETFH 6 /* Get a file handle (used by mountd(8))
(only in Linux 2.4.x and earlier). */
-
+\&
struct nfsctl_arg {
int ca_version; /* safeguard */
union {
@@ -49,7 +49,7 @@ struct nfsctl_arg {
unsigned int u_debug;
} u;
}
-
+\&
union nfsctl_res {
struct knfs_fh cr_getfh;
unsigned int cr_debug;
diff --git a/man2/open.2 b/man2/open.2
index b5aff887c..f79330a17 100644
--- a/man2/open.2
+++ b/man2/open.2
@@ -803,16 +803,16 @@ permanent, using code like the following:
char path[PATH_MAX];
fd = open("/path/to/dir", O_TMPFILE | O_RDWR,
S_IRUSR | S_IWUSR);
-
+\&
/* File I/O on \[aq]fd\[aq]... */
-
+\&
linkat(fd, "", AT_FDCWD, "/path/for/file", AT_EMPTY_PATH);
-
+\&
/* If the caller doesn\[aq]t have the CAP_DAC_READ_SEARCH
capability (needed to use AT_EMPTY_PATH with linkat(2)),
and there is a proc(5) filesystem mounted, then the
linkat(2) call above can be replaced with:
-
+\&
snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd);
linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file",
AT_SYMLINK_FOLLOW);
diff --git a/man2/open_by_handle_at.2 b/man2/open_by_handle_at.2
index bbdafb76d..4061faea9 100644
--- a/man2/open_by_handle_at.2
+++ b/man2/open_by_handle_at.2
@@ -533,31 +533,31 @@ open_by_handle_at: Stale NFS file handle
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
int mount_id, fhsize, flags, dirfd;
char *pathname;
struct file_handle *fhp;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s pathname\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
pathname = argv[1];
-
+\&
/* Allocate file_handle structure. */
-
+\&
fhsize = sizeof(*fhp);
fhp = malloc(fhsize);
if (fhp == NULL)
err(EXIT_FAILURE, "malloc");
-
+\&
/* Make an initial call to name_to_handle_at() to discover
the size required for file handle. */
-
+\&
dirfd = AT_FDCWD; /* For name_to_handle_at() calls */
flags = 0; /* For name_to_handle_at() calls */
fhp\->handle_bytes = 0;
@@ -568,28 +568,28 @@ main(int argc, char *argv[])
fprintf(stderr, "Unexpected result from name_to_handle_at()\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Reallocate file_handle structure with correct size. */
-
+\&
fhsize = sizeof(*fhp) + fhp\->handle_bytes;
fhp = realloc(fhp, fhsize); /* Copies fhp\->handle_bytes */
if (fhp == NULL)
err(EXIT_FAILURE, "realloc");
-
+\&
/* Get file handle from pathname supplied on command line. */
-
+\&
if (name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags) == \-1)
err(EXIT_FAILURE, "name_to_handle_at");
-
+\&
/* Write mount ID, file handle size, and file handle to stdout,
for later reuse by t_open_by_handle_at.c. */
-
+\&
printf("%d\en", mount_id);
printf("%u %d ", fhp\->handle_bytes, fhp\->handle_type);
for (size_t j = 0; j < fhp\->handle_bytes; j++)
printf(" %02x", fhp\->f_handle[j]);
printf("\en");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -606,13 +606,13 @@ main(int argc, char *argv[])
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
+\&
/* Scan /proc/self/mountinfo to find the line whose mount ID matches
\[aq]mount_id\[aq]. (An easier way to do this is to install and use the
\[aq]libmount\[aq] library provided by the \[aq]util\-linux\[aq] project.)
Open the corresponding mount path and return the resulting file
descriptor. */
-
+\&
static int
open_mount_path_by_id(int mount_id)
{
@@ -622,40 +622,40 @@ open_mount_path_by_id(int mount_id)
FILE *fp;
size_t lsize;
ssize_t nread;
-
+\&
fp = fopen("/proc/self/mountinfo", "r");
if (fp == NULL)
err(EXIT_FAILURE, "fopen");
-
+\&
found = 0;
linep = NULL;
while (!found) {
nread = getline(&linep, &lsize, fp);
if (nread == \-1)
break;
-
+\&
nread = sscanf(linep, "%d %*d %*s %*s %s",
&mi_mount_id, mount_path);
if (nread != 2) {
fprintf(stderr, "Bad sscanf()\en");
exit(EXIT_FAILURE);
}
-
+\&
if (mi_mount_id == mount_id)
found = 1;
}
free(linep);
-
+\&
fclose(fp);
-
+\&
if (!found) {
fprintf(stderr, "Could not find mount point\en");
exit(EXIT_FAILURE);
}
-
+\&
return open(mount_path, O_RDONLY);
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -666,69 +666,69 @@ main(int argc, char *argv[])
char *nextp;
ssize_t nread;
struct file_handle *fhp;
-
+\&
if ((argc > 1 && strcmp(argv[1], "\-\-help") == 0) || argc > 2) {
fprintf(stderr, "Usage: %s [mount\-path]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Standard input contains mount ID and file handle information:
-
+\&
Line 1: <mount_id>
Line 2: <handle_bytes> <handle_type> <bytes of handle in hex>
*/
-
+\&
if (fgets(line1, sizeof(line1), stdin) == NULL ||
fgets(line2, sizeof(line2), stdin) == NULL)
{
fprintf(stderr, "Missing mount_id / file handle\en");
exit(EXIT_FAILURE);
}
-
+\&
mount_id = atoi(line1);
-
+\&
handle_bytes = strtoul(line2, &nextp, 0);
-
+\&
/* Given handle_bytes, we can now allocate file_handle structure. */
-
+\&
fhp = malloc(sizeof(*fhp) + handle_bytes);
if (fhp == NULL)
err(EXIT_FAILURE, "malloc");
-
+\&
fhp\->handle_bytes = handle_bytes;
-
+\&
fhp\->handle_type = strtoul(nextp, &nextp, 0);
-
+\&
for (size_t j = 0; j < fhp\->handle_bytes; j++)
fhp\->f_handle[j] = strtoul(nextp, &nextp, 16);
-
+\&
/* Obtain file descriptor for mount point, either by opening
the pathname specified on the command line, or by scanning
/proc/self/mounts to find a mount that matches the \[aq]mount_id\[aq]
that we received from stdin. */
-
+\&
if (argc > 1)
mount_fd = open(argv[1], O_RDONLY);
else
mount_fd = open_mount_path_by_id(mount_id);
-
+\&
if (mount_fd == \-1)
err(EXIT_FAILURE, "opening mount fd");
-
+\&
/* Open file using handle and mount point. */
-
+\&
fd = open_by_handle_at(mount_fd, fhp, O_RDONLY);
if (fd == \-1)
err(EXIT_FAILURE, "open_by_handle_at");
-
+\&
/* Try reading a few bytes from the file. */
-
+\&
nread = read(fd, buf, sizeof(buf));
if (nread == \-1)
err(EXIT_FAILURE, "read");
-
+\&
printf("Read %zd bytes\en", nread);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index 61a62f7f4..aa23a4977 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -198,15 +198,15 @@ struct perf_event_attr {
__u32 type; /* Type of event */
__u32 size; /* Size of attribute structure */
__u64 config; /* Type\-specific configuration */
-
+\&
union {
__u64 sample_period; /* Period of sampling */
__u64 sample_freq; /* Frequency of sampling */
};
-
+\&
__u64 sample_type; /* Specifies values included in sample */
__u64 read_format; /* Specifies values returned in read */
-
+\&
__u64 disabled : 1, /* off by default */
inherit : 1, /* children inherit it */
pinned : 1, /* must always be on PMU */
@@ -252,23 +252,23 @@ struct perf_event_attr {
on exec */
sigtrap : 1, /* send synchronous SIGTRAP
on event */
-
+\&
__reserved_1 : 26;
-
+\&
union {
__u32 wakeup_events; /* wakeup every n events */
__u32 wakeup_watermark; /* bytes before wakeup */
};
-
+\&
__u32 bp_type; /* breakpoint type */
-
+\&
union {
__u64 bp_addr; /* breakpoint address */
__u64 kprobe_func; /* for perf_kprobe */
__u64 uprobe_path; /* for perf_uprobe */
__u64 config1; /* extension of config */
};
-
+\&
union {
__u64 bp_len; /* breakpoint length */
__u64 kprobe_addr; /* with kprobe_func == NULL */
@@ -287,7 +287,7 @@ struct perf_event_attr {
__u32 aux_sample_size; /* max aux sample size */
__u32 __reserved_3; /* align to u64 */
__u64 sig_data; /* user data for sigtrap */
-
+\&
};
.EE
.in
@@ -1725,7 +1725,7 @@ struct perf_event_mmap_page {
__u64 aux_tail;
__u64 aux_offset;
__u64 aux_size;
-
+\&
}
.EE
.in
@@ -1807,28 +1807,28 @@ the following code can be used to do a read:
u32 seq, time_mult, time_shift, idx, width;
u64 count, enabled, running;
u64 cyc, time_offset;
-
+\&
do {
seq = pc\->lock;
barrier();
enabled = pc\->time_enabled;
running = pc\->time_running;
-
+\&
if (pc\->cap_usr_time && enabled != running) {
cyc = rdtsc();
time_offset = pc\->time_offset;
time_mult = pc\->time_mult;
time_shift = pc\->time_shift;
}
-
+\&
idx = pc\->index;
count = pc\->offset;
-
+\&
if (pc\->cap_usr_rdpmc && idx) {
width = pc\->pmc_width;
count += rdpmc(idx \- 1);
}
-
+\&
barrier();
} while (pc\->lock != seq);
.EE
@@ -1874,7 +1874,7 @@ delta since
.EX
u64 quot, rem;
u64 delta;
-
+\&
quot = cyc >> time_shift;
rem = cyc & (((u64)1 << time_shift) \- 1);
delta = time_offset + quot * time_mult +
@@ -3930,25 +3930,25 @@ instruction count of a call to
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
static long
perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
int cpu, int group_fd, unsigned long flags)
{
int ret;
-
+\&
ret = syscall(SYS_perf_event_open, hw_event, pid, cpu,
group_fd, flags);
return ret;
}
-
+\&
int
main(void)
{
int fd;
long long count;
struct perf_event_attr pe;
-
+\&
memset(&pe, 0, sizeof(pe));
pe.type = PERF_TYPE_HARDWARE;
pe.size = sizeof(pe);
@@ -3956,23 +3956,23 @@ main(void)
pe.disabled = 1;
pe.exclude_kernel = 1;
pe.exclude_hv = 1;
-
+\&
fd = perf_event_open(&pe, 0, \-1, \-1, 0);
if (fd == \-1) {
fprintf(stderr, "Error opening leader %llx\en", pe.config);
exit(EXIT_FAILURE);
}
-
+\&
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
-
+\&
printf("Measuring instruction count for this printf\en");
-
+\&
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
read(fd, &count, sizeof(count));
-
+\&
printf("Used %lld instructions\en", count);
-
+\&
close(fd);
}
.EE
diff --git a/man2/pidfd_open.2 b/man2/pidfd_open.2
index 701abd419..a1eac4cf3 100644
--- a/man2/pidfd_open.2
+++ b/man2/pidfd_open.2
@@ -215,42 +215,42 @@ event.
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
static int
pidfd_open(pid_t pid, unsigned int flags)
{
return syscall(SYS_pidfd_open, pid, flags);
}
-
+\&
int
main(int argc, char *argv[])
{
int pidfd, ready;
struct pollfd pollfd;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <pid>\en", argv[0]);
exit(EXIT_SUCCESS);
}
-
+\&
pidfd = pidfd_open(atoi(argv[1]), 0);
if (pidfd == \-1) {
perror("pidfd_open");
exit(EXIT_FAILURE);
}
-
+\&
pollfd.fd = pidfd;
pollfd.events = POLLIN;
-
+\&
ready = poll(&pollfd, 1, \-1);
if (ready == \-1) {
perror("poll");
exit(EXIT_FAILURE);
}
-
+\&
printf("Events (%#x): POLLIN is %sset\en", pollfd.revents,
(pollfd.revents & POLLIN) ? "" : "not ");
-
+\&
close(pidfd);
exit(EXIT_SUCCESS);
}
diff --git a/man2/pidfd_send_signal.2 b/man2/pidfd_send_signal.2
index d44a369f3..3693664c0 100644
--- a/man2/pidfd_send_signal.2
+++ b/man2/pidfd_send_signal.2
@@ -175,42 +175,42 @@ fails with the error
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
static int
pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
unsigned int flags)
{
return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
}
-
+\&
int
main(int argc, char *argv[])
{
int pidfd, sig;
char path[PATH_MAX];
siginfo_t info;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <pid> <signal>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
sig = atoi(argv[2]);
-
+\&
/* Obtain a PID file descriptor by opening the /proc/PID directory
of the target process. */
-
+\&
snprintf(path, sizeof(path), "/proc/%s", argv[1]);
-
+\&
pidfd = open(path, O_RDONLY);
if (pidfd == \-1) {
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
/* Populate a \[aq]siginfo_t\[aq] structure for use with
pidfd_send_signal(). */
-
+\&
memset(&info, 0, sizeof(info));
info.si_code = SI_QUEUE;
info.si_signo = sig;
@@ -218,14 +218,14 @@ main(int argc, char *argv[])
info.si_uid = getuid();
info.si_pid = getpid();
info.si_value.sival_int = 1234;
-
+\&
/* Send the signal. */
-
+\&
if (pidfd_send_signal(pidfd, sig, &info, 0) == \-1) {
perror("pidfd_send_signal");
exit(EXIT_FAILURE);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/pipe.2 b/man2/pipe.2
index adf6d73bf..3634a8c27 100644
--- a/man2/pipe.2
+++ b/man2/pipe.2
@@ -248,40 +248,40 @@ and echoes it on standard output.
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int pipefd[2];
char buf;
pid_t cpid;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <string>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (pipe(pipefd) == \-1) {
perror("pipe");
exit(EXIT_FAILURE);
}
-
+\&
cpid = fork();
if (cpid == \-1) {
perror("fork");
exit(EXIT_FAILURE);
}
-
+\&
if (cpid == 0) { /* Child reads from pipe */
close(pipefd[1]); /* Close unused write end */
-
+\&
while (read(pipefd[0], &buf, 1) > 0)
write(STDOUT_FILENO, &buf, 1);
-
+\&
write(STDOUT_FILENO, "\en", 1);
close(pipefd[0]);
_exit(EXIT_SUCCESS);
-
+\&
} else { /* Parent writes argv[1] to pipe */
close(pipefd[0]); /* Close unused read end */
write(pipefd[1], argv[1], strlen(argv[1]));
diff --git a/man2/pivot_root.2 b/man2/pivot_root.2
index 6fa240c06..2035b58dd 100644
--- a/man2/pivot_root.2
+++ b/man2/pivot_root.2
@@ -300,7 +300,7 @@ hello world
.\" SRC BEGIN (pivot_root.c)
.EX
/* pivot_root_demo.c */
-
+\&
#define _GNU_SOURCE
#include <err.h>
#include <limits.h>
@@ -314,15 +314,15 @@ hello world
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
static int
pivot_root(const char *new_root, const char *put_old)
{
return syscall(SYS_pivot_root, new_root, put_old);
}
-
+\&
#define STACK_SIZE (1024 * 1024)
-
+\&
static int /* Startup function for cloned child */
child(void *arg)
{
@@ -330,70 +330,70 @@ child(void *arg)
char **args = arg;
char *new_root = args[0];
const char *put_old = "/oldrootfs";
-
+\&
/* Ensure that \[aq]new_root\[aq] and its parent mount don\[aq]t have
shared propagation (which would cause pivot_root() to
return an error), and prevent propagation of mount
events to the initial mount namespace. */
-
+\&
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) == \-1)
err(EXIT_FAILURE, "mount\-MS_PRIVATE");
-
+\&
/* Ensure that \[aq]new_root\[aq] is a mount point. */
-
+\&
if (mount(new_root, new_root, NULL, MS_BIND, NULL) == \-1)
err(EXIT_FAILURE, "mount\-MS_BIND");
-
+\&
/* Create directory to which old root will be pivoted. */
-
+\&
snprintf(path, sizeof(path), "%s/%s", new_root, put_old);
if (mkdir(path, 0777) == \-1)
err(EXIT_FAILURE, "mkdir");
-
+\&
/* And pivot the root filesystem. */
-
+\&
if (pivot_root(new_root, path) == \-1)
err(EXIT_FAILURE, "pivot_root");
-
+\&
/* Switch the current working directory to "/". */
-
+\&
if (chdir("/") == \-1)
err(EXIT_FAILURE, "chdir");
-
+\&
/* Unmount old root and remove mount point. */
-
+\&
if (umount2(put_old, MNT_DETACH) == \-1)
perror("umount2");
if (rmdir(put_old) == \-1)
perror("rmdir");
-
+\&
/* Execute the command specified in argv[1]... */
-
+\&
execv(args[1], &args[1]);
err(EXIT_FAILURE, "execv");
}
-
+\&
int
main(int argc, char *argv[])
{
char *stack;
-
+\&
/* Create a child process in a new mount namespace. */
-
+\&
stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, \-1, 0);
if (stack == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
-
+\&
if (clone(child, stack + STACK_SIZE,
CLONE_NEWNS | SIGCHLD, &argv[1]) == \-1)
err(EXIT_FAILURE, "clone");
-
+\&
/* Parent falls through to here; wait for child. */
-
+\&
if (wait(NULL) == \-1)
err(EXIT_FAILURE, "wait");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/poll.2 b/man2/poll.2
index 4e26e62d4..0b834306a 100644
--- a/man2/poll.2
+++ b/man2/poll.2
@@ -264,7 +264,7 @@ executing the following calls:
.EX
sigset_t origmask;
int timeout;
-
+\&
timeout = (tmo_p == NULL) ? \-1 :
(tmo_p\->tv_sec * 1000 + tmo_p\->tv_nsec / 1000000);
pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
@@ -506,7 +506,7 @@ About to poll()
Ready: 1
fd=3; events: POLLIN POLLHUP
read 6 bytes: ccccc
-
+\&
About to poll()
Ready: 1
fd=3; events: POLLHUP
@@ -548,7 +548,7 @@ at which point the file descriptor was closed and the program terminated.
.\" SRC BEGIN (poll_input.c)
.EX
/* poll_input.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <fcntl.h>
@@ -556,10 +556,10 @@ at which point the file descriptor was closed and the program terminated.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
int
main(int argc, char *argv[])
{
@@ -568,49 +568,49 @@ main(int argc, char *argv[])
nfds_t num_open_fds, nfds;
ssize_t s;
struct pollfd *pfds;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s file...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
num_open_fds = nfds = argc \- 1;
pfds = calloc(nfds, sizeof(struct pollfd));
if (pfds == NULL)
errExit("malloc");
-
+\&
/* Open each file on command line, and add it to \[aq]pfds\[aq] array. */
-
+\&
for (nfds_t j = 0; j < nfds; j++) {
pfds[j].fd = open(argv[j + 1], O_RDONLY);
if (pfds[j].fd == \-1)
errExit("open");
-
+\&
printf("Opened \e"%s\e" on fd %d\en", argv[j + 1], pfds[j].fd);
-
+\&
pfds[j].events = POLLIN;
}
-
+\&
/* Keep calling poll() as long as at least one file descriptor is
open. */
-
+\&
while (num_open_fds > 0) {
printf("About to poll()\en");
ready = poll(pfds, nfds, \-1);
if (ready == \-1)
errExit("poll");
-
+\&
printf("Ready: %d\en", ready);
-
+\&
/* Deal with array returned by poll(). */
-
+\&
for (nfds_t j = 0; j < nfds; j++) {
if (pfds[j].revents != 0) {
printf(" fd=%d; events: %s%s%s\en", pfds[j].fd,
(pfds[j].revents & POLLIN) ? "POLLIN " : "",
(pfds[j].revents & POLLHUP) ? "POLLHUP " : "",
(pfds[j].revents & POLLERR) ? "POLLERR " : "");
-
+\&
if (pfds[j].revents & POLLIN) {
s = read(pfds[j].fd, buf, sizeof(buf));
if (s == \-1)
@@ -626,7 +626,7 @@ main(int argc, char *argv[])
}
}
}
-
+\&
printf("All file descriptors closed; bye\en");
exit(EXIT_SUCCESS);
}
diff --git a/man2/process_vm_readv.2 b/man2/process_vm_readv.2
index 4ce4ec86a..4f484b161 100644
--- a/man2/process_vm_readv.2
+++ b/man2/process_vm_readv.2
@@ -283,7 +283,7 @@ and the second 10 bytes into
#include <stdlib.h>
#include <sys/types.h>
#include <sys/uio.h>
-
+\&
int
main(void)
{
@@ -293,18 +293,18 @@ main(void)
ssize_t nread;
struct iovec local[2];
struct iovec remote[1];
-
+\&
local[0].iov_base = buf1;
local[0].iov_len = 10;
local[1].iov_base = buf2;
local[1].iov_len = 10;
remote[0].iov_base = (void *) 0x10000;
remote[0].iov_len = 20;
-
+\&
nread = process_vm_readv(pid, local, 2, remote, 1, 0);
if (nread != 20)
exit(EXIT_FAILURE);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/quotactl.2 b/man2/quotactl.2
index 53506c211..5bf9ae71e 100644
--- a/man2/quotactl.2
+++ b/man2/quotactl.2
@@ -148,7 +148,7 @@ as follows:
.EX
/* uint64_t is an unsigned 64\-bit integer;
uint32_t is an unsigned 32\-bit integer */
-
+\&
struct dqblk { /* Definition since Linux 2.4.22 */
uint64_t dqb_bhardlimit; /* Absolute limit on disk
quota blocks alloc */
@@ -168,10 +168,10 @@ struct dqblk { /* Definition since Linux 2.4.22 */
uint32_t dqb_valid; /* Bit mask of QIF_*
constants */
};
-
+\&
/* Flags in dqb_valid that indicate which fields in
dqblk structure are valid. */
-
+\&
#define QIF_BLIMITS 1
#define QIF_SPACE 2
#define QIF_ILIMITS 4
@@ -271,7 +271,7 @@ as follows:
.EX
/* uint64_t is an unsigned 64\-bit integer;
uint32_t is an unsigned 32\-bit integer */
-
+\&
struct dqinfo { /* Defined since Linux 2.4.22 */
uint64_t dqi_bgrace; /* Time before block soft limit
becomes hard limit */
@@ -281,23 +281,23 @@ struct dqinfo { /* Defined since Linux 2.4.22 */
(DQF_*) */
uint32_t dqi_valid;
};
-
+\&
/* Bits for dqi_flags */
-
+\&
/* Quota format QFMT_VFS_OLD */
-
+\&
#define DQF_ROOT_SQUASH (1 << 0) /* Root squash enabled */
/* Before Linux v4.0, this had been defined
privately as V1_DQF_RSQUASH */
-
+\&
/* Quota format QFMT_VFS_V0 / QFMT_VFS_V1 */
-
+\&
#define DQF_SYS_FILE (1 << 16) /* Quota stored in
a system file */
-
+\&
/* Flags in dqi_valid that indicate which fields in
dqinfo structure are valid. */
-
+\&
#define IIF_BGRACE 1
#define IIF_IGRACE 2
#define IIF_FLAGS 4
@@ -443,13 +443,13 @@ as follows:
.EX
/* All the blk units are in BBs (Basic Blocks) of
512 bytes. */
-
+\&
#define FS_DQUOT_VERSION 1 /* fs_disk_quota.d_version */
-
+\&
#define XFS_USER_QUOTA (1<<0) /* User quota type */
#define XFS_PROJ_QUOTA (1<<1) /* Project quota type */
#define XFS_GROUP_QUOTA (1<<2) /* Group quota type */
-
+\&
struct fs_disk_quota {
int8_t d_version; /* Version of this structure */
int8_t d_flags; /* XFS_{USER,PROJ,GROUP}_QUOTA */
@@ -541,14 +541,14 @@ structure itself is defined as follows:
.in +4n
.EX
#define FS_QSTAT_VERSION 1 /* fs_quota_stat.qs_version */
-
+\&
struct fs_qfilestat {
uint64_t qfs_ino; /* Inode number */
uint64_t qfs_nblks; /* Number of BBs
512\-byte\-blocks */
uint32_t qfs_nextents; /* Number of extents */
};
-
+\&
struct fs_quota_stat {
int8_t qs_version; /* Version number for
future changes */
@@ -590,7 +590,7 @@ structure itself is defined as follows:
.in +4n
.EX
#define FS_QSTATV_VERSION1 1 /* fs_quota_statv.qs_version */
-
+\&
struct fs_qfilestatv {
uint64_t qfs_ino; /* Inode number */
uint64_t qfs_nblks; /* Number of BBs
@@ -598,7 +598,7 @@ struct fs_qfilestatv {
uint32_t qfs_nextents; /* Number of extents */
uint32_t qfs_pad; /* Pad for 8\-byte alignment */
};
-
+\&
struct fs_quota_statv {
int8_t qs_version; /* Version for future
changes */
diff --git a/man2/readlink.2 b/man2/readlink.2
index c911c4a7b..e0d191884 100644
--- a/man2/readlink.2
+++ b/man2/readlink.2
@@ -261,61 +261,61 @@ reports a size of zero.
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
char *buf;
ssize_t nbytes, bufsiz;
struct stat sb;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <pathname>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (lstat(argv[1], &sb) == \-1) {
perror("lstat");
exit(EXIT_FAILURE);
}
-
+\&
/* Add one to the link size, so that we can determine whether
the buffer returned by readlink() was truncated. */
-
+\&
bufsiz = sb.st_size + 1;
-
+\&
/* Some magic symlinks under (for example) /proc and /sys
report \[aq]st_size\[aq] as zero. In that case, take PATH_MAX as
a "good enough" estimate. */
-
+\&
if (sb.st_size == 0)
bufsiz = PATH_MAX;
-
+\&
buf = malloc(bufsiz);
if (buf == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
nbytes = readlink(argv[1], buf, bufsiz);
if (nbytes == \-1) {
perror("readlink");
exit(EXIT_FAILURE);
}
-
+\&
/* Print only \[aq]nbytes\[aq] of \[aq]buf\[aq], as it doesn't contain a terminating
null byte (\[aq]\e0\[aq]). */
printf("\[aq]%s\[aq] points to \[aq]%.*s\[aq]\en", argv[1], (int) nbytes, buf);
-
+\&
/* If the return value was equal to the buffer size, then the
the link target was larger than expected (perhaps because the
target was changed between the call to lstat() and the call to
readlink()). Warn the user that the returned target may have
been truncated. */
-
+\&
if (nbytes == bufsiz)
printf("(Returned buffer may have been truncated)\en");
-
+\&
free(buf);
exit(EXIT_SUCCESS);
}
diff --git a/man2/readv.2 b/man2/readv.2
index b80d7ff02..fa9b0e4e4 100644
--- a/man2/readv.2
+++ b/man2/readv.2
@@ -412,12 +412,12 @@ char *str0 = "hello ";
char *str1 = "world\en";
ssize_t nwritten;
struct iovec iov[2];
-
+\&
iov[0].iov_base = str0;
iov[0].iov_len = strlen(str0);
iov[1].iov_base = str1;
iov[1].iov_len = strlen(str1);
-
+\&
nwritten = writev(STDOUT_FILENO, iov, 2);
.EE
.in
diff --git a/man2/recv.2 b/man2/recv.2
index a81d6e290..660c103fb 100644
--- a/man2/recv.2
+++ b/man2/recv.2
@@ -155,7 +155,7 @@ structure:
#define SO_EE_ORIGIN_LOCAL 1
#define SO_EE_ORIGIN_ICMP 2
#define SO_EE_ORIGIN_ICMP6 3
-
+\&
struct sock_extended_err
{
uint32_t ee_errno; /* Error number */
@@ -167,7 +167,7 @@ struct sock_extended_err
uint32_t ee_data; /* Other data */
/* More data may follow */
};
-
+\&
struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);
.EE
.in
diff --git a/man2/recvmmsg.2 b/man2/recvmmsg.2
index b1d9f2a28..1cd76e526 100644
--- a/man2/recvmmsg.2
+++ b/man2/recvmmsg.2
@@ -213,7 +213,7 @@ can give the following output:
#include <string.h>
#include <sys/socket.h>
#include <time.h>
-
+\&
int
main(void)
{
@@ -226,13 +226,13 @@ main(void)
struct mmsghdr msgs[VLEN];
struct timespec timeout;
struct sockaddr_in addr;
-
+\&
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == \-1) {
perror("socket()");
exit(EXIT_FAILURE);
}
-
+\&
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(1234);
@@ -240,7 +240,7 @@ main(void)
perror("bind()");
exit(EXIT_FAILURE);
}
-
+\&
memset(msgs, 0, sizeof(msgs));
for (size_t i = 0; i < VLEN; i++) {
iovecs[i].iov_base = bufs[i];
@@ -248,16 +248,16 @@ main(void)
msgs[i].msg_hdr.msg_iov = &iovecs[i];
msgs[i].msg_hdr.msg_iovlen = 1;
}
-
+\&
timeout.tv_sec = TIMEOUT;
timeout.tv_nsec = 0;
-
+\&
retval = recvmmsg(sockfd, msgs, VLEN, 0, &timeout);
if (retval == \-1) {
perror("recvmmsg()");
exit(EXIT_FAILURE);
}
-
+\&
printf("%d messages received\en", retval);
for (size_t i = 0; i < retval; i++) {
bufs[i][msgs[i].msg_len] = 0;
diff --git a/man2/request_key.2 b/man2/request_key.2
index 2d9416ba8..e090f647d 100644
--- a/man2/request_key.2
+++ b/man2/request_key.2
@@ -502,32 +502,32 @@ For another example of the use of this program, see
.\" SRC BEGIN (t_request_key.c)
.EX
/* t_request_key.c */
-
+\&
#include <keyutils.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
key_serial_t key;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage: %s type description callout\-data\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
key = request_key(argv[1], argv[2], argv[3],
KEY_SPEC_SESSION_KEYRING);
if (key == \-1) {
perror("request_key");
exit(EXIT_FAILURE);
}
-
+\&
printf("Key ID is %jx\en", (uintmax_t) key);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/sched_setaffinity.2 b/man2/sched_setaffinity.2
index 01e4a4f9e..958d14cd2 100644
--- a/man2/sched_setaffinity.2
+++ b/man2/sched_setaffinity.2
@@ -351,50 +351,50 @@ sys 12.07
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int parentCPU, childCPU;
cpu_set_t set;
unsigned int nloops;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage: %s parent\-cpu child\-cpu num\-loops\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
parentCPU = atoi(argv[1]);
childCPU = atoi(argv[2]);
nloops = atoi(argv[3]);
-
+\&
CPU_ZERO(&set);
-
+\&
switch (fork()) {
case \-1: /* Error */
err(EXIT_FAILURE, "fork");
-
+\&
case 0: /* Child */
CPU_SET(childCPU, &set);
-
+\&
if (sched_setaffinity(getpid(), sizeof(set), &set) == \-1)
err(EXIT_FAILURE, "sched_setaffinity");
-
+\&
for (unsigned int j = 0; j < nloops; j++)
getppid();
-
+\&
exit(EXIT_SUCCESS);
-
+\&
default: /* Parent */
CPU_SET(parentCPU, &set);
-
+\&
if (sched_setaffinity(getpid(), sizeof(set), &set) == \-1)
err(EXIT_FAILURE, "sched_setaffinity");
-
+\&
for (unsigned int j = 0; j < nloops; j++)
getppid();
-
+\&
wait(NULL); /* Wait for child to terminate */
exit(EXIT_SUCCESS);
}
diff --git a/man2/seccomp.2 b/man2/seccomp.2
index ecfdb8696..b5020b883 100644
--- a/man2/seccomp.2
+++ b/man2/seccomp.2
@@ -1114,71 +1114,71 @@ cecilia
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
#define X32_SYSCALL_BIT 0x40000000
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
+\&
static int
install_filter(int syscall_nr, unsigned int t_arch, int f_errno)
{
unsigned int upper_nr_limit = 0xffffffff;
-
+\&
/* Assume that AUDIT_ARCH_X86_64 means the normal x86\-64 ABI
(in the x32 ABI, all system calls have bit 30 set in the
\[aq]nr\[aq] field, meaning the numbers are >= X32_SYSCALL_BIT). */
if (t_arch == AUDIT_ARCH_X86_64)
upper_nr_limit = X32_SYSCALL_BIT \- 1;
-
+\&
struct sock_filter filter[] = {
/* [0] Load architecture from \[aq]seccomp_data\[aq] buffer into
accumulator. */
BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
(offsetof(struct seccomp_data, arch))),
-
+\&
/* [1] Jump forward 5 instructions if architecture does not
match \[aq]t_arch\[aq]. */
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, t_arch, 0, 5),
-
+\&
/* [2] Load system call number from \[aq]seccomp_data\[aq] buffer into
accumulator. */
BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
(offsetof(struct seccomp_data, nr))),
-
+\&
/* [3] Check ABI \- only needed for x86\-64 in deny\-list use
cases. Use BPF_JGT instead of checking against the bit
mask to avoid having to reload the syscall number. */
BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, upper_nr_limit, 3, 0),
-
+\&
/* [4] Jump forward 1 instruction if system call number
does not match \[aq]syscall_nr\[aq]. */
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, syscall_nr, 0, 1),
-
+\&
/* [5] Matching architecture and system call: don\[aq]t execute
the system call, and return \[aq]f_errno\[aq] in \[aq]errno\[aq]. */
BPF_STMT(BPF_RET | BPF_K,
SECCOMP_RET_ERRNO | (f_errno & SECCOMP_RET_DATA)),
-
+\&
/* [6] Destination of system call number mismatch: allow other
system calls. */
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
-
+\&
/* [7] Destination of architecture mismatch: kill process. */
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
};
-
+\&
struct sock_fprog prog = {
.len = ARRAY_SIZE(filter),
.filter = filter,
};
-
+\&
if (syscall(SYS_seccomp, SECCOMP_SET_MODE_FILTER, 0, &prog)) {
perror("seccomp");
return 1;
}
-
+\&
return 0;
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -1190,17 +1190,17 @@ main(int argc, char *argv[])
"\en", argv[0], AUDIT_ARCH_I386, AUDIT_ARCH_X86_64);
exit(EXIT_FAILURE);
}
-
+\&
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
perror("prctl");
exit(EXIT_FAILURE);
}
-
+\&
if (install_filter(strtol(argv[1], NULL, 0),
strtoul(argv[2], NULL, 0),
strtol(argv[3], NULL, 0)))
exit(EXIT_FAILURE);
-
+\&
execv(argv[4], &argv[4]);
perror("execv");
exit(EXIT_FAILURE);
diff --git a/man2/seccomp_unotify.2 b/man2/seccomp_unotify.2
index 4fde10db1..32f183704 100644
--- a/man2/seccomp_unotify.2
+++ b/man2/seccomp_unotify.2
@@ -847,21 +847,21 @@ operation (here, to emulate a call to
.EX
.in +4n
int fd, removeFd;
-
+\&
fd = openat(req\->data.args[0], path, req\->data.args[2],
req\->data.args[3]);
-
+\&
struct seccomp_notif_addfd addfd;
addfd.id = req\->id; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */
addfd.srcfd = fd;
addfd.newfd = 0;
addfd.flags = 0;
addfd.newfd_flags = O_CLOEXEC;
-
+\&
targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
-
+\&
close(fd); /* No longer needed in supervisor */
-
+\&
struct seccomp_notif_resp *resp;
/* Code to allocate 'resp' omitted */
resp\->id = req\->id;
@@ -1252,14 +1252,14 @@ call.
.EX
$ \fB./seccomp_unotify /tmp/x\fP
T: PID = 23168
-
+\&
T: about to mkdir("/tmp/x")
S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168
S: executing: mkdir("/tmp/x", 0700)
S: success! spoofed return = 6
S: sending response (flags = 0; val = 6; error = 0)
T: SUCCESS: mkdir(2) returned 6
-
+\&
T: terminating
S: target has terminated; bye
.EE
@@ -1287,13 +1287,13 @@ call.
.EX
$ \fB./seccomp_unotify ./sub\fP
T: PID = 23204
-
+\&
T: about to mkdir("./sub")
S: got notification (ID 0xddb16abe25b4c12) for PID 23204
S: target can execute system call
S: sending response (flags = 0x1; val = 0; error = 0)
T: SUCCESS: mkdir(2) returned 0
-
+\&
T: terminating
S: target has terminated; bye
.EE
@@ -1312,13 +1312,13 @@ call (which is not executed):
.EX
$ \fB./seccomp_unotify /xxx\fP
T: PID = 23178
-
+\&
T: about to mkdir("/xxx")
S: got notification (ID 0xe7dc095d1c524e80) for PID 23178
S: spoofing error response (Operation not supported)
S: sending response (flags = 0; val = 0; error = \-95)
T: ERROR: mkdir(2): Operation not supported
-
+\&
T: terminating
S: target has terminated; bye
.EE
@@ -1342,14 +1342,14 @@ call.
.EX
$ \fB./seccomp_unotify /tmp/nosuchdir/b\fP
T: PID = 23199
-
+\&
T: about to mkdir("/tmp/nosuchdir/b")
S: got notification (ID 0x8744454293506046) for PID 23199
S: executing: mkdir("/tmp/nosuchdir/b", 0700)
S: failure! (errno = 2; No such file or directory)
S: sending response (flags = 0; val = 0; error = \-2)
T: ERROR: mkdir(2): No such file or directory
-
+\&
T: terminating
S: target has terminated; bye
.EE
@@ -1375,17 +1375,17 @@ This is demonstrated by the following example:
.EX
$ \fB./seccomp_unotify /bye /tmp/y\fP
T: PID = 23185
-
+\&
T: about to mkdir("/bye")
S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185
S: spoofing error response (Operation not supported)
S: sending response (flags = 0; val = 0; error = \-95)
S: terminating **********
T: ERROR: mkdir(2): Operation not supported
-
+\&
T: about to mkdir("/tmp/y")
T: ERROR: mkdir(2): Function not implemented
-
+\&
T: terminating
.EE
.in
@@ -1416,12 +1416,12 @@ T: terminating
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
-
+\&
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
+\&
/* Send the file descriptor \[aq]fd\[aq] over the connected UNIX domain socket
\[aq]sockfd\[aq]. Returns 0 on success, or \-1 on error. */
-
+\&
static int
sendfd(int sockfd, int fd)
{
@@ -1429,7 +1429,7 @@ sendfd(int sockfd, int fd)
struct iovec iov;
struct msghdr msgh;
struct cmsghdr *cmsgp;
-
+\&
/* Allocate a char array of suitable size to hold the ancillary data.
However, since this buffer is in reality a \[aq]struct cmsghdr\[aq], use a
union to ensure that it is suitably aligned. */
@@ -1438,48 +1438,48 @@ sendfd(int sockfd, int fd)
/* Space large enough to hold an \[aq]int\[aq] */
struct cmsghdr align;
} controlMsg;
-
+\&
/* The \[aq]msg_name\[aq] field can be used to specify the address of the
destination socket when sending a datagram. However, we do not
need to use this field because \[aq]sockfd\[aq] is a connected socket. */
-
+\&
msgh.msg_name = NULL;
msgh.msg_namelen = 0;
-
+\&
/* On Linux, we must transmit at least one byte of real data in
order to send ancillary data. We transmit an arbitrary integer
whose value is ignored by recvfd(). */
-
+\&
msgh.msg_iov = &iov;
msgh.msg_iovlen = 1;
iov.iov_base = &data;
iov.iov_len = sizeof(int);
data = 12345;
-
+\&
/* Set \[aq]msghdr\[aq] fields that describe ancillary data */
-
+\&
msgh.msg_control = controlMsg.buf;
msgh.msg_controllen = sizeof(controlMsg.buf);
-
+\&
/* Set up ancillary data describing file descriptor to send */
-
+\&
cmsgp = CMSG_FIRSTHDR(&msgh);
cmsgp\->cmsg_level = SOL_SOCKET;
cmsgp\->cmsg_type = SCM_RIGHTS;
cmsgp\->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));
-
+\&
/* Send real plus ancillary data */
-
+\&
if (sendmsg(sockfd, &msgh, 0) == \-1)
return \-1;
-
+\&
return 0;
}
-
+\&
/* Receive a file descriptor on a connected UNIX domain socket. Returns
the received file descriptor on success, or \-1 on error. */
-
+\&
static int
recvfd(int sockfd)
{
@@ -1487,7 +1487,7 @@ recvfd(int sockfd)
ssize_t nr;
struct iovec iov;
struct msghdr msgh;
-
+\&
/* Allocate a char buffer for the ancillary data. See the comments
in sendfd() */
union {
@@ -1495,35 +1495,35 @@ recvfd(int sockfd)
struct cmsghdr align;
} controlMsg;
struct cmsghdr *cmsgp;
-
+\&
/* The \[aq]msg_name\[aq] field can be used to obtain the address of the
sending socket. However, we do not need this information. */
-
+\&
msgh.msg_name = NULL;
msgh.msg_namelen = 0;
-
+\&
/* Specify buffer for receiving real data */
-
+\&
msgh.msg_iov = &iov;
msgh.msg_iovlen = 1;
iov.iov_base = &data; /* Real data is an \[aq]int\[aq] */
iov.iov_len = sizeof(int);
-
+\&
/* Set \[aq]msghdr\[aq] fields that describe ancillary data */
-
+\&
msgh.msg_control = controlMsg.buf;
msgh.msg_controllen = sizeof(controlMsg.buf);
-
+\&
/* Receive real plus ancillary data; real data is ignored */
-
+\&
nr = recvmsg(sockfd, &msgh, 0);
if (nr == \-1)
return \-1;
-
+\&
cmsgp = CMSG_FIRSTHDR(&msgh);
-
+\&
/* Check the validity of the \[aq]cmsghdr\[aq] */
-
+\&
if (cmsgp == NULL
|| cmsgp\->cmsg_len != CMSG_LEN(sizeof(int))
|| cmsgp\->cmsg_level != SOL_SOCKET
@@ -1532,37 +1532,37 @@ recvfd(int sockfd)
errno = EINVAL;
return \-1;
}
-
+\&
/* Return the received file descriptor to our caller */
-
+\&
memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));
return fd;
}
-
+\&
static void
sigchldHandler(int sig)
{
char msg[] = "\etS: target has terminated; bye\en";
-
+\&
write(STDOUT_FILENO, msg, sizeof(msg) \- 1);
_exit(EXIT_SUCCESS);
}
-
+\&
static int
seccomp(unsigned int operation, unsigned int flags, void *args)
{
return syscall(SYS_seccomp, operation, flags, args);
}
-
+\&
/* The following is the x86\-64\-specific BPF boilerplate code for checking
that the BPF program is running on the right architecture + ABI. At
completion of these instructions, the accumulator contains the system
call number. */
-
+\&
/* For the x32 ABI, all system call numbers have bit 30 set */
-
+\&
#define X32_SYSCALL_BIT 0x40000000
-
+\&
#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \e
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \e
(offsetof(struct seccomp_data, arch))), \e
@@ -1571,50 +1571,50 @@ seccomp(unsigned int operation, unsigned int flags, void *args)
(offsetof(struct seccomp_data, nr))), \e
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \e
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)
-
+\&
/* installNotifyFilter() installs a seccomp filter that generates
user\-space notifications (SECCOMP_RET_USER_NOTIF) when the process
calls mkdir(2); the filter allows all other system calls.
-
+\&
The function return value is a file descriptor from which the
user\-space notifications can be fetched. */
-
+\&
static int
installNotifyFilter(void)
{
int notifyFd;
-
+\&
struct sock_filter filter[] = {
X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,
-
+\&
/* mkdir() triggers notification to user\-space supervisor */
-
+\&
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),
BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),
-
+\&
/* Every other system call is allowed */
-
+\&
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
};
-
+\&
struct sock_fprog prog = {
.len = ARRAY_SIZE(filter),
.filter = filter,
};
-
+\&
/* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;
as a result, seccomp() returns a notification file descriptor. */
-
+\&
notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,
SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);
if (notifyFd == \-1)
err(EXIT_FAILURE, "seccomp\-install\-notify\-filter");
-
+\&
return notifyFd;
}
-
+\&
/* Close a pair of sockets created by socketpair() */
-
+\&
static void
closeSocketPair(int sockPair[2])
{
@@ -1623,96 +1623,96 @@ closeSocketPair(int sockPair[2])
if (close(sockPair[1]) == \-1)
err(EXIT_FAILURE, "closeSocketPair\-close\-1");
}
-
+\&
/* Implementation of the target process; create a child process that:
-
+\&
(1) installs a seccomp filter with the
SECCOMP_FILTER_FLAG_NEW_LISTENER flag;
(2) writes the seccomp notification file descriptor returned from
the previous step onto the UNIX domain socket, \[aq]sockPair[0]\[aq];
(3) calls mkdir(2) for each element of \[aq]argv\[aq].
-
+\&
The function return value in the parent is the PID of the child
process; the child does not return from this function. */
-
+\&
static pid_t
targetProcess(int sockPair[2], char *argv[])
{
int notifyFd, s;
pid_t targetPid;
-
+\&
targetPid = fork();
-
+\&
if (targetPid == \-1)
err(EXIT_FAILURE, "fork");
-
+\&
if (targetPid > 0) /* In parent, return PID of child */
return targetPid;
-
+\&
/* Child falls through to here */
-
+\&
printf("T: PID = %ld\en", (long) getpid());
-
+\&
/* Install seccomp filter(s) */
-
+\&
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
err(EXIT_FAILURE, "prctl");
-
+\&
notifyFd = installNotifyFilter();
-
+\&
/* Pass the notification file descriptor to the tracing process over
a UNIX domain socket */
-
+\&
if (sendfd(sockPair[0], notifyFd) == \-1)
err(EXIT_FAILURE, "sendfd");
-
+\&
/* Notification and socket FDs are no longer needed in target */
-
+\&
if (close(notifyFd) == \-1)
err(EXIT_FAILURE, "close\-target\-notify\-fd");
-
+\&
closeSocketPair(sockPair);
-
+\&
/* Perform a mkdir() call for each of the command\-line arguments */
-
+\&
for (char **ap = argv; *ap != NULL; ap++) {
printf("\enT: about to mkdir(\e"%s\e")\en", *ap);
-
+\&
s = mkdir(*ap, 0700);
if (s == \-1)
perror("T: ERROR: mkdir(2)");
else
printf("T: SUCCESS: mkdir(2) returned %d\en", s);
}
-
+\&
printf("\enT: terminating\en");
exit(EXIT_SUCCESS);
}
-
+\&
/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV
operation is still valid. It will no longer be valid if the target
process has terminated or is no longer blocked in the system call that
generated the notification (because it was interrupted by a signal).
-
+\&
This operation can be used when doing such things as accessing
/proc/PID files in the target process in order to avoid TOCTOU race
conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV
terminates and is reused by another process. */
-
+\&
static bool
cookieIsValid(int notifyFd, uint64_t id)
{
return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;
}
-
+\&
/* Access the memory of the target process in order to fetch the
pathname referred to by the system call argument \[aq]argNum\[aq] in
\[aq]req\->data.args[]\[aq]. The pathname is returned in \[aq]path\[aq],
a buffer of \[aq]len\[aq] bytes allocated by the caller.
-
+\&
Returns true if the pathname is successfully fetched, and false
otherwise. For possible causes of failure, see the comments below. */
-
+\&
static bool
getTargetPathname(struct seccomp_notif *req, int notifyFd,
int argNum, char *path, size_t len)
@@ -1720,13 +1720,13 @@ getTargetPathname(struct seccomp_notif *req, int notifyFd,
int procMemFd;
char procMemPath[PATH_MAX];
ssize_t nread;
-
+\&
snprintf(procMemPath, sizeof(procMemPath), "/proc/%d/mem", req\->pid);
-
+\&
procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);
if (procMemFd == \-1)
return false;
-
+\&
/* Check that the process whose info we are accessing is still alive
and blocked in the system call that caused the notification.
If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in
@@ -1734,21 +1734,21 @@ getTargetPathname(struct seccomp_notif *req, int notifyFd,
descriptor that we opened corresponded to the process for which we
received a notification. If that process subsequently terminates,
then read() on that file descriptor will return 0 (EOF). */
-
+\&
if (!cookieIsValid(notifyFd, req\->id)) {
close(procMemFd);
return false;
}
-
+\&
/* Read bytes at the location containing the pathname argument */
-
+\&
nread = pread(procMemFd, path, len, req\->data.args[argNum]);
-
+\&
close(procMemFd);
-
+\&
if (nread <= 0)
return false;
-
+\&
/* Once again check that the notification ID is still valid. The
case we are particularly concerned about here is that just
before we fetched the pathname, the target\[aq]s blocked system
@@ -1757,12 +1757,12 @@ getTargetPathname(struct seccomp_notif *req, int notifyFd,
system call). In that case, we have no guarantees about what we
are reading, since the target\[aq]s memory may have been arbitrarily
changed by subsequent operations. */
-
+\&
if (!cookieIsValid(notifyFd, req\->id)) {
perror("\etS: notification ID check failed!!!");
return false;
}
-
+\&
/* Even if the target\[aq]s system call was not interrupted by a signal,
we have no guarantees about what was in the memory of the target
process. (The memory may have been modified by another thread, or
@@ -1770,35 +1770,35 @@ getTargetPathname(struct seccomp_notif *req, int notifyFd,
buffer returned by pread() as untrusted input. The buffer should
contain a terminating null byte; if not, then we will trigger an
error for the target process. */
-
+\&
if (strnlen(path, nread) < nread)
return true;
-
+\&
return false;
}
-
+\&
/* Allocate buffers for the seccomp user\-space notification request and
response structures. It is the caller\[aq]s responsibility to free the
buffers returned via \[aq]req\[aq] and \[aq]resp\[aq]. */
-
+\&
static void
allocSeccompNotifBuffers(struct seccomp_notif **req,
struct seccomp_notif_resp **resp,
struct seccomp_notif_sizes *sizes)
{
size_t resp_size;
-
+\&
/* Discover the sizes of the structures that are used to receive
notifications and send notification responses, and allocate
buffers of those sizes. */
-
+\&
if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == \-1)
err(EXIT_FAILURE, "seccomp\-SECCOMP_GET_NOTIF_SIZES");
-
+\&
*req = malloc(sizes\->seccomp_notif);
if (*req == NULL)
err(EXIT_FAILURE, "malloc\-seccomp_notif");
-
+\&
/* When allocating the response buffer, we must allow for the fact
that the user\-space binary may have been built with user\-space
headers where \[aq]struct seccomp_notif_resp\[aq] is bigger than the
@@ -1807,20 +1807,20 @@ allocSeccompNotifBuffers(struct seccomp_notif **req,
ensures that if the supervisor places bytes into the response
structure that are past the response size that the kernel expects,
then the supervisor is not touching an invalid memory location. */
-
+\&
resp_size = sizes\->seccomp_notif_resp;
if (sizeof(struct seccomp_notif_resp) > resp_size)
resp_size = sizeof(struct seccomp_notif_resp);
-
+\&
*resp = malloc(resp_size);
if (*resp == NULL)
err(EXIT_FAILURE, "malloc\-seccomp_notif_resp");
-
+\&
}
-
+\&
/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file
descriptor, \[aq]notifyFd\[aq]. */
-
+\&
static void
handleNotifications(int notifyFd)
{
@@ -1829,45 +1829,45 @@ handleNotifications(int notifyFd)
struct seccomp_notif *req;
struct seccomp_notif_resp *resp;
struct seccomp_notif_sizes sizes;
-
+\&
allocSeccompNotifBuffers(&req, &resp, &sizes);
-
+\&
/* Loop handling notifications */
-
+\&
for (;;) {
-
+\&
/* Wait for next notification, returning info in \[aq]*req\[aq] */
-
+\&
memset(req, 0, sizes.seccomp_notif);
if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == \-1) {
if (errno == EINTR)
continue;
err(EXIT_FAILURE, "\etS: ioctl\-SECCOMP_IOCTL_NOTIF_RECV");
}
-
+\&
printf("\etS: got notification (ID %#llx) for PID %d\en",
req\->id, req\->pid);
-
+\&
/* The only system call that can generate a notification event
is mkdir(2). Nevertheless, we check that the notified system
call is indeed mkdir() as kind of future\-proofing of this
code in case the seccomp filter is later modified to
generate notifications for other system calls. */
-
+\&
if (req\->data.nr != SYS_mkdir) {
printf("\etS: notification contained unexpected "
"system call number; bye!!!\en");
exit(EXIT_FAILURE);
}
-
+\&
pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));
-
+\&
/* Prepopulate some fields of the response */
-
+\&
resp\->id = req\->id; /* Response includes notification ID */
resp\->flags = 0;
resp\->val = 0;
-
+\&
/* If getTargetPathname() failed, trigger an EINVAL error
response (sending this response may yield an error if the
failure occurred because the notification ID was no longer
@@ -1876,7 +1876,7 @@ handleNotifications(int notifyFd)
kernel to let the target process execute the mkdir();
otherwise, give an error for a directory pathname in any other
location. */
-
+\&
if (!pathOK) {
resp\->error = \-EINVAL;
printf("\etS: spoofing error for invalid pathname (%s)\en",
@@ -1884,7 +1884,7 @@ handleNotifications(int notifyFd)
} else if (strncmp(path, "/tmp/", strlen("/tmp/")) == 0) {
printf("\etS: executing: mkdir(\e"%s\e", %#llo)\en",
path, req\->data.args[1]);
-
+\&
if (mkdir(path, req\->data.args[1]) == 0) {
resp\->error = 0; /* "Success" */
resp\->val = strlen(path); /* Used as return value of
@@ -1892,10 +1892,10 @@ handleNotifications(int notifyFd)
printf("\etS: success! spoofed return = %lld\en",
resp\->val);
} else {
-
+\&
/* If mkdir() failed in the supervisor, pass the error
back to the target */
-
+\&
resp\->error = \-errno;
printf("\etS: failure! (errno = %d; %s)\en", errno,
strerror(errno));
@@ -1909,13 +1909,13 @@ handleNotifications(int notifyFd)
printf("\etS: spoofing error response (%s)\en",
strerror(\-resp\->error));
}
-
+\&
/* Send a response to the notification */
-
+\&
printf("\etS: sending response "
"(flags = %#x; val = %lld; error = %d)\en",
resp\->flags, resp\->val, resp\->error);
-
+\&
if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == \-1) {
if (errno == ENOENT)
printf("\etS: response failed with ENOENT; "
@@ -1924,79 +1924,79 @@ handleNotifications(int notifyFd)
else
perror("ioctl\-SECCOMP_IOCTL_NOTIF_SEND");
}
-
+\&
/* If the pathname is just "/bye", then the supervisor breaks out
of the loop and terminates. This allows us to see what happens
if the target process makes further calls to mkdir(2). */
-
+\&
if (strcmp(path, "/bye") == 0)
break;
}
-
+\&
free(req);
free(resp);
printf("\etS: terminating **********\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Implementation of the supervisor process:
-
+\&
(1) obtains the notification file descriptor from \[aq]sockPair[1]\[aq]
(2) handles notifications that arrive on that file descriptor. */
-
+\&
static void
supervisor(int sockPair[2])
{
int notifyFd;
-
+\&
notifyFd = recvfd(sockPair[1]);
-
+\&
if (notifyFd == \-1)
err(EXIT_FAILURE, "recvfd");
-
+\&
closeSocketPair(sockPair); /* We no longer need the socket pair */
-
+\&
handleNotifications(notifyFd);
}
-
+\&
int
main(int argc, char *argv[])
{
int sockPair[2];
struct sigaction sa;
-
+\&
setbuf(stdout, NULL);
-
+\&
if (argc < 2) {
fprintf(stderr, "At least one pathname argument is required\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Create a UNIX domain socket that is used to pass the seccomp
notification file descriptor from the target process to the
supervisor process. */
-
+\&
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == \-1)
err(EXIT_FAILURE, "socketpair");
-
+\&
/* Create a child process\-\-the "target"\-\-that installs seccomp
filtering. The target process writes the seccomp notification
file descriptor onto \[aq]sockPair[0]\[aq] and then calls mkdir(2) for
each directory in the command\-line arguments. */
-
+\&
(void) targetProcess(sockPair, &argv[optind]);
-
+\&
/* Catch SIGCHLD when the target terminates, so that the
supervisor can also terminate. */
-
+\&
sa.sa_handler = sigchldHandler;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGCHLD, &sa, NULL) == \-1)
err(EXIT_FAILURE, "sigaction");
-
+\&
supervisor(sockPair);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/select.2 b/man2/select.2
index fd592a3b2..ef01cc85e 100644
--- a/man2/select.2
+++ b/man2/select.2
@@ -304,7 +304,7 @@ executing the following calls:
.in +4n
.EX
sigset_t origmask;
-
+\&
pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
ready = select(nfds, &readfds, &writefds, &exceptfds, timeout);
pthread_sigmask(SIG_SETMASK, &origmask, NULL);
@@ -714,27 +714,27 @@ to a local variable and passing that variable to the system call.
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
-
+\&
int
main(void)
{
int retval;
fd_set rfds;
struct timeval tv;
-
+\&
/* Watch stdin (fd 0) to see when it has input. */
-
+\&
FD_ZERO(&rfds);
FD_SET(0, &rfds);
-
+\&
/* Wait up to five seconds. */
-
+\&
tv.tv_sec = 5;
tv.tv_usec = 0;
-
+\&
retval = select(1, &rfds, NULL, NULL, &tv);
/* Don\[aq]t rely on the value of tv now! */
-
+\&
if (retval == \-1)
perror("select()");
else if (retval)
@@ -742,7 +742,7 @@ main(void)
/* FD_ISSET(0, &rfds) will be true. */
else
printf("No data within five seconds.\en");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/select_tut.2 b/man2/select_tut.2
index 8fb04e9d4..80db88f5e 100644
--- a/man2/select_tut.2
+++ b/man2/select_tut.2
@@ -85,13 +85,13 @@ Our program would look like:
.PP
.EX
static volatile sig_atomic_t got_SIGCHLD = 0;
-
+\&
static void
child_sig_handler(int sig)
{
got_SIGCHLD = 1;
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -99,14 +99,14 @@ main(int argc, char *argv[])
struct sigaction sa;
fd_set readfds, writefds, exceptfds;
int r;
-
+\&
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == \-1) {
perror("sigprocmask");
exit(EXIT_FAILURE);
}
-
+\&
sa.sa_flags = 0;
sa.sa_handler = child_sig_handler;
sigemptyset(&sa.sa_mask);
@@ -114,26 +114,26 @@ main(int argc, char *argv[])
perror("sigaction");
exit(EXIT_FAILURE);
}
-
+\&
sigemptyset(&empty_mask);
-
+\&
for (;;) { /* main loop */
/* Initialize readfds, writefds, and exceptfds
before the pselect() call. (Code omitted.) */
-
+\&
r = pselect(nfds, &readfds, &writefds, &exceptfds,
NULL, &empty_mask);
if (r == \-1 && errno != EINTR) {
/* Handle error */
}
-
+\&
if (got_SIGCHLD) {
got_SIGCHLD = 0;
-
+\&
/* Handle signalled event here; e.g., wait() for all
terminated children. (Code omitted.) */
}
-
+\&
/* main body of program */
}
}
@@ -345,25 +345,25 @@ from one TCP port to another.
#include <sys/select.h>
#include <sys/socket.h>
#include <unistd.h>
-
+\&
static int forward_port;
-
+\&
#undef max
#define max(x, y) ((x) > (y) ? (x) : (y))
-
+\&
static int
listen_socket(int listen_port)
{
int lfd;
int yes;
struct sockaddr_in addr;
-
+\&
lfd = socket(AF_INET, SOCK_STREAM, 0);
if (lfd == \-1) {
perror("socket");
return \-1;
}
-
+\&
yes = 1;
if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,
&yes, sizeof(yes)) == \-1)
@@ -372,7 +372,7 @@ listen_socket(int listen_port)
close(lfd);
return \-1;
}
-
+\&
memset(&addr, 0, sizeof(addr));
addr.sin_port = htons(listen_port);
addr.sin_family = AF_INET;
@@ -381,34 +381,34 @@ listen_socket(int listen_port)
close(lfd);
return \-1;
}
-
+\&
printf("accepting connections on port %d\en", listen_port);
listen(lfd, 10);
return lfd;
}
-
+\&
static int
connect_socket(int connect_port, char *address)
{
int cfd;
struct sockaddr_in addr;
-
+\&
cfd = socket(AF_INET, SOCK_STREAM, 0);
if (cfd == \-1) {
perror("socket");
return \-1;
}
-
+\&
memset(&addr, 0, sizeof(addr));
addr.sin_port = htons(connect_port);
addr.sin_family = AF_INET;
-
+\&
if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {
fprintf(stderr, "inet_aton(): bad IP address format\en");
close(cfd);
return \-1;
}
-
+\&
if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == \-1) {
perror("connect()");
shutdown(cfd, SHUT_RDWR);
@@ -417,7 +417,7 @@ connect_socket(int connect_port, char *address)
}
return cfd;
}
-
+\&
#define SHUT_FD1 do { \e
if (fd1 >= 0) { \e
shutdown(fd1, SHUT_RDWR); \e
@@ -425,7 +425,7 @@ connect_socket(int connect_port, char *address)
fd1 = \-1; \e
} \e
} while (0)
-
+\&
#define SHUT_FD2 do { \e
if (fd2 >= 0) { \e
shutdown(fd2, SHUT_RDWR); \e
@@ -433,9 +433,9 @@ connect_socket(int connect_port, char *address)
fd2 = \-1; \e
} \e
} while (0)
-
+\&
#define BUF_SIZE 1024
-
+\&
int
main(int argc, char *argv[])
{
@@ -447,42 +447,42 @@ main(int argc, char *argv[])
char buf1[BUF_SIZE], buf2[BUF_SIZE];
fd_set readfds, writefds, exceptfds;
ssize_t nbytes;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage\en\etfwd <listen\-port> "
"<forward\-to\-port> <forward\-to\-ip\-address>\en");
exit(EXIT_FAILURE);
}
-
+\&
signal(SIGPIPE, SIG_IGN);
-
+\&
forward_port = atoi(argv[2]);
-
+\&
h = listen_socket(atoi(argv[1]));
if (h == \-1)
exit(EXIT_FAILURE);
-
+\&
for (;;) {
nfds = 0;
-
+\&
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(h, &readfds);
nfds = max(nfds, h);
-
+\&
if (fd1 > 0 && buf1_avail < BUF_SIZE)
FD_SET(fd1, &readfds);
/* Note: nfds is updated below, when fd1 is added to
exceptfds. */
if (fd2 > 0 && buf2_avail < BUF_SIZE)
FD_SET(fd2, &readfds);
-
+\&
if (fd1 > 0 && buf2_avail \- buf2_written > 0)
FD_SET(fd1, &writefds);
if (fd2 > 0 && buf1_avail \- buf1_written > 0)
FD_SET(fd2, &writefds);
-
+\&
if (fd1 > 0) {
FD_SET(fd1, &exceptfds);
nfds = max(nfds, fd1);
@@ -491,22 +491,22 @@ main(int argc, char *argv[])
FD_SET(fd2, &exceptfds);
nfds = max(nfds, fd2);
}
-
+\&
ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);
-
+\&
if (ready == \-1 && errno == EINTR)
continue;
-
+\&
if (ready == \-1) {
perror("select()");
exit(EXIT_FAILURE);
}
-
+\&
if (FD_ISSET(h, &readfds)) {
socklen_t addrlen;
struct sockaddr_in client_addr;
int fd;
-
+\&
addrlen = sizeof(client_addr);
memset(&client_addr, 0, addrlen);
fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);
@@ -524,19 +524,19 @@ main(int argc, char *argv[])
else
printf("connect from %s\en",
inet_ntoa(client_addr.sin_addr));
-
+\&
/* Skip any events on the old, closed file
descriptors. */
-
+\&
continue;
}
}
-
+\&
/* NB: read OOB data before normal reads. */
-
+\&
if (fd1 > 0 && FD_ISSET(fd1, &exceptfds)) {
char c;
-
+\&
nbytes = recv(fd1, &c, 1, MSG_OOB);
if (nbytes < 1)
SHUT_FD1;
@@ -545,7 +545,7 @@ main(int argc, char *argv[])
}
if (fd2 > 0 && FD_ISSET(fd2, &exceptfds)) {
char c;
-
+\&
nbytes = recv(fd2, &c, 1, MSG_OOB);
if (nbytes < 1)
SHUT_FD2;
@@ -584,17 +584,17 @@ main(int argc, char *argv[])
else
buf1_written += nbytes;
}
-
+\&
/* Check if write data has caught read data. */
-
+\&
if (buf1_written == buf1_avail)
buf1_written = buf1_avail = 0;
if (buf2_written == buf2_avail)
buf2_written = buf2_avail = 0;
-
+\&
/* One side has closed the connection, keep
writing to the other side until empty. */
-
+\&
if (fd1 < 0 && buf1_avail \- buf1_written == 0)
SHUT_FD2;
if (fd2 < 0 && buf2_avail \- buf2_written == 0)
diff --git a/man2/semget.2 b/man2/semget.2
index a89550585..4164ed709 100644
--- a/man2/semget.2
+++ b/man2/semget.2
@@ -324,7 +324,7 @@ ID = 9
$ \fB./t_semget \-c mykey2 p 2\fP
ID = 10
$ \fBipcs \-s\fP
-
+\&
\-\-\-\-\-\- Semaphore Arrays \-\-\-\-\-\-\-\-
key semid owner perms nsems
0x7004136d 9 mtk 600 1
@@ -368,7 +368,7 @@ ID = 9
.\" SRC BEGIN (t_semget.c)
.EX
/* t_semget.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <stdio.h>
@@ -376,7 +376,7 @@ ID = 9
#include <sys/ipc.h>
#include <sys/sem.h>
#include <unistd.h>
-
+\&
static void
usage(const char *pname)
{
@@ -386,13 +386,13 @@ usage(const char *pname)
fprintf(stderr, " \-x Use IPC_EXCL flag\en");
exit(EXIT_FAILURE);
}
-
+\&
int
main(int argc, char *argv[])
{
int semid, nsems, flags, opt;
key_t key;
-
+\&
flags = 0;
while ((opt = getopt(argc, argv, "cx")) != \-1) {
switch (opt) {
@@ -401,26 +401,26 @@ main(int argc, char *argv[])
default: usage(argv[0]);
}
}
-
+\&
if (argc != optind + 3)
usage(argv[0]);
-
+\&
key = ftok(argv[optind], argv[optind + 1][0]);
if (key == \-1) {
perror("ftok");
exit(EXIT_FAILURE);
}
-
+\&
nsems = atoi(argv[optind + 2]);
-
+\&
semid = semget(key, nsems, flags | 0600);
if (semid == \-1) {
perror("semget");
exit(EXIT_FAILURE);
}
-
+\&
printf("ID = %d\en", semid);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/semop.2 b/man2/semop.2
index fe2906be4..4dd1ef19e 100644
--- a/man2/semop.2
+++ b/man2/semop.2
@@ -490,17 +490,17 @@ and then increment the semaphore value by one.
.EX
struct sembuf sops[2];
int semid;
-
+\&
/* Code to set \fIsemid\fP omitted */
-
+\&
sops[0].sem_num = 0; /* Operate on semaphore 0 */
sops[0].sem_op = 0; /* Wait for value to equal 0 */
sops[0].sem_flg = 0;
-
+\&
sops[1].sem_num = 0; /* Operate on semaphore 0 */
sops[1].sem_op = 1; /* Increment value by one */
sops[1].sem_flg = 0;
-
+\&
if (semop(semid, sops, 2) == \-1) {
perror("semop");
exit(EXIT_FAILURE);
diff --git a/man2/sendmmsg.2 b/man2/sendmmsg.2
index b9f4786ac..010cd9a76 100644
--- a/man2/sendmmsg.2
+++ b/man2/sendmmsg.2
@@ -174,7 +174,7 @@ The contents of the first datagram originates from a pair of buffers.
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
-
+\&
int
main(void)
{
@@ -183,13 +183,13 @@ main(void)
struct iovec msg1[2], msg2;
struct mmsghdr msg[2];
struct sockaddr_in addr;
-
+\&
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == \-1) {
perror("socket()");
exit(EXIT_FAILURE);
}
-
+\&
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(1234);
@@ -197,30 +197,30 @@ main(void)
perror("connect()");
exit(EXIT_FAILURE);
}
-
+\&
memset(msg1, 0, sizeof(msg1));
msg1[0].iov_base = "one";
msg1[0].iov_len = 3;
msg1[1].iov_base = "two";
msg1[1].iov_len = 3;
-
+\&
memset(&msg2, 0, sizeof(msg2));
msg2.iov_base = "three";
msg2.iov_len = 5;
-
+\&
memset(msg, 0, sizeof(msg));
msg[0].msg_hdr.msg_iov = msg1;
msg[0].msg_hdr.msg_iovlen = 2;
-
+\&
msg[1].msg_hdr.msg_iov = &msg2;
msg[1].msg_hdr.msg_iovlen = 1;
-
+\&
retval = sendmmsg(sockfd, msg, 2, 0);
if (retval == \-1)
perror("sendmmsg()");
else
printf("%d messages sent\en", retval);
-
+\&
exit(0);
}
.EE
diff --git a/man2/setns.2 b/man2/setns.2
index b4ce783f4..6f117b49f 100644
--- a/man2/setns.2
+++ b/man2/setns.2
@@ -382,28 +382,28 @@ bizarro
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd;
-
+\&
if (argc < 3) {
fprintf(stderr, "%s /proc/PID/ns/FILE cmd args...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Get file descriptor for namespace; the file descriptor is opened
with O_CLOEXEC so as to ensure that it is not inherited by the
program that is later executed. */
-
+\&
fd = open(argv[1], O_RDONLY | O_CLOEXEC);
if (fd == \-1)
err(EXIT_FAILURE, "open");
-
+\&
if (setns(fd, 0) == \-1) /* Join that namespace */
err(EXIT_FAILURE, "setns");
-
+\&
execvp(argv[2], &argv[2]); /* Execute a command in namespace */
err(EXIT_FAILURE, "execvp");
}
diff --git a/man2/shmop.2 b/man2/shmop.2
index a28d249e1..083b039ab 100644
--- a/man2/shmop.2
+++ b/man2/shmop.2
@@ -316,7 +316,7 @@ The following header file is included by the "reader" and "writer" programs:
.\" SRC BEGIN (svshm_string.h)
.EX
/* svshm_string.h
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <sys/types.h>
@@ -326,10 +326,10 @@ The following header file is included by the "reader" and "writer" programs:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
union semun { /* Used in calls to semctl() */
int val;
struct semid_ds * buf;
@@ -338,7 +338,7 @@ union semun { /* Used in calls to semctl() */
struct seminfo * __buf;
#endif
};
-
+\&
#define MEM_SIZE 4096
.EE
.\" SRC END
@@ -357,7 +357,7 @@ shared memory segment by the "writer".
.\" SRC BEGIN (svshm_string_read.c)
.EX
/* svshm_string_read.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <stdio.h>
@@ -365,9 +365,9 @@ shared memory segment by the "writer".
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
-
+\&
#include "svshm_string.h"
-
+\&
int
main(void)
{
@@ -375,52 +375,52 @@ main(void)
char *addr;
union semun arg, dummy;
struct sembuf sop;
-
+\&
/* Create shared memory and semaphore set containing one
semaphore. */
-
+\&
shmid = shmget(IPC_PRIVATE, MEM_SIZE, IPC_CREAT | 0600);
if (shmid == \-1)
errExit("shmget");
-
+\&
semid = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
if (semid == \-1)
errExit("semget");
-
+\&
/* Attach shared memory into our address space. */
-
+\&
addr = shmat(shmid, NULL, SHM_RDONLY);
if (addr == (void *) \-1)
errExit("shmat");
-
+\&
/* Initialize semaphore 0 in set with value 1. */
-
+\&
arg.val = 1;
if (semctl(semid, 0, SETVAL, arg) == \-1)
errExit("semctl");
-
+\&
printf("shmid = %d; semid = %d\en", shmid, semid);
-
+\&
/* Wait for semaphore value to become 0. */
-
+\&
sop.sem_num = 0;
sop.sem_op = 0;
sop.sem_flg = 0;
-
+\&
if (semop(semid, &sop, 1) == \-1)
errExit("semop");
-
+\&
/* Print the string from shared memory. */
-
+\&
printf("%s\en", addr);
-
+\&
/* Remove shared memory and semaphore set. */
-
+\&
if (shmctl(shmid, IPC_RMID, NULL) == \-1)
errExit("shmctl");
if (semctl(semid, 0, IPC_RMID, dummy) == \-1)
errExit("semctl");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -439,7 +439,7 @@ and then decrements the semaphore value to 0 in order to inform the
.\" SRC BEGIN (svshm_string_write.c)
.EX
/* svshm_string_write.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <stdio.h>
@@ -447,9 +447,9 @@ and then decrements the semaphore value to 0 in order to inform the
#include <string.h>
#include <sys/sem.h>
#include <sys/shm.h>
-
+\&
#include "svshm_string.h"
-
+\&
int
main(int argc, char *argv[])
{
@@ -457,41 +457,41 @@ main(int argc, char *argv[])
char *addr;
size_t len;
struct sembuf sop;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage: %s shmid semid string\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
len = strlen(argv[3]) + 1; /* +1 to include trailing \[aq]\e0\[aq] */
if (len > MEM_SIZE) {
fprintf(stderr, "String is too big!\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Get object IDs from command\-line. */
-
+\&
shmid = atoi(argv[1]);
semid = atoi(argv[2]);
-
+\&
/* Attach shared memory into our address space and copy string
(including trailing null byte) into memory. */
-
+\&
addr = shmat(shmid, NULL, 0);
if (addr == (void *) \-1)
errExit("shmat");
-
+\&
memcpy(addr, argv[3], len);
-
+\&
/* Decrement semaphore to 0. */
-
+\&
sop.sem_num = 0;
sop.sem_op = \-1;
sop.sem_flg = 0;
-
+\&
if (semop(semid, &sop, 1) == \-1)
errExit("semop");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/sigaction.2 b/man2/sigaction.2
index 6c241561b..662100c82 100644
--- a/man2/sigaction.2
+++ b/man2/sigaction.2
@@ -1147,12 +1147,12 @@ otherwise.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
void
handler(int signo, siginfo_t *info, void *context)
{
struct sigaction oldact;
-
+\&
if (sigaction(SIGSEGV, NULL, &oldact) == \-1
|| (oldact.sa_flags & SA_UNSUPPORTED)
|| !(oldact.sa_flags & SA_EXPOSE_TAGBITS))
@@ -1161,19 +1161,19 @@ handler(int signo, siginfo_t *info, void *context)
}
_exit(EXIT_SUCCESS);
}
-
+\&
int
main(void)
{
struct sigaction act = { 0 };
-
+\&
act.sa_flags = SA_SIGINFO | SA_UNSUPPORTED | SA_EXPOSE_TAGBITS;
act.sa_sigaction = &handler;
if (sigaction(SIGSEGV, &act, NULL) == \-1) {
perror("sigaction");
exit(EXIT_FAILURE);
}
-
+\&
raise(SIGSEGV);
}
.EE
diff --git a/man2/sigaltstack.2 b/man2/sigaltstack.2
index 095c95742..6ae8a612c 100644
--- a/man2/sigaltstack.2
+++ b/man2/sigaltstack.2
@@ -333,20 +333,20 @@ signal:
.in +4n
.EX
stack_t ss;
-
+\&
ss.ss_sp = malloc(SIGSTKSZ);
if (ss.ss_sp == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
ss.ss_size = SIGSTKSZ;
ss.ss_flags = 0;
if (sigaltstack(&ss, NULL) == \-1) {
perror("sigaltstack");
exit(EXIT_FAILURE);
}
-
+\&
sa.sa_flags = SA_ONSTACK;
sa.sa_handler = handler(); /* Address of a signal handler */
sigemptyset(&sa.sa_mask);
diff --git a/man2/signalfd.2 b/man2/signalfd.2
index 8e86d6528..2b97c4640 100644
--- a/man2/signalfd.2
+++ b/man2/signalfd.2
@@ -466,7 +466,7 @@ $
#include <stdlib.h>
#include <sys/signalfd.h>
#include <unistd.h>
-
+\&
int
main(void)
{
@@ -474,26 +474,26 @@ main(void)
ssize_t s;
sigset_t mask;
struct signalfd_siginfo fdsi;
-
+\&
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT);
-
+\&
/* Block signals so that they aren\[aq]t handled
according to their default dispositions. */
-
+\&
if (sigprocmask(SIG_BLOCK, &mask, NULL) == \-1)
err(EXIT_FAILURE, "sigprocmask");
-
+\&
sfd = signalfd(\-1, &mask, 0);
if (sfd == \-1)
err(EXIT_FAILURE, "signalfd");
-
+\&
for (;;) {
s = read(sfd, &fdsi, sizeof(fdsi));
if (s != sizeof(fdsi))
err(EXIT_FAILURE, "read");
-
+\&
if (fdsi.ssi_signo == SIGINT) {
printf("Got SIGINT\en");
} else if (fdsi.ssi_signo == SIGQUIT) {
diff --git a/man2/spu_run.2 b/man2/spu_run.2
index c3df3ad63..1828ad7e8 100644
--- a/man2/spu_run.2
+++ b/man2/spu_run.2
@@ -208,45 +208,45 @@ system call.
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
-
+\&
int main(void)
{
int context, fd, spu_status;
uint32_t instruction, npc;
-
+\&
context = syscall(SYS_spu_create, "/spu/example\-context", 0, 0755);
if (context == \-1)
err(EXIT_FAILURE, "spu_create");
-
+\&
/*
* Write a \[aq]stop 0x1234\[aq] instruction to the SPU\[aq]s
* local store memory.
*/
instruction = 0x00001234;
-
+\&
fd = open("/spu/example\-context/mem", O_RDWR);
if (fd == \-1)
err(EXIT_FAILURE, "open");
write(fd, &instruction, sizeof(instruction));
-
+\&
/*
* set npc to the starting instruction address of the
* SPU program. Since we wrote the instruction at the
* start of the mem file, the entry point will be 0x0.
*/
npc = 0;
-
+\&
spu_status = syscall(SYS_spu_run, context, &npc, NULL);
if (spu_status == \-1)
err(EXIT_FAILURE, "open");
-
+\&
/*
* We should see a status code of 0x12340002:
* 0x00000002 (spu was stopped due to stop\-and\-signal)
* | 0x12340000 (the stop\-and\-signal code)
*/
printf("SPU Status: %#08x\en", spu_status);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/stat.2 b/man2/stat.2
index 546e80ab4..1a59f21c9 100644
--- a/man2/stat.2
+++ b/man2/stat.2
@@ -467,28 +467,28 @@ structure.
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <time.h>
-
+\&
int
main(int argc, char *argv[])
{
struct stat sb;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <pathname>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (lstat(argv[1], &sb) == \-1) {
perror("lstat");
exit(EXIT_FAILURE);
}
-
+\&
printf("ID of containing device: [%x,%x]\en",
major(sb.st_dev),
minor(sb.st_dev));
-
+\&
printf("File type: ");
-
+\&
switch (sb.st_mode & S_IFMT) {
case S_IFBLK: printf("block device\en"); break;
case S_IFCHR: printf("character device\en"); break;
@@ -499,27 +499,27 @@ main(int argc, char *argv[])
case S_IFSOCK: printf("socket\en"); break;
default: printf("unknown?\en"); break;
}
-
+\&
printf("I\-node number: %ju\en", (uintmax_t) sb.st_ino);
-
+\&
printf("Mode: %jo (octal)\en",
(uintmax_t) sb.st_mode);
-
+\&
printf("Link count: %ju\en", (uintmax_t) sb.st_nlink);
printf("Ownership: UID=%ju GID=%ju\en",
(uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid);
-
+\&
printf("Preferred I/O block size: %jd bytes\en",
(intmax_t) sb.st_blksize);
printf("File size: %jd bytes\en",
(intmax_t) sb.st_size);
printf("Blocks allocated: %jd\en",
(intmax_t) sb.st_blocks);
-
+\&
printf("Last status change: %s", ctime(&sb.st_ctime));
printf("Last file access: %s", ctime(&sb.st_atime));
printf("Last file modification: %s", ctime(&sb.st_mtime));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/statx.2 b/man2/statx.2
index ef35efd98..3bc4932b0 100644
--- a/man2/statx.2
+++ b/man2/statx.2
@@ -46,25 +46,25 @@ struct statx {
__u64 stx_attributes_mask;
/* Mask to show what\[aq]s supported
in stx_attributes */
-
+\&
/* The following fields are file timestamps */
struct statx_timestamp stx_atime; /* Last access */
struct statx_timestamp stx_btime; /* Creation */
struct statx_timestamp stx_ctime; /* Last status change */
struct statx_timestamp stx_mtime; /* Last modification */
-
+\&
/* If this file represents a device, then the next two
fields contain the ID of the device */
__u32 stx_rdev_major; /* Major ID */
__u32 stx_rdev_minor; /* Minor ID */
-
+\&
/* The next two fields contain the ID of the device
containing the filesystem where the file resides */
__u32 stx_dev_major; /* Major ID */
__u32 stx_dev_minor; /* Minor ID */
-
+\&
__u64 stx_mnt_id; /* Mount ID */
-
+\&
/* Direct I/O alignment restrictions */
__u32 stx_dio_mem_align;
__u32 stx_dio_offset_align;
diff --git a/man2/syscall.2 b/man2/syscall.2
index 0ba537f4f..fea186515 100644
--- a/man2/syscall.2
+++ b/man2/syscall.2
@@ -348,12 +348,12 @@ architectures may indiscriminately clobber other registers not listed here.
#include <signal.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
int
main(void)
{
pid_t tid;
-
+\&
tid = syscall(SYS_gettid);
syscall(SYS_tgkill, getpid(), tid, SIGHUP);
}
diff --git a/man2/sysctl.2 b/man2/sysctl.2
index 83af5efd4..44134d82b 100644
--- a/man2/sysctl.2
+++ b/man2/sysctl.2
@@ -120,15 +120,15 @@ It is not yet possible to change operating system by writing to
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
#include <linux/sysctl.h>
-
+\&
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
+\&
int _sysctl(struct __sysctl_args *args);
-
+\&
#define OSNAMESZ 100
-
+\&
int
main(void)
{
@@ -136,15 +136,15 @@ main(void)
char osname[OSNAMESZ];
size_t osnamelth;
struct __sysctl_args args;
-
+\&
memset(&args, 0, sizeof(args));
args.name = name;
args.nlen = ARRAY_SIZE(name);
args.oldval = osname;
args.oldlenp = &osnamelth;
-
+\&
osnamelth = sizeof(osname);
-
+\&
if (syscall(SYS__sysctl, &args) == \-1) {
perror("_sysctl");
exit(EXIT_FAILURE);
diff --git a/man2/tee.2 b/man2/tee.2
index 35975badf..141ee7f94 100644
--- a/man2/tee.2
+++ b/man2/tee.2
@@ -141,24 +141,24 @@ Tue Oct 28 10:06:00 CET 2014
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd;
ssize_t len, slen;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <file>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == \-1) {
perror("open");
exit(EXIT_FAILURE);
}
-
+\&
for (;;) {
/*
* tee stdin to stdout.
@@ -173,7 +173,7 @@ main(int argc, char *argv[])
}
if (len == 0)
break;
-
+\&
/*
* Consume stdin by splicing it to a file.
*/
@@ -187,7 +187,7 @@ main(int argc, char *argv[])
len \-= slen;
}
}
-
+\&
close(fd);
exit(EXIT_SUCCESS);
}
diff --git a/man2/timer_create.2 b/man2/timer_create.2
index ba5ad78fb..a3987bb1e 100644
--- a/man2/timer_create.2
+++ b/man2/timer_create.2
@@ -360,31 +360,31 @@ Caught signal 34
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
-
+\&
#define CLOCKID CLOCK_REALTIME
#define SIG SIGRTMIN
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
static void
print_siginfo(siginfo_t *si)
{
int or;
timer_t *tidp;
-
+\&
tidp = si\->si_value.sival_ptr;
-
+\&
printf(" sival_ptr = %p; ", si\->si_value.sival_ptr);
printf(" *sival_ptr = %#jx\en", (uintmax_t) *tidp);
-
+\&
or = timer_getoverrun(*tidp);
if (or == \-1)
errExit("timer_getoverrun");
else
printf(" overrun count = %d\en", or);
}
-
+\&
static void
handler(int sig, siginfo_t *si, void *uc)
{
@@ -393,12 +393,12 @@ handler(int sig, siginfo_t *si, void *uc)
printf() is not async\-signal\-safe; see signal\-safety(7).
Nevertheless, we use printf() here as a simple way of
showing that the handler was called. */
-
+\&
printf("Caught signal %d\en", sig);
print_siginfo(si);
signal(sig, SIG_IGN);
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -408,64 +408,64 @@ main(int argc, char *argv[])
struct sigevent sev;
struct sigaction sa;
struct itimerspec its;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <sleep\-secs> <freq\-nanosecs>\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Establish handler for timer signal. */
-
+\&
printf("Establishing handler for signal %d\en", SIG);
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIG, &sa, NULL) == \-1)
errExit("sigaction");
-
+\&
/* Block timer signal temporarily. */
-
+\&
printf("Blocking signal %d\en", SIG);
sigemptyset(&mask);
sigaddset(&mask, SIG);
if (sigprocmask(SIG_SETMASK, &mask, NULL) == \-1)
errExit("sigprocmask");
-
+\&
/* Create the timer. */
-
+\&
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIG;
sev.sigev_value.sival_ptr = &timerid;
if (timer_create(CLOCKID, &sev, &timerid) == \-1)
errExit("timer_create");
-
+\&
printf("timer ID is %#jx\en", (uintmax_t) timerid);
-
+\&
/* Start the timer. */
-
+\&
freq_nanosecs = atoll(argv[2]);
its.it_value.tv_sec = freq_nanosecs / 1000000000;
its.it_value.tv_nsec = freq_nanosecs % 1000000000;
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
-
+\&
if (timer_settime(timerid, 0, &its, NULL) == \-1)
errExit("timer_settime");
-
+\&
/* Sleep for a while; meanwhile, the timer may expire
multiple times. */
-
+\&
printf("Sleeping for %d seconds\en", atoi(argv[1]));
sleep(atoi(argv[1]));
-
+\&
/* Unlock the timer signal, so that timer notification
can be delivered. */
-
+\&
printf("Unblocking signal %d\en", SIG);
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == \-1)
errExit("sigprocmask");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/timerfd_create.2 b/man2/timerfd_create.2
index 516e050b3..d68206b05 100644
--- a/man2/timerfd_create.2
+++ b/man2/timerfd_create.2
@@ -602,7 +602,7 @@ a.out 3 1 100
#include <sys/timerfd.h>
#include <time.h>
#include <unistd.h>
-
+\&
static void
print_elapsed_time(void)
{
@@ -610,16 +610,16 @@ print_elapsed_time(void)
static int first_call = 1;
struct timespec curr;
static struct timespec start;
-
+\&
if (first_call) {
first_call = 0;
if (clock_gettime(CLOCK_MONOTONIC, &start) == \-1)
err(EXIT_FAILURE, "clock_gettime");
}
-
+\&
if (clock_gettime(CLOCK_MONOTONIC, &curr) == \-1)
err(EXIT_FAILURE, "clock_gettime");
-
+\&
secs = curr.tv_sec \- start.tv_sec;
nsecs = curr.tv_nsec \- start.tv_nsec;
if (nsecs < 0) {
@@ -628,7 +628,7 @@ print_elapsed_time(void)
}
printf("%d.%03d: ", secs, (nsecs + 500000) / 1000000);
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -637,19 +637,19 @@ main(int argc, char *argv[])
uint64_t exp, tot_exp, max_exp;
struct timespec now;
struct itimerspec new_value;
-
+\&
if (argc != 2 && argc != 4) {
fprintf(stderr, "%s init\-secs [interval\-secs max\-exp]\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (clock_gettime(CLOCK_REALTIME, &now) == \-1)
err(EXIT_FAILURE, "clock_gettime");
-
+\&
/* Create a CLOCK_REALTIME absolute timer with initial
expiration and interval as specified in command line. */
-
+\&
new_value.it_value.tv_sec = now.tv_sec + atoi(argv[1]);
new_value.it_value.tv_nsec = now.tv_nsec;
if (argc == 2) {
@@ -660,27 +660,27 @@ main(int argc, char *argv[])
max_exp = atoi(argv[3]);
}
new_value.it_interval.tv_nsec = 0;
-
+\&
fd = timerfd_create(CLOCK_REALTIME, 0);
if (fd == \-1)
err(EXIT_FAILURE, "timerfd_create");
-
+\&
if (timerfd_settime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == \-1)
err(EXIT_FAILURE, "timerfd_settime");
-
+\&
print_elapsed_time();
printf("timer started\en");
-
+\&
for (tot_exp = 0; tot_exp < max_exp;) {
s = read(fd, &exp, sizeof(uint64_t));
if (s != sizeof(uint64_t))
err(EXIT_FAILURE, "read");
-
+\&
tot_exp += exp;
print_elapsed_time();
printf("read: %" PRIu64 "; total=%" PRIu64 "\en", exp, tot_exp);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/unshare.2 b/man2/unshare.2
index 229e065c8..58d57a86b 100644
--- a/man2/unshare.2
+++ b/man2/unshare.2
@@ -496,7 +496,7 @@ commands shows that the two shells are in different mount namespaces.
.\" SRC BEGIN (unshare.c)
.EX
/* unshare.c
-
+\&
A simple implementation of the unshare(1) command: unshare
namespaces and execute a command.
*/
@@ -506,7 +506,7 @@ commands shows that the two shells are in different mount namespaces.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
static void
usage(char *pname)
{
@@ -522,14 +522,14 @@ usage(char *pname)
fprintf(stderr, " \-U unshare user namespace\en");
exit(EXIT_FAILURE);
}
-
+\&
int
main(int argc, char *argv[])
{
int flags, opt;
-
+\&
flags = 0;
-
+\&
while ((opt = getopt(argc, argv, "CimnptuU")) != \-1) {
switch (opt) {
case \[aq]C\[aq]: flags |= CLONE_NEWCGROUP; break;
@@ -543,13 +543,13 @@ main(int argc, char *argv[])
default: usage(argv[0]);
}
}
-
+\&
if (optind >= argc)
usage(argv[0]);
-
+\&
if (unshare(flags) == \-1)
err(EXIT_FAILURE, "unshare");
-
+\&
execvp(argv[optind], &argv[optind]);
err(EXIT_FAILURE, "execvp");
}
diff --git a/man2/userfaultfd.2 b/man2/userfaultfd.2
index 4fe404edd..40354065c 100644
--- a/man2/userfaultfd.2
+++ b/man2/userfaultfd.2
@@ -407,25 +407,25 @@ struct uffd_msg {
__u32 ptid; /* Thread ID of the fault */
} feat;
} pagefault;
-
+\&
struct { /* Since Linux 4.11 */
__u32 ufd; /* Userfault file descriptor
of the child process */
} fork;
-
+\&
struct { /* Since Linux 4.11 */
__u64 from; /* Old address of remapped area */
__u64 to; /* New address of remapped area */
__u64 len; /* Original mapping length */
} remap;
-
+\&
struct { /* Since Linux 4.11 */
__u64 start; /* Start address of removed area */
__u64 end; /* End address of removed area */
} remove;
...
} arg;
-
+\&
/* Padding fields omitted */
} __packed;
.EE
@@ -706,7 +706,7 @@ The following is an example of what we see when running the program:
.EX
$ \fB./userfaultfd_demo 3\fP
Address returned by mmap() = 0x7fd30106c000
-
+\&
fault_handler_thread():
poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c00f
@@ -715,7 +715,7 @@ Read address 0x7fd30106c00f in main(): A
Read address 0x7fd30106c40f in main(): A
Read address 0x7fd30106c80f in main(): A
Read address 0x7fd30106cc0f in main(): A
-
+\&
fault_handler_thread():
poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d00f
@@ -724,7 +724,7 @@ Read address 0x7fd30106d00f in main(): B
Read address 0x7fd30106d40f in main(): B
Read address 0x7fd30106d80f in main(): B
Read address 0x7fd30106dc0f in main(): B
-
+\&
fault_handler_thread():
poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e00f
@@ -740,7 +740,7 @@ Read address 0x7fd30106ec0f in main(): C
.\" SRC BEGIN (userfaultfd.c)
.EX
/* userfaultfd_demo.c
-
+\&
Licensed under the GNU General Public License version 2 or later.
*/
#define _GNU_SOURCE
@@ -758,9 +758,9 @@ Read address 0x7fd30106ec0f in main(): C
#include <sys/mman.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
static int page_size;
-
+\&
static void *
fault_handler_thread(void *arg)
{
@@ -769,77 +769,77 @@ fault_handler_thread(void *arg)
ssize_t nread;
struct pollfd pollfd;
struct uffdio_copy uffdio_copy;
-
+\&
static int fault_cnt = 0; /* Number of faults so far handled */
static char *page = NULL;
static struct uffd_msg msg; /* Data read from userfaultfd */
-
+\&
uffd = (long) arg;
-
+\&
/* Create a page that will be copied into the faulting region. */
-
+\&
if (page == NULL) {
page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, \-1, 0);
if (page == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
}
-
+\&
/* Loop, handling incoming events on the userfaultfd
file descriptor. */
-
+\&
for (;;) {
-
+\&
/* See what poll() tells us about the userfaultfd. */
-
+\&
pollfd.fd = uffd;
pollfd.events = POLLIN;
nready = poll(&pollfd, 1, \-1);
if (nready == \-1)
err(EXIT_FAILURE, "poll");
-
+\&
printf("\enfault_handler_thread():\en");
printf(" poll() returns: nready = %d; "
"POLLIN = %d; POLLERR = %d\en", nready,
(pollfd.revents & POLLIN) != 0,
(pollfd.revents & POLLERR) != 0);
-
+\&
/* Read an event from the userfaultfd. */
-
+\&
nread = read(uffd, &msg, sizeof(msg));
if (nread == 0) {
printf("EOF on userfaultfd!\en");
exit(EXIT_FAILURE);
}
-
+\&
if (nread == \-1)
err(EXIT_FAILURE, "read");
-
+\&
/* We expect only one kind of event; verify that assumption. */
-
+\&
if (msg.event != UFFD_EVENT_PAGEFAULT) {
fprintf(stderr, "Unexpected event on userfaultfd\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Display info about the page\-fault event. */
-
+\&
printf(" UFFD_EVENT_PAGEFAULT event: ");
printf("flags = %"PRIx64"; ", msg.arg.pagefault.flags);
printf("address = %"PRIx64"\en", msg.arg.pagefault.address);
-
+\&
/* Copy the page pointed to by \[aq]page\[aq] into the faulting
region. Vary the contents that are copied in, so that it
is more obvious that each fault is handled separately. */
-
+\&
memset(page, \[aq]A\[aq] + fault_cnt % 20, page_size);
fault_cnt++;
-
+\&
uffdio_copy.src = (unsigned long) page;
-
+\&
/* We need to handle page faults in units of pages(!).
So, round faulting address down to page boundary. */
-
+\&
uffdio_copy.dst = (unsigned long) msg.arg.pagefault.address &
\[ti](page_size \- 1);
uffdio_copy.len = page_size;
@@ -847,12 +847,12 @@ fault_handler_thread(void *arg)
uffdio_copy.copy = 0;
if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == \-1)
err(EXIT_FAILURE, "ioctl\-UFFDIO_COPY");
-
+\&
printf(" (uffdio_copy.copy returned %"PRId64")\en",
uffdio_copy.copy);
}
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -864,59 +864,59 @@ main(int argc, char *argv[])
pthread_t thr; /* ID of thread that handles page faults */
struct uffdio_api uffdio_api;
struct uffdio_register uffdio_register;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s num\-pages\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
page_size = sysconf(_SC_PAGE_SIZE);
len = strtoull(argv[1], NULL, 0) * page_size;
-
+\&
/* Create and enable userfaultfd object. */
-
+\&
uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK);
if (uffd == \-1)
err(EXIT_FAILURE, "userfaultfd");
-
+\&
uffdio_api.api = UFFD_API;
uffdio_api.features = 0;
if (ioctl(uffd, UFFDIO_API, &uffdio_api) == \-1)
err(EXIT_FAILURE, "ioctl\-UFFDIO_API");
-
+\&
/* Create a private anonymous mapping. The memory will be
demand\-zero paged\-\-that is, not yet allocated. When we
actually touch the memory, it will be allocated via
the userfaultfd. */
-
+\&
addr = mmap(NULL, len, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, \-1, 0);
if (addr == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
-
+\&
printf("Address returned by mmap() = %p\en", addr);
-
+\&
/* Register the memory range of the mapping we just created for
handling by the userfaultfd object. In mode, we request to track
missing pages (i.e., pages that have not yet been faulted in). */
-
+\&
uffdio_register.range.start = (unsigned long) addr;
uffdio_register.range.len = len;
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == \-1)
err(EXIT_FAILURE, "ioctl\-UFFDIO_REGISTER");
-
+\&
/* Create a thread that will process the userfaultfd events. */
-
+\&
s = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd);
if (s != 0) {
errc(EXIT_FAILURE, s, "pthread_create");
}
-
+\&
/* Main thread now touches memory in the mapping, touching
locations 1024 bytes apart. This will trigger userfaultfd
events for all pages in the region. */
-
+\&
l = 0xf; /* Ensure that faulting address is not on a page
boundary, in order to test that we correctly
handle that case in fault_handling_thread(). */
@@ -927,7 +927,7 @@ main(int argc, char *argv[])
l += 1024;
usleep(100000); /* Slow things down a little */
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man2/wait.2 b/man2/wait.2
index 7386dffef..d50e2fd58 100644
--- a/man2/wait.2
+++ b/man2/wait.2
@@ -663,25 +663,25 @@ $
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int wstatus;
pid_t cpid, w;
-
+\&
cpid = fork();
if (cpid == \-1) {
perror("fork");
exit(EXIT_FAILURE);
}
-
+\&
if (cpid == 0) { /* Code executed by child */
printf("Child PID is %jd\en", (intmax_t) getpid());
if (argc == 1)
pause(); /* Wait for signals */
_exit(atoi(argv[1]));
-
+\&
} else { /* Code executed by parent */
do {
w = waitpid(cpid, &wstatus, WUNTRACED | WCONTINUED);
@@ -689,7 +689,7 @@ main(int argc, char *argv[])
perror("waitpid");
exit(EXIT_FAILURE);
}
-
+\&
if (WIFEXITED(wstatus)) {
printf("exited, status=%d\en", WEXITSTATUS(wstatus));
} else if (WIFSIGNALED(wstatus)) {
diff --git a/man3/CPU_SET.3 b/man3/CPU_SET.3
index 46acaa88f..a0461104a 100644
--- a/man3/CPU_SET.3
+++ b/man3/CPU_SET.3
@@ -306,36 +306,36 @@ used for dynamically allocated CPU sets.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#include <assert.h>
-
+\&
int
main(int argc, char *argv[])
{
cpu_set_t *cpusetp;
size_t size, num_cpus;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s <num\-cpus>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
num_cpus = atoi(argv[1]);
-
+\&
cpusetp = CPU_ALLOC(num_cpus);
if (cpusetp == NULL) {
perror("CPU_ALLOC");
exit(EXIT_FAILURE);
}
-
+\&
size = CPU_ALLOC_SIZE(num_cpus);
-
+\&
CPU_ZERO_S(size, cpusetp);
for (size_t cpu = 0; cpu < num_cpus; cpu += 2)
CPU_SET_S(cpu, size, cpusetp);
-
+\&
printf("CPU_COUNT() of set: %d\en", CPU_COUNT_S(size, cpusetp));
-
+\&
CPU_FREE(cpusetp);
exit(EXIT_SUCCESS);
}
diff --git a/man3/MAX.3 b/man3/MAX.3
index eb9710912..6b9bb5803 100644
--- a/man3/MAX.3
+++ b/man3/MAX.3
@@ -50,22 +50,22 @@ To avoid this, ensure that both arguments have the same type.
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
-
+\&
int
main(int argc, char *argv[])
{
int a, b, x;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <num> <num>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
a = atoi(argv[1]);
b = atoi(argv[2]);
x = MAX(a, b);
printf("MAX(%d, %d) is %d\en", a, b, x);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/_Generic.3 b/man3/_Generic.3
index 378eb338c..e37f22020 100644
--- a/man3/_Generic.3
+++ b/man3/_Generic.3
@@ -40,24 +40,24 @@ seamlessly upgrading to the widest available type.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
#define my_imaxabs _Generic(INTMAX_C(0), \e
long: labs, \e
long long: llabs \e
/* long long long: lllabs */ \e
)
-
+\&
int
main(void)
{
off_t a;
-
+\&
a = \-42;
printf("imaxabs(%jd) == %jd\en", (intmax_t) a, my_imaxabs(a));
printf("&imaxabs == %p\en", &my_imaxabs);
printf("&labs == %p\en", &labs);
printf("&llabs == %p\en", &llabs);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/__ppc_get_timebase.3 b/man3/__ppc_get_timebase.3
index ec7204191..d796ca077 100644
--- a/man3/__ppc_get_timebase.3
+++ b/man3/__ppc_get_timebase.3
@@ -60,36 +60,36 @@ between two calls to
#include <stdio.h>
#include <stdlib.h>
#include <sys/platform/ppc.h>
-
+\&
/* Maximum value of the Time Base Register: 2\[ha]60 \- 1.
Source: POWER ISA. */
#define MAX_TB 0xFFFFFFFFFFFFFFF
-
+\&
int
main(void)
{
uint64_t tb1, tb2, diff;
uint64_t freq;
-
+\&
freq = __ppc_get_timebase_freq();
printf("Time Base frequency = %"PRIu64" Hz\en", freq);
-
+\&
tb1 = __ppc_get_timebase();
-
+\&
// Do some stuff...
-
+\&
tb2 = __ppc_get_timebase();
-
+\&
if (tb2 > tb1) {
diff = tb2 \- tb1;
} else {
/* Treat Time Base Register overflow. */
diff = (MAX_TB \- tb2) + tb1;
}
-
+\&
printf("Elapsed time = %1.2f usecs\en",
(double) diff * 1000000 / freq);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/atexit.3 b/man3/atexit.3
index 32682a337..9084dabab 100644
--- a/man3/atexit.3
+++ b/man3/atexit.3
@@ -139,28 +139,28 @@ that are called when the shared library is unloaded.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
void
bye(void)
{
printf("That was all, folks\en");
}
-
+\&
int
main(void)
{
long a;
int i;
-
+\&
a = sysconf(_SC_ATEXIT_MAX);
printf("ATEXIT_MAX = %ld\en", a);
-
+\&
i = atexit(bye);
if (i != 0) {
fprintf(stderr, "cannot set exit function\en");
exit(EXIT_FAILURE);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/backtrace.3 b/man3/backtrace.3
index 157fca076..a0fb7cf34 100644
--- a/man3/backtrace.3
+++ b/man3/backtrace.3
@@ -221,40 +221,40 @@ backtrace() returned 8 addresses
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define BT_BUF_SIZE 100
-
+\&
void
myfunc3(void)
{
int nptrs;
void *buffer[BT_BUF_SIZE];
char **strings;
-
+\&
nptrs = backtrace(buffer, BT_BUF_SIZE);
printf("backtrace() returned %d addresses\en", nptrs);
-
+\&
/* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
would produce similar output to the following: */
-
+\&
strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
-
+\&
for (size_t j = 0; j < nptrs; j++)
printf("%s\en", strings[j]);
-
+\&
free(strings);
}
-
+\&
static void /* "static" means don\[aq]t export the symbol... */
myfunc2(void)
{
myfunc3();
}
-
+\&
void
myfunc(int ncalls)
{
@@ -263,7 +263,7 @@ myfunc(int ncalls)
else
myfunc2();
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -271,7 +271,7 @@ main(int argc, char *argv[])
fprintf(stderr, "%s num\-calls\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
myfunc(atoi(argv[1]));
exit(EXIT_SUCCESS);
}
diff --git a/man3/basename.3 b/man3/basename.3
index fdbfa1636..87ffde36e 100644
--- a/man3/basename.3
+++ b/man3/basename.3
@@ -177,7 +177,7 @@ and
.EX
char *dirc, *basec, *bname, *dname;
char *path = "/etc/passwd";
-
+\&
dirc = strdup(path);
basec = strdup(path);
dname = dirname(dirc);
diff --git a/man3/bsearch.3 b/man3/bsearch.3
index b0760f72b..ca8991dc5 100644
--- a/man3/bsearch.3
+++ b/man3/bsearch.3
@@ -92,29 +92,29 @@ then retrieves desired elements using
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
#define ARRAY_SIZE(arr) (sizeof((arr)) / sizeof((arr)[0]))
-
+\&
struct mi {
int nr;
const char *name;
};
-
+\&
static struct mi months[] = {
{ 1, "jan" }, { 2, "feb" }, { 3, "mar" }, { 4, "apr" },
{ 5, "may" }, { 6, "jun" }, { 7, "jul" }, { 8, "aug" },
{ 9, "sep" }, {10, "oct" }, {11, "nov" }, {12, "dec" }
};
-
+\&
static int
compmi(const void *m1, const void *m2)
{
const struct mi *mi1 = m1;
const struct mi *mi2 = m2;
-
+\&
return strcmp(mi1\->name, mi2\->name);
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -122,7 +122,7 @@ main(int argc, char *argv[])
for (size_t i = 1; i < argc; i++) {
struct mi key;
struct mi *res;
-
+\&
key.name = argv[i];
res = bsearch(&key, months, ARRAY_SIZE(months),
sizeof(months[0]), compmi);
diff --git a/man3/bswap.3 b/man3/bswap.3
index 41dad78ed..c142e956b 100644
--- a/man3/bswap.3
+++ b/man3/bswap.3
@@ -45,20 +45,20 @@ $ \fB./a.out 0x0123456789abcdef\fP
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
uint64_t x;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <num>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
x = strtoull(argv[1], NULL, 0);
printf("%#" PRIx64 " ==> %#" PRIx64 "\en", x, bswap_64(x));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/cacos.3 b/man3/cacos.3
index a32826e98..ba1354c2d 100644
--- a/man3/cacos.3
+++ b/man3/cacos.3
@@ -59,33 +59,33 @@ C99, POSIX.1-2001.
.\" SRC BEGIN (cacos.c)
.EX
/* Link with "\-lm" */
-
+\&
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
double complex z, c, f;
double complex i = I;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <real> <imag>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
z = atof(argv[1]) + atof(argv[2]) * I;
-
+\&
c = cacos(z);
-
+\&
printf("cacos() = %6.3f %6.3f*i\en", creal(c), cimag(c));
-
+\&
f = \-i * clog(z + i * csqrt(1 \- z * z));
-
+\&
printf("formula = %6.3f %6.3f*i\en", creal(f), cimag(f));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/cacosh.3 b/man3/cacosh.3
index 979bad42a..b9624a4b0 100644
--- a/man3/cacosh.3
+++ b/man3/cacosh.3
@@ -62,30 +62,30 @@ glibc 2.1.
.\" SRC BEGIN (cacosh.c)
.EX
/* Link with "\-lm" */
-
+\&
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
double complex z, c, f;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <real> <imag>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
z = atof(argv[1]) + atof(argv[2]) * I;
-
+\&
c = cacosh(z);
printf("cacosh() = %6.3f %6.3f*i\en", creal(c), cimag(c));
-
+\&
f = 2 * clog(csqrt((z + 1)/2) + csqrt((z \- 1)/2));
printf("formula = %6.3f %6.3f*i\en", creal(f), cimag(f));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/catan.3 b/man3/catan.3
index 3c0cc84da..4ba880226 100644
--- a/man3/catan.3
+++ b/man3/catan.3
@@ -59,31 +59,31 @@ C99, POSIX.1-2001.
.\" SRC BEGIN (catan.c)
.EX
/* Link with "\-lm" */
-
+\&
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
double complex z, c, f;
double complex i = I;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <real> <imag>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
z = atof(argv[1]) + atof(argv[2]) * I;
-
+\&
c = catan(z);
printf("catan() = %6.3f %6.3f*i\en", creal(c), cimag(c));
-
+\&
f = (clog(1 + i * z) \- clog(1 \- i * z)) / (2 * i);
printf("formula = %6.3f %6.3f*i\en", creal(f), cimag(f));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/catanh.3 b/man3/catanh.3
index c936cc5e2..b0134546d 100644
--- a/man3/catanh.3
+++ b/man3/catanh.3
@@ -61,30 +61,30 @@ C99, POSIX.1-2001.
.\" SRC BEGIN (catanh.c)
.EX
/* Link with "\-lm" */
-
+\&
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
double complex z, c, f;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <real> <imag>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
z = atof(argv[1]) + atof(argv[2]) * I;
-
+\&
c = catanh(z);
printf("catanh() = %6.3f %6.3f*i\en", creal(c), cimag(c));
-
+\&
f = 0.5 * (clog(1 + z) \- clog(1 \- z));
printf("formula = %6.3f %6.3f*i\en", creal(f), cimag(f));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/circleq.3 b/man3/circleq.3
index d8bf80302..e9063d76e 100644
--- a/man3/circleq.3
+++ b/man3/circleq.3
@@ -262,35 +262,35 @@ without interfering with the traversal.
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
-
+\&
struct entry {
int data;
CIRCLEQ_ENTRY(entry) entries; /* Queue */
};
-
+\&
CIRCLEQ_HEAD(circlehead, entry);
-
+\&
int
main(void)
{
struct entry *n1, *n2, *n3, *np;
struct circlehead head; /* Queue head */
int i;
-
+\&
CIRCLEQ_INIT(&head); /* Initialize the queue */
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the head */
CIRCLEQ_INSERT_HEAD(&head, n1, entries);
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the tail */
CIRCLEQ_INSERT_TAIL(&head, n1, entries);
-
+\&
n2 = malloc(sizeof(struct entry)); /* Insert after */
CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
-
+\&
n3 = malloc(sizeof(struct entry)); /* Insert before */
CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);
-
+\&
CIRCLEQ_REMOVE(&head, n2, entries); /* Deletion */
free(n2);
/* Forward traversal */
@@ -308,7 +308,7 @@ main(void)
n1 = n2;
}
CIRCLEQ_INIT(&head);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/clock_getcpuclockid.3 b/man3/clock_getcpuclockid.3
index 4c249b120..05569614f 100644
--- a/man3/clock_getcpuclockid.3
+++ b/man3/clock_getcpuclockid.3
@@ -123,28 +123,28 @@ CPU\-time clock for PID 1 is 2.213466748 seconds
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
clockid_t clockid;
struct timespec ts;
-
+\&
if (argc != 2) {
fprintf(stderr, "%s <process\-ID>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
perror("clock_getcpuclockid");
exit(EXIT_FAILURE);
}
-
+\&
if (clock_gettime(clockid, &ts) == \-1) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
-
+\&
printf("CPU\-time clock for PID %s is %jd.%09ld seconds\en",
argv[1], (intmax_t) ts.tv_sec, ts.tv_nsec);
exit(EXIT_SUCCESS);
diff --git a/man3/cmsg.3 b/man3/cmsg.3
index ee7ba45e0..c1368b5ad 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -206,9 +206,9 @@ option in a received ancillary buffer:
struct msghdr msgh;
struct cmsghdr *cmsg;
int received_ttl;
-
+\&
/* Receive auxiliary data in msgh */
-
+\&
for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
if (cmsg\->cmsg_level == IPPROTO_IP
@@ -217,7 +217,7 @@ for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
break;
}
}
-
+\&
if (cmsg == NULL) {
/* Error: IP_TTL not enabled or small buffer or I/O error */
}
@@ -243,7 +243,7 @@ union { /* Ancillary data buffer, wrapped in a union
char buf[CMSG_SPACE(sizeof(myfds))];
struct cmsghdr align;
} u;
-
+\&
msg.msg_iov = &io;
msg.msg_iovlen = 1;
msg.msg_control = u.buf;
diff --git a/man3/confstr.3 b/man3/confstr.3
index 20a7781e7..6abcfcd2f 100644
--- a/man3/confstr.3
+++ b/man3/confstr.3
@@ -141,7 +141,7 @@ the POSIX.2 system utilities:
.EX
char *pathbuf;
size_t n;
-
+\&
n = confstr(_CS_PATH, NULL, (size_t) 0);
pathbuf = malloc(n);
if (pathbuf == NULL)
diff --git a/man3/dl_iterate_phdr.3 b/man3/dl_iterate_phdr.3
index 7e478973f..554750ca1 100644
--- a/man3/dl_iterate_phdr.3
+++ b/man3/dl_iterate_phdr.3
@@ -67,12 +67,12 @@ struct dl_phdr_info {
ELF program headers
for this object */
ElfW(Half) dlpi_phnum; /* # of items in \fIdlpi_phdr\fP */
-
+\&
/* The following fields were added in glibc 2.4, after the first
version of this structure was available. Check the \fIsize\fP
argument passed to the dl_iterate_phdr callback to determine
whether or not each later member is available. */
-
+\&
unsigned long long dlpi_adds;
/* Incremented when a new object may
have been added */
@@ -290,16 +290,16 @@ Name: "/lib64/ld\-linux\-x86\-64.so.2" (7 segments)
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
static int
callback(struct dl_phdr_info *info, size_t size, void *data)
{
char *type;
int p_type;
-
+\&
printf("Name: \e"%s\e" (%d segments)\en", info\->dlpi_name,
info\->dlpi_phnum);
-
+\&
for (size_t j = 0; j < info\->dlpi_phnum; j++) {
p_type = info\->dlpi_phdr[j].p_type;
type = (p_type == PT_LOAD) ? "PT_LOAD" :
@@ -312,7 +312,7 @@ callback(struct dl_phdr_info *info, size_t size, void *data)
(p_type == PT_GNU_EH_FRAME) ? "PT_GNU_EH_FRAME" :
(p_type == PT_GNU_STACK) ? "PT_GNU_STACK" :
(p_type == PT_GNU_RELRO) ? "PT_GNU_RELRO" : NULL;
-
+\&
printf(" %2zu: [%14p; memsz:%7jx] flags: %#jx; ", j,
(void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr),
(uintmax_t) info\->dlpi_phdr[j].p_memsz,
@@ -322,15 +322,15 @@ callback(struct dl_phdr_info *info, size_t size, void *data)
else
printf("[other (%#x)]\en", p_type);
}
-
+\&
return 0;
}
-
+\&
int
main(void)
{
dl_iterate_phdr(callback, NULL);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/dladdr.3 b/man3/dladdr.3
index 90b770cb8..e7a25d687 100644
--- a/man3/dladdr.3
+++ b/man3/dladdr.3
@@ -90,7 +90,7 @@ struct link_map {
shared object */
struct link_map *l_next, *l_prev;
/* Chain of loaded objects */
-
+\&
/* Plus additional fields private to the
implementation */
};
diff --git a/man3/dlinfo.3 b/man3/dlinfo.3
index 5163aeab0..96ef06829 100644
--- a/man3/dlinfo.3
+++ b/man3/dlinfo.3
@@ -73,7 +73,7 @@ struct link_map {
shared object */
struct link_map *l_next, *l_prev;
/* Chain of loaded objects */
-
+\&
/* Plus additional fields private to the
implementation */
};
@@ -251,62 +251,62 @@ dls_serpath[1].dls_name = /usr/lib64
#include <link.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
void *handle;
Dl_serinfo serinfo;
Dl_serinfo *sip;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <libpath>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Obtain a handle for shared object specified on command line. */
-
+\&
handle = dlopen(argv[1], RTLD_NOW);
if (handle == NULL) {
fprintf(stderr, "dlopen() failed: %s\en", dlerror());
exit(EXIT_FAILURE);
}
-
+\&
/* Discover the size of the buffer that we must pass to
RTLD_DI_SERINFO. */
-
+\&
if (dlinfo(handle, RTLD_DI_SERINFOSIZE, &serinfo) == \-1) {
fprintf(stderr, "RTLD_DI_SERINFOSIZE failed: %s\en", dlerror());
exit(EXIT_FAILURE);
}
-
+\&
/* Allocate the buffer for use with RTLD_DI_SERINFO. */
-
+\&
sip = malloc(serinfo.dls_size);
if (sip == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
/* Initialize the \[aq]dls_size\[aq] and \[aq]dls_cnt\[aq] fields in the newly
allocated buffer. */
-
+\&
if (dlinfo(handle, RTLD_DI_SERINFOSIZE, sip) == \-1) {
fprintf(stderr, "RTLD_DI_SERINFOSIZE failed: %s\en", dlerror());
exit(EXIT_FAILURE);
}
-
+\&
/* Fetch and print library search list. */
-
+\&
if (dlinfo(handle, RTLD_DI_SERINFO, sip) == \-1) {
fprintf(stderr, "RTLD_DI_SERINFO failed: %s\en", dlerror());
exit(EXIT_FAILURE);
}
-
+\&
for (size_t j = 0; j < serinfo.dls_cnt; j++)
printf("dls_serpath[%zu].dls_name = %s\en",
j, sip\->dls_serpath[j].dls_name);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/dlopen.3 b/man3/dlopen.3
index 90c365a65..a21e6e1b4 100644
--- a/man3/dlopen.3
+++ b/man3/dlopen.3
@@ -560,7 +560,7 @@ $ \fB./a.out\fP
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
#include <gnu/lib\-names.h> /* Defines LIBM_SO (which will be a
string such as "libm.so.6") */
int
@@ -569,27 +569,27 @@ main(void)
void *handle;
double (*cosine)(double);
char *error;
-
+\&
handle = dlopen(LIBM_SO, RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s\en", dlerror());
exit(EXIT_FAILURE);
}
-
+\&
dlerror(); /* Clear any existing error */
-
+\&
cosine = (double (*)(double)) dlsym(handle, "cos");
-
+\&
/* According to the ISO C standard, casting between function
pointers and \[aq]void *\[aq], as done above, produces undefined results.
POSIX.1\-2001 and POSIX.1\-2008 accepted this state of affairs and
proposed the following workaround:
-
+\&
*(void **) (&cosine) = dlsym(handle, "cos");
-
+\&
This (clumsy) cast conforms with the ISO C standard and will
avoid any compiler warnings.
-
+\&
The 2013 Technical Corrigendum 1 to POSIX.1\-2008 improved matters
by requiring that conforming implementations support casting
\[aq]void *\[aq] to a function pointer. Nevertheless, some compilers
@@ -598,13 +598,13 @@ main(void)
.\" http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html#tag_03_112_08
.\" http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html#tag_16_96_07
.\" http://austingroupbugs.net/view.php?id=74
-
+\&
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\en", error);
exit(EXIT_FAILURE);
}
-
+\&
printf("%f\en", (*cosine)(2.0));
dlclose(handle);
exit(EXIT_SUCCESS);
diff --git a/man3/duplocale.3 b/man3/duplocale.3
index c8872a091..2e3126863 100644
--- a/man3/duplocale.3
+++ b/man3/duplocale.3
@@ -122,39 +122,39 @@ ABC
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
int
main(int argc, char *argv[])
{
locale_t loc, nloc;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s string\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* This sequence is necessary, because uselocale() might return
the value LC_GLOBAL_LOCALE, which can\[aq]t be passed as an
argument to toupper_l(). */
-
+\&
loc = uselocale((locale_t) 0);
if (loc == (locale_t) 0)
errExit("uselocale");
-
+\&
nloc = duplocale(loc);
if (nloc == (locale_t) 0)
errExit("duplocale");
-
+\&
for (char *p = argv[1]; *p; p++)
putchar(toupper_l(*p, nloc));
-
+\&
printf("\en");
-
+\&
freelocale(nloc);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/encrypt.3 b/man3/encrypt.3
index d0d35e922..9f7ea9627 100644
--- a/man3/encrypt.3
+++ b/man3/encrypt.3
@@ -163,7 +163,7 @@ In glibc 2.2, these functions use the DES algorithm.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(void)
{
@@ -171,11 +171,11 @@ main(void)
char orig[9] = "eggplant";
char buf[64];
char txt[9];
-
+\&
for (size_t i = 0; i < 64; i++) {
key[i] = rand() & 1;
}
-
+\&
for (size_t i = 0; i < 8; i++) {
for (size_t j = 0; j < 8; j++) {
buf[i * 8 + j] = orig[i] >> j & 1;
@@ -183,7 +183,7 @@ main(void)
setkey(key);
}
printf("Before encrypting: %s\en", orig);
-
+\&
encrypt(buf, 0);
for (size_t i = 0; i < 8; i++) {
for (size_t j = 0, txt[i] = \[aq]\e0\[aq]; j < 8; j++) {
@@ -192,7 +192,7 @@ main(void)
txt[8] = \[aq]\e0\[aq];
}
printf("After encrypting: %s\en", txt);
-
+\&
encrypt(buf, 1);
for (size_t i = 0; i < 8; i++) {
for (size_t j = 0, txt[i] = \[aq]\e0\[aq]; j < 8; j++) {
diff --git a/man3/end.3 b/man3/end.3
index 2b54bf5be..2ad58d957 100644
--- a/man3/end.3
+++ b/man3/end.3
@@ -73,10 +73,10 @@ First address past:
.EX
#include <stdio.h>
#include <stdlib.h>
-
+\&
extern char etext, edata, end; /* The symbols must have some type,
or "gcc \-Wall" complains */
-
+\&
int
main(void)
{
@@ -84,7 +84,7 @@ main(void)
printf(" program text (etext) %10p\en", &etext);
printf(" initialized data (edata) %10p\en", &edata);
printf(" uninitialized data (end) %10p\en", &end);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/endian.3 b/man3/endian.3
index 28f8fbee9..4d85cecd7 100644
--- a/man3/endian.3
+++ b/man3/endian.3
@@ -137,7 +137,7 @@ htobe32(x.u32) = 0x11223344
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
@@ -145,16 +145,16 @@ main(void)
uint32_t u32;
uint8_t arr[4];
} x;
-
+\&
x.arr[0] = 0x11; /* Lowest\-address byte */
x.arr[1] = 0x22;
x.arr[2] = 0x33;
x.arr[3] = 0x44; /* Highest\-address byte */
-
+\&
printf("x.u32 = %#x\en", x.u32);
printf("htole32(x.u32) = %#x\en", htole32(x.u32));
printf("htobe32(x.u32) = %#x\en", htobe32(x.u32));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/envz_add.3 b/man3/envz_add.3
index c7a4cf182..73bcc11ca 100644
--- a/man3/envz_add.3
+++ b/man3/envz_add.3
@@ -149,16 +149,16 @@ GNU.
#include <envz.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[], char *envp[])
{
char *str;
size_t e_len = 0;
-
+\&
for (size_t i = 0; envp[i] != NULL; i++)
e_len += strlen(envp[i]) + 1;
-
+\&
str = envz_entry(*envp, e_len, "HOME");
printf("%s\en", str);
str = envz_get(*envp, e_len, "HOME");
diff --git a/man3/fmemopen.3 b/man3/fmemopen.3
index c623878be..a97aa8fa3 100644
--- a/man3/fmemopen.3
+++ b/man3/fmemopen.3
@@ -307,7 +307,7 @@ size=11; ptr=1 529 1849
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -315,35 +315,35 @@ main(int argc, char *argv[])
int v, s;
size_t size;
char *ptr;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s \[aq]<num>...\[aq]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
in = fmemopen(argv[1], strlen(argv[1]), "r");
if (in == NULL)
err(EXIT_FAILURE, "fmemopen");
-
+\&
out = open_memstream(&ptr, &size);
if (out == NULL)
err(EXIT_FAILURE, "open_memstream");
-
+\&
for (;;) {
s = fscanf(in, "%d", &v);
if (s <= 0)
break;
-
+\&
s = fprintf(out, "%d ", v * v);
if (s == \-1)
err(EXIT_FAILURE, "fprintf");
}
-
+\&
fclose(in);
fclose(out);
-
+\&
printf("size=%zu; ptr=%s\en", size, ptr);
-
+\&
free(ptr);
exit(EXIT_SUCCESS);
}
diff --git a/man3/fmtmsg.3 b/man3/fmtmsg.3
index 97f74c569..b2da3085c 100644
--- a/man3/fmtmsg.3
+++ b/man3/fmtmsg.3
@@ -278,13 +278,13 @@ vpfmt(), lfmt(), and vlfmt()", and will be removed later.
#include <fmtmsg.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
int err;
-
+\&
err = fmtmsg(class, "util\-linux:mount", MM_ERROR,
"unknown mount option", "See mount(8).",
"util\-linux:mount:017");
diff --git a/man3/fopencookie.3 b/man3/fopencookie.3
index 36616af12..409a3c81a 100644
--- a/man3/fopencookie.3
+++ b/man3/fopencookie.3
@@ -295,24 +295,24 @@ closing a stream that has already been closed).
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
-
+\&
#define INIT_BUF_SIZE 4
-
+\&
struct memfile_cookie {
char *buf; /* Dynamically sized buffer for data */
size_t allocated; /* Size of buf */
size_t endpos; /* Number of characters in buf */
off_t offset; /* Current file offset in buf */
};
-
+\&
ssize_t
memfile_write(void *c, const char *buf, size_t size)
{
char *new_buff;
struct memfile_cookie *cookie = c;
-
+\&
/* Buffer too small? Keep doubling size until big enough. */
-
+\&
while (size + cookie\->offset > cookie\->allocated) {
new_buff = realloc(cookie\->buf, cookie\->allocated * 2);
if (new_buff == NULL)
@@ -320,42 +320,42 @@ memfile_write(void *c, const char *buf, size_t size)
cookie\->allocated *= 2;
cookie\->buf = new_buff;
}
-
+\&
memcpy(cookie\->buf + cookie\->offset, buf, size);
-
+\&
cookie\->offset += size;
if (cookie\->offset > cookie\->endpos)
cookie\->endpos = cookie\->offset;
-
+\&
return size;
}
-
+\&
ssize_t
memfile_read(void *c, char *buf, size_t size)
{
ssize_t xbytes;
struct memfile_cookie *cookie = c;
-
+\&
/* Fetch minimum of bytes requested and bytes available. */
-
+\&
xbytes = size;
if (cookie\->offset + size > cookie\->endpos)
xbytes = cookie\->endpos \- cookie\->offset;
if (xbytes < 0) /* offset may be past endpos */
xbytes = 0;
-
+\&
memcpy(buf, cookie\->buf + cookie\->offset, xbytes);
-
+\&
cookie\->offset += xbytes;
return xbytes;
}
-
+\&
int
memfile_seek(void *c, off64_t *offset, int whence)
{
off64_t new_offset;
struct memfile_cookie *cookie = c;
-
+\&
if (whence == SEEK_SET)
new_offset = *offset;
else if (whence == SEEK_END)
@@ -364,27 +364,27 @@ memfile_seek(void *c, off64_t *offset, int whence)
new_offset = cookie\->offset + *offset;
else
return \-1;
-
+\&
if (new_offset < 0)
return \-1;
-
+\&
cookie\->offset = new_offset;
*offset = new_offset;
return 0;
}
-
+\&
int
memfile_close(void *c)
{
struct memfile_cookie *cookie = c;
-
+\&
free(cookie\->buf);
cookie\->allocated = 0;
cookie\->buf = NULL;
-
+\&
return 0;
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -398,35 +398,35 @@ main(int argc, char *argv[])
struct memfile_cookie mycookie;
size_t nread;
char buf[1000];
-
+\&
/* Set up the cookie before calling fopencookie(). */
-
+\&
mycookie.buf = malloc(INIT_BUF_SIZE);
if (mycookie.buf == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
mycookie.allocated = INIT_BUF_SIZE;
mycookie.offset = 0;
mycookie.endpos = 0;
-
+\&
stream = fopencookie(&mycookie, "w+", memfile_func);
if (stream == NULL) {
perror("fopencookie");
exit(EXIT_FAILURE);
}
-
+\&
/* Write command\-line arguments to our file. */
-
+\&
for (size_t j = 1; j < argc; j++)
if (fputs(argv[j], stream) == EOF) {
perror("fputs");
exit(EXIT_FAILURE);
}
-
+\&
/* Read two bytes out of every five, until EOF. */
-
+\&
for (long p = 0; ; p += 5) {
if (fseek(stream, p, SEEK_SET) == \-1) {
perror("fseek");
@@ -441,12 +441,12 @@ main(int argc, char *argv[])
printf("Reached end of file\en");
break;
}
-
+\&
printf("/%.*s/\en", (int) nread, buf);
}
-
+\&
free(mycookie.buf);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/fread.3 b/man3/fread.3
index 7f4dac813..2668fdc57 100644
--- a/man3/fread.3
+++ b/man3/fread.3
@@ -120,41 +120,41 @@ Class: 0x02
.EX
#include <stdio.h>
#include <stdlib.h>
-
+\&
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
+\&
int
main(void)
{
FILE *fp;
size_t ret;
unsigned char buffer[4];
-
+\&
fp = fopen("/bin/sh", "rb");
if (!fp) {
perror("fopen");
return EXIT_FAILURE;
}
-
+\&
ret = fread(buffer, sizeof(*buffer), ARRAY_SIZE(buffer), fp);
if (ret != ARRAY_SIZE(buffer)) {
fprintf(stderr, "fread() failed: %zu\en", ret);
exit(EXIT_FAILURE);
}
-
+\&
printf("ELF magic: %#04x%02x%02x%02x\en", buffer[0], buffer[1],
buffer[2], buffer[3]);
-
+\&
ret = fread(buffer, 1, 1, fp);
if (ret != 1) {
fprintf(stderr, "fread() failed: %zu\en", ret);
exit(EXIT_FAILURE);
}
-
+\&
printf("Class: %#04x\en", buffer[0]);
-
+\&
fclose(fp);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/frexp.3 b/man3/frexp.3
index 79aa51342..9576b0306 100644
--- a/man3/frexp.3
+++ b/man3/frexp.3
@@ -124,16 +124,16 @@ frexp(\-4, &e) = \-0.5: \-0.5 * 2\[ha]3 = \-4
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
double x, r;
int exp;
-
+\&
x = strtod(argv[1], NULL);
r = frexp(x, &exp);
-
+\&
printf("frexp(%g, &e) = %g: %g * %d\[ha]%d = %g\en",
x, r, r, FLT_RADIX, exp, x);
exit(EXIT_SUCCESS);
diff --git a/man3/ftw.3 b/man3/ftw.3
index 59931bb3b..68f181825 100644
--- a/man3/ftw.3
+++ b/man3/ftw.3
@@ -453,7 +453,7 @@ argument when calling
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
static int
display_info(const char *fpath, const struct stat *sb,
int tflag, struct FTW *ftwbuf)
@@ -464,35 +464,35 @@ display_info(const char *fpath, const struct stat *sb,
(tflag == FTW_NS) ? "ns" : (tflag == FTW_SL) ? "sl" :
(tflag == FTW_SLN) ? "sln" : "???",
ftwbuf\->level);
-
+\&
if (tflag == FTW_NS)
printf("\-\-\-\-\-\-\-");
else
printf("%7jd", (intmax_t) sb\->st_size);
-
+\&
printf(" %\-40s %d %s\en",
fpath, ftwbuf\->base, fpath + ftwbuf\->base);
-
+\&
return 0; /* To tell nftw() to continue */
}
-
+\&
int
main(int argc, char *argv[])
{
int flags = 0;
-
+\&
if (argc > 2 && strchr(argv[2], \[aq]d\[aq]) != NULL)
flags |= FTW_DEPTH;
if (argc > 2 && strchr(argv[2], \[aq]p\[aq]) != NULL)
flags |= FTW_PHYS;
-
+\&
if (nftw((argc < 2) ? "." : argv[1], display_info, 20, flags)
== \-1)
{
perror("nftw");
exit(EXIT_FAILURE);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/get_nprocs.3 b/man3/get_nprocs.3
index 092c6affa..22d3380d3 100644
--- a/man3/get_nprocs.3
+++ b/man3/get_nprocs.3
@@ -81,7 +81,7 @@ can be used.
#include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
-
+\&
int
main(void)
{
diff --git a/man3/get_phys_pages.3 b/man3/get_phys_pages.3
index 78e79f06f..8fed56998 100644
--- a/man3/get_phys_pages.3
+++ b/man3/get_phys_pages.3
@@ -75,7 +75,7 @@ can be used.
#include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
-
+\&
int
main(void)
{
diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 5af0709fc..8c4de3b16 100644
--- a/man3/getaddrinfo.3
+++ b/man3/getaddrinfo.3
@@ -656,9 +656,9 @@ The programs are an echo server and client for UDP datagrams.
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
-
+\&
#define BUF_SIZE 500
-
+\&
int
main(int argc, char *argv[])
{
@@ -669,12 +669,12 @@ main(int argc, char *argv[])
struct addrinfo hints;
struct addrinfo *result, *rp;
struct sockaddr_storage peer_addr;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s port\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
@@ -683,48 +683,48 @@ main(int argc, char *argv[])
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
-
+\&
s = getaddrinfo(NULL, argv[1], &hints, &result);
if (s != 0) {
fprintf(stderr, "getaddrinfo: %s\en", gai_strerror(s));
exit(EXIT_FAILURE);
}
-
+\&
/* getaddrinfo() returns a list of address structures.
Try each address until we successfully bind(2).
If socket(2) (or bind(2)) fails, we (close the socket
and) try the next address. */
-
+\&
for (rp = result; rp != NULL; rp = rp\->ai_next) {
sfd = socket(rp\->ai_family, rp\->ai_socktype,
rp\->ai_protocol);
if (sfd == \-1)
continue;
-
+\&
if (bind(sfd, rp\->ai_addr, rp\->ai_addrlen) == 0)
break; /* Success */
-
+\&
close(sfd);
}
-
+\&
freeaddrinfo(result); /* No longer needed */
-
+\&
if (rp == NULL) { /* No address succeeded */
fprintf(stderr, "Could not bind\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Read datagrams and echo them back to sender. */
-
+\&
for (;;) {
char host[NI_MAXHOST], service[NI_MAXSERV];
-
+\&
peer_addrlen = sizeof(peer_addr);
nread = recvfrom(sfd, buf, BUF_SIZE, 0,
(struct sockaddr *) &peer_addr, &peer_addrlen);
if (nread == \-1)
continue; /* Ignore failed request */
-
+\&
s = getnameinfo((struct sockaddr *) &peer_addr,
peer_addrlen, host, NI_MAXHOST,
service, NI_MAXSERV, NI_NUMERICSERV);
@@ -733,7 +733,7 @@ main(int argc, char *argv[])
nread, host, service);
else
fprintf(stderr, "getnameinfo: %s\en", gai_strerror(s));
-
+\&
if (sendto(sfd, buf, nread, 0, (struct sockaddr *) &peer_addr,
peer_addrlen) != nread)
{
@@ -754,9 +754,9 @@ main(int argc, char *argv[])
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
-
+\&
#define BUF_SIZE 500
-
+\&
int
main(int argc, char *argv[])
{
@@ -766,77 +766,77 @@ main(int argc, char *argv[])
ssize_t nread;
struct addrinfo hints;
struct addrinfo *result, *rp;
-
+\&
if (argc < 3) {
fprintf(stderr, "Usage: %s host port msg...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Obtain address(es) matching host/port. */
-
+\&
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
hints.ai_flags = 0;
hints.ai_protocol = 0; /* Any protocol */
-
+\&
s = getaddrinfo(argv[1], argv[2], &hints, &result);
if (s != 0) {
fprintf(stderr, "getaddrinfo: %s\en", gai_strerror(s));
exit(EXIT_FAILURE);
}
-
+\&
/* getaddrinfo() returns a list of address structures.
Try each address until we successfully connect(2).
If socket(2) (or connect(2)) fails, we (close the socket
and) try the next address. */
-
+\&
for (rp = result; rp != NULL; rp = rp\->ai_next) {
sfd = socket(rp\->ai_family, rp\->ai_socktype,
rp\->ai_protocol);
if (sfd == \-1)
continue;
-
+\&
if (connect(sfd, rp\->ai_addr, rp\->ai_addrlen) != \-1)
break; /* Success */
-
+\&
close(sfd);
}
-
+\&
freeaddrinfo(result); /* No longer needed */
-
+\&
if (rp == NULL) { /* No address succeeded */
fprintf(stderr, "Could not connect\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Send remaining command\-line arguments as separate
datagrams, and read responses from server. */
-
+\&
for (size_t j = 3; j < argc; j++) {
len = strlen(argv[j]) + 1;
/* +1 for terminating null byte */
-
+\&
if (len > BUF_SIZE) {
fprintf(stderr,
"Ignoring long message in argument %zu\en", j);
continue;
}
-
+\&
if (write(sfd, argv[j], len) != len) {
fprintf(stderr, "partial/failed write\en");
exit(EXIT_FAILURE);
}
-
+\&
nread = read(sfd, buf, BUF_SIZE);
if (nread == \-1) {
perror("read");
exit(EXIT_FAILURE);
}
-
+\&
printf("Received %zd bytes: %s\en", nread, buf);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getaddrinfo_a.3 b/man3/getaddrinfo_a.3
index 525720812..cff85e5e2 100644
--- a/man3/getaddrinfo_a.3
+++ b/man3/getaddrinfo_a.3
@@ -341,7 +341,7 @@ Here is the program source code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -349,12 +349,12 @@ main(int argc, char *argv[])
struct gaicb *reqs[argc \- 1];
char host[NI_MAXHOST];
struct addrinfo *res;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s HOST...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
for (size_t i = 0; i < argc \- 1; i++) {
reqs[i] = malloc(sizeof(*reqs[0]));
if (reqs[i] == NULL) {
@@ -364,20 +364,20 @@ main(int argc, char *argv[])
memset(reqs[i], 0, sizeof(*reqs[0]));
reqs[i]\->ar_name = argv[i + 1];
}
-
+\&
ret = getaddrinfo_a(GAI_WAIT, reqs, argc \- 1, NULL);
if (ret != 0) {
fprintf(stderr, "getaddrinfo_a() failed: %s\en",
gai_strerror(ret));
exit(EXIT_FAILURE);
}
-
+\&
for (size_t i = 0; i < argc \- 1; i++) {
printf("%s: ", reqs[i]\->ar_name);
ret = gai_error(reqs[i]);
if (ret == 0) {
res = reqs[i]\->ar_result;
-
+\&
ret = getnameinfo(res\->ai_addr, res\->ai_addrlen,
host, sizeof(host),
NULL, 0, NI_NUMERICHOST);
@@ -387,7 +387,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
puts(host);
-
+\&
} else {
puts(gai_strerror(ret));
}
@@ -432,25 +432,25 @@ The program source is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
static struct gaicb **reqs = NULL;
static size_t nreqs = 0;
-
+\&
static char *
getcmd(void)
{
static char buf[256];
-
+\&
fputs("> ", stdout); fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL)
return NULL;
-
+\&
if (buf[strlen(buf) \- 1] == \[aq]\en\[aq])
buf[strlen(buf) \- 1] = 0;
-
+\&
return buf;
}
-
+\&
/* Add requests for specified hostnames. */
static void
add_requests(void)
@@ -458,17 +458,17 @@ add_requests(void)
size_t nreqs_base = nreqs;
char *host;
int ret;
-
+\&
while ((host = strtok(NULL, " "))) {
nreqs++;
reqs = realloc(reqs, sizeof(reqs[0]) * nreqs);
-
+\&
reqs[nreqs \- 1] = calloc(1, sizeof(*reqs[0]));
reqs[nreqs \- 1]\->ar_name = strdup(host);
}
-
+\&
/* Queue nreqs_base..nreqs requests. */
-
+\&
ret = getaddrinfo_a(GAI_NOWAIT, &reqs[nreqs_base],
nreqs \- nreqs_base, NULL);
if (ret) {
@@ -477,7 +477,7 @@ add_requests(void)
exit(EXIT_FAILURE);
}
}
-
+\&
/* Wait until at least one of specified requests completes. */
static void
wait_requests(void)
@@ -487,37 +487,37 @@ wait_requests(void)
size_t n;
struct gaicb const **wait_reqs = calloc(nreqs, sizeof(*wait_reqs));
/* NULL elements are ignored by gai_suspend(). */
-
+\&
while ((id = strtok(NULL, " ")) != NULL) {
n = atoi(id);
-
+\&
if (n >= nreqs) {
printf("Bad request number: %s\en", id);
return;
}
-
+\&
wait_reqs[n] = reqs[n];
}
-
+\&
ret = gai_suspend(wait_reqs, nreqs, NULL);
if (ret) {
printf("gai_suspend(): %s\en", gai_strerror(ret));
return;
}
-
+\&
for (size_t i = 0; i < nreqs; i++) {
if (wait_reqs[i] == NULL)
continue;
-
+\&
ret = gai_error(reqs[i]);
if (ret == EAI_INPROGRESS)
continue;
-
+\&
printf("[%02zu] %s: %s\en", i, reqs[i]\->ar_name,
ret == 0 ? "Finished" : gai_strerror(ret));
}
}
-
+\&
/* Cancel specified requests. */
static void
cancel_requests(void)
@@ -525,21 +525,21 @@ cancel_requests(void)
char *id;
int ret;
size_t n;
-
+\&
while ((id = strtok(NULL, " ")) != NULL) {
n = atoi(id);
-
+\&
if (n >= nreqs) {
printf("Bad request number: %s\en", id);
return;
}
-
+\&
ret = gai_cancel(reqs[n]);
printf("[%s] %s: %s\en", id, reqs[atoi(id)]\->ar_name,
gai_strerror(ret));
}
}
-
+\&
/* List all requests. */
static void
list_requests(void)
@@ -547,14 +547,14 @@ list_requests(void)
int ret;
char host[NI_MAXHOST];
struct addrinfo *res;
-
+\&
for (size_t i = 0; i < nreqs; i++) {
printf("[%02zu] %s: ", i, reqs[i]\->ar_name);
ret = gai_error(reqs[i]);
-
+\&
if (!ret) {
res = reqs[i]\->ar_result;
-
+\&
ret = getnameinfo(res\->ai_addr, res\->ai_addrlen,
host, sizeof(host),
NULL, 0, NI_NUMERICHOST);
@@ -569,16 +569,16 @@ list_requests(void)
}
}
}
-
+\&
int
main(void)
{
char *cmdline;
char *cmd;
-
+\&
while ((cmdline = getcmd()) != NULL) {
cmd = strtok(cmdline, " ");
-
+\&
if (cmd == NULL) {
list_requests();
} else {
diff --git a/man3/getdate.3 b/man3/getdate.3
index b84199898..476c9a96f 100644
--- a/man3/getdate.3
+++ b/man3/getdate.3
@@ -278,21 +278,21 @@ Call 3 ("12:22:33") succeeded:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-
+\&
int
main(int argc, char *argv[])
{
struct tm *tmp;
-
+\&
for (size_t j = 1; j < argc; j++) {
tmp = getdate(argv[j]);
-
+\&
if (tmp == NULL) {
printf("Call %zu failed; getdate_err = %d\en",
j, getdate_err);
continue;
}
-
+\&
printf("Call %zu (\e"%s\e") succeeded:\en", j, argv[j]);
printf(" tm_sec = %d\en", tmp\->tm_sec);
printf(" tm_min = %d\en", tmp\->tm_min);
@@ -304,7 +304,7 @@ main(int argc, char *argv[])
printf(" tm_yday = %d\en", tmp\->tm_yday);
printf(" tm_isdst = %d\en", tmp\->tm_isdst);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getgrent_r.3 b/man3/getgrent_r.3
index 3fef0f399..c1bb2a5af 100644
--- a/man3/getgrent_r.3
+++ b/man3/getgrent_r.3
@@ -179,7 +179,7 @@ in the stream with all other threads.
#include <stdio.h>
#include <stdlib.h>
#define BUFLEN 4096
-
+\&
int
main(void)
{
@@ -187,7 +187,7 @@ main(void)
struct group *grpp;
char buf[BUFLEN];
int i;
-
+\&
setgrent();
while (1) {
i = getgrent_r(&grp, buf, sizeof(buf), &grpp);
diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index 470a001c8..14cab0f79 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -141,7 +141,7 @@ ngroups = 3
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -149,38 +149,38 @@ main(int argc, char *argv[])
struct passwd *pw;
struct group *gr;
gid_t *groups;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <user> <ngroups>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
ngroups = atoi(argv[2]);
-
+\&
groups = malloc(sizeof(*groups) * ngroups);
if (groups == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
/* Fetch passwd structure (contains first group ID for user). */
-
+\&
pw = getpwnam(argv[1]);
if (pw == NULL) {
perror("getpwnam");
exit(EXIT_SUCCESS);
}
-
+\&
/* Retrieve group list. */
-
+\&
if (getgrouplist(argv[1], pw\->pw_gid, groups, &ngroups) == \-1) {
fprintf(stderr, "getgrouplist() returned \-1; ngroups = %d\en",
ngroups);
exit(EXIT_FAILURE);
}
-
+\&
/* Display list of retrieved groups, along with group names. */
-
+\&
fprintf(stderr, "ngroups = %d\en", ngroups);
for (size_t j = 0; j < ngroups; j++) {
printf("%d", groups[j]);
@@ -189,7 +189,7 @@ main(int argc, char *argv[])
printf(" (%s)", gr\->gr_name);
printf("\en");
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getifaddrs.3 b/man3/getifaddrs.3
index d7ffe5261..b6c9421c8 100644
--- a/man3/getifaddrs.3
+++ b/man3/getifaddrs.3
@@ -247,40 +247,40 @@ wlp3s0 AF_INET6 (10)
#include <stdlib.h>
#include <unistd.h>
#include <linux/if_link.h>
-
+\&
int main(int argc, char *argv[])
{
struct ifaddrs *ifaddr;
int family, s;
char host[NI_MAXHOST];
-
+\&
if (getifaddrs(&ifaddr) == \-1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
}
-
+\&
/* Walk through linked list, maintaining head pointer so we
can free list later. */
-
+\&
for (struct ifaddrs *ifa = ifaddr; ifa != NULL;
ifa = ifa\->ifa_next) {
if (ifa\->ifa_addr == NULL)
continue;
-
+\&
family = ifa\->ifa_addr\->sa_family;
-
+\&
/* Display interface name and family (including symbolic
form of the latter for the common families). */
-
+\&
printf("%\-8s %s (%d)\en",
ifa\->ifa_name,
(family == AF_PACKET) ? "AF_PACKET" :
(family == AF_INET) ? "AF_INET" :
(family == AF_INET6) ? "AF_INET6" : "???",
family);
-
+\&
/* For an AF_INET* interface address, display the address. */
-
+\&
if (family == AF_INET || family == AF_INET6) {
s = getnameinfo(ifa\->ifa_addr,
(family == AF_INET) ? sizeof(struct sockaddr_in) :
@@ -291,19 +291,19 @@ int main(int argc, char *argv[])
printf("getnameinfo() failed: %s\en", gai_strerror(s));
exit(EXIT_FAILURE);
}
-
+\&
printf("\et\etaddress: <%s>\en", host);
-
+\&
} else if (family == AF_PACKET && ifa\->ifa_data != NULL) {
struct rtnl_link_stats *stats = ifa\->ifa_data;
-
+\&
printf("\et\ettx_packets = %10u; rx_packets = %10u\en"
"\et\ettx_bytes = %10u; rx_bytes = %10u\en",
stats\->tx_packets, stats\->rx_packets,
stats\->tx_bytes, stats\->rx_bytes);
}
}
-
+\&
freeifaddrs(ifaddr);
exit(EXIT_SUCCESS);
}
diff --git a/man3/getline.3 b/man3/getline.3
index b3e6ca4fe..b7835bedf 100644
--- a/man3/getline.3
+++ b/man3/getline.3
@@ -146,7 +146,7 @@ GNU, POSIX.1-2008.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -154,23 +154,23 @@ main(int argc, char *argv[])
char *line = NULL;
size_t len = 0;
ssize_t nread;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <file>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
stream = fopen(argv[1], "r");
if (stream == NULL) {
perror("fopen");
exit(EXIT_FAILURE);
}
-
+\&
while ((nread = getline(&line, &len, stream)) != \-1) {
printf("Retrieved line of length %zd:\en", nread);
fwrite(line, nread, 1, stdout);
}
-
+\&
free(line);
fclose(stream);
exit(EXIT_SUCCESS);
diff --git a/man3/getnameinfo.3 b/man3/getnameinfo.3
index 6e4331884..72844cfe6 100644
--- a/man3/getnameinfo.3
+++ b/man3/getnameinfo.3
@@ -283,7 +283,7 @@ a particular address family.
struct sockaddr *addr; /* input */
socklen_t addrlen; /* input */
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
-
+\&
if (getnameinfo(addr, addrlen, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
printf("host=%s, serv=%s\en", hbuf, sbuf);
@@ -298,7 +298,7 @@ reverse address mapping.
struct sockaddr *addr; /* input */
socklen_t addrlen; /* input */
char hbuf[NI_MAXHOST];
-
+\&
if (getnameinfo(addr, addrlen, hbuf, sizeof(hbuf),
NULL, 0, NI_NAMEREQD))
printf("could not resolve hostname");
diff --git a/man3/getopt.3 b/man3/getopt.3
index 45687b06e..b1c7f2df1 100644
--- a/man3/getopt.3
+++ b/man3/getopt.3
@@ -444,13 +444,13 @@ which expects an associated value.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int flags, opt;
int nsecs, tfnd;
-
+\&
nsecs = 0;
tfnd = 0;
flags = 0;
@@ -469,19 +469,19 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
-
+\&
printf("flags=%d; tfnd=%d; nsecs=%d; optind=%d\en",
flags, tfnd, nsecs, optind);
-
+\&
if (optind >= argc) {
fprintf(stderr, "Expected argument after options\en");
exit(EXIT_FAILURE);
}
-
+\&
printf("name argument = %s\en", argv[optind]);
-
+\&
/* Other code omitted */
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -496,13 +496,13 @@ with most of its features.
#include <getopt.h>
#include <stdio.h> /* for printf */
#include <stdlib.h> /* for exit */
-
+\&
int
main(int argc, char *argv[])
{
int c;
int digit_optind = 0;
-
+\&
while (1) {
int this_option_optind = optind ? optind : 1;
int option_index = 0;
@@ -515,12 +515,12 @@ main(int argc, char *argv[])
{"file", required_argument, 0, 0 },
{0, 0, 0, 0 }
};
-
+\&
c = getopt_long(argc, argv, "abc:d:012",
long_options, &option_index);
if (c == \-1)
break;
-
+\&
switch (c) {
case 0:
printf("option %s", long_options[option_index].name);
@@ -528,7 +528,7 @@ main(int argc, char *argv[])
printf(" with arg %s", optarg);
printf("\en");
break;
-
+\&
case \[aq]0\[aq]:
case \[aq]1\[aq]:
case \[aq]2\[aq]:
@@ -537,38 +537,38 @@ main(int argc, char *argv[])
digit_optind = this_option_optind;
printf("option %c\en", c);
break;
-
+\&
case \[aq]a\[aq]:
printf("option a\en");
break;
-
+\&
case \[aq]b\[aq]:
printf("option b\en");
break;
-
+\&
case \[aq]c\[aq]:
printf("option c with value \[aq]%s\[aq]\en", optarg);
break;
-
+\&
case \[aq]d\[aq]:
printf("option d with value \[aq]%s\[aq]\en", optarg);
break;
-
+\&
case \[aq]?\[aq]:
break;
-
+\&
default:
printf("?? getopt returned character code 0%o ??\en", c);
}
}
-
+\&
if (optind < argc) {
printf("non\-option ARGV\-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
printf("\en");
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getprotoent_r.3 b/man3/getprotoent_r.3
index 5bdcdb1b1..0c08368f7 100644
--- a/man3/getprotoent_r.3
+++ b/man3/getprotoent_r.3
@@ -176,9 +176,9 @@ Call failed/record not found
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
#define MAX_BUF 10000
-
+\&
int
main(int argc, char *argv[])
{
@@ -186,21 +186,21 @@ main(int argc, char *argv[])
struct protoent result_buf;
struct protoent *result;
char buf[MAX_BUF];
-
+\&
if (argc < 2) {
printf("Usage: %s proto\-name [buflen]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
buflen = 1024;
if (argc > 2)
buflen = atoi(argv[2]);
-
+\&
if (buflen > MAX_BUF) {
printf("Exceeded buffer limit (%d)\en", MAX_BUF);
exit(EXIT_FAILURE);
}
-
+\&
erange_cnt = 0;
do {
s = getprotobyname_r(argv[1], &result_buf,
@@ -209,34 +209,34 @@ main(int argc, char *argv[])
if (erange_cnt == 0)
printf("ERANGE! Retrying with larger buffer\en");
erange_cnt++;
-
+\&
/* Increment a byte at a time so we can see exactly
what size buffer was required. */
-
+\&
buflen++;
-
+\&
if (buflen > MAX_BUF) {
printf("Exceeded buffer limit (%d)\en", MAX_BUF);
exit(EXIT_FAILURE);
}
}
} while (s == ERANGE);
-
+\&
printf("getprotobyname_r() returned: %s (buflen=%d)\en",
(s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
strerror(s), buflen);
-
+\&
if (s != 0 || result == NULL) {
printf("Call failed/record not found\en");
exit(EXIT_FAILURE);
}
-
+\&
printf("p_name=%s; p_proto=%d; aliases=",
result_buf.p_name, result_buf.p_proto);
for (char **p = result_buf.p_aliases; *p != NULL; p++)
printf("%s ", *p);
printf("\en");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getpwent_r.3 b/man3/getpwent_r.3
index 0e3ed2e27..634cdc405 100644
--- a/man3/getpwent_r.3
+++ b/man3/getpwent_r.3
@@ -182,9 +182,9 @@ in the stream with all other threads.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
#define BUFLEN 4096
-
+\&
int
main(void)
{
@@ -192,7 +192,7 @@ main(void)
struct passwd *pwp;
char buf[BUFLEN];
int i;
-
+\&
setpwent();
while (1) {
i = getpwent_r(&pw, buf, sizeof(buf), &pwp);
diff --git a/man3/getpwnam.3 b/man3/getpwnam.3
index e65a6cd35..3d0c19563 100644
--- a/man3/getpwnam.3
+++ b/man3/getpwnam.3
@@ -289,7 +289,7 @@ supplied as a command-line argument.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -298,22 +298,22 @@ main(int argc, char *argv[])
char *buf;
long bufsize;
int s;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s username\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
if (bufsize == \-1) /* Value was indeterminate */
bufsize = 16384; /* Should be more than enough */
-
+\&
buf = malloc(bufsize);
if (buf == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
-
+\&
s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
if (result == NULL) {
if (s == 0)
@@ -324,7 +324,7 @@ main(int argc, char *argv[])
}
exit(EXIT_FAILURE);
}
-
+\&
printf("Name: %s; UID: %jd\en", pwd.pw_gecos,
(intmax_t) pwd.pw_uid);
exit(EXIT_SUCCESS);
diff --git a/man3/getservent_r.3 b/man3/getservent_r.3
index 4c0652ed3..2620d2b9e 100644
--- a/man3/getservent_r.3
+++ b/man3/getservent_r.3
@@ -176,9 +176,9 @@ Call failed/record not found
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
#define MAX_BUF 10000
-
+\&
int
main(int argc, char *argv[])
{
@@ -187,25 +187,25 @@ main(int argc, char *argv[])
struct servent *result;
char buf[MAX_BUF];
char *protop;
-
+\&
if (argc < 3) {
printf("Usage: %s port\-num proto\-name [buflen]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
port = htons(atoi(argv[1]));
protop = (strcmp(argv[2], "null") == 0 ||
strcmp(argv[2], "NULL") == 0) ? NULL : argv[2];
-
+\&
buflen = 1024;
if (argc > 3)
buflen = atoi(argv[3]);
-
+\&
if (buflen > MAX_BUF) {
printf("Exceeded buffer limit (%d)\en", MAX_BUF);
exit(EXIT_FAILURE);
}
-
+\&
erange_cnt = 0;
do {
s = getservbyport_r(port, protop, &result_buf,
@@ -214,35 +214,35 @@ main(int argc, char *argv[])
if (erange_cnt == 0)
printf("ERANGE! Retrying with larger buffer\en");
erange_cnt++;
-
+\&
/* Increment a byte at a time so we can see exactly
what size buffer was required. */
-
+\&
buflen++;
-
+\&
if (buflen > MAX_BUF) {
printf("Exceeded buffer limit (%d)\en", MAX_BUF);
exit(EXIT_FAILURE);
}
}
} while (s == ERANGE);
-
+\&
printf("getservbyport_r() returned: %s (buflen=%d)\en",
(s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
strerror(s), buflen);
-
+\&
if (s != 0 || result == NULL) {
printf("Call failed/record not found\en");
exit(EXIT_FAILURE);
}
-
+\&
printf("s_name=%s; s_proto=%s; s_port=%d; aliases=",
result_buf.s_name, result_buf.s_proto,
ntohs(result_buf.s_port));
for (char **p = result_buf.s_aliases; *p != NULL; p++)
printf("%s ", *p);
printf("\en");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getsubopt.3 b/man3/getsubopt.3
index 9aee2321b..50b392400 100644
--- a/man3/getsubopt.3
+++ b/man3/getsubopt.3
@@ -164,9 +164,9 @@ The following program expects suboptions following a "\-o" option.
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
-
+\&
#include <assert.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -184,27 +184,27 @@ main(int argc, char *argv[])
char *subopts;
char *value;
int opt;
-
+\&
int readonly = 0;
int readwrite = 0;
char *name = NULL;
int errfnd = 0;
-
+\&
while ((opt = getopt(argc, argv, "o:")) != \-1) {
switch (opt) {
case \[aq]o\[aq]:
subopts = optarg;
while (*subopts != \[aq]\e0\[aq] && !errfnd) {
-
+\&
switch (getsubopt(&subopts, token, &value)) {
case RO_OPT:
readonly = 1;
break;
-
+\&
case RW_OPT:
readwrite = 1;
break;
-
+\&
case NAME_OPT:
if (value == NULL) {
fprintf(stderr,
@@ -213,10 +213,10 @@ main(int argc, char *argv[])
errfnd = 1;
continue;
}
-
+\&
name = value;
break;
-
+\&
default:
fprintf(stderr,
"No match found for token: /%s/\en", value);
@@ -231,21 +231,21 @@ main(int argc, char *argv[])
errfnd = 1;
}
break;
-
+\&
default:
errfnd = 1;
}
}
-
+\&
if (errfnd || argc == 1) {
fprintf(stderr, "\enUsage: %s \-o <suboptstring>\en", argv[0]);
fprintf(stderr,
"suboptions are \[aq]ro\[aq], \[aq]rw\[aq], and \[aq]name=<value>\[aq]\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Remainder of program... */
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/getutent.3 b/man3/getutent.3
index f79479715..88d323990 100644
--- a/man3/getutent.3
+++ b/man3/getutent.3
@@ -304,14 +304,14 @@ and
#include <time.h>
#include <unistd.h>
#include <utmp.h>
-
+\&
int
main(void)
{
struct utmp entry;
-
+\&
system("echo before adding entry:;who");
-
+\&
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
@@ -323,18 +323,18 @@ main(void)
entry.ut_addr = 0;
setutent();
pututline(&entry);
-
+\&
system("echo after adding entry:;who");
-
+\&
entry.ut_type = DEAD_PROCESS;
memset(entry.ut_line, 0, UT_LINESIZE);
entry.ut_time = 0;
memset(entry.ut_user, 0, UT_NAMESIZE);
setutent();
pututline(&entry);
-
+\&
system("echo after removing entry:;who");
-
+\&
endutent();
exit(EXIT_SUCCESS);
}
diff --git a/man3/glob.3 b/man3/glob.3
index c8b5be332..41fb111e5 100644
--- a/man3/glob.3
+++ b/man3/glob.3
@@ -329,7 +329,7 @@ in the shell:
.in +4n
.EX
glob_t globbuf;
-
+\&
globbuf.gl_offs = 2;
glob("*.c", GLOB_DOOFFS, NULL, &globbuf);
glob("../*.c", GLOB_DOOFFS | GLOB_APPEND, NULL, &globbuf);
diff --git a/man3/gnu_get_libc_version.3 b/man3/gnu_get_libc_version.3
index 86f0ebeb4..c819d9c13 100644
--- a/man3/gnu_get_libc_version.3
+++ b/man3/gnu_get_libc_version.3
@@ -66,9 +66,9 @@ GNU libc release: stable
.EX
#include <stdio.h>
#include <stdlib.h>
-
+\&
#include <gnu/libc\-version.h>
-
+\&
int
main(void)
{
diff --git a/man3/hsearch.3 b/man3/hsearch.3
index dfd7787c7..422be88a9 100644
--- a/man3/hsearch.3
+++ b/man3/hsearch.3
@@ -307,22 +307,22 @@ some of them.
#include <search.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
static char *data[] = { "alpha", "bravo", "charlie", "delta",
"echo", "foxtrot", "golf", "hotel", "india", "juliet",
"kilo", "lima", "mike", "november", "oscar", "papa",
"quebec", "romeo", "sierra", "tango", "uniform",
"victor", "whisky", "x\-ray", "yankee", "zulu"
};
-
+\&
int
main(void)
{
ENTRY e;
ENTRY *ep;
-
+\&
hcreate(30);
-
+\&
for (size_t i = 0; i < 24; i++) {
e.key = data[i];
/* data is just an integer, instead of a
@@ -335,7 +335,7 @@ main(void)
exit(EXIT_FAILURE);
}
}
-
+\&
for (size_t i = 22; i < 26; i++) {
/* print two entries from the table, and
show that two are not in the table */
diff --git a/man3/if_nameindex.3 b/man3/if_nameindex.3
index 01dc65980..bb98bb312 100644
--- a/man3/if_nameindex.3
+++ b/man3/if_nameindex.3
@@ -127,23 +127,23 @@ $ \fB./a.out\fI
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
int
main(void)
{
struct if_nameindex *if_ni, *i;
-
+\&
if_ni = if_nameindex();
if (if_ni == NULL) {
perror("if_nameindex");
exit(EXIT_FAILURE);
}
-
+\&
for (i = if_ni; !(i\->if_index == 0 && i\->if_name == NULL); i++)
printf("%u: %s\en", i\->if_index, i\->if_name);
-
+\&
if_freenameindex(if_ni);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/inet.3 b/man3/inet.3
index 8c6912788..e482f12e8 100644
--- a/man3/inet.3
+++ b/man3/inet.3
@@ -197,7 +197,7 @@ as:
.in +4n
.EX
typedef uint32_t in_addr_t;
-
+\&
struct in_addr {
in_addr_t s_addr;
};
@@ -303,22 +303,22 @@ Here are some example runs:
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
struct in_addr addr;
-
+\&
if (argc != 2) {
fprintf(stderr, "%s <dotted\-address>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (inet_aton(argv[1], &addr) == 0) {
fprintf(stderr, "Invalid address\en");
exit(EXIT_FAILURE);
}
-
+\&
printf("%s\en", inet_ntoa(addr));
exit(EXIT_SUCCESS);
}
diff --git a/man3/inet_net_pton.3 b/man3/inet_net_pton.3
index 0da4030de..10ea3b3c6 100644
--- a/man3/inet_net_pton.3
+++ b/man3/inet_net_pton.3
@@ -307,59 +307,59 @@ Raw address: c1a80180
.\" SRC BEGIN (inet_net_pton.c)
.EX
/* Link with "\-lresolv" */
-
+\&
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
int
main(int argc, char *argv[])
{
char buf[100];
struct in_addr addr;
int bits;
-
+\&
if (argc < 2) {
fprintf(stderr,
"Usage: %s presentation\-form [addr\-init\-value]\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* If argv[2] is supplied (a numeric value), use it to initialize
the output buffer given to inet_net_pton(), so that we can see
that inet_net_pton() initializes only those bytes needed for
the network number. If argv[2] is not supplied, then initialize
the buffer to zero (as is recommended practice). */
-
+\&
addr.s_addr = (argc > 2) ? strtod(argv[2], NULL) : 0;
-
+\&
/* Convert presentation network number in argv[1] to binary. */
-
+\&
bits = inet_net_pton(AF_INET, argv[1], &addr, sizeof(addr));
if (bits == \-1)
errExit("inet_net_ntop");
-
+\&
printf("inet_net_pton() returned: %d\en", bits);
-
+\&
/* Convert binary format back to presentation, using \[aq]bits\[aq]
returned by inet_net_pton(). */
-
+\&
if (inet_net_ntop(AF_INET, &addr, bits, buf, sizeof(buf)) == NULL)
errExit("inet_net_ntop");
-
+\&
printf("inet_net_ntop() yielded: %s\en", buf);
-
+\&
/* Display \[aq]addr\[aq] in raw form (in network byte order), so we can
see bytes not displayed by inet_net_ntop(); some of those bytes
may not have been touched by inet_net_ntop(), and so will still
have any initial value that was specified in argv[2]. */
-
+\&
printf("Raw address: %x\en", htonl(addr.s_addr));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/inet_pton.3 b/man3/inet_pton.3
index d51f838fd..54295f648 100644
--- a/man3/inet_pton.3
+++ b/man3/inet_pton.3
@@ -184,22 +184,22 @@ Here are some example runs:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
unsigned char buf[sizeof(struct in6_addr)];
int domain, s;
char str[INET6_ADDRSTRLEN];
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s {i4|i6|<num>} string\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
domain = (strcmp(argv[1], "i4") == 0) ? AF_INET :
(strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]);
-
+\&
s = inet_pton(domain, argv[2], buf);
if (s <= 0) {
if (s == 0)
@@ -208,14 +208,14 @@ main(int argc, char *argv[])
perror("inet_pton");
exit(EXIT_FAILURE);
}
-
+\&
if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {
perror("inet_ntop");
exit(EXIT_FAILURE);
}
-
+\&
printf("%s\en", str);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/insque.3 b/man3/insque.3
index 8793fd272..0a601970a 100644
--- a/man3/insque.3
+++ b/man3/insque.3
@@ -158,36 +158,36 @@ That was a circular list
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
struct element {
struct element *forward;
struct element *backward;
char *name;
};
-
+\&
static struct element *
new_element(void)
{
struct element *e;
-
+\&
e = malloc(sizeof(*e));
if (e == NULL) {
fprintf(stderr, "malloc() failed\en");
exit(EXIT_FAILURE);
}
-
+\&
return e;
}
-
+\&
int
main(int argc, char *argv[])
{
struct element *first, *elem, *prev;
int circular, opt, errfnd;
-
+\&
/* The "\-c" command\-line option can be used to specify that the
list is circular. */
-
+\&
errfnd = 0;
circular = 0;
while ((opt = getopt(argc, argv, "c")) != \-1) {
@@ -200,19 +200,19 @@ main(int argc, char *argv[])
break;
}
}
-
+\&
if (errfnd || optind >= argc) {
fprintf(stderr, "Usage: %s [\-c] string...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Create first element and place it in the linked list. */
-
+\&
elem = new_element();
first = elem;
-
+\&
elem\->name = argv[optind];
-
+\&
if (circular) {
elem\->forward = elem;
elem\->backward = elem;
@@ -220,29 +220,29 @@ main(int argc, char *argv[])
} else {
insque(elem, NULL);
}
-
+\&
/* Add remaining command\-line arguments as list elements. */
-
+\&
while (++optind < argc) {
prev = elem;
-
+\&
elem = new_element();
elem\->name = argv[optind];
insque(elem, prev);
}
-
+\&
/* Traverse the list from the start, printing element names. */
-
+\&
printf("Traversing completed list:\en");
elem = first;
do {
printf(" %s\en", elem\->name);
elem = elem\->forward;
} while (elem != NULL && elem != first);
-
+\&
if (elem == first)
printf("That was a circular list\en");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/list.3 b/man3/list.3
index 03f26e0c8..dbc95bf14 100644
--- a/man3/list.3
+++ b/man3/list.3
@@ -255,36 +255,36 @@ without interfering with the traversal.
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
-
+\&
struct entry {
int data;
LIST_ENTRY(entry) entries; /* List */
};
-
+\&
LIST_HEAD(listhead, entry);
-
+\&
int
main(void)
{
struct entry *n1, *n2, *n3, *np;
struct listhead head; /* List head */
int i;
-
+\&
LIST_INIT(&head); /* Initialize the list */
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the head */
LIST_INSERT_HEAD(&head, n1, entries);
-
+\&
n2 = malloc(sizeof(struct entry)); /* Insert after */
LIST_INSERT_AFTER(n1, n2, entries);
-
+\&
n3 = malloc(sizeof(struct entry)); /* Insert before */
LIST_INSERT_BEFORE(n2, n3, entries);
-
+\&
i = 0; /* Forward traversal */
LIST_FOREACH(np, &head, entries)
np\->data = i++;
-
+\&
LIST_REMOVE(n2, entries); /* Deletion */
free(n2);
/* Forward traversal */
@@ -298,7 +298,7 @@ main(void)
n1 = n2;
}
LIST_INIT(&head);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/makecontext.3 b/man3/makecontext.3
index c46fb8708..89e073ac9 100644
--- a/man3/makecontext.3
+++ b/man3/makecontext.3
@@ -169,12 +169,12 @@ main: exiting
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
-
+\&
static ucontext_t uctx_main, uctx_func1, uctx_func2;
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void
func1(void)
{
@@ -184,7 +184,7 @@ func1(void)
handle_error("swapcontext");
printf("%s: returning\en", __func__);
}
-
+\&
static void
func2(void)
{
@@ -194,20 +194,20 @@ func2(void)
handle_error("swapcontext");
printf("%s: returning\en", __func__);
}
-
+\&
int
main(int argc, char *argv[])
{
char func1_stack[16384];
char func2_stack[16384];
-
+\&
if (getcontext(&uctx_func1) == \-1)
handle_error("getcontext");
uctx_func1.uc_stack.ss_sp = func1_stack;
uctx_func1.uc_stack.ss_size = sizeof(func1_stack);
uctx_func1.uc_link = &uctx_main;
makecontext(&uctx_func1, func1, 0);
-
+\&
if (getcontext(&uctx_func2) == \-1)
handle_error("getcontext");
uctx_func2.uc_stack.ss_sp = func2_stack;
@@ -215,11 +215,11 @@ main(int argc, char *argv[])
/* Successor context is f1(), unless argc > 1 */
uctx_func2.uc_link = (argc > 1) ? NULL : &uctx_func1;
makecontext(&uctx_func2, func2, 0);
-
+\&
printf("%s: swapcontext(&uctx_main, &uctx_func2)\en", __func__);
if (swapcontext(&uctx_main, &uctx_func2) == \-1)
handle_error("swapcontext");
-
+\&
printf("%s: exiting\en", __func__);
exit(EXIT_SUCCESS);
}
diff --git a/man3/mallinfo.3 b/man3/mallinfo.3
index 3a7ee0da6..452abedc9 100644
--- a/man3/mallinfo.3
+++ b/man3/mallinfo.3
@@ -226,7 +226,7 @@ Free bytes held in fastbins (fsmblks): 0
Total allocated space (uordblks): 0
Total free space (fordblks): 0
Topmost releasable block (keepcost): 0
-
+\&
============== After allocating blocks ==============
Total non\-mmapped bytes (arena): 135168
# of free chunks (ordblks): 1
@@ -238,7 +238,7 @@ Free bytes held in fastbins (fsmblks): 0
Total allocated space (uordblks): 104000
Total free space (fordblks): 31168
Topmost releasable block (keepcost): 31168
-
+\&
============== After freeing blocks ==============
Total non\-mmapped bytes (arena): 135168
# of free chunks (ordblks): 501
@@ -259,14 +259,14 @@ Topmost releasable block (keepcost): 31168
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
-
+\&
static void
display_mallinfo2(void)
{
struct mallinfo2 mi;
-
+\&
mi = mallinfo2();
-
+\&
printf("Total non\-mmapped bytes (arena): %zu\en", mi.arena);
printf("# of free chunks (ordblks): %zu\en", mi.ordblks);
printf("# of free fastbin blocks (smblks): %zu\en", mi.smblks);
@@ -278,51 +278,51 @@ display_mallinfo2(void)
printf("Total free space (fordblks): %zu\en", mi.fordblks);
printf("Topmost releasable block (keepcost): %zu\en", mi.keepcost);
}
-
+\&
int
main(int argc, char *argv[])
{
#define MAX_ALLOCS 2000000
char *alloc[MAX_ALLOCS];
size_t blockSize, numBlocks, freeBegin, freeEnd, freeStep;
-
+\&
if (argc < 3 || strcmp(argv[1], "\-\-help") == 0) {
fprintf(stderr, "%s num\-blocks block\-size [free\-step "
"[start\-free [end\-free]]]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
numBlocks = atoi(argv[1]);
blockSize = atoi(argv[2]);
freeStep = (argc > 3) ? atoi(argv[3]) : 1;
freeBegin = (argc > 4) ? atoi(argv[4]) : 0;
freeEnd = (argc > 5) ? atoi(argv[5]) : numBlocks;
-
+\&
printf("============== Before allocating blocks ==============\en");
display_mallinfo2();
-
+\&
for (size_t j = 0; j < numBlocks; j++) {
if (numBlocks >= MAX_ALLOCS) {
fprintf(stderr, "Too many allocations\en");
exit(EXIT_FAILURE);
}
-
+\&
alloc[j] = malloc(blockSize);
if (alloc[j] == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
}
-
+\&
printf("\en============== After allocating blocks ==============\en");
display_mallinfo2();
-
+\&
for (size_t j = freeBegin; j < freeEnd; j += freeStep)
free(alloc[j]);
-
+\&
printf("\en============== After freeing blocks ==============\en");
display_mallinfo2();
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/malloc.3 b/man3/malloc.3
index ad7eed289..7c86de8e4 100644
--- a/man3/malloc.3
+++ b/man3/malloc.3
@@ -403,25 +403,25 @@ and
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
#define MALLOCARRAY(n, type) ((type *) my_mallocarray(n, sizeof(type)))
#define MALLOC(type) MALLOCARRAY(1, type)
-
+\&
static inline void *my_mallocarray(size_t nmemb, size_t size);
-
+\&
int
main(void)
{
char *p;
-
+\&
p = MALLOCARRAY(32, char);
if (p == NULL)
err(EXIT_FAILURE, "malloc");
-
+\&
strlcpy(p, "foo", 32);
puts(p);
}
-
+\&
static inline void *
my_mallocarray(size_t nmemb, size_t size)
{
diff --git a/man3/malloc_hook.3 b/man3/malloc_hook.3
index 83b213cd5..e524d5939 100644
--- a/man3/malloc_hook.3
+++ b/man3/malloc_hook.3
@@ -105,45 +105,45 @@ Here is a short example of how to use these variables.
.EX
#include <stdio.h>
#include <malloc.h>
-
+\&
/* Prototypes for our hooks */
static void my_init_hook(void);
static void *my_malloc_hook(size_t, const void *);
-
+\&
/* Variables to save original hooks */
static void *(*old_malloc_hook)(size_t, const void *);
-
+\&
/* Override initializing hook from the C library */
void (*__malloc_initialize_hook)(void) = my_init_hook;
-
+\&
static void
my_init_hook(void)
{
old_malloc_hook = __malloc_hook;
__malloc_hook = my_malloc_hook;
}
-
+\&
static void *
my_malloc_hook(size_t size, const void *caller)
{
void *result;
-
+\&
/* Restore all old hooks */
__malloc_hook = old_malloc_hook;
-
+\&
/* Call recursively */
result = malloc(size);
-
+\&
/* Save underlying hooks */
old_malloc_hook = __malloc_hook;
-
+\&
/* printf() might call malloc(), so protect it too */
printf("malloc(%zu) called from %p returns %p\en",
size, caller, result);
-
+\&
/* Restore our own hooks */
__malloc_hook = my_malloc_hook;
-
+\&
return result;
}
.EE
diff --git a/man3/malloc_info.3 b/man3/malloc_info.3
index 70f5a8e03..6c73f72c8 100644
--- a/man3/malloc_info.3
+++ b/man3/malloc_info.3
@@ -132,7 +132,7 @@ glibc 2.13
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</malloc>
-
+\&
============ After allocating blocks ============
<malloc version="1">
<heap nr="0">
@@ -173,81 +173,81 @@ glibc 2.13
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
static size_t blockSize;
static size_t numThreads;
static unsigned int numBlocks;
-
+\&
static void *
thread_func(void *arg)
{
int tn = (int) arg;
-
+\&
/* The multiplier \[aq](2 + tn)\[aq] ensures that each thread (including
the main thread) allocates a different amount of memory. */
-
+\&
for (unsigned int j = 0; j < numBlocks; j++)
if (malloc(blockSize * (2 + tn)) == NULL)
err(EXIT_FAILURE, "malloc\-thread");
-
+\&
sleep(100); /* Sleep until main thread terminates. */
return NULL;
}
-
+\&
int
main(int argc, char *argv[])
{
int sleepTime;
pthread_t *thr;
-
+\&
if (argc < 4) {
fprintf(stderr,
"%s num\-threads num\-blocks block\-size [sleep\-time]\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
numThreads = atoi(argv[1]);
numBlocks = atoi(argv[2]);
blockSize = atoi(argv[3]);
sleepTime = (argc > 4) ? atoi(argv[4]) : 0;
-
+\&
thr = calloc(numThreads, sizeof(*thr));
if (thr == NULL)
err(EXIT_FAILURE, "calloc");
-
+\&
printf("============ Before allocating blocks ============\en");
malloc_info(0, stdout);
-
+\&
/* Create threads that allocate different amounts of memory. */
-
+\&
for (size_t tn = 0; tn < numThreads; tn++) {
errno = pthread_create(&thr[tn], NULL, thread_func,
(void *) tn);
if (errno != 0)
err(EXIT_FAILURE, "pthread_create");
-
+\&
/* If we add a sleep interval after the start\-up of each
thread, the threads likely won\[aq]t contend for malloc
mutexes, and therefore additional arenas won\[aq]t be
allocated (see malloc(3)). */
-
+\&
if (sleepTime > 0)
sleep(sleepTime);
}
-
+\&
/* The main thread also allocates some memory. */
-
+\&
for (unsigned int j = 0; j < numBlocks; j++)
if (malloc(blockSize) == NULL)
err(EXIT_FAILURE, "malloc");
-
+\&
sleep(2); /* Give all threads a chance to
complete allocations. */
-
+\&
printf("\en============ After allocating blocks ============\en");
malloc_info(0, stdout);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/mallopt.3 b/man3/mallopt.3
index f43b6d578..5f73c499d 100644
--- a/man3/mallopt.3
+++ b/man3/mallopt.3
@@ -574,31 +574,31 @@ main(): returned from second free() call
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
char *p;
-
+\&
if (argc > 1) {
if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
fprintf(stderr, "mallopt() failed");
exit(EXIT_FAILURE);
}
}
-
+\&
p = malloc(1000);
if (p == NULL) {
fprintf(stderr, "malloc() failed");
exit(EXIT_FAILURE);
}
-
+\&
free(p);
printf("%s(): returned from first free() call\en", __func__);
-
+\&
free(p);
printf("%s(): returned from second free() call\en", __func__);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/matherr.3 b/man3/matherr.3
index 40ff9a62d..5447775c0 100644
--- a/man3/matherr.3
+++ b/man3/matherr.3
@@ -367,13 +367,13 @@ x=12345.000000
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
static int matherr_ret = 0; /* Value that matherr()
should return */
static int change_retval = 0; /* Should matherr() change
function\[aq]s return value? */
static double new_retval; /* New function return value */
-
+\&
int
matherr(struct exception *exc)
{
@@ -388,38 +388,38 @@ matherr(struct exception *exc)
fprintf(stderr, " args: %f, %f\en",
exc\->arg1, exc\->arg2);
fprintf(stderr, " retval: %f\en", exc\->retval);
-
+\&
if (change_retval)
exc\->retval = new_retval;
-
+\&
return matherr_ret;
}
-
+\&
int
main(int argc, char *argv[])
{
double x;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s <argval>"
" [<matherr\-ret> [<new\-func\-retval>]]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (argc > 2) {
_LIB_VERSION = _SVID_;
matherr_ret = atoi(argv[2]);
}
-
+\&
if (argc > 3) {
change_retval = 1;
new_retval = atof(argv[3]);
}
-
+\&
x = log(atof(argv[1]));
if (errno != 0)
perror("errno");
-
+\&
printf("x=%f\en", x);
exit(EXIT_SUCCESS);
}
diff --git a/man3/mbstowcs.3 b/man3/mbstowcs.3
index 8337cb1bd..19651ea57 100644
--- a/man3/mbstowcs.3
+++ b/man3/mbstowcs.3
@@ -137,7 +137,7 @@ $ ./t_mbstowcs de_DE.UTF\-8 Grüße!
Length of source string (excluding terminator):
8 bytes
6 multibyte characters
-
+\&
Wide character string is: Grüße! (6 characters)
G alpha upper
r alpha lower
@@ -157,81 +157,81 @@ Wide character string is: Grüße! (6 characters)
#include <string.h>
#include <wchar.h>
#include <wctype.h>
-
+\&
int
main(int argc, char *argv[])
{
size_t mbslen; /* Number of multibyte characters in source */
wchar_t *wcs; /* Pointer to converted wide character string */
-
+\&
if (argc < 3) {
fprintf(stderr, "Usage: %s <locale> <string>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Apply the specified locale. */
-
+\&
if (setlocale(LC_ALL, argv[1]) == NULL) {
perror("setlocale");
exit(EXIT_FAILURE);
}
-
+\&
/* Calculate the length required to hold argv[2] converted to
a wide character string. */
-
+\&
mbslen = mbstowcs(NULL, argv[2], 0);
if (mbslen == (size_t) \-1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
-
+\&
/* Describe the source string to the user. */
-
+\&
printf("Length of source string (excluding terminator):\en");
printf(" %zu bytes\en", strlen(argv[2]));
printf(" %zu multibyte characters\en\en", mbslen);
-
+\&
/* Allocate wide character string of the desired size. Add 1
to allow for terminating null wide character (L\[aq]\e0\[aq]). */
-
+\&
wcs = calloc(mbslen + 1, sizeof(*wcs));
if (wcs == NULL) {
perror("calloc");
exit(EXIT_FAILURE);
}
-
+\&
/* Convert the multibyte character string in argv[2] to a
wide character string. */
-
+\&
if (mbstowcs(wcs, argv[2], mbslen + 1) == (size_t) \-1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
-
+\&
printf("Wide character string is: %ls (%zu characters)\en",
wcs, mbslen);
-
+\&
/* Now do some inspection of the classes of the characters in
the wide character string. */
-
+\&
for (wchar_t *wp = wcs; *wp != 0; wp++) {
printf(" %lc ", (wint_t) *wp);
-
+\&
if (!iswalpha(*wp))
printf("!");
printf("alpha ");
-
+\&
if (iswalpha(*wp)) {
if (iswupper(*wp))
printf("upper ");
-
+\&
if (iswlower(*wp))
printf("lower ");
}
-
+\&
putchar(\[aq]\en\[aq]);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/mcheck.3 b/man3/mcheck.3
index adf98213a..9d24aaf0a 100644
--- a/man3/mcheck.3
+++ b/man3/mcheck.3
@@ -172,7 +172,7 @@ when running the program:
.EX
.RB "$" " ./a.out"
About to free
-
+\&
About to free a second time
block freed twice
Aborted (core dumped)
@@ -185,25 +185,25 @@ Aborted (core dumped)
#include <mcheck.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
char *p;
-
+\&
if (mcheck(NULL) != 0) {
fprintf(stderr, "mcheck() failed\en");
-
+\&
exit(EXIT_FAILURE);
}
-
+\&
p = malloc(1000);
-
+\&
fprintf(stderr, "About to free\en");
free(p);
fprintf(stderr, "\enAbout to free a second time\en");
free(p);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/mq_getattr.3 b/man3/mq_getattr.3
index 895c4067b..5baf065bf 100644
--- a/man3/mq_getattr.3
+++ b/man3/mq_getattr.3
@@ -190,34 +190,34 @@ $ \fBcat /proc/sys/fs/mqueue/msgsize_default\fP
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
int
main(int argc, char *argv[])
{
mqd_t mqd;
struct mq_attr attr;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s mq\-name\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
mqd = mq_open(argv[1], O_CREAT | O_EXCL, 0600, NULL);
if (mqd == (mqd_t) \-1)
errExit("mq_open");
-
+\&
if (mq_getattr(mqd, &attr) == \-1)
errExit("mq_getattr");
-
+\&
printf("Maximum # of messages on queue: %ld\en", attr.mq_maxmsg);
printf("Maximum message size: %ld\en", attr.mq_msgsize);
-
+\&
if (mq_unlink(argv[1]) == \-1)
errExit("mq_unlink");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/mq_notify.3 b/man3/mq_notify.3
index 371ae4617..4f8eb3f88 100644
--- a/man3/mq_notify.3
+++ b/man3/mq_notify.3
@@ -210,10 +210,10 @@ queue and then terminates the process.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void /* Thread start function */
tfunc(union sigval sv)
{
@@ -221,46 +221,46 @@ tfunc(union sigval sv)
ssize_t nr;
void *buf;
mqd_t mqdes = *((mqd_t *) sv.sival_ptr);
-
+\&
/* Determine max. msg size; allocate buffer to receive msg */
-
+\&
if (mq_getattr(mqdes, &attr) == \-1)
handle_error("mq_getattr");
buf = malloc(attr.mq_msgsize);
if (buf == NULL)
handle_error("malloc");
-
+\&
nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL);
if (nr == \-1)
handle_error("mq_receive");
-
+\&
printf("Read %zd bytes from MQ\en", nr);
free(buf);
exit(EXIT_SUCCESS); /* Terminate the process */
}
-
+\&
int
main(int argc, char *argv[])
{
mqd_t mqdes;
struct sigevent sev;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <mq\-name>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
mqdes = mq_open(argv[1], O_RDONLY);
if (mqdes == (mqd_t) \-1)
handle_error("mq_open");
-
+\&
sev.sigev_notify = SIGEV_THREAD;
sev.sigev_notify_function = tfunc;
sev.sigev_notify_attributes = NULL;
sev.sigev_value.sival_ptr = &mqdes; /* Arg. to thread func. */
if (mq_notify(mqdes, &sev) == \-1)
handle_error("mq_notify");
-
+\&
pause(); /* Process will be terminated by thread function */
}
.EE
diff --git a/man3/mtrace.3 b/man3/mtrace.3
index 3713ffedf..c7fb2f81f 100644
--- a/man3/mtrace.3
+++ b/man3/mtrace.3
@@ -132,15 +132,15 @@ The demonstration uses the following program:
#include <mcheck.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
mtrace();
-
+\&
for (unsigned int j = 0; j < 2; j++)
malloc(100); /* Never freed\-\-a memory leak */
-
+\&
calloc(16, 16); /* Never freed\-\-a memory leak */
exit(EXIT_SUCCESS);
}
diff --git a/man3/newlocale.3 b/man3/newlocale.3
index 48fbeff6e..5d10e9a90 100644
--- a/man3/newlocale.3
+++ b/man3/newlocale.3
@@ -279,10 +279,10 @@ Te Paraire, te 07 o Poutū\-te\-rangi, 2014 00:38:44 CET
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
int
main(int argc, char *argv[])
{
@@ -291,58 +291,58 @@ main(int argc, char *argv[])
size_t s;
struct tm *tm;
locale_t loc, nloc;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s locale1 [locale2]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
/* Create a new locale object, taking the LC_NUMERIC settings
from the locale specified in argv[1]. */
-
+\&
loc = newlocale(LC_NUMERIC_MASK, argv[1], (locale_t) 0);
if (loc == (locale_t) 0)
errExit("newlocale");
-
+\&
/* If a second command\-line argument was specified, modify the
locale object to take the LC_TIME settings from the locale
specified in argv[2]. We assign the result of this newlocale()
call to \[aq]nloc\[aq] rather than \[aq]loc\[aq], since in some cases, we might
want to preserve \[aq]loc\[aq] if this call fails. */
-
+\&
if (argc > 2) {
nloc = newlocale(LC_TIME_MASK, argv[2], loc);
if (nloc == (locale_t) 0)
errExit("newlocale");
loc = nloc;
}
-
+\&
/* Apply the newly created locale to this thread. */
-
+\&
uselocale(loc);
-
+\&
/* Test effect of LC_NUMERIC. */
-
+\&
printf("%8.3f\en", 123456.789);
-
+\&
/* Test effect of LC_TIME. */
-
+\&
t = time(NULL);
tm = localtime(&t);
if (tm == NULL)
errExit("time");
-
+\&
s = strftime(buf, sizeof(buf), "%c", tm);
if (s == 0)
errExit("strftime");
-
+\&
printf("%s\en", buf);
-
+\&
/* Free the locale object. */
-
+\&
uselocale(LC_GLOBAL_LOCALE); /* So \[aq]loc\[aq] is no longer in use */
freelocale(loc);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/nl_langinfo.3 b/man3/nl_langinfo.3
index 63d411745..efe74e9e4 100644
--- a/man3/nl_langinfo.3
+++ b/man3/nl_langinfo.3
@@ -332,16 +332,16 @@ the radix character.
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "");
-
+\&
printf("%s\en", nl_langinfo(CODESET));
printf("%s\en", nl_langinfo(RADIXCHAR));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/ntp_gettime.3 b/man3/ntp_gettime.3
index 8899b56e9..5da0b0915 100644
--- a/man3/ntp_gettime.3
+++ b/man3/ntp_gettime.3
@@ -28,7 +28,7 @@ struct ntptimeval {
long maxerror; /* Maximum error */
long esterror; /* Estimated error */
long tai; /* TAI offset */
-
+\&
/* Further padding bytes allowing for future expansion */
};
.EE
diff --git a/man3/offsetof.3 b/man3/offsetof.3
index b234e5ce1..65e0ee4c2 100644
--- a/man3/offsetof.3
+++ b/man3/offsetof.3
@@ -86,7 +86,7 @@ sizeof(struct s)=16
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
@@ -96,14 +96,14 @@ main(void)
double d;
char a[];
};
-
+\&
/* Output is compiler dependent */
-
+\&
printf("offsets: i=%zu; c=%zu; d=%zu a=%zu\en",
offsetof(struct s, i), offsetof(struct s, c),
offsetof(struct s, d), offsetof(struct s, a));
printf("sizeof(struct s)=%zu\en", sizeof(struct s));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/posix_spawn.3 b/man3/posix_spawn.3
index 32dc1211c..b0190858d 100644
--- a/man3/posix_spawn.3
+++ b/man3/posix_spawn.3
@@ -635,7 +635,7 @@ can't be blocked).
$ \fB./a.out \-s sleep 60 &\fP
[1] 7637
$ PID of child: 7638
-
+.PP
$ \fBkill 7638\fP
$ \fBkill \-KILL 7638\fP
$ Child status: killed by signal 9
@@ -666,16 +666,16 @@ Child status: exited, status=127
#include <string.h>
#include <unistd.h>
#include <wait.h>
-
+\&
#define errExit(msg) do { perror(msg); \e
exit(EXIT_FAILURE); } while (0)
-
+\&
#define errExitEN(en, msg) \e
do { errno = en; perror(msg); \e
exit(EXIT_FAILURE); } while (0)
-
+\&
char **environ;
-
+\&
int
main(int argc, char *argv[])
{
@@ -686,87 +686,87 @@ main(int argc, char *argv[])
posix_spawnattr_t *attrp;
posix_spawn_file_actions_t file_actions;
posix_spawn_file_actions_t *file_actionsp;
-
+\&
/* Parse command\-line options, which can be used to specify an
attributes object and file actions object for the child. */
-
+\&
attrp = NULL;
file_actionsp = NULL;
-
+\&
while ((opt = getopt(argc, argv, "sc")) != \-1) {
switch (opt) {
case \[aq]c\[aq]: /* \-c: close standard output in child */
-
+\&
/* Create a file actions object and add a "close"
action to it. */
-
+\&
s = posix_spawn_file_actions_init(&file_actions);
if (s != 0)
errExitEN(s, "posix_spawn_file_actions_init");
-
+\&
s = posix_spawn_file_actions_addclose(&file_actions,
STDOUT_FILENO);
if (s != 0)
errExitEN(s, "posix_spawn_file_actions_addclose");
-
+\&
file_actionsp = &file_actions;
break;
-
+\&
case \[aq]s\[aq]: /* \-s: block all signals in child */
-
+\&
/* Create an attributes object and add a "set signal mask"
action to it. */
-
+\&
s = posix_spawnattr_init(&attr);
if (s != 0)
errExitEN(s, "posix_spawnattr_init");
s = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK);
if (s != 0)
errExitEN(s, "posix_spawnattr_setflags");
-
+\&
sigfillset(&mask);
s = posix_spawnattr_setsigmask(&attr, &mask);
if (s != 0)
errExitEN(s, "posix_spawnattr_setsigmask");
-
+\&
attrp = &attr;
break;
}
}
-
+\&
/* Spawn the child. The name of the program to execute and the
command\-line arguments are taken from the command\-line arguments
of this program. The environment of the program execed in the
child is made the same as the parent\[aq]s environment. */
-
+\&
s = posix_spawnp(&child_pid, argv[optind], file_actionsp, attrp,
&argv[optind], environ);
if (s != 0)
errExitEN(s, "posix_spawn");
-
+\&
/* Destroy any objects that we created earlier. */
-
+\&
if (attrp != NULL) {
s = posix_spawnattr_destroy(attrp);
if (s != 0)
errExitEN(s, "posix_spawnattr_destroy");
}
-
+\&
if (file_actionsp != NULL) {
s = posix_spawn_file_actions_destroy(file_actionsp);
if (s != 0)
errExitEN(s, "posix_spawn_file_actions_destroy");
}
-
+\&
printf("PID of child: %jd\en", (intmax_t) child_pid);
-
+\&
/* Monitor status of the child until it terminates. */
-
+\&
do {
s = waitpid(child_pid, &status, WUNTRACED | WCONTINUED);
if (s == \-1)
errExit("waitpid");
-
+\&
printf("Child status: ");
if (WIFEXITED(status)) {
printf("exited, status=%d\en", WEXITSTATUS(status));
@@ -778,7 +778,7 @@ main(int argc, char *argv[])
printf("continued\en");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/printf.3 b/man3/printf.3
index b90a71293..962881a9c 100644
--- a/man3/printf.3
+++ b/man3/printf.3
@@ -1192,7 +1192,7 @@ To allocate a sufficiently large string and print into it
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-
+\&
char *
make_message(const char *fmt, ...)
{
@@ -1200,30 +1200,30 @@ make_message(const char *fmt, ...)
size_t size = 0;
char *p = NULL;
va_list ap;
-
+\&
/* Determine required size. */
-
+\&
va_start(ap, fmt);
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
-
+\&
if (n < 0)
return NULL;
-
+\&
size = (size_t) n + 1; /* One extra byte for \[aq]\e0\[aq] */
p = malloc(size);
if (p == NULL)
return NULL;
-
+\&
va_start(ap, fmt);
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
-
+\&
if (n < 0) {
free(p);
return NULL;
}
-
+\&
return p;
}
.EE
diff --git a/man3/pthread_attr_init.3 b/man3/pthread_attr_init.3
index 22abc969d..60657ee4b 100644
--- a/man3/pthread_attr_init.3
+++ b/man3/pthread_attr_init.3
@@ -158,7 +158,7 @@ Thread attributes:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
static void
display_pthread_attr(pthread_attr_t *attr, char *prefix)
{
@@ -166,7 +166,7 @@ display_pthread_attr(pthread_attr_t *attr, char *prefix)
size_t v;
void *stkaddr;
struct sched_param sp;
-
+\&
s = pthread_attr_getdetachstate(attr, &i);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");
@@ -174,7 +174,7 @@ display_pthread_attr(pthread_attr_t *attr, char *prefix)
(i == PTHREAD_CREATE_DETACHED) ? "PTHREAD_CREATE_DETACHED" :
(i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE" :
"???");
-
+\&
s = pthread_attr_getscope(attr, &i);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getscope");
@@ -182,7 +182,7 @@ display_pthread_attr(pthread_attr_t *attr, char *prefix)
(i == PTHREAD_SCOPE_SYSTEM) ? "PTHREAD_SCOPE_SYSTEM" :
(i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS" :
"???");
-
+\&
s = pthread_attr_getinheritsched(attr, &i);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");
@@ -190,7 +190,7 @@ display_pthread_attr(pthread_attr_t *attr, char *prefix)
(i == PTHREAD_INHERIT_SCHED) ? "PTHREAD_INHERIT_SCHED" :
(i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED" :
"???");
-
+\&
s = pthread_attr_getschedpolicy(attr, &i);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");
@@ -199,44 +199,44 @@ display_pthread_attr(pthread_attr_t *attr, char *prefix)
(i == SCHED_FIFO) ? "SCHED_FIFO" :
(i == SCHED_RR) ? "SCHED_RR" :
"???");
-
+\&
s = pthread_attr_getschedparam(attr, &sp);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");
printf("%sScheduling priority = %d\en", prefix, sp.sched_priority);
-
+\&
s = pthread_attr_getguardsize(attr, &v);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
printf("%sGuard size = %zu bytes\en", prefix, v);
-
+\&
s = pthread_attr_getstack(attr, &stkaddr, &v);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getstack");
printf("%sStack address = %p\en", prefix, stkaddr);
printf("%sStack size = %#zx bytes\en", prefix, v);
}
-
+\&
static void *
thread_start(void *arg)
{
int s;
pthread_attr_t gattr;
-
+\&
/* pthread_getattr_np() is a non\-standard GNU extension that
retrieves the attributes of the thread specified in its
first argument. */
-
+\&
s = pthread_getattr_np(pthread_self(), &gattr);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_getattr_np");
-
+\&
printf("Thread attributes:\en");
display_pthread_attr(&gattr, "\et");
-
+\&
exit(EXIT_SUCCESS); /* Terminate all threads */
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -244,54 +244,54 @@ main(int argc, char *argv[])
pthread_attr_t attr;
pthread_attr_t *attrp; /* NULL or &attr */
int s;
-
+\&
attrp = NULL;
-
+\&
/* If a command\-line argument was supplied, use it to set the
stack\-size attribute and set a few other thread attributes,
and set attrp pointing to thread attributes object. */
-
+\&
if (argc > 1) {
size_t stack_size;
void *sp;
-
+\&
attrp = &attr;
-
+\&
s = pthread_attr_init(&attr);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_init");
-
+\&
s = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_setdetachstate");
-
+\&
s = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_setinheritsched");
-
+\&
stack_size = strtoul(argv[1], NULL, 0);
-
+\&
s = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stack_size);
if (s != 0)
errc(EXIT_FAILURE, s, "posix_memalign");
-
+\&
printf("posix_memalign() allocated at %p\en", sp);
-
+\&
s = pthread_attr_setstack(&attr, sp, stack_size);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_setstack");
}
-
+\&
s = pthread_create(&thr, attrp, &thread_start, NULL);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_create");
-
+\&
if (attrp != NULL) {
s = pthread_attr_destroy(attrp);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_destroy");
}
-
+\&
pause(); /* Terminates when other thread calls exit() */
}
.EE
diff --git a/man3/pthread_cancel.3 b/man3/pthread_cancel.3
index 231466119..5ff2ff8f7 100644
--- a/man3/pthread_cancel.3
+++ b/man3/pthread_cancel.3
@@ -157,66 +157,66 @@ main(): thread was canceled
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void *
thread_func(void *ignored_argument)
{
int s;
-
+\&
/* Disable cancelation for a while, so that we don\[aq]t
immediately react to a cancelation request. */
-
+\&
s = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
if (s != 0)
handle_error_en(s, "pthread_setcancelstate");
-
+\&
printf("%s(): started; cancelation disabled\en", __func__);
sleep(5);
printf("%s(): about to enable cancelation\en", __func__);
-
+\&
s = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
if (s != 0)
handle_error_en(s, "pthread_setcancelstate");
-
+\&
/* sleep() is a cancelation point. */
-
+\&
sleep(1000); /* Should get canceled while we sleep */
-
+\&
/* Should never get here. */
-
+\&
printf("%s(): not canceled!\en", __func__);
return NULL;
}
-
+\&
int
main(void)
{
pthread_t thr;
void *res;
int s;
-
+\&
/* Start a thread and then send it a cancelation request. */
-
+\&
s = pthread_create(&thr, NULL, &thread_func, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
-
+\&
sleep(2); /* Give thread a chance to get started */
-
+\&
printf("%s(): sending cancelation request\en", __func__);
s = pthread_cancel(thr);
if (s != 0)
handle_error_en(s, "pthread_cancel");
-
+\&
/* Join with thread to see what its exit status was. */
-
+\&
s = pthread_join(thr, &res);
if (s != 0)
handle_error_en(s, "pthread_join");
-
+\&
if (res == PTHREAD_CANCELED)
printf("%s(): thread was canceled\en", __func__);
else
diff --git a/man3/pthread_cleanup_push.3 b/man3/pthread_cleanup_push.3
index 658b73277..215f01d9f 100644
--- a/man3/pthread_cleanup_push.3
+++ b/man3/pthread_cleanup_push.3
@@ -238,32 +238,32 @@ was nonzero.
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static int done = 0;
static int cleanup_pop_arg = 0;
static int cnt = 0;
-
+\&
static void
cleanup_handler(void *arg)
{
printf("Called clean\-up handler\en");
cnt = 0;
}
-
+\&
static void *
thread_start(void *arg)
{
time_t curr;
-
+\&
printf("New thread started\en");
-
+\&
pthread_cleanup_push(cleanup_handler, NULL);
-
+\&
curr = time(NULL);
-
+\&
while (!done) {
pthread_testcancel(); /* A cancelation point */
if (curr < time(NULL)) {
@@ -272,40 +272,40 @@ thread_start(void *arg)
cnt++;
}
}
-
+\&
pthread_cleanup_pop(cleanup_pop_arg);
return NULL;
}
-
+\&
int
main(int argc, char *argv[])
{
pthread_t thr;
int s;
void *res;
-
+\&
s = pthread_create(&thr, NULL, thread_start, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
-
+\&
sleep(2); /* Allow new thread to run a while */
-
+\&
if (argc > 1) {
if (argc > 2)
cleanup_pop_arg = atoi(argv[2]);
done = 1;
-
+\&
} else {
printf("Canceling thread\en");
s = pthread_cancel(thr);
if (s != 0)
handle_error_en(s, "pthread_cancel");
}
-
+\&
s = pthread_join(thr, &res);
if (s != 0)
handle_error_en(s, "pthread_join");
-
+\&
if (res == PTHREAD_CANCELED)
printf("Thread was canceled; cnt = %d\en", cnt);
else
diff --git a/man3/pthread_cleanup_push_defer_np.3 b/man3/pthread_cleanup_push_defer_np.3
index b14c11a86..b60ea81c2 100644
--- a/man3/pthread_cleanup_push_defer_np.3
+++ b/man3/pthread_cleanup_push_defer_np.3
@@ -79,7 +79,7 @@ is equivalent to (but shorter and more efficient than):
.in +4n
.EX
int oldtype;
-
+\&
pthread_cleanup_push(routine, arg);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
\&...
diff --git a/man3/pthread_create.3 b/man3/pthread_create.3
index b90bd7494..033acf01e 100644
--- a/man3/pthread_create.3
+++ b/man3/pthread_create.3
@@ -276,41 +276,41 @@ Joined with thread 3; returned value was SERVUS
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
struct thread_info { /* Used as argument to thread_start() */
pthread_t thread_id; /* ID returned by pthread_create() */
int thread_num; /* Application\-defined thread # */
char *argv_string; /* From command\-line argument */
};
-
+\&
/* Thread start function: display address near top of our stack,
and return upper\-cased copy of argv_string. */
-
+\&
static void *
thread_start(void *arg)
{
struct thread_info *tinfo = arg;
char *uargv;
-
+\&
printf("Thread %d: top of stack near %p; argv_string=%s\en",
tinfo\->thread_num, (void *) &tinfo, tinfo\->argv_string);
-
+\&
uargv = strdup(tinfo\->argv_string);
if (uargv == NULL)
handle_error("strdup");
-
+\&
for (char *p = uargv; *p != \[aq]\e0\[aq]; p++)
*p = toupper(*p);
-
+\&
return uargv;
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -320,77 +320,77 @@ main(int argc, char *argv[])
ssize_t stack_size;
pthread_attr_t attr;
struct thread_info *tinfo;
-
+\&
/* The "\-s" option specifies a stack size for our threads. */
-
+\&
stack_size = \-1;
while ((opt = getopt(argc, argv, "s:")) != \-1) {
switch (opt) {
case \[aq]s\[aq]:
stack_size = strtoul(optarg, NULL, 0);
break;
-
+\&
default:
fprintf(stderr, "Usage: %s [\-s stack\-size] arg...\en",
argv[0]);
exit(EXIT_FAILURE);
}
}
-
+\&
num_threads = argc \- optind;
-
+\&
/* Initialize thread creation attributes. */
-
+\&
s = pthread_attr_init(&attr);
if (s != 0)
handle_error_en(s, "pthread_attr_init");
-
+\&
if (stack_size > 0) {
s = pthread_attr_setstacksize(&attr, stack_size);
if (s != 0)
handle_error_en(s, "pthread_attr_setstacksize");
}
-
+\&
/* Allocate memory for pthread_create() arguments. */
-
+\&
tinfo = calloc(num_threads, sizeof(*tinfo));
if (tinfo == NULL)
handle_error("calloc");
-
+\&
/* Create one thread for each command\-line argument. */
-
+\&
for (size_t tnum = 0; tnum < num_threads; tnum++) {
tinfo[tnum].thread_num = tnum + 1;
tinfo[tnum].argv_string = argv[optind + tnum];
-
+\&
/* The pthread_create() call stores the thread ID into
corresponding element of tinfo[]. */
-
+\&
s = pthread_create(&tinfo[tnum].thread_id, &attr,
&thread_start, &tinfo[tnum]);
if (s != 0)
handle_error_en(s, "pthread_create");
}
-
+\&
/* Destroy the thread attributes object, since it is no
longer needed. */
-
+\&
s = pthread_attr_destroy(&attr);
if (s != 0)
handle_error_en(s, "pthread_attr_destroy");
-
+\&
/* Now join with each thread, and display its returned value. */
-
+\&
for (size_t tnum = 0; tnum < num_threads; tnum++) {
s = pthread_join(tinfo[tnum].thread_id, &res);
if (s != 0)
handle_error_en(s, "pthread_join");
-
+\&
printf("Joined with thread %d; returned value was %s\en",
tinfo[tnum].thread_num, (char *) res);
free(res); /* Free memory allocated by thread */
}
-
+\&
free(tinfo);
exit(EXIT_SUCCESS);
}
diff --git a/man3/pthread_getattr_default_np.3 b/man3/pthread_getattr_default_np.3
index 271df0852..1eb434ad1 100644
--- a/man3/pthread_getattr_default_np.3
+++ b/man3/pthread_getattr_default_np.3
@@ -109,7 +109,7 @@ Inherit scheduler: INHERIT
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
static void
display_pthread_attr(pthread_attr_t *attr)
{
@@ -120,17 +120,17 @@ display_pthread_attr(pthread_attr_t *attr)
struct sched_param schedparam;
int detachstate;
int inheritsched;
-
+\&
s = pthread_attr_getstacksize(attr, &stacksize);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getstacksize");
printf("Stack size: %zd\en", stacksize);
-
+\&
s = pthread_attr_getguardsize(attr, &guardsize);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
printf("Guard size: %zd\en", guardsize);
-
+\&
s = pthread_attr_getschedpolicy(attr, &policy);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");
@@ -138,12 +138,12 @@ display_pthread_attr(pthread_attr_t *attr)
(policy == SCHED_FIFO) ? "SCHED_FIFO" :
(policy == SCHED_RR) ? "SCHED_RR" :
(policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
-
+\&
s = pthread_attr_getschedparam(attr, &schedparam);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");
printf("Scheduling priority: %d\en", schedparam.sched_priority);
-
+\&
s = pthread_attr_getdetachstate(attr, &detachstate);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");
@@ -151,7 +151,7 @@ display_pthread_attr(pthread_attr_t *attr)
(detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
(detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
"???");
-
+\&
s = pthread_attr_getinheritsched(attr, &inheritsched);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");
@@ -160,19 +160,19 @@ display_pthread_attr(pthread_attr_t *attr)
(inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
"???");
}
-
+\&
int
main(void)
{
int s;
pthread_attr_t attr;
-
+\&
s = pthread_getattr_default_np(&attr);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_getattr_default_np");
-
+\&
display_pthread_attr(&attr);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/pthread_getattr_np.3 b/man3/pthread_getattr_np.3
index cc397c36d..ddf846010 100644
--- a/man3/pthread_getattr_np.3
+++ b/man3/pthread_getattr_np.3
@@ -134,7 +134,7 @@ Thread attributes object after initializations:
Guard size = 4097 bytes
Stack address = (nil)
Stack size = 0x0 (0) bytes
-
+\&
Attributes of created thread:
Guard size = 8192 bytes
Stack address = 0x40196000 (EOS = 0x40397000)
@@ -163,12 +163,12 @@ In this case, the guard size attribute is ignored.
.EX
.RB "$" " ./a.out \-g 4096 \-s 0x8000 \-a"
Allocated thread stack at 0x804d000
-
+\&
Thread attributes object after initializations:
Guard size = 4096 bytes
Stack address = 0x804d000 (EOS = 0x8055000)
Stack size = 0x8000 (32768) bytes
-
+\&
Attributes of created thread:
Guard size = 0 bytes
Stack address = 0x804d000 (EOS = 0x8055000)
@@ -186,19 +186,19 @@ Attributes of created thread:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
static void
display_stack_related_attributes(pthread_attr_t *attr, char *prefix)
{
int s;
size_t stack_size, guard_size;
void *stack_addr;
-
+\&
s = pthread_attr_getguardsize(attr, &guard_size);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
printf("%sGuard size = %zu bytes\en", prefix, guard_size);
-
+\&
s = pthread_attr_getstack(attr, &stack_addr, &stack_size);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_getstack");
@@ -209,33 +209,33 @@ display_stack_related_attributes(pthread_attr_t *attr, char *prefix)
printf("%sStack size = %#zx (%zu) bytes\en",
prefix, stack_size, stack_size);
}
-
+\&
static void
display_thread_attributes(pthread_t thread, char *prefix)
{
int s;
pthread_attr_t attr;
-
+\&
s = pthread_getattr_np(thread, &attr);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_getattr_np");
-
+\&
display_stack_related_attributes(&attr, prefix);
-
+\&
s = pthread_attr_destroy(&attr);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_destroy");
}
-
+\&
static void * /* Start function for thread we create */
thread_start(void *arg)
{
printf("Attributes of created thread:\en");
display_thread_attributes(pthread_self(), "\et");
-
+\&
exit(EXIT_SUCCESS); /* Terminate all threads */
}
-
+\&
static void
usage(char *pname, char *msg)
{
@@ -246,7 +246,7 @@ usage(char *pname, char *msg)
fprintf(stderr, "\et\et\-a means program should allocate stack\en");
exit(EXIT_FAILURE);
}
-
+\&
static pthread_attr_t * /* Get thread attributes from command line */
get_thread_attributes_from_cl(int argc, char *argv[],
pthread_attr_t *attrp)
@@ -259,7 +259,7 @@ get_thread_attributes_from_cl(int argc, char *argv[],
allocate_stack = 0;
stack_size = \-1;
guard_size = \-1;
-
+\&
while ((opt = getopt(argc, argv, "ag:s:")) != \-1) {
switch (opt) {
case \[aq]a\[aq]: allocate_stack = 1; break;
@@ -268,21 +268,21 @@ get_thread_attributes_from_cl(int argc, char *argv[],
default: usage(argv[0], NULL);
}
}
-
+\&
if (allocate_stack && stack_size == \-1)
usage(argv[0], "Specifying \-a without \-s makes no sense\en");
-
+\&
if (argc > optind)
usage(argv[0], "Extraneous command\-line arguments\en");
-
+\&
if (stack_size >= 0 || guard_size > 0) {
ret_attrp = attrp;
-
+\&
s = pthread_attr_init(attrp);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_init");
}
-
+\&
if (stack_size >= 0) {
if (!allocate_stack) {
s = pthread_attr_setstacksize(attrp, stack_size);
@@ -294,22 +294,22 @@ get_thread_attributes_from_cl(int argc, char *argv[],
if (s != 0)
errc(EXIT_FAILURE, s, "posix_memalign");
printf("Allocated thread stack at %p\en\en", stack_addr);
-
+\&
s = pthread_attr_setstack(attrp, stack_addr, stack_size);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_setstacksize");
}
}
-
+\&
if (guard_size >= 0) {
s = pthread_attr_setguardsize(attrp, guard_size);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_setstacksize");
}
-
+\&
return ret_attrp;
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -318,25 +318,25 @@ main(int argc, char *argv[])
pthread_attr_t attr;
pthread_attr_t *attrp = NULL; /* Set to &attr if we initialize
a thread attributes object */
-
+\&
attrp = get_thread_attributes_from_cl(argc, argv, &attr);
-
+\&
if (attrp != NULL) {
printf("Thread attributes object after initializations:\en");
display_stack_related_attributes(attrp, "\et");
printf("\en");
}
-
+\&
s = pthread_create(&thr, attrp, &thread_start, NULL);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_create");
-
+\&
if (attrp != NULL) {
s = pthread_attr_destroy(attrp);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_attr_destroy");
}
-
+\&
pause(); /* Terminates when other thread calls exit() */
}
.EE
diff --git a/man3/pthread_getcpuclockid.3 b/man3/pthread_getcpuclockid.3
index 92c4b47a0..bac136159 100644
--- a/man3/pthread_getcpuclockid.3
+++ b/man3/pthread_getcpuclockid.3
@@ -101,7 +101,7 @@ Subthread CPU time: 0.992
.\" SRC BEGIN (pthread_getcpuclockid.c)
.EX
/* Link with "\-lrt" */
-
+\&
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
@@ -110,13 +110,13 @@ Subthread CPU time: 0.992
#include <string.h>
#include <time.h>
#include <unistd.h>
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void *
thread_start(void *arg)
{
@@ -124,51 +124,51 @@ thread_start(void *arg)
for (;;)
continue;
}
-
+\&
static void
pclock(char *msg, clockid_t cid)
{
struct timespec ts;
-
+\&
printf("%s", msg);
if (clock_gettime(cid, &ts) == \-1)
handle_error("clock_gettime");
printf("%4jd.%03ld\en", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000);
}
-
+\&
int
main(void)
{
pthread_t thread;
clockid_t cid;
int s;
-
+\&
s = pthread_create(&thread, NULL, thread_start, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
-
+\&
printf("Main thread sleeping\en");
sleep(1);
-
+\&
printf("Main thread consuming some CPU time...\en");
for (unsigned int j = 0; j < 2000000; j++)
getppid();
-
+\&
pclock("Process total CPU time: ", CLOCK_PROCESS_CPUTIME_ID);
-
+\&
s = pthread_getcpuclockid(pthread_self(), &cid);
if (s != 0)
handle_error_en(s, "pthread_getcpuclockid");
pclock("Main thread CPU time: ", cid);
-
+\&
/* The preceding 4 lines of code could have been replaced by:
pclock("Main thread CPU time: ", CLOCK_THREAD_CPUTIME_ID); */
-
+\&
s = pthread_getcpuclockid(thread, &cid);
if (s != 0)
handle_error_en(s, "pthread_getcpuclockid");
pclock("Subthread CPU time: 1 ", cid);
-
+\&
exit(EXIT_SUCCESS); /* Terminates both threads */
}
.EE
diff --git a/man3/pthread_mutexattr_setrobust.3 b/man3/pthread_mutexattr_setrobust.3
index b13ddc8eb..fef113db2 100644
--- a/man3/pthread_mutexattr_setrobust.3
+++ b/man3/pthread_mutexattr_setrobust.3
@@ -195,12 +195,12 @@ $ \fB./a.out\fP
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static pthread_mutex_t mtx;
-
+\&
static void *
original_owner_thread(void *ptr)
{
@@ -209,26 +209,26 @@ original_owner_thread(void *ptr)
printf("[original owner] Locked. Now exiting without unlocking.\en");
pthread_exit(NULL);
}
-
+\&
int
main(void)
{
pthread_t thr;
pthread_mutexattr_t attr;
int s;
-
+\&
pthread_mutexattr_init(&attr);
-
+\&
pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
-
+\&
pthread_mutex_init(&mtx, &attr);
-
+\&
pthread_create(&thr, NULL, original_owner_thread, NULL);
-
+\&
sleep(2);
-
+\&
/* "original_owner_thread" should have exited by now. */
-
+\&
printf("[main] Attempting to lock the robust mutex.\en");
s = pthread_mutex_lock(&mtx);
if (s == EOWNERDEAD) {
@@ -241,7 +241,7 @@ main(void)
s = pthread_mutex_unlock(&mtx);
if (s != 0)
handle_error_en(s, "pthread_mutex_unlock");
-
+\&
exit(EXIT_SUCCESS);
} else if (s == 0) {
printf("[main] pthread_mutex_lock() unexpectedly succeeded\en");
diff --git a/man3/pthread_setaffinity_np.3 b/man3/pthread_setaffinity_np.3
index ed2bb82d7..3aa75c196 100644
--- a/man3/pthread_setaffinity_np.3
+++ b/man3/pthread_setaffinity_np.3
@@ -164,37 +164,37 @@ to check the resulting CPU affinity mask of the thread.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
int s;
cpu_set_t cpuset;
pthread_t thread;
-
+\&
thread = pthread_self();
-
+\&
/* Set affinity mask to include CPUs 0 to 7. */
-
+\&
CPU_ZERO(&cpuset);
for (size_t j = 0; j < 8; j++)
CPU_SET(j, &cpuset);
-
+\&
s = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_setaffinity_np");
-
+\&
/* Check the actual affinity mask assigned to the thread. */
-
+\&
s = pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_getaffinity_np");
-
+\&
printf("Set returned by pthread_getaffinity_np() contained:\en");
for (size_t j = 0; j < CPU_SETSIZE; j++)
if (CPU_ISSET(j, &cpuset))
printf(" CPU %zu\en", j);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/pthread_setname_np.3 b/man3/pthread_setname_np.3
index 71c871497..6cca4c448 100644
--- a/man3/pthread_setname_np.3
+++ b/man3/pthread_setname_np.3
@@ -151,47 +151,47 @@ THREADFOO
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
+\&
#define NAMELEN 16
-
+\&
static void *
threadfunc(void *parm)
{
sleep(5); // allow main program to set the thread name
return NULL;
}
-
+\&
int
main(int argc, char *argv[])
{
pthread_t thread;
int rc;
char thread_name[NAMELEN];
-
+\&
rc = pthread_create(&thread, NULL, threadfunc, NULL);
if (rc != 0)
errc(EXIT_FAILURE, rc, "pthread_create");
-
+\&
rc = pthread_getname_np(thread, thread_name, NAMELEN);
if (rc != 0)
errc(EXIT_FAILURE, rc, "pthread_getname_np");
-
+\&
printf("Created a thread. Default name is: %s\en", thread_name);
rc = pthread_setname_np(thread, (argc > 1) ? argv[1] : "THREADFOO");
if (rc != 0)
errc(EXIT_FAILURE, rc, "pthread_setname_np");
-
+\&
sleep(2);
-
+\&
rc = pthread_getname_np(thread, thread_name, NAMELEN);
if (rc != 0)
errc(EXIT_FAILURE, rc, "pthread_getname_np");
printf("The thread name after setting it is %s.\en", thread_name);
-
+\&
rc = pthread_join(thread, NULL);
if (rc != 0)
errc(EXIT_FAILURE, rc, "pthread_join");
-
+\&
printf("Done\en");
exit(EXIT_SUCCESS);
}
diff --git a/man3/pthread_setschedparam.3 b/man3/pthread_setschedparam.3
index 4de5d4cd7..7b34fdb84 100644
--- a/man3/pthread_setschedparam.3
+++ b/man3/pthread_setschedparam.3
@@ -178,11 +178,11 @@ Password:
# \fB./a.out \-mf10 \-ar20 \-i e\fP
Scheduler settings of main thread
policy=SCHED_FIFO, priority=10
-
+\&
Scheduler settings in \[aq]attr\[aq]
policy=SCHED_RR, priority=20
inheritsched is EXPLICIT
-
+\&
Scheduler attributes of new thread
policy=SCHED_RR, priority=20
.EE
@@ -203,11 +203,11 @@ and instead take their scheduling attributes from the creating thread.
# \fB./a.out \-mf10 \-ar20 \-i i\fP
Scheduler settings of main thread
policy=SCHED_FIFO, priority=10
-
+\&
Scheduler settings in \[aq]attr\[aq]
policy=SCHED_RR, priority=20
inheritsched is INHERIT
-
+\&
Scheduler attributes of new thread
policy=SCHED_FIFO, priority=10
.EE
@@ -227,22 +227,22 @@ is the default for the inherit scheduler attribute.
.\" SRC BEGIN (pthreads_sched_test.c)
.EX
/* pthreads_sched_test.c */
-
+\&
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void
usage(char *prog_name, char *msg)
{
if (msg != NULL)
fputs(msg, stderr);
-
+\&
fprintf(stderr, "Usage: %s [options]\en", prog_name);
fprintf(stderr, "Options are:\en");
#define fpe(msg) fprintf(stderr, "\et%s", msg) /* Shorter */
@@ -259,7 +259,7 @@ usage(char *prog_name, char *msg)
fpe(" main thread before pthread_create() call\en");
exit(EXIT_FAILURE);
}
-
+\&
static int
get_policy(char p, int *policy)
{
@@ -270,7 +270,7 @@ get_policy(char p, int *policy)
default: return 0;
}
}
-
+\&
static void
display_sched_attr(int policy, struct sched_param *param)
{
@@ -281,29 +281,29 @@ display_sched_attr(int policy, struct sched_param *param)
"???",
param\->sched_priority);
}
-
+\&
static void
display_thread_sched_attr(char *msg)
{
int policy, s;
struct sched_param param;
-
+\&
s = pthread_getschedparam(pthread_self(), &policy, &param);
if (s != 0)
handle_error_en(s, "pthread_getschedparam");
-
+\&
printf("%s\en", msg);
display_sched_attr(policy, &param);
}
-
+\&
static void *
thread_start(void *arg)
{
display_thread_sched_attr("Scheduler attributes of new thread");
-
+\&
return NULL;
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -313,14 +313,14 @@ main(int argc, char *argv[])
pthread_attr_t *attrp;
char *attr_sched_str, *main_sched_str, *inheritsched_str;
struct sched_param param;
-
+\&
/* Process command\-line options. */
-
+\&
use_null_attrib = 0;
attr_sched_str = NULL;
main_sched_str = NULL;
inheritsched_str = NULL;
-
+\&
while ((opt = getopt(argc, argv, "a:Ai:m:")) != \-1) {
switch (opt) {
case \[aq]a\[aq]: attr_sched_str = optarg; break;
@@ -330,40 +330,40 @@ main(int argc, char *argv[])
default: usage(argv[0], "Unrecognized option\en");
}
}
-
+\&
if (use_null_attrib
&& (inheritsched_str != NULL || attr_sched_str != NULL))
{
usage(argv[0], "Can\[aq]t specify \-A with \-i or \-a\en");
}
-
+\&
/* Optionally set scheduling attributes of main thread,
and display the attributes. */
-
+\&
if (main_sched_str != NULL) {
if (!get_policy(main_sched_str[0], &policy))
usage(argv[0], "Bad policy for main thread (\-m)\en");
param.sched_priority = strtol(&main_sched_str[1], NULL, 0);
-
+\&
s = pthread_setschedparam(pthread_self(), policy, &param);
if (s != 0)
handle_error_en(s, "pthread_setschedparam");
}
-
+\&
display_thread_sched_attr("Scheduler settings of main thread");
printf("\en");
-
+\&
/* Initialize thread attributes object according to options. */
-
+\&
attrp = NULL;
-
+\&
if (!use_null_attrib) {
s = pthread_attr_init(&attr);
if (s != 0)
handle_error_en(s, "pthread_attr_init");
attrp = &attr;
}
-
+\&
if (inheritsched_str != NULL) {
if (inheritsched_str[0] == \[aq]e\[aq])
inheritsched = PTHREAD_EXPLICIT_SCHED;
@@ -371,17 +371,17 @@ main(int argc, char *argv[])
inheritsched = PTHREAD_INHERIT_SCHED;
else
usage(argv[0], "Value for \-i must be \[aq]e\[aq] or \[aq]i\[aq]\en");
-
+\&
s = pthread_attr_setinheritsched(&attr, inheritsched);
if (s != 0)
handle_error_en(s, "pthread_attr_setinheritsched");
}
-
+\&
if (attr_sched_str != NULL) {
if (!get_policy(attr_sched_str[0], &policy))
usage(argv[0], "Bad policy for \[aq]attr\[aq] (\-a)\en");
param.sched_priority = strtol(&attr_sched_str[1], NULL, 0);
-
+\&
s = pthread_attr_setschedpolicy(&attr, policy);
if (s != 0)
handle_error_en(s, "pthread_attr_setschedpolicy");
@@ -389,10 +389,10 @@ main(int argc, char *argv[])
if (s != 0)
handle_error_en(s, "pthread_attr_setschedparam");
}
-
+\&
/* If we initialized a thread attributes object, display
the scheduling attributes that were set in the object. */
-
+\&
if (attrp != NULL) {
s = pthread_attr_getschedparam(&attr, &param);
if (s != 0)
@@ -400,10 +400,10 @@ main(int argc, char *argv[])
s = pthread_attr_getschedpolicy(&attr, &policy);
if (s != 0)
handle_error_en(s, "pthread_attr_getschedpolicy");
-
+\&
printf("Scheduler settings in \[aq]attr\[aq]\en");
display_sched_attr(policy, &param);
-
+\&
pthread_attr_getinheritsched(&attr, &inheritsched);
printf(" inheritsched is %s\en",
(inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
@@ -411,25 +411,25 @@ main(int argc, char *argv[])
"???");
printf("\en");
}
-
+\&
/* Create a thread that will display its scheduling attributes. */
-
+\&
s = pthread_create(&thread, attrp, &thread_start, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
-
+\&
/* Destroy unneeded thread attributes object. */
-
+\&
if (!use_null_attrib) {
s = pthread_attr_destroy(&attr);
if (s != 0)
handle_error_en(s, "pthread_attr_destroy");
}
-
+\&
s = pthread_join(thread, NULL);
if (s != 0)
handle_error_en(s, "pthread_join");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/pthread_sigmask.3 b/man3/pthread_sigmask.3
index f91b6d365..b4c912e49 100644
--- a/man3/pthread_sigmask.3
+++ b/man3/pthread_sigmask.3
@@ -105,18 +105,18 @@ Signal handling thread got signal 10
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
/* Simple error handling functions */
-
+\&
#define handle_error_en(en, msg) \e
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void *
sig_thread(void *arg)
{
sigset_t *set = arg;
int s, sig;
-
+\&
for (;;) {
s = sigwait(set, &sig);
if (s != 0)
@@ -124,31 +124,31 @@ sig_thread(void *arg)
printf("Signal handling thread got signal %d\en", sig);
}
}
-
+\&
int
main(void)
{
pthread_t thread;
sigset_t set;
int s;
-
+\&
/* Block SIGQUIT and SIGUSR1; other threads created by main()
will inherit a copy of the signal mask. */
-
+\&
sigemptyset(&set);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGUSR1);
s = pthread_sigmask(SIG_BLOCK, &set, NULL);
if (s != 0)
handle_error_en(s, "pthread_sigmask");
-
+\&
s = pthread_create(&thread, NULL, &sig_thread, &set);
if (s != 0)
handle_error_en(s, "pthread_create");
-
+\&
/* Main thread carries on to create other threads and/or do
other work. */
-
+\&
pause(); /* Dummy pause so we can test program */
}
.EE
diff --git a/man3/pthread_tryjoin_np.3 b/man3/pthread_tryjoin_np.3
index d2def80e1..ea6afb46d 100644
--- a/man3/pthread_tryjoin_np.3
+++ b/man3/pthread_tryjoin_np.3
@@ -134,15 +134,15 @@ The following code waits to join for up to 5 seconds:
.EX
struct timespec ts;
int s;
-
+\&
\&...
-
+\&
if (clock_gettime(CLOCK_REALTIME, &ts) == \-1) {
/* Handle error */
}
-
+\&
ts.tv_sec += 5;
-
+\&
s = pthread_timedjoin_np(thread, NULL, &ts);
if (s != 0) {
/* Handle error */
diff --git a/man3/qsort.3 b/man3/qsort.3
index 0801a7eb0..955f8cb43 100644
--- a/man3/qsort.3
+++ b/man3/qsort.3
@@ -126,17 +126,17 @@ which sorts the strings given in its command-line arguments:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
static int
cmpstringp(const void *p1, const void *p2)
{
/* The actual arguments to this function are "pointers to
pointers to char", but strcmp(3) arguments are "pointers
to char", hence the following cast plus dereference. */
-
+\&
return strcmp(*(const char **) p1, *(const char **) p2);
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -144,9 +144,9 @@ main(int argc, char *argv[])
fprintf(stderr, "Usage: %s <string>...\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
-
+\&
for (size_t j = 1; j < argc; j++)
puts(argv[j]);
exit(EXIT_SUCCESS);
diff --git a/man3/rand.3 b/man3/rand.3
index e6cd1fa25..8dfd80fb1 100644
--- a/man3/rand.3
+++ b/man3/rand.3
@@ -181,13 +181,13 @@ possibly useful when one needs the same sequence on two different machines.
.in +4n
.EX
static unsigned long next = 1;
-
+\&
/* RAND_MAX assumed to be 32767 */
int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}
-
+\&
void mysrand(unsigned int seed) {
next = seed;
}
@@ -207,32 +207,32 @@ the program uses a random seed.
.EX
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
int r;
unsigned int seed, nloops;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <seed> <nloops>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
seed = atoi(argv[1]);
nloops = atoi(argv[2]);
-
+\&
if (seed == \-1) {
seed = arc4random();
printf("seed: %u\en", seed);
}
-
+\&
srand(seed);
for (unsigned int j = 0; j < nloops; j++) {
r = rand();
printf("%d\en", r);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/regex.3 b/man3/regex.3
index d245daf23..13e540b22 100644
--- a/man3/regex.3
+++ b/man3/regex.3
@@ -365,40 +365,40 @@ Always reference them by name.
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
-
+\&
#define ARRAY_SIZE(arr) (sizeof((arr)) / sizeof((arr)[0]))
-
+\&
static const char *const str =
"1) John Driverhacker;\en2) John Doe;\en3) John Foo;\en";
static const char *const re = "John.*o";
-
+\&
int main(void)
{
static const char *s = str;
regex_t regex;
regmatch_t pmatch[1];
regoff_t off, len;
-
+\&
if (regcomp(&regex, re, REG_NEWLINE))
exit(EXIT_FAILURE);
-
+\&
printf("String = \e"%s\e"\en", str);
printf("Matches:\en");
-
+\&
for (unsigned int i = 0; ; i++) {
if (regexec(&regex, s, ARRAY_SIZE(pmatch), pmatch, 0))
break;
-
+\&
off = pmatch[0].rm_so + (s \- str);
len = pmatch[0].rm_eo \- pmatch[0].rm_so;
printf("#%zu:\en", i);
printf("offset = %jd; length = %jd\en", (intmax_t) off,
(intmax_t) len);
printf("substring = \e"%.*s\e"\en", len, s + pmatch[0].rm_so);
-
+\&
s += pmatch[0].rm_eo;
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/rpmatch.3 b/man3/rpmatch.3
index 5f5246bb3..b70bf2557 100644
--- a/man3/rpmatch.3
+++ b/man3/rpmatch.3
@@ -149,7 +149,7 @@ is applied to the string given in the program's command-line argument.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
fprintf(stderr, "%s response\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
setlocale(LC_ALL, "");
printf("rpmatch() returns: %d\en", rpmatch(argv[1]));
exit(EXIT_SUCCESS);
diff --git a/man3/rtime.3 b/man3/rtime.3
index 0abcf6fce..80ee2655f 100644
--- a/man3/rtime.3
+++ b/man3/rtime.3
@@ -115,12 +115,12 @@ The result is the localtime of the computer "linux".
#include <stdlib.h>
#include <string.h>
#include <time.h>
-
+\&
#include <rpc/auth_des.h>
-
+\&
static int use_tcp = 0;
static const char servername[] = "linux";
-
+\&
int
main(void)
{
@@ -130,12 +130,12 @@ main(void)
struct rpc_timeval time1 = {0, 0};
struct rpc_timeval timeout = {1, 0};
struct sockaddr_in name;
-
+\&
memset(&name, 0, sizeof(name));
sethostent(1);
hent = gethostbyname(servername);
memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length);
-
+\&
ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
if (ret < 0)
perror("rtime error");
@@ -143,7 +143,7 @@ main(void)
t = time1.tv_sec;
printf("%s\en", ctime(&t));
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/rtnetlink.3 b/man3/rtnetlink.3
index 8050d31d2..4e9a0a02a 100644
--- a/man3/rtnetlink.3
+++ b/man3/rtnetlink.3
@@ -90,20 +90,20 @@ Creating a rtnetlink message to set the MTU of a device:
.in +4n
.EX
#include <linux/rtnetlink.h>
-
+\&
\&...
-
+\&
struct {
struct nlmsghdr nh;
struct ifinfomsg if;
char attrbuf[512];
} req;
-
+\&
struct rtattr *rta;
unsigned int mtu = 1000;
-
+\&
int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
-
+\&
memset(&req, 0, sizeof(req));
req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
req.nh.nlmsg_flags = NLM_F_REQUEST;
diff --git a/man3/scandir.3 b/man3/scandir.3
index 27359c923..3eb65a9a4 100644
--- a/man3/scandir.3
+++ b/man3/scandir.3
@@ -275,25 +275,25 @@ in reverse order.
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
struct dirent **namelist;
int n;
-
+\&
n = scandir(".", &namelist, NULL, alphasort);
if (n == \-1) {
perror("scandir");
exit(EXIT_FAILURE);
}
-
+\&
while (n\-\-) {
printf("%s\en", namelist[n]\->d_name);
free(namelist[n]);
}
free(namelist);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/sem_wait.3 b/man3/sem_wait.3
index 7b61f6dbe..da4893202 100644
--- a/man3/sem_wait.3
+++ b/man3/sem_wait.3
@@ -175,14 +175,14 @@ sem_timedwait() timed out
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
-
+\&
#include <assert.h>
-
+\&
sem_t sem;
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static void
handler(int sig)
{
@@ -192,47 +192,47 @@ handler(int sig)
_exit(EXIT_FAILURE);
}
}
-
+\&
int
main(int argc, char *argv[])
{
struct sigaction sa;
struct timespec ts;
int s;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <alarm\-secs> <wait\-secs>\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (sem_init(&sem, 0, 0) == \-1)
handle_error("sem_init");
-
+\&
/* Establish SIGALRM handler; set alarm timer using argv[1]. */
-
+\&
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGALRM, &sa, NULL) == \-1)
handle_error("sigaction");
-
+\&
alarm(atoi(argv[1]));
-
+\&
/* Calculate relative interval as current time plus
number of seconds given argv[2]. */
-
+\&
if (clock_gettime(CLOCK_REALTIME, &ts) == \-1)
handle_error("clock_gettime");
-
+\&
ts.tv_sec += atoi(argv[2]);
-
+\&
printf("%s() about to call sem_timedwait()\en", __func__);
while ((s = sem_timedwait(&sem, &ts)) == \-1 && errno == EINTR)
continue; /* Restart if interrupted by handler. */
-
+\&
/* Check what happened. */
-
+\&
if (s == \-1) {
if (errno == ETIMEDOUT)
printf("sem_timedwait() timed out\en");
@@ -240,7 +240,7 @@ main(int argc, char *argv[])
perror("sem_timedwait");
} else
printf("sem_timedwait() succeeded\en");
-
+\&
exit((s == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
}
.EE
diff --git a/man3/setaliasent.3 b/man3/setaliasent.3
index 0b67451a4..adf5f13d7 100644
--- a/man3/setaliasent.3
+++ b/man3/setaliasent.3
@@ -134,7 +134,7 @@ The NeXT system has similar routines:
.in +4n
.EX
#include <aliasdb.h>
-
+\&
void alias_setent(void);
void alias_endent(void);
alias_ent *alias_getent(void);
@@ -152,12 +152,12 @@ It will dump all names in the alias database.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(void)
{
struct aliasent *al;
-
+\&
setaliasent();
for (;;) {
al = getaliasent();
diff --git a/man3/setbuf.3 b/man3/setbuf.3
index 7ee7c56a0..7db3f1c55 100644
--- a/man3/setbuf.3
+++ b/man3/setbuf.3
@@ -207,12 +207,12 @@ For example, the following is invalid:
.\" [[invalid]] SRC BEGIN (setbuf.c)
.EX
#include <stdio.h>
-
+\&
int
main(void)
{
char buf[BUFSIZ];
-
+\&
setbuf(stdout, buf);
printf("Hello, world!\en");
return 0;
diff --git a/man3/shm_open.3 b/man3/shm_open.3
index c888c969c..ee1c54d46 100644
--- a/man3/shm_open.3
+++ b/man3/shm_open.3
@@ -300,15 +300,15 @@ on the memory object that is shared between the two programs.
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
#define BUF_SIZE 1024 /* Maximum size for exchanged string */
-
+\&
/* Define a structure that will be imposed on the shared
memory object */
-
+\&
struct shmbuf {
sem_t sem1; /* POSIX unnamed semaphore */
sem_t sem2; /* POSIX unnamed semaphore */
@@ -337,74 +337,74 @@ to tell the "send" program that it may now access the shared memory.
.\" SRC BEGIN (pshm_ucase_bounce.c)
.EX
/* pshm_ucase_bounce.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <ctype.h>
-
+\&
#include "pshm_ucase.h"
-
+\&
int
main(int argc, char *argv[])
{
int fd;
char *shmpath;
struct shmbuf *shmp;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s /shm\-path\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
shmpath = argv[1];
-
+\&
/* Create shared memory object and set its size to the size
of our structure. */
-
+\&
fd = shm_open(shmpath, O_CREAT | O_EXCL | O_RDWR, 0600);
if (fd == \-1)
errExit("shm_open");
-
+\&
if (ftruncate(fd, sizeof(struct shmbuf)) == \-1)
errExit("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");
-
+\&
/* Initialize semaphores as process\-shared, with value 0. */
-
+\&
if (sem_init(&shmp\->sem1, 1, 0) == \-1)
errExit("sem_init\-sem1");
if (sem_init(&shmp\->sem2, 1, 0) == \-1)
errExit("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");
-
+\&
/* Convert data in shared memory into upper case. */
-
+\&
for (size_t j = 0; j < shmp\->cnt; j++)
shmp\->buf[j] = toupper((unsigned char) shmp\->buf[j]);
-
+\&
/* Post \[aq]sem2\[aq] to tell the peer that it can now
access the modified data in shared memory. */
-
+\&
if (sem_post(&shmp\->sem2) == \-1)
errExit("sem_post");
-
+\&
/* Unlink the shared memory object. Even if the peer process
is still using the object, this is okay. The object will
be removed only after all open references are closed. */
-
+\&
shm_unlink(shmpath);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -430,13 +430,13 @@ on standard output.
.\" SRC BEGIN (pshm_ucase_send.c)
.EX
/* pshm_ucase_send.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <string.h>
-
+\&
#include "pshm_ucase.h"
-
+\&
int
main(int argc, char *argv[])
{
@@ -444,54 +444,54 @@ main(int argc, char *argv[])
char *shmpath, *string;
size_t len;
struct shmbuf *shmp;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s /shm\-path string\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
shmpath = argv[1];
string = argv[2];
len = strlen(string);
-
+\&
if (len > BUF_SIZE) {
fprintf(stderr, "String is too long\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Open the existing shared memory object and map it
into the caller\[aq]s address space. */
-
+\&
fd = shm_open(shmpath, O_RDWR, 0);
if (fd == \-1)
errExit("shm_open");
-
+\&
shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (shmp == MAP_FAILED)
errExit("mmap");
-
+\&
/* Copy data into the shared memory object. */
-
+\&
shmp\->cnt = len;
memcpy(&shmp\->buf, string, len);
-
+\&
/* Tell peer that it can now access shared memory. */
-
+\&
if (sem_post(&shmp\->sem1) == \-1)
errExit("sem_post");
-
+\&
/* Wait until peer says that it has finished accessing
the shared memory. */
-
+\&
if (sem_wait(&shmp\->sem2) == \-1)
errExit("sem_wait");
-
+\&
/* Write modified data in shared memory to standard output. */
-
+\&
write(STDOUT_FILENO, &shmp\->buf, len);
write(STDOUT_FILENO, "\en", 1);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/slist.3 b/man3/slist.3
index 2aa31865c..bbfc8de18 100644
--- a/man3/slist.3
+++ b/man3/slist.3
@@ -263,53 +263,53 @@ without interfering with the traversal.
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
-
+\&
struct entry {
int data;
SLIST_ENTRY(entry) entries; /* Singly linked list */
};
-
+\&
SLIST_HEAD(slisthead, entry);
-
+\&
int
main(void)
{
struct entry *n1, *n2, *n3, *np;
struct slisthead head; /* Singly linked list
head */
-
+\&
SLIST_INIT(&head); /* Initialize the queue */
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the head */
SLIST_INSERT_HEAD(&head, n1, entries);
-
+\&
n2 = malloc(sizeof(struct entry)); /* Insert after */
SLIST_INSERT_AFTER(n1, n2, entries);
-
+\&
SLIST_REMOVE(&head, n2, entry, entries);/* Deletion */
free(n2);
-
+\&
n3 = SLIST_FIRST(&head);
SLIST_REMOVE_HEAD(&head, entries); /* Deletion from the head */
free(n3);
-
+\&
for (unsigned int i = 0; i < 5; i++) {
n1 = malloc(sizeof(struct entry));
SLIST_INSERT_HEAD(&head, n1, entries);
n1\->data = i;
}
-
+\&
/* Forward traversal */
SLIST_FOREACH(np, &head, entries)
printf("%i\en", np\->data);
-
+\&
while (!SLIST_EMPTY(&head)) { /* List deletion */
n1 = SLIST_FIRST(&head);
SLIST_REMOVE_HEAD(&head, entries);
free(n1);
}
SLIST_INIT(&head);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/sockatmark.3 b/man3/sockatmark.3
index 254145cfc..b5627052d 100644
--- a/man3/sockatmark.3
+++ b/man3/sockatmark.3
@@ -109,24 +109,24 @@ and then read the byte of data at the mark:
char buf[BUF_LEN];
char oobdata;
int atmark, s;
-
+\&
for (;;) {
atmark = sockatmark(sockfd);
if (atmark == \-1) {
perror("sockatmark");
break;
}
-
+\&
if (atmark)
break;
-
+\&
s = read(sockfd, buf, BUF_LEN);
if (s == \-1)
perror("read");
if (s <= 0)
break;
}
-
+\&
if (atmark == 1) {
if (recv(sockfd, &oobdata, 1, MSG_OOB) == \-1) {
perror("recv");
diff --git a/man3/sscanf.3 b/man3/sscanf.3
index 4269eda27..922c9e62d 100644
--- a/man3/sscanf.3
+++ b/man3/sscanf.3
@@ -716,7 +716,7 @@ the returned string, as in the following example:
.EX
char *p;
int n;
-
+\&
errno = 0;
n = sscanf(str, "%m[a\-z]", &p);
if (n == 1) {
diff --git a/man3/stailq.3 b/man3/stailq.3
index ddbcccc83..f0584beec 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -316,39 +316,39 @@ BSD.
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
-
+\&
struct entry {
int data;
STAILQ_ENTRY(entry) entries; /* Singly linked tail queue */
};
-
+\&
STAILQ_HEAD(stailhead, entry);
-
+\&
int
main(void)
{
struct entry *n1, *n2, *n3, *np;
struct stailhead head; /* Singly linked tail queue
head */
-
+\&
STAILQ_INIT(&head); /* Initialize the queue */
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the head */
STAILQ_INSERT_HEAD(&head, n1, entries);
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the tail */
STAILQ_INSERT_TAIL(&head, n1, entries);
-
+\&
n2 = malloc(sizeof(struct entry)); /* Insert after */
STAILQ_INSERT_AFTER(&head, n1, n2, entries);
-
+\&
STAILQ_REMOVE(&head, n2, entry, entries); /* Deletion */
free(n2);
-
+\&
n3 = STAILQ_FIRST(&head);
STAILQ_REMOVE_HEAD(&head, entries); /* Deletion from the head */
free(n3);
-
+\&
n1 = STAILQ_FIRST(&head);
n1\->data = 0;
for (unsigned int i = 1; i < 5; i++) {
@@ -367,7 +367,7 @@ main(void)
n1 = n2;
}
STAILQ_INIT(&head);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/static_assert.3 b/man3/static_assert.3
index f24837576..e01ff1d47 100644
--- a/man3/static_assert.3
+++ b/man3/static_assert.3
@@ -67,7 +67,7 @@ The following program uses the macro to get the size of an array safely.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
/*
* This macro behaves like static_assert(), failing to
* compile if its argument is not true. However, it always
@@ -83,33 +83,33 @@ The following program uses the macro to get the size of an array safely.
} \e
) \e
)
-
+\&
#define is_same_type(a, b) \e
__builtin_types_compatible_p(typeof(a), typeof(b))
-
+\&
#define is_array(arr) (!is_same_type((arr), &*(arr)))
#define must_be_array(arr) must_be(is_array(arr))
-
+\&
#define sizeof_array(arr) (sizeof(arr) + must_be_array(arr))
#define nitems(arr) (sizeof((arr)) / sizeof((arr)[0]) \e
+ must_be_array(arr))
-
+\&
int foo[10];
int8_t bar[sizeof_array(foo)];
-
+\&
int
main(void)
{
for (size_t i = 0; i < nitems(foo); i++) {
foo[i] = i;
}
-
+\&
memcpy(bar, foo, sizeof_array(bar));
-
+\&
for (size_t i = 0; i < nitems(bar); i++) {
printf("%d,", bar[i]);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/stdarg.3 b/man3/stdarg.3
index 59af5d58e..68529802a 100644
--- a/man3/stdarg.3
+++ b/man3/stdarg.3
@@ -261,16 +261,16 @@ with each format character based on the type.
.EX
#include <stdio.h>
#include <stdarg.h>
-
+\&
void
foo(char *fmt, ...) /* \[aq]...\[aq] is C syntax for a variadic function */
-
+\&
{
va_list ap;
int d;
char c;
char *s;
-
+\&
va_start(ap, fmt);
while (*fmt)
switch (*fmt++) {
diff --git a/man3/stpncpy.3 b/man3/stpncpy.3
index 8e2af8c77..e7367cf63 100644
--- a/man3/stpncpy.3
+++ b/man3/stpncpy.3
@@ -57,7 +57,7 @@ strncpy(char *restrict dst, const char *restrict src, size_t sz)
stpncpy(dst, src, sz);
return dst;
}
-
+\&
char *
stpncpy(char *restrict dst, const char *restrict src, size_t sz)
{
@@ -131,7 +131,7 @@ instead of its size.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(void)
{
@@ -139,23 +139,23 @@ main(void)
char buf1[20];
char buf2[20];
size_t len;
-
+\&
if (sizeof(buf2) < strlen("Hello world!"))
warnx("strncpy: truncating character sequence");
strncpy(buf2, "Hello world!", sizeof(buf2));
len = strnlen(buf2, sizeof(buf2));
-
+\&
printf("[len = %zu]: ", len);
printf("%.*s\en", (int) len, buf2); // "Hello world!"
-
+\&
if (sizeof(buf1) < strlen("Hello world!"))
warnx("stpncpy: truncating character sequence");
p = stpncpy(buf1, "Hello world!", sizeof(buf1));
len = p \- buf1;
-
+\&
printf("[len = %zu]: ", len);
printf("%.*s\en", (int) len, buf1); // "Hello world!"
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/strcmp.3 b/man3/strcmp.3
index 2a58c37e0..a6cd2c758 100644
--- a/man3/strcmp.3
+++ b/man3/strcmp.3
@@ -162,28 +162,28 @@ $ \fB./string_comp ABC AB 2\fP
.\" SRC BEGIN (string_comp.c)
.EX
/* string_comp.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
int res;
-
+\&
if (argc < 3) {
fprintf(stderr, "Usage: %s <str1> <str2> [<len>]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (argc == 3)
res = strcmp(argv[1], argv[2]);
else
res = strncmp(argv[1], argv[2], atoi(argv[3]));
-
+\&
if (res == 0) {
printf("<str1> and <str2> are equal");
if (argc > 3)
@@ -194,7 +194,7 @@ main(int argc, char *argv[])
} else {
printf("<str1> is greater than <str2> (%d)\en", res);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/strcpy.3 b/man3/strcpy.3
index 03ffeaedc..74f67644c 100644
--- a/man3/strcpy.3
+++ b/man3/strcpy.3
@@ -63,20 +63,20 @@ char *
stpcpy(char *restrict dst, const char *restrict src)
{
char *p;
-
+\&
p = mempcpy(dst, src, strlen(src));
*p = \[aq]\e0\[aq];
-
+\&
return p;
}
-
+\&
char *
strcpy(char *restrict dst, const char *restrict src)
{
stpcpy(dst, src);
return dst;
}
-
+\&
char *
strcat(char *restrict dst, const char *restrict src)
{
@@ -160,7 +160,7 @@ Shlemiel the painter
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(void)
{
@@ -168,7 +168,7 @@ main(void)
char *buf1;
char *buf2;
size_t len, maxsize;
-
+\&
maxsize = strlen("Hello ") + strlen("world") + strlen("!") + 1;
buf1 = malloc(sizeof(*buf1) * maxsize);
if (buf1 == NULL)
@@ -176,26 +176,26 @@ main(void)
buf2 = malloc(sizeof(*buf2) * maxsize);
if (buf2 == NULL)
err(EXIT_FAILURE, "malloc()");
-
+\&
p = buf1;
p = stpcpy(p, "Hello ");
p = stpcpy(p, "world");
p = stpcpy(p, "!");
len = p \- buf1;
-
+\&
printf("[len = %zu]: ", len);
puts(buf1); // "Hello world!"
free(buf1);
-
+\&
strcpy(buf2, "Hello ");
strcat(buf2, "world");
strcat(buf2, "!");
len = strlen(buf2);
-
+\&
printf("[len = %zu]: ", len);
puts(buf2); // "Hello world!"
free(buf2);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/strftime.3 b/man3/strftime.3
index 38bb8814b..6d77faf14 100644
--- a/man3/strftime.3
+++ b/man3/strftime.3
@@ -745,26 +745,26 @@ Result string is " 11"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-
+\&
int
main(int argc, char *argv[])
{
char outstr[200];
time_t t;
struct tm *tmp;
-
+\&
t = time(NULL);
tmp = localtime(&t);
if (tmp == NULL) {
perror("localtime");
exit(EXIT_FAILURE);
}
-
+\&
if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
fprintf(stderr, "strftime returned 0");
exit(EXIT_FAILURE);
}
-
+\&
printf("Result string is \e"%s\e"\en", outstr);
exit(EXIT_SUCCESS);
}
diff --git a/man3/strncat.3 b/man3/strncat.3
index 9a9fa4f4d..266268199 100644
--- a/man3/strncat.3
+++ b/man3/strncat.3
@@ -34,12 +34,12 @@ strncat(char *restrict dst, const char *restrict src, size_t sz)
{
int len;
char *p;
-
+\&
len = strnlen(src, sz);
p = dst + strlen(dst);
p = mempcpy(p, src, len);
*p = \[aq]\e0\[aq];
-
+\&
return dst;
}
.EE
@@ -93,34 +93,34 @@ Shlemiel the painter
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
#define nitems(arr) (sizeof((arr)) / sizeof((arr)[0]))
-
+\&
int
main(void)
{
size_t maxsize;
-
+\&
// Null-padded fixed-width character sequences
char pre[4] = "pre.";
char new_post[50] = ".foo.bar";
-
+\&
// Strings
char post[] = ".post";
char src[] = "some_long_body.post";
char *dest;
-
+\&
maxsize = nitems(pre) + strlen(src) \- strlen(post) +
nitems(new_post) + 1;
dest = malloc(sizeof(*dest) * maxsize);
if (dest == NULL)
err(EXIT_FAILURE, "malloc()");
-
+\&
dest[0] = \[aq]\e0\[aq]; // There's no 'cpy' function to this 'cat'.
strncat(dest, pre, nitems(pre));
strncat(dest, src, strlen(src) \- strlen(post));
strncat(dest, new_post, nitems(new_post));
-
+\&
puts(dest); // "pre.some_long_body.foo.bar"
free(dest);
exit(EXIT_SUCCESS);
diff --git a/man3/strptime.3 b/man3/strptime.3
index 69996f398..0a1bf4c49 100644
--- a/man3/strptime.3
+++ b/man3/strptime.3
@@ -393,13 +393,13 @@ and
#include <stdlib.h>
#include <string.h>
#include <time.h>
-
+\&
int
main(void)
{
struct tm tm;
char buf[255];
-
+\&
memset(&tm, 0, sizeof(tm));
strptime("2001\-11\-12 18:31:01", "%Y\-%m\-%d %H:%M:%S", &tm);
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
diff --git a/man3/strsep.3 b/man3/strsep.3
index 6d7c66176..19caafeb1 100644
--- a/man3/strsep.3
+++ b/man3/strsep.3
@@ -133,24 +133,24 @@ which, however, doesn't discard multiple delimiters or empty tokens:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
char *token, *subtoken;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage: %s string delim subdelim\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
for (unsigned int j = 1; (token = strsep(&argv[1], argv[2])); j++) {
printf("%u: %s\en", j, token);
-
+\&
while ((subtoken = strsep(&token, argv[3])))
printf("\et \-\-> %s\en", subtoken);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/strtok.3 b/man3/strtok.3
index e99092110..b702e287a 100644
--- a/man3/strtok.3
+++ b/man3/strtok.3
@@ -241,26 +241,26 @@ An example of the output produced by this program is the following:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
char *str1, *str2, *token, *subtoken;
char *saveptr1, *saveptr2;
int j;
-
+\&
if (argc != 4) {
fprintf(stderr, "Usage: %s string delim subdelim\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
token = strtok_r(str1, argv[2], &saveptr1);
if (token == NULL)
break;
printf("%d: %s\en", j, token);
-
+\&
for (str2 = token; ; str2 = NULL) {
subtoken = strtok_r(str2, argv[3], &saveptr2);
if (subtoken == NULL)
@@ -268,7 +268,7 @@ main(int argc, char *argv[])
printf("\et \-\-> %s\en", subtoken);
}
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/strtol.3 b/man3/strtol.3
index 3c5ddddb3..95b291ab8 100644
--- a/man3/strtol.3
+++ b/man3/strtol.3
@@ -246,44 +246,44 @@ strtol: Numerical result out of range
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
int base;
char *endptr, *str;
long val;
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s str [base]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
str = argv[1];
base = (argc > 2) ? atoi(argv[2]) : 0;
-
+\&
errno = 0; /* To distinguish success/failure after call */
val = strtol(str, &endptr, base);
-
+\&
/* Check for various possible errors. */
-
+\&
if (errno != 0) {
perror("strtol");
exit(EXIT_FAILURE);
}
-
+\&
if (endptr == str) {
fprintf(stderr, "No digits were found\en");
exit(EXIT_FAILURE);
}
-
+\&
/* If we got here, strtol() successfully parsed a number. */
-
+\&
printf("strtol() returned %ld\en", val);
-
+\&
if (*endptr != \[aq]\e0\[aq]) /* Not necessarily an error... */
printf("Further characters after number: \e"%s\e"\en", endptr);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/strverscmp.3 b/man3/strverscmp.3
index ad781ab9a..6cea27af4 100644
--- a/man3/strverscmp.3
+++ b/man3/strverscmp.3
@@ -122,22 +122,22 @@ jan1 < jan10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
int
main(int argc, char *argv[])
{
int res;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s <string1> <string2>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
res = strverscmp(argv[1], argv[2]);
-
+\&
printf("%s %s %s\en", argv[1],
(res < 0) ? "<" : (res == 0) ? "==" : ">", argv[2]);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/system.3 b/man3/system.3
index 867632bb3..9bf432b09 100644
--- a/man3/system.3
+++ b/man3/system.3
@@ -167,7 +167,7 @@ For example:
.EX
while (something) {
int ret = system("foo");
-
+\&
if (WIFSIGNALED(ret) &&
(WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
break;
diff --git a/man3/tailq.3 b/man3/tailq.3
index e57dd6438..af34c5424 100644
--- a/man3/tailq.3
+++ b/man3/tailq.3
@@ -341,35 +341,35 @@ without interfering with the traversal.
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
-
+\&
struct entry {
int data;
TAILQ_ENTRY(entry) entries; /* Tail queue */
};
-
+\&
TAILQ_HEAD(tailhead, entry);
-
+\&
int
main(void)
{
struct entry *n1, *n2, *n3, *np;
struct tailhead head; /* Tail queue head */
int i;
-
+\&
TAILQ_INIT(&head); /* Initialize the queue */
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the head */
TAILQ_INSERT_HEAD(&head, n1, entries);
-
+\&
n1 = malloc(sizeof(struct entry)); /* Insert at the tail */
TAILQ_INSERT_TAIL(&head, n1, entries);
-
+\&
n2 = malloc(sizeof(struct entry)); /* Insert after */
TAILQ_INSERT_AFTER(&head, n1, n2, entries);
-
+\&
n3 = malloc(sizeof(struct entry)); /* Insert before */
TAILQ_INSERT_BEFORE(n2, n3, entries);
-
+\&
TAILQ_REMOVE(&head, n2, entries); /* Deletion */
free(n2);
/* Forward traversal */
@@ -387,7 +387,7 @@ main(void)
n1 = n2;
}
TAILQ_INIT(&head);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man3/tsearch.3 b/man3/tsearch.3
index 35b052886..958de6d2c 100644
--- a/man3/tsearch.3
+++ b/man3/tsearch.3
@@ -278,21 +278,21 @@ in order.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-
+\&
static void *root = NULL;
-
+\&
static void *
xmalloc(size_t n)
{
void *p;
-
+\&
p = malloc(n);
if (p)
return p;
fprintf(stderr, "insufficient memory\en");
exit(EXIT_FAILURE);
}
-
+\&
static int
compare(const void *pa, const void *pb)
{
@@ -302,12 +302,12 @@ compare(const void *pa, const void *pb)
return 1;
return 0;
}
-
+\&
static void
action(const void *nodep, VISIT which, int depth)
{
int *datap;
-
+\&
switch (which) {
case preorder:
break;
@@ -323,13 +323,13 @@ action(const void *nodep, VISIT which, int depth)
break;
}
}
-
+\&
int
main(void)
{
int *ptr;
int **val;
-
+\&
srand(time(NULL));
for (unsigned int i = 0; i < 12; i++) {
ptr = xmalloc(sizeof(*ptr));
diff --git a/man3/wordexp.3 b/man3/wordexp.3
index 1a1f284bb..2a9e0fa93 100644
--- a/man3/wordexp.3
+++ b/man3/wordexp.3
@@ -222,13 +222,13 @@ is approximately that of "ls [a-c]*.c".
#include <stdio.h>
#include <stdlib.h>
#include <wordexp.h>
-
+\&
int
main(void)
{
wordexp_t p;
char **w;
-
+\&
wordexp("[a\-c]*.c", &p, 0);
w = p.we_wordv;
for (size_t i = 0; i < p.we_wordc; i++)
diff --git a/man3const/EXIT_SUCCESS.3const b/man3const/EXIT_SUCCESS.3const
index 431f43bbb..067e0b689 100644
--- a/man3const/EXIT_SUCCESS.3const
+++ b/man3const/EXIT_SUCCESS.3const
@@ -32,25 +32,25 @@ POSIX.1-2001 and later.
.EX
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
FILE *fp;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <file>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fp = fopen(argv[1], "r");
if (fp == NULL) {
perror(argv[1]);
exit(EXIT_FAILURE);
}
-
+\&
/* Other code omitted */
-
+\&
fclose(fp);
exit(EXIT_SUCCESS);
}
diff --git a/man3head/printf.h.3head b/man3head/printf.h.3head
index e432d3cb9..2729a0184 100644
--- a/man3head/printf.h.3head
+++ b/man3head/printf.h.3head
@@ -242,7 +242,7 @@ This can be used to print in binary prior to C23.
.\" SRC BEGIN (register_printf_specifier.c)
.EX
/* This code is in the public domain */
-
+\&
#include <err.h>
#include <limits.h>
#include <stddef.h>
@@ -251,21 +251,21 @@ This can be used to print in binary prior to C23.
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
-
+\&
#include <printf.h>
-
+\&
#define GROUP_SEP \[aq]\e\[aq]\[aq]
-
+\&
struct Printf_Pad {
char ch;
size_t len;
};
-
+\&
static int b_printf(FILE *stream, const struct printf_info *info,
const void *const args[]);
static int b_arginf_sz(const struct printf_info *info,
size_t n, int argtypes[n], int size[n]);
-
+\&
static uintmax_t b_value(const struct printf_info *info,
const void *arg);
static size_t b_bin_repr(char bin[UINTMAX_WIDTH],
@@ -284,7 +284,7 @@ static ssize_t b_print_number(FILE *stream,
size_t min_len, size_t bin_len);
static char pad_ch(const struct printf_info *info);
static ssize_t pad_spaces(FILE *stream, size_t pad_len);
-
+\&
int
main(void)
{
@@ -292,7 +292,7 @@ main(void)
err(EXIT_FAILURE, "register_printf_specifier(\[aq]b\[aq], ...)");
if (register_printf_specifier(\[aq]B\[aq], b_printf, b_arginf_sz) == \-1)
err(EXIT_FAILURE, "register_printf_specifier(\[aq]B\[aq], ...)");
-
+\&
printf("....----....----....----....----\en");
printf("%llb;\en", 0x5Ellu);
printf("%lB;\en", 0x5Elu);
@@ -342,10 +342,10 @@ main(void)
printf("%019B;\en", 0xAB);
printf("%#016b;\en", 0xAB);
printf("....----....----....----....----\en");
-
+\&
return 0;
}
-
+\&
static int
b_printf(FILE *stream, const struct printf_info *info,
const void *const args[])
@@ -354,16 +354,16 @@ b_printf(FILE *stream, const struct printf_info *info,
size_t min_len, bin_len;
ssize_t len, tmp;
struct Printf_Pad pad = {0};
-
+\&
len = 0;
-
+\&
min_len = b_bin_repr(bin, info, args[0]);
bin_len = b_bin_len(info, min_len);
-
+\&
pad.ch = pad_ch(info);
if (pad.ch == \[aq] \[aq])
pad.len = b_pad_len(info, bin_len);
-
+\&
/* Padding with \[aq] \[aq] (right aligned) */
if ((pad.ch == \[aq] \[aq]) && !info->left) {
tmp = pad_spaces(stream, pad.len);
@@ -371,7 +371,7 @@ b_printf(FILE *stream, const struct printf_info *info,
return EOF;
len += tmp;
}
-
+\&
/* "0b"/"0B" prefix */
if (info->alt) {
tmp = b_print_prefix(stream, info);
@@ -379,7 +379,7 @@ b_printf(FILE *stream, const struct printf_info *info,
return EOF;
len += tmp;
}
-
+\&
/* Padding with \[aq]0\[aq] */
if (pad.ch == \[aq]0\[aq]) {
tmp = b_pad_zeros(stream, info, min_len);
@@ -387,13 +387,13 @@ b_printf(FILE *stream, const struct printf_info *info,
return EOF;
len += tmp;
}
-
+\&
/* Print number (including leading 0s to fill precision) */
tmp = b_print_number(stream, info, bin, min_len, bin_len);
if (tmp == EOF)
return EOF;
len += tmp;
-
+\&
/* Padding with \[aq] \[aq] (left aligned) */
if (info\->left) {
tmp = pad_spaces(stream, pad.len);
@@ -401,27 +401,27 @@ b_printf(FILE *stream, const struct printf_info *info,
return EOF;
len += tmp;
}
-
+\&
return len;
}
-
+\&
static int
b_arginf_sz(const struct printf_info *info, size_t n, int argtypes[n],
[[maybe_unused]] int size[n])
{
if (n < 1)
return \-1;
-
+\&
if (info\->is_long_double)
argtypes[0] = PA_INT | PA_FLAG_LONG_LONG;
else if (info\->is_long)
argtypes[0] = PA_INT | PA_FLAG_LONG;
else
argtypes[0] = PA_INT;
-
+\&
return 1;
}
-
+\&
static uintmax_t
b_value(const struct printf_info *info, const void *arg)
{
@@ -429,54 +429,54 @@ b_value(const struct printf_info *info, const void *arg)
return *(const unsigned long long *)arg;
if (info\->is_long)
return *(const unsigned long *)arg;
-
+\&
/* short and char are both promoted to int */
return *(const unsigned int *)arg;
}
-
+\&
static size_t
b_bin_repr(char bin[UINTMAX_WIDTH],
const struct printf_info *info, const void *arg)
{
size_t min_len;
uintmax_t val;
-
+\&
val = b_value(info, arg);
-
+\&
bin[0] = \[aq]0\[aq];
for (min_len = 0; val; min_len++) {
bin[min_len] = \[aq]0\[aq] + (val % 2);
val >>= 1;
}
-
+\&
return MAX(min_len, 1);
}
-
+\&
static size_t
b_bin_len(const struct printf_info *info, ptrdiff_t min_len)
{
return MAX(info\->prec, min_len);
}
-
+\&
static size_t
b_pad_len(const struct printf_info *info, ptrdiff_t bin_len)
{
ptrdiff_t pad_len;
-
+\&
pad_len = info\->width \- bin_len;
if (info\->alt)
pad_len \-= 2;
if (info\->group)
pad_len \-= (bin_len \- 1) / 4;
-
+\&
return MAX(pad_len, 0);
}
-
+\&
static ssize_t
b_print_prefix(FILE *stream, const struct printf_info *info)
{
ssize_t len;
-
+\&
len = 0;
if (fputc(\[aq]0\[aq], stream) == EOF)
return EOF;
@@ -484,17 +484,17 @@ b_print_prefix(FILE *stream, const struct printf_info *info)
if (fputc(info\->spec, stream) == EOF)
return EOF;
len++;
-
+\&
return len;
}
-
+\&
static ssize_t
b_pad_zeros(FILE *stream, const struct printf_info *info,
ptrdiff_t min_len)
{
ssize_t len;
ptrdiff_t tmp;
-
+\&
len = 0;
tmp = info\->width \- (info\->alt * 2);
if (info\->group)
@@ -503,55 +503,55 @@ b_pad_zeros(FILE *stream, const struct printf_info *info,
if (fputc(\[aq]0\[aq], stream) == EOF)
return EOF;
len++;
-
+\&
if (!info\->group || (i % 4))
continue;
if (fputc(GROUP_SEP, stream) == EOF)
return EOF;
len++;
}
-
+\&
return len;
}
-
+\&
static ssize_t
b_print_number(FILE *stream, const struct printf_info *info,
const char bin[UINTMAX_WIDTH],
size_t min_len, size_t bin_len)
{
ssize_t len;
-
+\&
len = 0;
-
+\&
/* Print leading zeros to fill precision */
for (size_t i = bin_len \- 1; i > min_len \- 1; i\-\-) {
if (fputc(\[aq]0\[aq], stream) == EOF)
return EOF;
len++;
-
+\&
if (!info\->group || (i % 4))
continue;
if (fputc(GROUP_SEP, stream) == EOF)
return EOF;
len++;
}
-
+\&
/* Print number */
for (size_t i = min_len \- 1; i < min_len; i\-\-) {
if (fputc(bin[i], stream) == EOF)
return EOF;
len++;
-
+\&
if (!info\->group || (i % 4) || !i)
continue;
if (fputc(GROUP_SEP, stream) == EOF)
return EOF;
len++;
}
-
+\&
return len;
}
-
+\&
static char
pad_ch(const struct printf_info *info)
{
@@ -559,19 +559,19 @@ pad_ch(const struct printf_info *info)
return \[aq] \[aq];
return \[aq]0\[aq];
}
-
+\&
static ssize_t
pad_spaces(FILE *stream, size_t pad_len)
{
ssize_t len;
-
+\&
len = 0;
for (size_t i = pad_len - 1; i < pad_len; i\-\-) {
if (fputc(\[aq] \[aq], stream) == EOF)
return EOF;
len++;
}
-
+\&
return len;
}
.EE
diff --git a/man3type/epoll_event.3type b/man3type/epoll_event.3type
index 4806bca66..efb229fd3 100644
--- a/man3type/epoll_event.3type
+++ b/man3type/epoll_event.3type
@@ -41,7 +41,7 @@ with a slightly different definition:
.in +4n
.EX
#include <linux/eventpoll.h>
-
+\&
struct epoll_event {
__poll_t events;
__u64 data;
diff --git a/man3type/stat.3type b/man3type/stat.3type
index dd3c0aca5..939dc3c8f 100644
--- a/man3type/stat.3type
+++ b/man3type/stat.3type
@@ -25,15 +25,15 @@ Standard C library
.BR " off_t st_size;" " /* Total size, in bytes */"
.BR " blksize_t st_blksize;" " /* Block size for filesystem I/O */"
.BR " blkcnt_t st_blocks;" " /* Number of 512 B blocks allocated */"
-
+\&
/* Since POSIX.1-2008, this structure supports nanosecond
precision for the following timestamp fields.
For the details before POSIX.1-2008, see VERSIONS. */
-
+\&
.BR " struct timespec st_atim;" " /* Time of last access */"
.BR " struct timespec st_mtim;" " /* Time of last modification */"
.BR " struct timespec st_ctim;" " /* Time of last status change */"
-
+\&
.BR "#define st_atime st_atim.tv_sec" " /* Backward compatibility */"
.B "#define st_mtime st_mtim.tv_sec"
.B "#define st_ctime st_ctim.tv_sec"
diff --git a/man4/cciss.4 b/man4/cciss.4
index 5db37159e..873ef9118 100644
--- a/man4/cciss.4
+++ b/man4/cciss.4
@@ -128,7 +128,7 @@ li l.
/dev/cciss/c0d0p1 Controller 0, disk 0, partition 1
/dev/cciss/c0d0p2 Controller 0, disk 0, partition 2
/dev/cciss/c0d0p3 Controller 0, disk 0, partition 3
-
+\&
/dev/cciss/c1d1 Controller 1, disk 1, whole device
/dev/cciss/c1d1p1 Controller 1, disk 1, partition 1
/dev/cciss/c1d1p2 Controller 1, disk 1, partition 2
@@ -161,7 +161,7 @@ Max Q depth since init: 1
Max # commands on controller since init: 2
Max SG entries since init: 32
Sequential access devices: 0
-
+\&
cciss/c2d0: 36.38GB RAID 0
.EE
.in
diff --git a/man4/fuse.4 b/man4/fuse.4
index 64d798bff..612070787 100644
--- a/man4/fuse.4
+++ b/man4/fuse.4
@@ -433,7 +433,7 @@ struct fuse_kstatfs {
uint32_t padding;
uint32_t spare[6];
};
-
+\&
struct fuse_statfs_out {
struct fuse_kstatfs st;
};
diff --git a/man4/lirc.4 b/man4/lirc.4
index d4461d479..4bd356d2e 100644
--- a/man4/lirc.4
+++ b/man4/lirc.4
@@ -116,7 +116,7 @@ device cannot transmit.
.SH IOCTL COMMANDS
.nf
#include <linux/lirc.h> /* But see BUGS */
-
+\&
int ioctl(int fd, int cmd, int *val);
.fi
.PP
diff --git a/man4/loop.4 b/man4/loop.4
index 5f923d1ba..72a243192 100644
--- a/man4/loop.4
+++ b/man4/loop.4
@@ -313,44 +313,44 @@ loopname = /dev/loop5
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
int
main(int argc, char *argv[])
{
int loopctlfd, loopfd, backingfile;
long devnr;
char loopname[4096];
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s backing\-file\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
loopctlfd = open("/dev/loop\-control", O_RDWR);
if (loopctlfd == \-1)
errExit("open: /dev/loop\-control");
-
+\&
devnr = ioctl(loopctlfd, LOOP_CTL_GET_FREE);
if (devnr == \-1)
errExit("ioctl\-LOOP_CTL_GET_FREE");
-
+\&
sprintf(loopname, "/dev/loop%ld", devnr);
printf("loopname = %s\en", loopname);
-
+\&
loopfd = open(loopname, O_RDWR);
if (loopfd == \-1)
errExit("open: loopname");
-
+\&
backingfile = open(argv[1], O_RDWR);
if (backingfile == \-1)
errExit("open: backing\-file");
-
+\&
if (ioctl(loopfd, LOOP_SET_FD, backingfile) == \-1)
errExit("ioctl\-LOOP_SET_FD");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man4/vcs.4 b/man4/vcs.4
index 7eef1648b..66f06ab11 100644
--- a/man4/vcs.4
+++ b/man4/vcs.4
@@ -123,7 +123,7 @@ there:
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
-
+\&
int
main(void)
{
@@ -135,7 +135,7 @@ main(void)
unsigned short mask;
unsigned char attrib;
int ch;
-
+\&
fd = open(console, O_RDWR);
if (fd < 0) {
perror(console);
diff --git a/man5/acct.5 b/man5/acct.5
index d879dfde0..e7fd97ff2 100644
--- a/man5/acct.5
+++ b/man5/acct.5
@@ -30,9 +30,9 @@ as follows:
.in +4n
.EX
#define ACCT_COMM 16
-
+\&
typedef u_int16_t comp_t;
-
+\&
struct acct {
char ac_flag; /* Accounting flags */
u_int16_t ac_uid; /* Accounting user ID */
@@ -56,7 +56,7 @@ struct acct {
executed command; null\-terminated) */
char ac_pad[\fIX\fP]; /* padding bytes */
};
-
+\&
enum { /* Bits that may be set in ac_flag field */
AFORK = 0x01, /* Has executed fork, but no exec */
ASU = 0x02, /* Used superuser privileges */
diff --git a/man5/core.5 b/man5/core.5
index 816712149..2b1c0f7ec 100644
--- a/man5/core.5
+++ b/man5/core.5
@@ -620,7 +620,7 @@ Total bytes in core dump: 282624
\&
.EX
/* core_pattern_pipe_test.c */
-
+\&
#define _GNU_SOURCE
#include <sys/stat.h>
#include <fcntl.h>
@@ -628,9 +628,9 @@ Total bytes in core dump: 282624
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#define BUF_SIZE 1024
-
+\&
int
main(int argc, char *argv[])
{
@@ -638,33 +638,33 @@ main(int argc, char *argv[])
char buf[BUF_SIZE];
FILE *fp;
char cwd[PATH_MAX];
-
+\&
/* Change our current working directory to that of the
crashing process. */
-
+\&
snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
chdir(cwd);
-
+\&
/* Write output to file "core.info" in that directory. */
-
+\&
fp = fopen("core.info", "w+");
if (fp == NULL)
exit(EXIT_FAILURE);
-
+\&
/* Display command\-line arguments given to core_pattern
pipe program. */
-
+\&
fprintf(fp, "argc=%d\en", argc);
for (size_t j = 0; j < argc; j++)
fprintf(fp, "argc[%zu]=<%s>\en", j, argv[j]);
-
+\&
/* Count bytes in standard input (the core dump). */
-
+\&
tot = 0;
while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
tot += nread;
fprintf(fp, "Total bytes in core dump: %zd\en", tot);
-
+\&
fclose(fp);
exit(EXIT_SUCCESS);
}
diff --git a/man5/elf.5 b/man5/elf.5
index 2abf79a8f..1518a2ac8 100644
--- a/man5/elf.5
+++ b/man5/elf.5
@@ -142,7 +142,7 @@ or
.in +4n
.EX
#define EI_NIDENT 16
-
+\&
typedef struct {
unsigned char e_ident[EI_NIDENT];
uint16_t e_type;
@@ -1871,19 +1871,19 @@ in memory:
.EX
void *memory, *name, *desc;
Elf64_Nhdr *note, *next_note;
-
+\&
/* The buffer is pointing to the start of the section/segment. */
note = memory;
-
+\&
/* If the name is defined, it follows the note. */
name = note\->n_namesz == 0 ? NULL : memory + sizeof(*note);
-
+\&
/* If the descriptor is defined, it follows the name
(with alignment). */
-
+\&
desc = note\->n_descsz == 0 ? NULL :
memory + sizeof(*note) + ALIGN_UP(note\->n_namesz, 4);
-
+\&
/* The next note follows both (with alignment). */
next_note = memory + sizeof(*note) +
ALIGN_UP(note\->n_namesz, 4) +
diff --git a/man5/hosts.5 b/man5/hosts.5
index 6436c781f..b89dd98e1 100644
--- a/man5/hosts.5
+++ b/man5/hosts.5
@@ -94,14 +94,14 @@ I just found three, from 92,
.EX
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 localhost
-
+\&
# 127.0.1.1 is often used for the FQDN of the machine
127.0.1.1 thishost.example.org thishost
192.168.1.10 foo.example.org foo
192.168.1.13 bar.example.org bar
146.82.138.7 master.debian.org master
209.237.226.90 www.opensource.org
-
+\&
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6\-localhost ip6\-loopback
ff02::1 ip6\-allnodes
diff --git a/man5/nsswitch.conf.5 b/man5/nsswitch.conf.5
index 53b590fd2..371a0dbae 100644
--- a/man5/nsswitch.conf.5
+++ b/man5/nsswitch.conf.5
@@ -110,7 +110,7 @@ file:
passwd: compat
group: compat
shadow: compat
-
+\&
hosts: dns [!UNAVAIL=return] files
networks: nis [NOTFOUND=return] files
ethers: nis [NOTFOUND=return] files
diff --git a/man5/utmp.5 b/man5/utmp.5
index ec68b97e6..0c3430abd 100644
--- a/man5/utmp.5
+++ b/man5/utmp.5
@@ -44,7 +44,7 @@ around; details depend on the version of libc):
.in +4n
.EX
/* Values for ut_type field, below */
-
+\&
#define EMPTY 0 /* Record does not contain valid info
(formerly known as UT_UNKNOWN on Linux) */
#define RUN_LVL 1 /* Change in system run\-level (see
@@ -59,16 +59,16 @@ around; details depend on the version of libc):
#define USER_PROCESS 7 /* Normal process */
#define DEAD_PROCESS 8 /* Terminated process */
#define ACCOUNTING 9 /* Not implemented */
-
+\&
#define UT_LINESIZE 32
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
-
+\&
struct exit_status { /* Type for ut_exit, below */
short e_termination; /* Process termination status */
short e_exit; /* Process exit status */
};
-
+\&
struct utmp {
short ut_type; /* Type of record */
pid_t ut_pid; /* PID of login process */
@@ -96,13 +96,13 @@ struct utmp {
long ut_session; /* Session ID */
struct timeval ut_tv; /* Time entry was made */
#endif
-
+\&
int32_t ut_addr_v6[4]; /* Internet address of remote
host; IPv4 address uses
just ut_addr_v6[0] */
char __unused[20]; /* Reserved for future use */
};
-
+\&
/* Backward compatibility hacks */
#define ut_name ut_user
#ifndef _NO_UT_TIME
@@ -316,7 +316,7 @@ the following method of setting this field is recommended:
.EX
struct utmp ut;
struct timeval tv;
-
+\&
gettimeofday(&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
diff --git a/man7/aio.7 b/man7/aio.7
index 84613b622..31edacf28 100644
--- a/man7/aio.7
+++ b/man7/aio.7
@@ -60,10 +60,10 @@ This structure has the following form:
.in +4n
.EX
#include <aiocb.h>
-
+\&
struct aiocb {
/* The order of these fields is implementation\-dependent */
-
+\&
int aio_fildes; /* File descriptor */
off_t aio_offset; /* File offset */
volatile void *aio_buf; /* Location of buffer */
@@ -72,12 +72,12 @@ struct aiocb {
struct sigevent aio_sigevent; /* Notification method */
int aio_lio_opcode; /* Operation to be performed;
lio_listio() only */
-
+\&
/* Various implementation\-internal fields not shown */
};
-
+\&
/* Operation codes for \[aq]aio_lio_opcode\[aq]: */
-
+\&
enum { LIO_READ, LIO_WRITE, LIO_NOP };
.EE
.in
@@ -233,43 +233,43 @@ aio_return():
#include <errno.h>
#include <aio.h>
#include <signal.h>
-
+\&
#define BUF_SIZE 20 /* Size of buffers for read operations */
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
struct ioRequest { /* Application\-defined structure for tracking
I/O requests */
int reqNum;
int status;
struct aiocb *aiocbp;
};
-
+\&
static volatile sig_atomic_t gotSIGQUIT = 0;
/* On delivery of SIGQUIT, we attempt to
cancel all outstanding I/O requests */
-
+\&
static void /* Handler for SIGQUIT */
quitHandler(int sig)
{
gotSIGQUIT = 1;
}
-
+\&
#define IO_SIGNAL SIGUSR1 /* Signal used to notify I/O completion */
-
+\&
static void /* Handler for I/O completion signal */
aioSigHandler(int sig, siginfo_t *si, void *ucontext)
{
if (si\->si_code == SI_ASYNCIO) {
write(STDOUT_FILENO, "I/O completion signal received\en", 31);
-
+\&
/* The corresponding ioRequest structure would be available as
struct ioRequest *ioReq = si\->si_value.sival_ptr;
and the file descriptor would then be available via
ioReq\->aiocbp\->aio_fildes */
}
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -277,57 +277,57 @@ main(int argc, char *argv[])
int s;
int numReqs; /* Total number of queued I/O requests */
int openReqs; /* Number of I/O requests still in progress */
-
+\&
if (argc < 2) {
fprintf(stderr, "Usage: %s <pathname> <pathname>...\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
numReqs = argc \- 1;
-
+\&
/* Allocate our arrays. */
-
+\&
struct ioRequest *ioList = calloc(numReqs, sizeof(*ioList));
if (ioList == NULL)
errExit("calloc");
-
+\&
struct aiocb *aiocbList = calloc(numReqs, sizeof(*aiocbList));
if (aiocbList == NULL)
errExit("calloc");
-
+\&
/* Establish handlers for SIGQUIT and the I/O completion signal. */
-
+\&
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
-
+\&
sa.sa_handler = quitHandler;
if (sigaction(SIGQUIT, &sa, NULL) == \-1)
errExit("sigaction");
-
+\&
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = aioSigHandler;
if (sigaction(IO_SIGNAL, &sa, NULL) == \-1)
errExit("sigaction");
-
+\&
/* Open each file specified on the command line, and queue
a read request on the resulting file descriptor. */
-
+\&
for (size_t j = 0; j < numReqs; j++) {
ioList[j].reqNum = j;
ioList[j].status = EINPROGRESS;
ioList[j].aiocbp = &aiocbList[j];
-
+\&
ioList[j].aiocbp\->aio_fildes = open(argv[j + 1], O_RDONLY);
if (ioList[j].aiocbp\->aio_fildes == \-1)
errExit("open");
printf("opened %s on descriptor %d\en", argv[j + 1],
ioList[j].aiocbp\->aio_fildes);
-
+\&
ioList[j].aiocbp\->aio_buf = malloc(BUF_SIZE);
if (ioList[j].aiocbp\->aio_buf == NULL)
errExit("malloc");
-
+\&
ioList[j].aiocbp\->aio_nbytes = BUF_SIZE;
ioList[j].aiocbp\->aio_reqprio = 0;
ioList[j].aiocbp\->aio_offset = 0;
@@ -335,27 +335,27 @@ main(int argc, char *argv[])
ioList[j].aiocbp\->aio_sigevent.sigev_signo = IO_SIGNAL;
ioList[j].aiocbp\->aio_sigevent.sigev_value.sival_ptr =
&ioList[j];
-
+\&
s = aio_read(ioList[j].aiocbp);
if (s == \-1)
errExit("aio_read");
}
-
+\&
openReqs = numReqs;
-
+\&
/* Loop, monitoring status of I/O requests. */
-
+\&
while (openReqs > 0) {
sleep(3); /* Delay between each monitoring step */
-
+\&
if (gotSIGQUIT) {
-
+\&
/* On receipt of SIGQUIT, attempt to cancel each of the
outstanding I/O requests, and display status returned
from the cancelation requests. */
-
+\&
printf("got SIGQUIT; canceling I/O requests: \en");
-
+\&
for (size_t j = 0; j < numReqs; j++) {
if (ioList[j].status == EINPROGRESS) {
printf(" Request %zu on descriptor %d:", j,
@@ -372,20 +372,20 @@ main(int argc, char *argv[])
perror("aio_cancel");
}
}
-
+\&
gotSIGQUIT = 0;
}
-
+\&
/* Check the status of each I/O request that is still
in progress. */
-
+\&
printf("aio_error():\en");
for (size_t j = 0; j < numReqs; j++) {
if (ioList[j].status == EINPROGRESS) {
printf(" for request %zu (descriptor %d): ",
j, ioList[j].aiocbp\->aio_fildes);
ioList[j].status = aio_error(ioList[j].aiocbp);
-
+\&
switch (ioList[j].status) {
case 0:
printf("I/O succeeded\en");
@@ -400,26 +400,26 @@ main(int argc, char *argv[])
perror("aio_error");
break;
}
-
+\&
if (ioList[j].status != EINPROGRESS)
openReqs\-\-;
}
}
}
-
+\&
printf("All I/O requests completed\en");
-
+\&
/* Check status return of all I/O requests. */
-
+\&
printf("aio_return():\en");
for (size_t j = 0; j < numReqs; j++) {
ssize_t s;
-
+\&
s = aio_return(ioList[j].aiocbp);
printf(" for request %zu (descriptor %d): %zd\en",
j, ioList[j].aiocbp\->aio_fildes, s);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man7/capabilities.7 b/man7/capabilities.7
index 013efb0a5..dca8b01cf 100644
--- a/man7/capabilities.7
+++ b/man7/capabilities.7
@@ -1180,14 +1180,14 @@ the process using the following algorithm:
.in +4n
.EX
P'(ambient) = (file is privileged) ? 0 : P(ambient)
-
+\&
P'(permitted) = (P(inheritable) & F(inheritable)) |
(F(permitted) & P(bounding)) | P'(ambient)
-
+\&
P'(effective) = F(effective) ? P'(permitted) : P'(ambient)
-
+\&
P'(inheritable) = P(inheritable) [i.e., unchanged]
-
+\&
P'(bounding) = P(bounding) [i.e., unchanged]
.EE
.in
@@ -1323,7 +1323,7 @@ permitted capabilities simplifies to:
.in +4n
.EX
P'(permitted) = P(inheritable) | P(bounding)
-
+\&
P'(effective) = P'(permitted)
.EE
.in
diff --git a/man7/complex.7 b/man7/complex.7
index 7409ba177..51690c8b1 100644
--- a/man7/complex.7
+++ b/man7/complex.7
@@ -43,7 +43,7 @@ The imaginary unit is represented by I.
#include <math.h> /* for atan */
#include <stdio.h>
#include <complex.h>
-
+\&
int
main(void)
{
diff --git a/man7/ddp.7 b/man7/ddp.7
index 019f67f16..950c3b541 100644
--- a/man7/ddp.7
+++ b/man7/ddp.7
@@ -72,7 +72,7 @@ struct at_addr {
unsigned short s_net;
unsigned char s_node;
};
-
+\&
struct sockaddr_atalk {
sa_family_t sat_family; /* address family */
unsigned char sat_port; /* port */
diff --git a/man7/epoll.7 b/man7/epoll.7
index 1e8679946..1559f2f7b 100644
--- a/man7/epoll.7
+++ b/man7/epoll.7
@@ -290,30 +290,30 @@ from where it stopped before.
#define MAX_EVENTS 10
struct epoll_event ev, events[MAX_EVENTS];
int listen_sock, conn_sock, nfds, epollfd;
-
+\&
/* Code to set up listening socket, \[aq]listen_sock\[aq],
(socket(), bind(), listen()) omitted. */
-
+\&
epollfd = epoll_create1(0);
if (epollfd == \-1) {
perror("epoll_create1");
exit(EXIT_FAILURE);
}
-
+\&
ev.events = EPOLLIN;
ev.data.fd = listen_sock;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == \-1) {
perror("epoll_ctl: listen_sock");
exit(EXIT_FAILURE);
}
-
+\&
for (;;) {
nfds = epoll_wait(epollfd, events, MAX_EVENTS, \-1);
if (nfds == \-1) {
perror("epoll_wait");
exit(EXIT_FAILURE);
}
-
+\&
for (n = 0; n < nfds; ++n) {
if (events[n].data.fd == listen_sock) {
conn_sock = accept(listen_sock,
diff --git a/man7/fanotify.7 b/man7/fanotify.7
index 9026375be..7c72a2996 100644
--- a/man7/fanotify.7
+++ b/man7/fanotify.7
@@ -1030,7 +1030,7 @@ Press enter key to terminate.
Listening for events.
FAN_OPEN_PERM: File /home/user/temp/notes
FAN_CLOSE_WRITE: File /home/user/temp/notes
-
+\&
Listening for events stopped.
.EE
.in
@@ -1046,9 +1046,9 @@ Listening for events stopped.
#include <stdlib.h>
#include <sys/fanotify.h>
#include <unistd.h>
-
+\&
/* Read all available fanotify events from the file descriptor \[aq]fd\[aq]. */
-
+\&
static void
handle_events(int fd)
{
@@ -1059,65 +1059,65 @@ handle_events(int fd)
ssize_t path_len;
char procfd_path[PATH_MAX];
struct fanotify_response response;
-
+\&
/* Loop while events can be read from fanotify file descriptor. */
-
+\&
for (;;) {
-
+\&
/* Read some events. */
-
+\&
len = read(fd, buf, sizeof(buf));
if (len == \-1 && errno != EAGAIN) {
perror("read");
exit(EXIT_FAILURE);
}
-
+\&
/* Check if end of available data reached. */
-
+\&
if (len <= 0)
break;
-
+\&
/* Point to the first event in the buffer. */
-
+\&
metadata = buf;
-
+\&
/* Loop over all events in the buffer. */
-
+\&
while (FAN_EVENT_OK(metadata, len)) {
-
+\&
/* Check that run\-time and compile\-time structures match. */
-
+\&
if (metadata\->vers != FANOTIFY_METADATA_VERSION) {
fprintf(stderr,
"Mismatch of fanotify metadata version.\en");
exit(EXIT_FAILURE);
}
-
+\&
/* metadata\->fd contains either FAN_NOFD, indicating a
queue overflow, or a file descriptor (a nonnegative
integer). Here, we simply ignore queue overflow. */
-
+\&
if (metadata\->fd >= 0) {
-
+\&
/* Handle open permission event. */
-
+\&
if (metadata\->mask & FAN_OPEN_PERM) {
printf("FAN_OPEN_PERM: ");
-
+\&
/* Allow file to be opened. */
-
+\&
response.fd = metadata\->fd;
response.response = FAN_ALLOW;
write(fd, &response, sizeof(response));
}
-
+\&
/* Handle closing of writable file event. */
-
+\&
if (metadata\->mask & FAN_CLOSE_WRITE)
printf("FAN_CLOSE_WRITE: ");
-
+\&
/* Retrieve and print pathname of the accessed file. */
-
+\&
snprintf(procfd_path, sizeof(procfd_path),
"/proc/self/fd/%d", metadata\->fd);
path_len = readlink(procfd_path, path,
@@ -1126,22 +1126,22 @@ handle_events(int fd)
perror("readlink");
exit(EXIT_FAILURE);
}
-
+\&
path[path_len] = \[aq]\e0\[aq];
printf("File %s\en", path);
-
+\&
/* Close the file descriptor of the event. */
-
+\&
close(metadata\->fd);
}
-
+\&
/* Advance to next event. */
-
+\&
metadata = FAN_EVENT_NEXT(metadata, len);
}
}
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -1149,80 +1149,80 @@ main(int argc, char *argv[])
int fd, poll_num;
nfds_t nfds;
struct pollfd fds[2];
-
+\&
/* Check mount point is supplied. */
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s MOUNT\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
printf("Press enter key to terminate.\en");
-
+\&
/* Create the file descriptor for accessing the fanotify API. */
-
+\&
fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,
O_RDONLY | O_LARGEFILE);
if (fd == \-1) {
perror("fanotify_init");
exit(EXIT_FAILURE);
}
-
+\&
/* Mark the mount for:
\- permission events before opening files
\- notification events after closing a write\-enabled
file descriptor. */
-
+\&
if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,
argv[1]) == \-1) {
perror("fanotify_mark");
exit(EXIT_FAILURE);
}
-
+\&
/* Prepare for polling. */
-
+\&
nfds = 2;
-
+\&
fds[0].fd = STDIN_FILENO; /* Console input */
fds[0].events = POLLIN;
-
+\&
fds[1].fd = fd; /* Fanotify input */
fds[1].events = POLLIN;
-
+\&
/* This is the loop to wait for incoming events. */
-
+\&
printf("Listening for events.\en");
-
+\&
while (1) {
poll_num = poll(fds, nfds, \-1);
if (poll_num == \-1) {
if (errno == EINTR) /* Interrupted by a signal */
continue; /* Restart poll() */
-
+\&
perror("poll"); /* Unexpected error */
exit(EXIT_FAILURE);
}
-
+\&
if (poll_num > 0) {
if (fds[0].revents & POLLIN) {
-
+\&
/* Console input is available: empty stdin and quit. */
-
+\&
while (read(STDIN_FILENO, &buf, 1) > 0 && buf != \[aq]\en\[aq])
continue;
break;
}
-
+\&
if (fds[1].revents & POLLIN) {
-
+\&
/* Fanotify events are available. */
-
+\&
handle_events(fd);
}
}
}
-
+\&
printf("Listening for events stopped.\en");
exit(EXIT_SUCCESS);
}
@@ -1263,7 +1263,7 @@ FAN_CREATE (file created):
Directory /home/user has been modified.
Entry \[aq]testfile.txt\[aq] is not a subdirectory.
All events processed successfully. Program exiting.
-
+\&
$ \fBtouch /home/user/testfile.txt\fP # In another terminal
.EE
.in
@@ -1286,7 +1286,7 @@ FAN_CREATE | FAN_ONDIR (subdirectory created):
Directory /home/user has been modified.
Entry \[aq]testdir\[aq] is a subdirectory.
All events processed successfully. Program exiting.
-
+\&
$ \fBmkdir \-p /home/user/testdir\fP # In another terminal
.EE
.in
@@ -1303,9 +1303,9 @@ $ \fBmkdir \-p /home/user/testdir\fP # In another terminal
#include <sys/stat.h>
#include <sys/fanotify.h>
#include <unistd.h>
-
+\&
#define BUF_SIZE 256
-
+\&
int
main(int argc, char *argv[])
{
@@ -1319,31 +1319,30 @@ main(int argc, char *argv[])
struct fanotify_event_info_fid *fid;
const char *file_name;
struct stat sb;
-
+\&
if (argc != 2) {
fprintf(stderr, "Invalid number of command line arguments.\en");
exit(EXIT_FAILURE);
}
-
+\&
mount_fd = open(argv[1], O_DIRECTORY | O_RDONLY);
if (mount_fd == \-1) {
perror(argv[1]);
exit(EXIT_FAILURE);
}
-
-
+\&
/* Create an fanotify file descriptor with FAN_REPORT_DFID_NAME as
a flag so that program can receive fid events with directory
entry name. */
-
+\&
fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, 0);
if (fd == \-1) {
perror("fanotify_init");
exit(EXIT_FAILURE);
}
-
+\&
/* Place a mark on the filesystem object supplied in argv[1]. */
-
+\&
ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR,
FAN_CREATE | FAN_ONDIR,
AT_FDCWD, argv[1]);
@@ -1351,27 +1350,27 @@ main(int argc, char *argv[])
perror("fanotify_mark");
exit(EXIT_FAILURE);
}
-
+\&
printf("Listening for events.\en");
-
+\&
/* Read events from the event queue into a buffer. */
-
+\&
len = read(fd, events_buf, sizeof(events_buf));
if (len == \-1 && errno != EAGAIN) {
perror("read");
exit(EXIT_FAILURE);
}
-
+\&
/* Process all events within the buffer. */
-
+\&
for (metadata = (struct fanotify_event_metadata *) events_buf;
FAN_EVENT_OK(metadata, len);
metadata = FAN_EVENT_NEXT(metadata, len)) {
fid = (struct fanotify_event_info_fid *) (metadata + 1);
file_handle = (struct file_handle *) fid\->handle;
-
+\&
/* Ensure that the event info is of the correct type. */
-
+\&
if (fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_FID ||
fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_DFID) {
file_name = NULL;
@@ -1382,13 +1381,13 @@ main(int argc, char *argv[])
fprintf(stderr, "Received unexpected event info type.\en");
exit(EXIT_FAILURE);
}
-
+\&
if (metadata\->mask == FAN_CREATE)
printf("FAN_CREATE (file created):\en");
-
+\&
if (metadata\->mask == (FAN_CREATE | FAN_ONDIR))
printf("FAN_CREATE | FAN_ONDIR (subdirectory created):\en");
-
+\&
/* metadata\->fd is set to FAN_NOFD when the group identifies
objects by file handles. To obtain a file descriptor for
the file object corresponding to an event you can use the
@@ -1397,7 +1396,7 @@ main(int argc, char *argv[])
open_by_handle_at(2) system call. A check for ESTALE is
done to accommodate for the situation where the file handle
for the object was deleted prior to this system call. */
-
+\&
event_fd = open_by_handle_at(mount_fd, file_handle, O_RDONLY);
if (event_fd == \-1) {
if (errno == ESTALE) {
@@ -1409,21 +1408,21 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
-
+\&
snprintf(procfd_path, sizeof(procfd_path), "/proc/self/fd/%d",
event_fd);
-
+\&
/* Retrieve and print the path of the modified dentry. */
-
+\&
path_len = readlink(procfd_path, path, sizeof(path) \- 1);
if (path_len == \-1) {
perror("readlink");
exit(EXIT_FAILURE);
}
-
+\&
path[path_len] = \[aq]\e0\[aq];
printf("\etDirectory \[aq]%s\[aq] has been modified.\en", path);
-
+\&
if (file_name) {
ret = fstatat(event_fd, file_name, &sb, 0);
if (ret == \-1) {
@@ -1439,12 +1438,12 @@ main(int argc, char *argv[])
file_name);
}
}
-
+\&
/* Close associated file descriptor for this event. */
-
+\&
close(event_fd);
}
-
+\&
printf("All events processed successfully. Program exiting.\en");
exit(EXIT_SUCCESS);
}
diff --git a/man7/feature_test_macros.7 b/man7/feature_test_macros.7
index ba5e091ec..f1620611c 100644
--- a/man7/feature_test_macros.7
+++ b/man7/feature_test_macros.7
@@ -840,84 +840,84 @@ _GNU_SOURCE defined
\&
.EX
/* ftm.c */
-
+\&
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
#ifdef _POSIX_SOURCE
printf("_POSIX_SOURCE defined\en");
#endif
-
+\&
#ifdef _POSIX_C_SOURCE
printf("_POSIX_C_SOURCE defined: %jdL\en",
(intmax_t) _POSIX_C_SOURCE);
#endif
-
+\&
#ifdef _ISOC99_SOURCE
printf("_ISOC99_SOURCE defined\en");
#endif
-
+\&
#ifdef _ISOC11_SOURCE
printf("_ISOC11_SOURCE defined\en");
#endif
-
+\&
#ifdef _XOPEN_SOURCE
printf("_XOPEN_SOURCE defined: %d\en", _XOPEN_SOURCE);
#endif
-
+\&
#ifdef _XOPEN_SOURCE_EXTENDED
printf("_XOPEN_SOURCE_EXTENDED defined\en");
#endif
-
+\&
#ifdef _LARGEFILE64_SOURCE
printf("_LARGEFILE64_SOURCE defined\en");
#endif
-
+\&
#ifdef _FILE_OFFSET_BITS
printf("_FILE_OFFSET_BITS defined: %d\en", _FILE_OFFSET_BITS);
#endif
-
+\&
#ifdef _TIME_BITS
printf("_TIME_BITS defined: %d\en", _TIME_BITS);
#endif
-
+\&
#ifdef _BSD_SOURCE
printf("_BSD_SOURCE defined\en");
#endif
-
+\&
#ifdef _SVID_SOURCE
printf("_SVID_SOURCE defined\en");
#endif
-
+\&
#ifdef _DEFAULT_SOURCE
printf("_DEFAULT_SOURCE defined\en");
#endif
-
+\&
#ifdef _ATFILE_SOURCE
printf("_ATFILE_SOURCE defined\en");
#endif
-
+\&
#ifdef _GNU_SOURCE
printf("_GNU_SOURCE defined\en");
#endif
-
+\&
#ifdef _REENTRANT
printf("_REENTRANT defined\en");
#endif
-
+\&
#ifdef _THREAD_SAFE
printf("_THREAD_SAFE defined\en");
#endif
-
+\&
#ifdef _FORTIFY_SOURCE
printf("_FORTIFY_SOURCE defined\en");
#endif
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man7/inotify.7 b/man7/inotify.7
index 78ec0317f..4fe83902a 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -893,7 +893,7 @@ IN_OPEN: /home/user/temp/foo [file]
IN_CLOSE_WRITE: /home/user/temp/foo [file]
IN_OPEN: /tmp/ [directory]
IN_CLOSE_NOWRITE: /tmp/ [directory]
-
+\&
Listening for events stopped.
.EE
.in
@@ -907,13 +907,13 @@ Listening for events stopped.
#include <sys/inotify.h>
#include <unistd.h>
#include <string.h>
-
+\&
/* Read all available inotify events from the file descriptor \[aq]fd\[aq].
wd is the table of watch descriptors for the directories in argv.
argc is the length of wd and argv.
argv is the list of watched directories.
Entry 0 of wd and argv is unused. */
-
+\&
static void
handle_events(int fd, int *wd, int argc, char* argv[])
{
@@ -922,63 +922,63 @@ handle_events(int fd, int *wd, int argc, char* argv[])
decrease performance. Hence, the buffer used for reading from
the inotify file descriptor should have the same alignment as
struct inotify_event. */
-
+\&
char buf[4096]
__attribute__ ((aligned(__alignof__(struct inotify_event))));
const struct inotify_event *event;
ssize_t len;
-
+\&
/* Loop while events can be read from inotify file descriptor. */
-
+\&
for (;;) {
-
+\&
/* Read some events. */
-
+\&
len = read(fd, buf, sizeof(buf));
if (len == \-1 && errno != EAGAIN) {
perror("read");
exit(EXIT_FAILURE);
}
-
+\&
/* If the nonblocking read() found no events to read, then
it returns \-1 with errno set to EAGAIN. In that case,
we exit the loop. */
-
+\&
if (len <= 0)
break;
-
+\&
/* Loop over all events in the buffer. */
-
+\&
for (char *ptr = buf; ptr < buf + len;
ptr += sizeof(struct inotify_event) + event\->len) {
-
+\&
event = (const struct inotify_event *) ptr;
-
+\&
/* Print event type. */
-
+\&
if (event\->mask & IN_OPEN)
printf("IN_OPEN: ");
if (event\->mask & IN_CLOSE_NOWRITE)
printf("IN_CLOSE_NOWRITE: ");
if (event\->mask & IN_CLOSE_WRITE)
printf("IN_CLOSE_WRITE: ");
-
+\&
/* Print the name of the watched directory. */
-
+\&
for (size_t i = 1; i < argc; ++i) {
if (wd[i] == event\->wd) {
printf("%s/", argv[i]);
break;
}
}
-
+\&
/* Print the name of the file. */
-
+\&
if (event\->len)
printf("%s", event\->name);
-
+\&
/* Print type of filesystem object. */
-
+\&
if (event\->mask & IN_ISDIR)
printf(" [directory]\en");
else
@@ -986,7 +986,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
}
}
}
-
+\&
int
main(int argc, char* argv[])
{
@@ -995,34 +995,34 @@ main(int argc, char* argv[])
int *wd;
nfds_t nfds;
struct pollfd fds[2];
-
+\&
if (argc < 2) {
printf("Usage: %s PATH [PATH ...]\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
printf("Press ENTER key to terminate.\en");
-
+\&
/* Create the file descriptor for accessing the inotify API. */
-
+\&
fd = inotify_init1(IN_NONBLOCK);
if (fd == \-1) {
perror("inotify_init1");
exit(EXIT_FAILURE);
}
-
+\&
/* Allocate memory for watch descriptors. */
-
+\&
wd = calloc(argc, sizeof(int));
if (wd == NULL) {
perror("calloc");
exit(EXIT_FAILURE);
}
-
+\&
/* Mark directories for events
\- file was opened
\- file was closed */
-
+\&
for (i = 1; i < argc; i++) {
wd[i] = inotify_add_watch(fd, argv[i],
IN_OPEN | IN_CLOSE);
@@ -1032,19 +1032,19 @@ main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
}
-
+\&
/* Prepare for polling. */
-
+\&
nfds = 2;
-
+\&
fds[0].fd = STDIN_FILENO; /* Console input */
fds[0].events = POLLIN;
-
+\&
fds[1].fd = fd; /* Inotify input */
fds[1].events = POLLIN;
-
+\&
/* Wait for events and/or terminal input. */
-
+\&
printf("Listening for events.\en");
while (1) {
poll_num = poll(fds, nfds, \-1);
@@ -1054,33 +1054,33 @@ main(int argc, char* argv[])
perror("poll");
exit(EXIT_FAILURE);
}
-
+\&
if (poll_num > 0) {
-
+\&
if (fds[0].revents & POLLIN) {
-
+\&
/* Console input is available. Empty stdin and quit. */
-
+\&
while (read(STDIN_FILENO, &buf, 1) > 0 && buf != \[aq]\en\[aq])
continue;
break;
}
-
+\&
if (fds[1].revents & POLLIN) {
-
+\&
/* Inotify events are available. */
-
+\&
handle_events(fd, wd, argc, argv);
}
}
}
-
+\&
printf("Listening for events stopped.\en");
-
+\&
/* Close inotify file descriptor. */
-
+\&
close(fd);
-
+\&
free(wd);
exit(EXIT_SUCCESS);
}
diff --git a/man7/ip.7 b/man7/ip.7
index 235edf63b..92ecf4b3e 100644
--- a/man7/ip.7
+++ b/man7/ip.7
@@ -164,7 +164,7 @@ struct sockaddr_in {
in_port_t sin_port; /* port in network byte order */
struct in_addr sin_addr; /* internet address */
};
-
+\&
/* Internet address */
struct in_addr {
uint32_t s_addr; /* address in network byte order */
@@ -513,7 +513,7 @@ struct ip_msfilter {
struct in_addr imsf_interface; /* IP address of local
interface */
uint32_t imsf_fmode; /* Filter\-mode */
-
+\&
uint32_t imsf_numsrc; /* Number of sources in
the following array */
struct in_addr imsf_slist[1]; /* Array of source
@@ -842,7 +842,7 @@ structure:
#define SO_EE_ORIGIN_LOCAL 1
#define SO_EE_ORIGIN_ICMP 2
#define SO_EE_ORIGIN_ICMP6 3
-
+\&
struct sock_extended_err {
uint32_t ee_errno; /* error number */
uint8_t ee_origin; /* where the error originated */
@@ -853,7 +853,7 @@ struct sock_extended_err {
uint32_t ee_data; /* other data */
/* More data may follow */
};
-
+\&
struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);
.EE
.in
diff --git a/man7/ipv6.7 b/man7/ipv6.7
index aae68c45a..223bf30ce 100644
--- a/man7/ipv6.7
+++ b/man7/ipv6.7
@@ -148,7 +148,7 @@ struct sockaddr_in6 {
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* Scope ID (new in Linux 2.4) */
};
-
+\&
struct in6_addr {
unsigned char s6_addr[16]; /* IPv6 address */
};
diff --git a/man7/landlock.7 b/man7/landlock.7
index df7b87e80..4a763851d 100644
--- a/man7/landlock.7
+++ b/man7/landlock.7
@@ -407,7 +407,7 @@ section for the description of filesystem actions.
.EX
struct landlock_ruleset_attr attr = {0};
int ruleset_fd;
-
+\&
attr.handled_access_fs =
LANDLOCK_ACCESS_FS_EXECUTE |
LANDLOCK_ACCESS_FS_WRITE_FILE |
@@ -442,7 +442,7 @@ __u64 landlock_fs_access_rights[] = {
(LANDLOCK_ACCESS_FS_REFER << 1) \- 1, /* v2: add "refer" */
(LANDLOCK_ACCESS_FS_TRUNCATE << 1) \- 1, /* v3: add "truncate" */
};
-
+\&
int abi = landlock_create_ruleset(NULL, 0,
LANDLOCK_CREATE_RULESET_VERSION);
if (abi == \-1) {
@@ -454,7 +454,7 @@ if (abi == \-1) {
return; /* Graceful fallback: Do nothing. */
}
abi = MIN(abi, 3);
-
+\&
/* Only use the available rights in the ruleset. */
attr.handled_access_fs &= landlock_fs_access_rights[abi \- 1];
.EE
@@ -512,12 +512,12 @@ with this file descriptor.
.EX
struct landlock_path_beneath_attr path_beneath = {0};
int err;
-
+\&
path_beneath.allowed_access =
LANDLOCK_ACCESS_FS_EXECUTE |
LANDLOCK_ACCESS_FS_READ_FILE |
LANDLOCK_ACCESS_FS_READ_DIR;
-
+\&
path_beneath.parent_fd = open("/usr", O_PATH | O_CLOEXEC);
if (path_beneath.parent_fd == \-1) {
perror("Failed to open file");
diff --git a/man7/locale.7 b/man7/locale.7
index 02fdd57f4..c3026cef7 100644
--- a/man7/locale.7
+++ b/man7/locale.7
@@ -244,9 +244,9 @@ function, which has the following declaration:
.in +4n
.EX
struct lconv {
-
+\&
/* Numeric (nonmonetary) information */
-
+\&
char *decimal_point; /* Radix character */
char *thousands_sep; /* Separator for digit groups to left
of radix character */
@@ -257,9 +257,9 @@ struct lconv {
is done. An element with value 0 means
that the previous element is used for
all groups further left. */
-
+\&
/* Remaining fields are for monetary information */
-
+\&
char *int_curr_symbol; /* First three chars are a currency
symbol from ISO 4217. Fourth char
is the separator. Fifth char
diff --git a/man7/math_error.7 b/man7/math_error.7
index b2ff1c75d..bb7c2eaf6 100644
--- a/man7/math_error.7
+++ b/man7/math_error.7
@@ -203,11 +203,11 @@ less than zero (a domain error):
.in +4n
.EX
double x, r;
-
+\&
if (isnan(x) || islessequal(x, 0)) {
/* Deal with NaN / pole error / domain error */
}
-
+\&
r = log(x);
.EE
.in
diff --git a/man7/mount_namespaces.7 b/man7/mount_namespaces.7
index 7fd983af5..da34c1902 100644
--- a/man7/mount_namespaces.7
+++ b/man7/mount_namespaces.7
@@ -608,7 +608,7 @@ Before going further, we show that unbindable mounts are indeed unbindable:
# \fBmount \-\-bind /home/cecilia /mntZ\fP
mount: wrong fs type, bad option, bad superblock on /home/cecilia,
missing codepage or helper program, or other error
-
+\&
In some cases useful info is found in syslog \- try
dmesg | tail or so.
.EE
diff --git a/man7/netlink.7 b/man7/netlink.7
index e9ee021b3..84b24f308 100644
--- a/man7/netlink.7
+++ b/man7/netlink.7
@@ -538,11 +538,11 @@ netlink socket which will listen to the
.in +4n
.EX
struct sockaddr_nl sa;
-
+\&
memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
-
+\&
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
bind(fd, (struct sockaddr *) &sa, sizeof(sa));
.EE
@@ -559,7 +559,7 @@ struct nlmsghdr *nh; /* The nlmsghdr with payload to send */
struct sockaddr_nl sa;
struct iovec iov = { nh, nh\->nlmsg_len };
struct msghdr msg;
-
+\&
msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
@@ -567,7 +567,7 @@ nh\->nlmsg_pid = 0;
nh\->nlmsg_seq = ++sequence_number;
/* Request an ack from kernel by setting NLM_F_ACK */
nh\->nlmsg_flags |= NLM_F_ACK;
-
+\&
sendmsg(fd, &msg, 0);
.EE
.in
@@ -584,20 +584,20 @@ struct iovec iov = { buf, sizeof(buf) };
struct sockaddr_nl sa;
struct msghdr msg;
struct nlmsghdr *nh;
-
+\&
msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
len = recvmsg(fd, &msg, 0);
-
+\&
for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len);
nh = NLMSG_NEXT (nh, len)) {
/* The end of multipart message */
if (nh\->nlmsg_type == NLMSG_DONE)
return;
-
+\&
if (nh\->nlmsg_type == NLMSG_ERROR)
/* Do some error handling */
...
-
+\&
/* Continue with parsing payload */
...
}
diff --git a/man7/pkeys.7 b/man7/pkeys.7
index 2ef56711f..6edfe9fcf 100644
--- a/man7/pkeys.7
+++ b/man7/pkeys.7
@@ -169,14 +169,14 @@ Segmentation fault (core dumped)
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
-
+\&
int
main(void)
{
int status;
int pkey;
int *buffer;
-
+\&
/*
* Allocate one page of memory.
*/
@@ -184,20 +184,20 @@ main(void)
MAP_ANONYMOUS | MAP_PRIVATE, \-1, 0);
if (buffer == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
-
+\&
/*
* Put some random data into the page (still OK to touch).
*/
*buffer = __LINE__;
printf("buffer contains: %d\en", *buffer);
-
+\&
/*
* Allocate a protection key:
*/
pkey = pkey_alloc(0, 0);
if (pkey == \-1)
err(EXIT_FAILURE, "pkey_alloc");
-
+\&
/*
* Disable access to any memory with "pkey" set,
* even though there is none right now.
@@ -205,7 +205,7 @@ main(void)
status = pkey_set(pkey, PKEY_DISABLE_ACCESS);
if (status)
err(EXIT_FAILURE, "pkey_set");
-
+\&
/*
* Set the protection key on "buffer".
* Note that it is still read/write as far as mprotect() is
@@ -215,18 +215,18 @@ main(void)
PROT_READ | PROT_WRITE, pkey);
if (status == \-1)
err(EXIT_FAILURE, "pkey_mprotect");
-
+\&
printf("about to read buffer again...\en");
-
+\&
/*
* This will crash, because we have disallowed access.
*/
printf("buffer contains: %d\en", *buffer);
-
+\&
status = pkey_free(pkey);
if (status == \-1)
err(EXIT_FAILURE, "pkey_free");
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man7/rtld-audit.7 b/man7/rtld-audit.7
index cc4b0431b..9e0e4a369 100644
--- a/man7/rtld-audit.7
+++ b/man7/rtld-audit.7
@@ -502,16 +502,16 @@ This is reportedly fixed in glibc 2.10.
.EX
#include <link.h>
#include <stdio.h>
-
+\&
unsigned int
la_version(unsigned int version)
{
printf("la_version(): version = %u; LAV_CURRENT = %u\en",
version, LAV_CURRENT);
-
+\&
return LAV_CURRENT;
}
-
+\&
char *
la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
{
@@ -524,10 +524,10 @@ la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
(flag == LA_SER_CONFIG) ? "LA_SER_CONFIG" :
(flag == LA_SER_SECURE) ? "LA_SER_SECURE" :
"???");
-
+\&
return name;
}
-
+\&
void
la_activity (uintptr_t *cookie, unsigned int flag)
{
@@ -537,7 +537,7 @@ la_activity (uintptr_t *cookie, unsigned int flag)
(flag == LA_ACT_DELETE) ? "LA_ACT_DELETE" :
"???");
}
-
+\&
unsigned int
la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
{
@@ -547,24 +547,24 @@ la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
(lmid == LM_ID_NEWLM) ? "LM_ID_NEWLM" :
"???",
cookie);
-
+\&
return LA_FLG_BINDTO | LA_FLG_BINDFROM;
}
-
+\&
unsigned int
la_objclose (uintptr_t *cookie)
{
printf("la_objclose(): %p\en", cookie);
-
+\&
return 0;
}
-
+\&
void
la_preinit(uintptr_t *cookie)
{
printf("la_preinit(): %p\en", cookie);
}
-
+\&
uintptr_t
la_symbind32(Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, unsigned int *flags, const char *symname)
@@ -573,10 +573,10 @@ la_symbind32(Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
symname, sym\->st_value);
printf(" ndx = %u; flags = %#x", ndx, *flags);
printf("; refcook = %p; defcook = %p\en", refcook, defcook);
-
+\&
return sym\->st_value;
}
-
+\&
uintptr_t
la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, unsigned int *flags, const char *symname)
@@ -585,17 +585,17 @@ la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
symname, sym\->st_value);
printf(" ndx = %u; flags = %#x", ndx, *flags);
printf("; refcook = %p; defcook = %p\en", refcook, defcook);
-
+\&
return sym\->st_value;
}
-
+\&
Elf32_Addr
la_i86_gnu_pltenter(Elf32_Sym *sym, unsigned int ndx,
uintptr_t *refcook, uintptr_t *defcook, La_i86_regs *regs,
unsigned int *flags, const char *symname, long *framesizep)
{
printf("la_i86_gnu_pltenter(): %s (%p)\en", symname, sym\->st_value);
-
+\&
return sym\->st_value;
}
.EE
diff --git a/man7/rtnetlink.7 b/man7/rtnetlink.7
index 807da1c83..069166b76 100644
--- a/man7/rtnetlink.7
+++ b/man7/rtnetlink.7
@@ -206,7 +206,7 @@ struct rtmsg {
unsigned char rtm_protocol; /* Routing protocol; see below */
unsigned char rtm_scope; /* See below */
unsigned char rtm_type; /* See below */
-
+\&
unsigned int rtm_flags;
};
.EE
@@ -443,7 +443,7 @@ struct ndmsg {
__u8 ndm_flags; /* Flags */
__u8 ndm_type;
};
-
+\&
struct nda_cacheinfo {
__u32 ndm_confirmed;
__u32 ndm_used;
diff --git a/man7/sock_diag.7 b/man7/sock_diag.7
index 6dfed2c35..8e1b260db 100644
--- a/man7/sock_diag.7
+++ b/man7/sock_diag.7
@@ -482,9 +482,9 @@ struct inet_diag_msg {
__u8 idiag_state;
__u8 idiag_timer;
__u8 idiag_retrans;
-
+\&
struct inet_diag_sockid id;
-
+\&
__u32 idiag_expires;
__u32 idiag_rqueue;
__u32 idiag_wqueue;
@@ -633,7 +633,7 @@ and name of all UNIX domain sockets in the current namespace.
#include <linux/rtnetlink.h>
#include <linux/sock_diag.h>
#include <linux/unix_diag.h>
-
+\&
static int
send_query(int fd)
{
@@ -666,20 +666,20 @@ send_query(int fd)
.msg_iov = &iov,
.msg_iovlen = 1
};
-
+\&
for (;;) {
if (sendmsg(fd, &msg, 0) < 0) {
if (errno == EINTR)
continue;
-
+\&
perror("sendmsg");
return \-1;
}
-
+\&
return 0;
}
}
-
+\&
static int
print_diag(const struct unix_diag_msg *diag, unsigned int len)
{
@@ -691,12 +691,12 @@ print_diag(const struct unix_diag_msg *diag, unsigned int len)
fprintf(stderr, "unexpected family %u\en", diag\->udiag_family);
return \-1;
}
-
+\&
unsigned int rta_len = len \- NLMSG_LENGTH(sizeof(*diag));
unsigned int peer = 0;
size_t path_len = 0;
char path[sizeof(((struct sockaddr_un *) 0)\->sun_path) + 1];
-
+\&
for (struct rtattr *attr = (struct rtattr *) (diag + 1);
RTA_OK(attr, rta_len); attr = RTA_NEXT(attr, rta_len)) {
switch (attr\->rta_type) {
@@ -709,27 +709,27 @@ print_diag(const struct unix_diag_msg *diag, unsigned int len)
path[path_len] = \[aq]\e0\[aq];
}
break;
-
+\&
case UNIX_DIAG_PEER:
if (RTA_PAYLOAD(attr) >= sizeof(peer))
peer = *(unsigned int *) RTA_DATA(attr);
break;
}
}
-
+\&
printf("inode=%u", diag\->udiag_ino);
-
+\&
if (peer)
printf(", peer=%u", peer);
-
+\&
if (path_len)
printf(", name=%s%s", *path ? "" : "@",
*path ? path : path + 1);
-
+\&
putchar(\[aq]\en\[aq]);
return 0;
}
-
+\&
static int
receive_responses(int fd)
{
@@ -740,7 +740,7 @@ receive_responses(int fd)
.iov_len = sizeof(buf)
};
int flags = 0;
-
+\&
for (;;) {
struct msghdr msg = {
.msg_name = &nladdr,
@@ -748,72 +748,72 @@ receive_responses(int fd)
.msg_iov = &iov,
.msg_iovlen = 1
};
-
+\&
ssize_t ret = recvmsg(fd, &msg, flags);
-
+\&
if (ret < 0) {
if (errno == EINTR)
continue;
-
+\&
perror("recvmsg");
return \-1;
}
if (ret == 0)
return 0;
-
+\&
if (nladdr.nl_family != AF_NETLINK) {
fputs("!AF_NETLINK\en", stderr);
return \-1;
}
-
+\&
const struct nlmsghdr *h = (struct nlmsghdr *) buf;
-
+\&
if (!NLMSG_OK(h, ret)) {
fputs("!NLMSG_OK\en", stderr);
return \-1;
}
-
+\&
for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) {
if (h\->nlmsg_type == NLMSG_DONE)
return 0;
-
+\&
if (h\->nlmsg_type == NLMSG_ERROR) {
const struct nlmsgerr *err = NLMSG_DATA(h);
-
+\&
if (h\->nlmsg_len < NLMSG_LENGTH(sizeof(*err))) {
fputs("NLMSG_ERROR\en", stderr);
} else {
errno = \-err\->error;
perror("NLMSG_ERROR");
}
-
+\&
return \-1;
}
-
+\&
if (h\->nlmsg_type != SOCK_DIAG_BY_FAMILY) {
fprintf(stderr, "unexpected nlmsg_type %u\en",
(unsigned) h\->nlmsg_type);
return \-1;
}
-
+\&
if (print_diag(NLMSG_DATA(h), h\->nlmsg_len))
return \-1;
}
}
}
-
+\&
int
main(void)
{
int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
-
+\&
if (fd < 0) {
perror("socket");
return 1;
}
-
+\&
int ret = send_query(fd) || receive_responses(fd);
-
+\&
close(fd);
return ret;
}
diff --git a/man7/socket.7 b/man7/socket.7
index 37faf89af..59a7a3f49 100644
--- a/man7/socket.7
+++ b/man7/socket.7
@@ -705,7 +705,7 @@ calls would have the effect noted in the comments:
.EX
int ov = 4; // Set peek offset to 4
setsockopt(fd, SOL_SOCKET, SO_PEEK_OFF, &ov, sizeof(ov));
-
+\&
recv(fd, buf, 2, MSG_PEEK); // Peeks "cc"; offset set to 6
recv(fd, buf, 2, MSG_PEEK); // Peeks "dd"; offset set to 8
recv(fd, buf, 2, 0); // Reads "aa"; offset set to 6
diff --git a/man7/string_copying.7 b/man7/string_copying.7
index fdac68969..da1fc6752 100644
--- a/man7/string_copying.7
+++ b/man7/string_copying.7
@@ -747,62 +747,62 @@ Here are reference implementations for functions not provided by libc.
.in +4n
.EX
/* This code is in the public domain. */
-
+\&
.\" ----- EXAMPLES :: Implementations :: stpecpy(3) -------------------/
char *
.IR stpecpy "(char *dst, char end[0], const char *restrict src)"
{
char *p;
-
+\&
if (dst == NULL)
return NULL;
if (dst == end)
return end;
-
+\&
p = memccpy(dst, src, \[aq]\e0\[aq], end \- dst);
if (p != NULL)
return p \- 1;
-
+\&
/* truncation detected */
end[\-1] = \[aq]\e0\[aq];
return end;
}
-
+\&
.\" ----- EXAMPLES :: Implementations :: zustr2ustp(3) ----------------/
char *
.IR zustr2ustp "(char *restrict dst, const char *restrict src, size_t sz)"
{
return ustpcpy(dst, src, strnlen(src, sz));
}
-
+\&
.\" ----- EXAMPLES :: Implementations :: zustr2stp(3) -----------------/
char *
.IR zustr2stp "(char *restrict dst, const char *restrict src, size_t sz)"
{
char *p;
-
+\&
p = zustr2ustp(dst, src, sz);
*p = \[aq]\e0\[aq];
-
+\&
return p;
}
-
+\&
.\" ----- EXAMPLES :: Implementations :: ustpcpy(3) -------------------/
char *
.IR ustpcpy "(char *restrict dst, const char *restrict src, size_t len)"
{
return mempcpy(dst, src, len);
}
-
+\&
.\" ----- EXAMPLES :: Implementations :: ustr2stp(3) ------------------/
char *
.IR ustr2stp "(char *restrict dst, const char *restrict src, size_t len)"
{
char *p;
-
+\&
p = ustpcpy(dst, src, len);
*p = \[aq]\e0\[aq];
-
+\&
return p;
}
.EE
diff --git a/man7/system_data_types.7 b/man7/system_data_types.7
index 3ab3e1d84..6bbf71004 100644
--- a/man7/system_data_types.7
+++ b/man7/system_data_types.7
@@ -276,42 +276,42 @@ are used as explained in the notes section above.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
-
+\&
int
main (void)
{
static const char *const str = "500000 us in half a second";
suseconds_t us;
intmax_t tmp;
-
+\&
/* Scan the number from the string into the temporary variable. */
-
+\&
sscanf(str, "%jd", &tmp);
-
+\&
/* Check that the value is within the valid range of suseconds_t. */
-
+\&
if (tmp < \-1 || tmp > 1000000) {
fprintf(stderr, "Scanned value outside valid range!\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Copy the value to the suseconds_t variable \[aq]us\[aq]. */
-
+\&
us = tmp;
-
+\&
/* Even though suseconds_t can hold the value \-1, this isn\[aq]t
a sensible number of microseconds. */
-
+\&
if (us < 0) {
fprintf(stderr, "Scanned value shouldn\[aq]t be negative!\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Print the value. */
-
+\&
printf("There are %jd microseconds in half a second.\en",
(intmax_t) us);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man7/unix.7 b/man7/unix.7
index e23ccbc12..b9e28b20e 100644
--- a/man7/unix.7
+++ b/man7/unix.7
@@ -907,16 +907,16 @@ a null terminator for the string returned in
.in +4n
.EX
void *addrp;
-
+\&
addrlen = sizeof(struct sockaddr_un);
addrp = malloc(addrlen + 1);
if (addrp == NULL)
/* Handle error */ ;
memset(addrp, 0, addrlen + 1);
-
+\&
if (getsockname(sfd, (struct sockaddr *) addrp, &addrlen)) == \-1)
/* handle error */ ;
-
+\&
printf("sun_path = %s\en", ((struct sockaddr_un *) addrp)\->sun_path);
.EE
.in
@@ -963,14 +963,14 @@ $
/*
* File connection.h
*/
-
+\&
#define SOCKET_NAME "/tmp/9Lq7BNBnBycd6nxy.socket"
#define BUFFER_SIZE 12
-
+\&
/*
* File server.c
*/
-
+\&
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -978,7 +978,7 @@ $
#include <sys/un.h>
#include <unistd.h>
#include "connection.h"
-
+\&
int
main(int argc, char *argv[])
{
@@ -989,123 +989,123 @@ main(int argc, char *argv[])
int data_socket;
int result;
char buffer[BUFFER_SIZE];
-
+\&
/* Create local socket. */
-
+\&
connection_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if (connection_socket == \-1) {
perror("socket");
exit(EXIT_FAILURE);
}
-
+\&
/*
* For portability clear the whole structure, since some
* implementations have additional (nonstandard) fields in
* the structure.
*/
-
+\&
memset(&name, 0, sizeof(name));
-
+\&
/* Bind socket to socket name. */
-
+\&
name.sun_family = AF_UNIX;
strncpy(name.sun_path, SOCKET_NAME, sizeof(name.sun_path) \- 1);
-
+\&
ret = bind(connection_socket, (const struct sockaddr *) &name,
sizeof(name));
if (ret == \-1) {
perror("bind");
exit(EXIT_FAILURE);
}
-
+\&
/*
* Prepare for accepting connections. The backlog size is set
* to 20. So while one request is being processed other requests
* can be waiting.
*/
-
+\&
ret = listen(connection_socket, 20);
if (ret == \-1) {
perror("listen");
exit(EXIT_FAILURE);
}
-
+\&
/* This is the main loop for handling connections. */
-
+\&
for (;;) {
-
+\&
/* Wait for incoming connection. */
-
+\&
data_socket = accept(connection_socket, NULL, NULL);
if (data_socket == \-1) {
perror("accept");
exit(EXIT_FAILURE);
}
-
+\&
result = 0;
for (;;) {
-
+\&
/* Wait for next data packet. */
-
+\&
ret = read(data_socket, buffer, sizeof(buffer));
if (ret == \-1) {
perror("read");
exit(EXIT_FAILURE);
}
-
+\&
/* Ensure buffer is 0\-terminated. */
-
+\&
buffer[sizeof(buffer) \- 1] = 0;
-
+\&
/* Handle commands. */
-
+\&
if (!strncmp(buffer, "DOWN", sizeof(buffer))) {
down_flag = 1;
break;
}
-
+\&
if (!strncmp(buffer, "END", sizeof(buffer))) {
break;
}
-
+\&
/* Add received summand. */
-
+\&
result += atoi(buffer);
}
-
+\&
/* Send result. */
-
+\&
sprintf(buffer, "%d", result);
ret = write(data_socket, buffer, sizeof(buffer));
if (ret == \-1) {
perror("write");
exit(EXIT_FAILURE);
}
-
+\&
/* Close socket. */
-
+\&
close(data_socket);
-
+\&
/* Quit on DOWN command. */
-
+\&
if (down_flag) {
break;
}
}
-
+\&
close(connection_socket);
-
+\&
/* Unlink the socket. */
-
+\&
unlink(SOCKET_NAME);
-
+\&
exit(EXIT_SUCCESS);
}
-
+\&
/*
* File client.c
*/
-
+\&
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1114,7 +1114,7 @@ main(int argc, char *argv[])
#include <sys/un.h>
#include <unistd.h>
#include "connection.h"
-
+\&
int
main(int argc, char *argv[])
{
@@ -1122,37 +1122,37 @@ main(int argc, char *argv[])
int ret;
int data_socket;
char buffer[BUFFER_SIZE];
-
+\&
/* Create local socket. */
-
+\&
data_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if (data_socket == \-1) {
perror("socket");
exit(EXIT_FAILURE);
}
-
+\&
/*
* For portability clear the whole structure, since some
* implementations have additional (nonstandard) fields in
* the structure.
*/
-
+\&
memset(&addr, 0, sizeof(addr));
-
+\&
/* Connect socket to socket address. */
-
+\&
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, SOCKET_NAME, sizeof(addr.sun_path) \- 1);
-
+\&
ret = connect(data_socket, (const struct sockaddr *) &addr,
sizeof(addr));
if (ret == \-1) {
fprintf(stderr, "The server is down.\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Send arguments. */
-
+\&
for (size_t i = 1; i < argc; ++i) {
ret = write(data_socket, argv[i], strlen(argv[i]) + 1);
if (ret == \-1) {
@@ -1160,34 +1160,34 @@ main(int argc, char *argv[])
break;
}
}
-
+\&
/* Request result. */
-
+\&
strcpy(buffer, "END");
ret = write(data_socket, buffer, strlen(buffer) + 1);
if (ret == \-1) {
perror("write");
exit(EXIT_FAILURE);
}
-
+\&
/* Receive result. */
-
+\&
ret = read(data_socket, buffer, sizeof(buffer));
if (ret == \-1) {
perror("read");
exit(EXIT_FAILURE);
}
-
+\&
/* Ensure buffer is 0\-terminated. */
-
+\&
buffer[sizeof(buffer) \- 1] = 0;
-
+\&
printf("Result = %s\en", buffer);
-
+\&
/* Close socket. */
-
+\&
close(data_socket);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man7/user_namespaces.7 b/man7/user_namespaces.7
index f2cb4e5b8..a65854d73 100644
--- a/man7/user_namespaces.7
+++ b/man7/user_namespaces.7
@@ -1153,9 +1153,9 @@ CapEff: 0000001fffffffff
\&
.EX
/* userns_child_exec.c
-
+\&
Licensed under GNU General Public License v2 or later
-
+\&
Create a child process that executes a shell command in new
namespace(s); allow UID and GID mappings to be specified when
creating a user namespace.
@@ -1173,14 +1173,14 @@ CapEff: 0000001fffffffff
#include <string.h>
#include <limits.h>
#include <errno.h>
-
+\&
struct child_args {
char **argv; /* Command to be executed by child, with args */
int pipe_fd[2]; /* Pipe used to synchronize parent and child */
};
-
+\&
static int verbose;
-
+\&
static void
usage(char *pname)
{
@@ -1213,51 +1213,51 @@ usage(char *pname)
" by commas;\en");
fpe("the commas are replaced by newlines before writing"
" to map files.\en");
-
+\&
exit(EXIT_FAILURE);
}
-
+\&
/* Update the mapping file \[aq]map_file\[aq], with the value provided in
\[aq]mapping\[aq], a string that defines a UID or GID mapping. A UID or
GID mapping consists of one or more newline\-delimited records
of the form:
-
+\&
ID_inside\-ns ID\-outside\-ns length
-
+\&
Requiring the user to supply a string that contains newlines is
of course inconvenient for command\-line use. Thus, we permit the
use of commas to delimit records in this string, and replace them
with newlines before writing the string to the file. */
-
+\&
static void
update_map(char *mapping, char *map_file)
{
int fd;
size_t map_len; /* Length of \[aq]mapping\[aq] */
-
+\&
/* Replace commas in mapping string with newlines. */
-
+\&
map_len = strlen(mapping);
for (size_t j = 0; j < map_len; j++)
if (mapping[j] == \[aq],\[aq])
mapping[j] = \[aq]\en\[aq];
-
+\&
fd = open(map_file, O_RDWR);
if (fd == \-1) {
fprintf(stderr, "ERROR: open %s: %s\en", map_file,
strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
if (write(fd, mapping, map_len) != map_len) {
fprintf(stderr, "ERROR: write %s: %s\en", map_file,
strerror(errno));
exit(EXIT_FAILURE);
}
-
+\&
close(fd);
}
-
+\&
/* Linux 3.19 made a change in the handling of setgroups(2) and
the \[aq]gid_map\[aq] file to address a security issue. The issue
allowed *unprivileged* users to employ user namespaces in
@@ -1266,53 +1266,53 @@ update_map(char *mapping, char *map_file)
system call in this user namespace must first be disabled by
writing "deny" to one of the /proc/PID/setgroups files for
this namespace. That is the purpose of the following function. */
-
+\&
static void
proc_setgroups_write(pid_t child_pid, char *str)
{
char setgroups_path[PATH_MAX];
int fd;
-
+\&
snprintf(setgroups_path, PATH_MAX, "/proc/%jd/setgroups",
(intmax_t) child_pid);
-
+\&
fd = open(setgroups_path, O_RDWR);
if (fd == \-1) {
-
+\&
/* We may be on a system that doesn\[aq]t support
/proc/PID/setgroups. In that case, the file won\[aq]t exist,
and the system won\[aq]t impose the restrictions that Linux 3.19
added. That\[aq]s fine: we don\[aq]t need to do anything in order
to permit \[aq]gid_map\[aq] to be updated.
-
+\&
However, if the error from open() was something other than
the ENOENT error that is expected for that case, let the
user know. */
-
+\&
if (errno != ENOENT)
fprintf(stderr, "ERROR: open %s: %s\en", setgroups_path,
strerror(errno));
return;
}
-
+\&
if (write(fd, str, strlen(str)) == \-1)
fprintf(stderr, "ERROR: write %s: %s\en", setgroups_path,
strerror(errno));
-
+\&
close(fd);
}
-
+\&
static int /* Start function for cloned child */
childFunc(void *arg)
{
struct child_args *args = arg;
char ch;
-
+\&
/* Wait until the parent has updated the UID and GID mappings.
See the comment in main(). We wait for end of file on a
pipe that will be closed by the parent process once it has
updated the mappings. */
-
+\&
close(args\->pipe_fd[1]); /* Close our descriptor for the write
end of the pipe so that we see EOF
when parent closes its descriptor. */
@@ -1321,20 +1321,20 @@ childFunc(void *arg)
"Failure in child: read from pipe returned != 0\en");
exit(EXIT_FAILURE);
}
-
+\&
close(args\->pipe_fd[0]);
-
+\&
/* Execute a shell command. */
-
+\&
printf("About to exec %s\en", args\->argv[0]);
execvp(args\->argv[0], args\->argv);
err(EXIT_FAILURE, "execvp");
}
-
+\&
#define STACK_SIZE (1024 * 1024)
-
+\&
static char child_stack[STACK_SIZE]; /* Space for child\[aq]s stack */
-
+\&
int
main(int argc, char *argv[])
{
@@ -1345,14 +1345,14 @@ main(int argc, char *argv[])
const int MAP_BUF_SIZE = 100;
char map_buf[MAP_BUF_SIZE];
char map_path[PATH_MAX];
-
+\&
/* Parse command\-line options. The initial \[aq]+\[aq] character in
the final getopt() argument prevents GNU\-style permutation
of command\-line options. That\[aq]s useful, since sometimes
the \[aq]command\[aq] to be executed by this program itself
has command\-line options. We don\[aq]t want getopt() to treat
those as options to this program. */
-
+\&
flags = 0;
verbose = 0;
gid_map = NULL;
@@ -1373,16 +1373,16 @@ main(int argc, char *argv[])
default: usage(argv[0]);
}
}
-
+\&
/* \-M or \-G without \-U is nonsensical */
-
+\&
if (((uid_map != NULL || gid_map != NULL || map_zero) &&
!(flags & CLONE_NEWUSER)) ||
(map_zero && (uid_map != NULL || gid_map != NULL)))
usage(argv[0]);
-
+\&
args.argv = &argv[optind];
-
+\&
/* We use a pipe to synchronize the parent and child, in order to
ensure that the parent sets the UID and GID maps before the child
calls execve(). This ensures that the child maintains its
@@ -1392,25 +1392,25 @@ main(int argc, char *argv[])
its capabilities if it performed an execve() with nonzero
user IDs (see the capabilities(7) man page for details of the
transformation of a process\[aq]s capabilities during execve()). */
-
+\&
if (pipe(args.pipe_fd) == \-1)
err(EXIT_FAILURE, "pipe");
-
+\&
/* Create the child in new namespace(s). */
-
+\&
child_pid = clone(childFunc, child_stack + STACK_SIZE,
flags | SIGCHLD, &args);
if (child_pid == \-1)
err(EXIT_FAILURE, "clone");
-
+\&
/* Parent falls through to here. */
-
+\&
if (verbose)
printf("%s: PID of child created by clone() is %jd\en",
argv[0], (intmax_t) child_pid);
-
+\&
/* Update the UID and GID maps in the child. */
-
+\&
if (uid_map != NULL || map_zero) {
snprintf(map_path, PATH_MAX, "/proc/%jd/uid_map",
(intmax_t) child_pid);
@@ -1421,10 +1421,10 @@ main(int argc, char *argv[])
}
update_map(uid_map, map_path);
}
-
+\&
if (gid_map != NULL || map_zero) {
proc_setgroups_write(child_pid, "deny");
-
+\&
snprintf(map_path, PATH_MAX, "/proc/%jd/gid_map",
(intmax_t) child_pid);
if (map_zero) {
@@ -1434,18 +1434,18 @@ main(int argc, char *argv[])
}
update_map(gid_map, map_path);
}
-
+\&
/* Close the write end of the pipe, to signal to the child that we
have updated the UID and GID maps. */
-
+\&
close(args.pipe_fd[1]);
-
+\&
if (waitpid(child_pid, NULL, 0) == \-1) /* Wait for child */
err(EXIT_FAILURE, "waitpid");
-
+\&
if (verbose)
printf("%s: terminating\en", argv[0]);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
diff --git a/man7/vdso.7 b/man7/vdso.7
index c48735f8c..021d300f3 100644
--- a/man7/vdso.7
+++ b/man7/vdso.7
@@ -606,7 +606,7 @@ The documents, examples, and source code in the Linux source code tree:
Documentation/ABI/stable/vdso
Documentation/ia64/fsys.rst
Documentation/vDSO/* (includes examples of using the vDSO)
-
+.PP
find arch/ \-iname \[aq]*vdso*\[aq] \-o \-iname \[aq]*gate*\[aq]
.EE
.in
diff --git a/share/lint/groff/man.ignore.grep b/share/lint/groff/man.ignore.grep
index 79682f42f..912eb576c 100644
--- a/share/lint/groff/man.ignore.grep
+++ b/share/lint/groff/man.ignore.grep
@@ -1,4 +1,3 @@
style: .TH missing fifth argument and second argument
-style: blank line in input$
style: use of deprecated macro: .PD$
style: use of deprecated macro: .UC$