aboutsummaryrefslogtreecommitdiffstats
path: root/man3
diff options
context:
space:
mode:
Diffstat (limited to 'man3')
-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
121 files changed, 1134 insertions, 1134 deletions
diff --git a/man3/CPU_SET.3 b/man3/CPU_SET.3
index 46acaa88fb..a0461104a3 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 eb9710912e..6b9bb58032 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 378eb338c7..e37f22020e 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 ec72041912..d796ca077d 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 32682a337c..9084dababb 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 157fca076f..a0fb7cf34b 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 fdbfa16369..87ffde36ee 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 b0760f72bb..ca8991dc59 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 41dad78ed2..c142e956bf 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 a32826e98f..ba1354c2d8 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 979bad42a4..b9624a4b05 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 3c0cc84da6..4ba8802260 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 c936cc5e29..b0134546d0 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 d8bf80302a..e9063d76e5 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 4c249b1205..05569614f0 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 ee7ba45e0a..c1368b5adb 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 20a7781e73..6abcfcd2f6 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 7e478973fe..554750ca18 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 90b770cb85..e7a25d6872 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 5163aeab04..96ef06829d 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 90c365a65f..a21e6e1b4a 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 c8872a0913..2e31268639 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 d0d35e9228..9f7ea96276 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 2b54bf5beb..2ad58d957a 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 28f8fbee9c..4d85cecd70 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 c7a4cf1821..73bcc11ca0 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 c623878bef..a97aa8fa37 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 97f74c569c..b2da3085cf 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 36616af128..409a3c81a6 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 7f4dac813b..2668fdc57d 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 79aa513428..9576b03069 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 59931bb3bf..68f1818250 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 092c6affa8..22d3380d3a 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 78e79f06fc..8fed569980 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 5af0709fc3..8c4de3b169 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 525720812d..cff85e5e2a 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 b841998986..476c9a96f6 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 3fef0f3991..c1bb2a5af8 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 470a001c8a..14cab0f79d 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 d7ffe52618..b6c9421c82 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 b3e6ca4fe8..b7835bedf0 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 6e4331884e..72844cfe67 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 45687b06e3..b1c7f2df18 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 5bdcdb1b12..0c08368f74 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 0e3ed2e271..634cdc4050 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 e65a6cd358..3d0c195633 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 4c0652ed3f..2620d2b9e4 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 9aee2321b8..50b3924001 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 f794797155..88d323990b 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 c8b5be332f..41fb111e54 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 86f0ebeb40..c819d9c130 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 dfd7787c7a..422be88a9d 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 01dc65980f..bb98bb312e 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 8c69127886..e482f12e85 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 0da4030dee..10ea3b3c68 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 d51f838fd3..54295f6485 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 8793fd2723..0a601970ae 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 03f26e0c83..dbc95bf144 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 c46fb8708c..89e073ac91 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 3a7ee0da66..452abedc93 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 ad7eed2895..7c86de8e45 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 83b213cd56..e524d59397 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 70f5a8e03c..6c73f72c82 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 f43b6d5782..5f73c499de 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 40ff9a62df..5447775c04 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 8337cb1bd1..19651ea57f 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 adf98213a8..9d24aaf0ad 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 895c4067bb..5baf065bf6 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 371ae4617a..4f8eb3f880 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 3713ffedf4..c7fb2f81f1 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 48fbeff6e7..5d10e9a901 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 63d411745b..efe74e9e4b 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 8899b56e97..5da0b09156 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 b234e5ce1b..65e0ee4c20 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 32dc1211ce..b0190858d1 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 b90a712938..962881a9cb 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 22abc969d9..60657ee4bf 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 231466119c..5ff2ff8f74 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 658b732770..215f01d9f5 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 b14c11a866..b60ea81c27 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 b90bd74941..033acf01e1 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 271df0852a..1eb434ad12 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 cc397c36d5..ddf8460105 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 92c4b47a01..bac136159f 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 b13ddc8eb3..fef113db23 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 ed2bb82d77..3aa75c1962 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 71c8714972..6cca4c448e 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 4de5d4cd7e..7b34fdb847 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 f91b6d365d..b4c912e49e 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 d2def80e10..ea6afb46d1 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 0801a7eb04..955f8cb434 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 e6cd1fa258..8dfd80fb14 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 d245daf237..13e540b22e 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 5f5246bb3d..b70bf25578 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 0abcf6fcec..80ee2655f2 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 8050d31d2d..4e9a0a02a0 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 27359c923b..3eb65a9a45 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 7b61f6dbe8..da4893202d 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 0b67451a41..adf5f13d73 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 7ee7c56a06..7db3f1c557 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 c888c969c1..ee1c54d469 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 2aa31865c4..bbfc8de18d 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 254145cfc4..b5627052de 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 4269eda27c..922c9e62de 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 ddbcccc83f..f0584beec9 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 f248375765..e01ff1d471 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 59af5d58e4..68529802a1 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 8e2af8c77b..e7367cf63f 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 2a58c37e0c..a6cd2c7584 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 03ffeaedc6..74f67644c7 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 38bb8814bd..6d77faf14c 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 9a9fa4f4d2..266268199a 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 69996f3989..0a1bf4c496 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 6d7c661769..19caafeb1d 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 e990921106..b702e287a7 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 3c5ddddb30..95b291ab8d 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 ad781ab9a2..6cea27af4d 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 867632bb3e..9bf432b09e 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 e57dd6438e..af34c5424f 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 35b0528861..958de6d2c1 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 1a1f284bb1..2a9e0fa933 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++)