aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man1/sprof.116
-rw-r--r--man2/eventfd.24
-rw-r--r--man2/execve.24
-rw-r--r--man2/futex.26
-rw-r--r--man2/getdents.23
-rw-r--r--man2/mprotect.23
-rw-r--r--man2/open_by_handle_at.28
-rw-r--r--man2/recvmmsg.26
-rw-r--r--man2/sched_setaffinity.26
-rw-r--r--man3/CPU_SET.34
-rw-r--r--man3/backtrace.34
-rw-r--r--man3/bsearch.34
-rw-r--r--man3/dl_iterate_phdr.34
-rw-r--r--man3/dlinfo.33
-rw-r--r--man3/duplocale.33
-rw-r--r--man3/encrypt.315
-rw-r--r--man3/envz_add.34
-rw-r--r--man3/fopencookie.36
-rw-r--r--man3/getaddrinfo.34
-rw-r--r--man3/getaddrinfo_a.36
-rw-r--r--man3/getdate.33
-rw-r--r--man3/getgrent_r.36
-rw-r--r--man3/getgrouplist.34
-rw-r--r--man3/getifaddrs.35
-rw-r--r--man3/getprotoent_r.33
-rw-r--r--man3/getservent_r.33
-rw-r--r--man3/hsearch.35
-rw-r--r--man3/mallinfo.36
-rw-r--r--man3/malloc_info.39
-rw-r--r--man3/mbstowcs.33
-rw-r--r--man3/mtrace.34
-rw-r--r--man3/pthread_create.310
-rw-r--r--man3/pthread_getcpuclockid.34
-rw-r--r--man3/pthread_setaffinity_np.36
-rw-r--r--man3/qsort.34
-rw-r--r--man3/rand.34
-rw-r--r--man3/strcat.33
-rw-r--r--man3/strtok.33
-rw-r--r--man3/tsearch.33
-rw-r--r--man3/wordexp.33
-rw-r--r--man5/core.54
-rw-r--r--man7/aio.710
-rw-r--r--man7/inotify.76
-rw-r--r--man7/sock_diag.73
-rw-r--r--man7/unix.73
-rw-r--r--man7/user_namespaces.74
46 files changed, 99 insertions, 135 deletions
diff --git a/man1/sprof.1 b/man1/sprof.1
index f65ee6cce2..dc7e04ece5 100644
--- a/man1/sprof.1
+++ b/man1/sprof.1
@@ -116,35 +116,27 @@ $ \fBcat libdemo.c\fP
void
consumeCpu1(int lim)
{
- int j;
-
- for (j = 0; j < lim; j++)
+ for (int j = 0; j < lim; j++)
getppid();
}
void
x1(void) {
- int j;
-
- for (j = 0; j < 100; j++)
+ for (int j = 0; j < 100; j++)
consumeCpu1(200000);
}
void
consumeCpu2(int lim)
{
- int j;
-
- for (j = 0; j < lim; j++)
+ for (int j = 0; j < lim; j++)
getppid();
}
void
x2(void)
{
- int j;
-
- for (j = 0; j < 1000; j++)
+ for (int j = 0; j < 1000; j++)
consumeCpu2(10000);
}
.EE
diff --git a/man2/eventfd.2 b/man2/eventfd.2
index 804cf796b8..929234ab79 100644
--- a/man2/eventfd.2
+++ b/man2/eventfd.2
@@ -396,7 +396,7 @@ Parent read 28 (0x1c) from efd
int
main(int argc, char *argv[])
{
- int efd, j;
+ int efd;
uint64_t u;
ssize_t s;
@@ -411,7 +411,7 @@ main(int argc, char *argv[])
switch (fork()) {
case 0:
- for (j = 1; j < argc; j++) {
+ for (int j = 1; j < argc; j++) {
printf("Child writing %s to efd\en", argv[j]);
u = strtoull(argv[j], NULL, 0);
/* strtoull() allows various bases */
diff --git a/man2/execve.2 b/man2/execve.2
index 7b7013403a..5f33332ca0 100644
--- a/man2/execve.2
+++ b/man2/execve.2
@@ -794,9 +794,7 @@ It just echoes its command-line arguments, one per line.
int
main(int argc, char *argv[])
{
- int j;
-
- for (j = 0; j < argc; j++)
+ for (int j = 0; j < argc; j++)
printf("argv[%d]: %s\en", j, argv[j]);
exit(EXIT_SUCCESS);
diff --git a/man2/futex.2 b/man2/futex.2
index 6192b145a1..e5fc28b4ae 100644
--- a/man2/futex.2
+++ b/man2/futex.2
@@ -1828,7 +1828,7 @@ int
main(int argc, char *argv[])
{
pid_t childPid;
- int j, nloops;
+ int nloops;
setbuf(stdout, NULL);
@@ -1858,7 +1858,7 @@ main(int argc, char *argv[])
errExit("fork");
if (childPid == 0) { /* Child */
- for (j = 0; j < nloops; j++) {
+ for (int j = 0; j < nloops; j++) {
fwait(futex1);
printf("Child (%ld) %d\en", (long) getpid(), j);
fpost(futex2);
@@ -1869,7 +1869,7 @@ main(int argc, char *argv[])
/* Parent falls through to here */
- for (j = 0; j < nloops; j++) {
+ for (int j = 0; j < nloops; j++) {
fwait(futex2);
printf("Parent (%ld) %d\en", (long) getpid(), j);
fpost(futex1);
diff --git a/man2/getdents.2 b/man2/getdents.2
index 7c26385613..4c02726ea7 100644
--- a/man2/getdents.2
+++ b/man2/getdents.2
@@ -280,7 +280,6 @@ main(int argc, char *argv[])
int fd, nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
- int bpos;
char d_type;
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
@@ -297,7 +296,7 @@ main(int argc, char *argv[])
printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
printf("inode# file type d_reclen d_off d_name\en");
- for (bpos = 0; bpos < nread;) {
+ for (int bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
printf("%8ld ", d\->d_ino);
d_type = *(buf + bpos + d\->d_reclen \- 1);
diff --git a/man2/mprotect.2 b/man2/mprotect.2
index 05cbed083d..556ee94467 100644
--- a/man2/mprotect.2
+++ b/man2/mprotect.2
@@ -334,7 +334,6 @@ handler(int sig, siginfo_t *si, void *unused)
int
main(int argc, char *argv[])
{
- char *p;
int pagesize;
struct sigaction sa;
@@ -361,7 +360,7 @@ main(int argc, char *argv[])
PROT_READ) == \-1)
handle_error("mprotect");
- for (p = buffer ; ; )
+ for (char *p = buffer ; ; )
*(p++) = \(aqa\(aq;
printf("Loop completed\en"); /* Should never happen */
diff --git a/man2/open_by_handle_at.2 b/man2/open_by_handle_at.2
index c6b1fb3244..fb89406960 100644
--- a/man2/open_by_handle_at.2
+++ b/man2/open_by_handle_at.2
@@ -555,7 +555,7 @@ int
main(int argc, char *argv[])
{
struct file_handle *fhp;
- int mount_id, fhsize, flags, dirfd, j;
+ int mount_id, fhsize, flags, dirfd;
char *pathname;
if (argc != 2) {
@@ -601,7 +601,7 @@ main(int argc, char *argv[])
printf("%d\en", mount_id);
printf("%d %d ", fhp\->handle_bytes, fhp\->handle_type);
- for (j = 0; j < fhp\->handle_bytes; j++)
+ for (int j = 0; j < fhp\->handle_bytes; j++)
printf(" %02x", fhp\->f_handle[j]);
printf("\en");
@@ -677,7 +677,7 @@ int
main(int argc, char *argv[])
{
struct file_handle *fhp;
- int mount_id, fd, mount_fd, handle_bytes, j;
+ int mount_id, fd, mount_fd, handle_bytes;
ssize_t nread;
char buf[1000];
#define LINE_SIZE 100
@@ -715,7 +715,7 @@ main(int argc, char *argv[])
fhp\->handle_type = strtoul(nextp, &nextp, 0);
- for (j = 0; j < fhp\->handle_bytes; j++)
+ for (int j = 0; j < fhp\->handle_bytes; j++)
fhp\->f_handle[j] = strtoul(nextp, &nextp, 16);
/* Obtain file descriptor for mount point, either by opening
diff --git a/man2/recvmmsg.2 b/man2/recvmmsg.2
index 096c4e04f6..37ac4c6b48 100644
--- a/man2/recvmmsg.2
+++ b/man2/recvmmsg.2
@@ -237,7 +237,7 @@ main(void)
#define VLEN 10
#define BUFSIZE 200
#define TIMEOUT 1
- int sockfd, retval, i;
+ int sockfd, retval;
struct sockaddr_in addr;
struct mmsghdr msgs[VLEN];
struct iovec iovecs[VLEN];
@@ -259,7 +259,7 @@ main(void)
}
memset(msgs, 0, sizeof(msgs));
- for (i = 0; i < VLEN; i++) {
+ for (int i = 0; i < VLEN; i++) {
iovecs[i].iov_base = bufs[i];
iovecs[i].iov_len = BUFSIZE;
msgs[i].msg_hdr.msg_iov = &iovecs[i];
@@ -276,7 +276,7 @@ main(void)
}
printf("%d messages received\en", retval);
- for (i = 0; i < retval; i++) {
+ for (int i = 0; i < retval; i++) {
bufs[i][msgs[i].msg_len] = 0;
printf("%d %s", i+1, bufs[i]);
}
diff --git a/man2/sched_setaffinity.2 b/man2/sched_setaffinity.2
index aeaa8ac70c..4f16268f86 100644
--- a/man2/sched_setaffinity.2
+++ b/man2/sched_setaffinity.2
@@ -370,7 +370,7 @@ main(int argc, char *argv[])
{
cpu_set_t set;
int parentCPU, childCPU;
- int nloops, j;
+ int nloops;
if (argc != 4) {
fprintf(stderr, "Usage: %s parent\-cpu child\-cpu num\-loops\en",
@@ -394,7 +394,7 @@ main(int argc, char *argv[])
if (sched_setaffinity(getpid(), sizeof(set), &set) == \-1)
errExit("sched_setaffinity");
- for (j = 0; j < nloops; j++)
+ for (int j = 0; j < nloops; j++)
getppid();
exit(EXIT_SUCCESS);
@@ -405,7 +405,7 @@ main(int argc, char *argv[])
if (sched_setaffinity(getpid(), sizeof(set), &set) == \-1)
errExit("sched_setaffinity");
- for (j = 0; j < nloops; j++)
+ for (int j = 0; j < nloops; j++)
getppid();
wait(NULL); /* Wait for child to terminate */
diff --git a/man3/CPU_SET.3 b/man3/CPU_SET.3
index db5da81eeb..8fc1db5dab 100644
--- a/man3/CPU_SET.3
+++ b/man3/CPU_SET.3
@@ -329,7 +329,7 @@ main(int argc, char *argv[])
{
cpu_set_t *cpusetp;
size_t size;
- int num_cpus, cpu;
+ int num_cpus;
if (argc < 2) {
fprintf(stderr, "Usage: %s <num\-cpus>\en", argv[0]);
@@ -347,7 +347,7 @@ main(int argc, char *argv[])
size = CPU_ALLOC_SIZE(num_cpus);
CPU_ZERO_S(size, cpusetp);
- for (cpu = 0; cpu < num_cpus; cpu += 2)
+ for (int 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));
diff --git a/man3/backtrace.3 b/man3/backtrace.3
index 703338b0f0..814cc12f7b 100644
--- a/man3/backtrace.3
+++ b/man3/backtrace.3
@@ -232,7 +232,7 @@ backtrace() returned 8 addresses
void
myfunc3(void)
{
- int j, nptrs;
+ int nptrs;
void *buffer[BT_BUF_SIZE];
char **strings;
@@ -248,7 +248,7 @@ myfunc3(void)
exit(EXIT_FAILURE);
}
- for (j = 0; j < nptrs; j++)
+ for (int j = 0; j < nptrs; j++)
printf("%s\en", strings[j]);
free(strings);
diff --git a/man3/bsearch.3 b/man3/bsearch.3
index 6859bdba22..6dfd5158f3 100644
--- a/man3/bsearch.3
+++ b/man3/bsearch.3
@@ -122,10 +122,8 @@ compmi(const void *m1, const void *m2)
int
main(int argc, char **argv)
{
- int i;
-
qsort(months, nr_of_months, sizeof(months[0]), compmi);
- for (i = 1; i < argc; i++) {
+ for (int i = 1; i < argc; i++) {
struct mi key, *res;
key.name = argv[i];
res = bsearch(&key, months, nr_of_months,
diff --git a/man3/dl_iterate_phdr.3 b/man3/dl_iterate_phdr.3
index f049c50719..f1bd3612fd 100644
--- a/man3/dl_iterate_phdr.3
+++ b/man3/dl_iterate_phdr.3
@@ -307,12 +307,12 @@ static int
callback(struct dl_phdr_info *info, size_t size, void *data)
{
char *type;
- int p_type, j;
+ int p_type;
printf("Name: \e"%s\e" (%d segments)\en", info\->dlpi_name,
info\->dlpi_phnum);
- for (j = 0; j < info\->dlpi_phnum; j++) {
+ for (int j = 0; j < info\->dlpi_phnum; j++) {
p_type = info\->dlpi_phdr[j].p_type;
type = (p_type == PT_LOAD) ? "PT_LOAD" :
(p_type == PT_DYNAMIC) ? "PT_DYNAMIC" :
diff --git a/man3/dlinfo.3 b/man3/dlinfo.3
index 91dedba86c..cdf63b3f31 100644
--- a/man3/dlinfo.3
+++ b/man3/dlinfo.3
@@ -271,7 +271,6 @@ main(int argc, char *argv[])
void *handle;
Dl_serinfo serinfo;
Dl_serinfo *sip;
- int j;
if (argc != 2) {
fprintf(stderr, "Usage: %s <libpath>\en", argv[0]);
@@ -317,7 +316,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- for (j = 0; j < serinfo.dls_cnt; j++)
+ for (int j = 0; j < serinfo.dls_cnt; j++)
printf("dls_serpath[%d].dls_name = %s\en",
j, sip\->dls_serpath[j].dls_name);
diff --git a/man3/duplocale.3 b/man3/duplocale.3
index d0f81d8bb1..70995a94b1 100644
--- a/man3/duplocale.3
+++ b/man3/duplocale.3
@@ -148,7 +148,6 @@ int
main(int argc, char *argv[])
{
locale_t loc, nloc;
- char *p;
if (argc != 2) {
fprintf(stderr, "Usage: %s string\en", argv[0]);
@@ -167,7 +166,7 @@ main(int argc, char *argv[])
if (nloc == (locale_t) 0)
errExit("duplocale");
- for (p = argv[1]; *p; p++)
+ for (char *p = argv[1]; *p; p++)
putchar(toupper_l(*p, nloc));
printf("\en");
diff --git a/man3/encrypt.3 b/man3/encrypt.3
index 24cfbbd735..ea4cbe96ff 100644
--- a/man3/encrypt.3
+++ b/man3/encrypt.3
@@ -178,14 +178,13 @@ main(void)
char orig[9] = "eggplant";
char buf[64];
char txt[9];
- int i, j;
- for (i = 0; i < 64; i++) {
+ for (int i = 0; i < 64; i++) {
key[i] = rand() & 1;
}
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
+ for (int i = 0; i < 8; i++) {
+ for (int j = 0; j < 8; j++) {
buf[i * 8 + j] = orig[i] >> j & 1;
}
setkey(key);
@@ -193,8 +192,8 @@ main(void)
printf("Before encrypting: %s\en", orig);
encrypt(buf, 0);
- for (i = 0; i < 8; i++) {
- for (j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) {
+ for (int i = 0; i < 8; i++) {
+ for (int j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) {
txt[i] |= buf[i * 8 + j] << j;
}
txt[8] = \(aq\e0\(aq;
@@ -202,8 +201,8 @@ main(void)
printf("After encrypting: %s\en", txt);
encrypt(buf, 1);
- for (i = 0; i < 8; i++) {
- for (j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) {
+ for (int i = 0; i < 8; i++) {
+ for (int j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) {
txt[i] |= buf[i * 8 + j] << j;
}
txt[8] = \(aq\e0\(aq;
diff --git a/man3/envz_add.3 b/man3/envz_add.3
index 5ee52f373a..9950b2ae25 100644
--- a/man3/envz_add.3
+++ b/man3/envz_add.3
@@ -147,10 +147,10 @@ Handle with care.
int
main(int argc, char *argv[], char *envp[])
{
- int i, e_len = 0;
+ int e_len = 0;
char *str;
- for (i = 0; envp[i] != NULL; i++)
+ for (int i = 0; envp[i] != NULL; i++)
e_len += strlen(envp[i]) + 1;
str = envz_entry(*envp, e_len, "HOME");
diff --git a/man3/fopencookie.3 b/man3/fopencookie.3
index f7803936ce..472a7f3d25 100644
--- a/man3/fopencookie.3
+++ b/man3/fopencookie.3
@@ -393,8 +393,6 @@ main(int argc, char *argv[])
FILE *stream;
struct memfile_cookie mycookie;
ssize_t nread;
- long p;
- int j;
char buf[1000];
/* Set up the cookie before calling fopencookie() */
@@ -417,7 +415,7 @@ main(int argc, char *argv[])
/* Write command\-line arguments to our file */
- for (j = 1; j < argc; j++)
+ for (int j = 1; j < argc; j++)
if (fputs(argv[j], stream) == EOF) {
perror("fputs");
exit(EXIT_FAILURE);
@@ -425,7 +423,7 @@ main(int argc, char *argv[])
/* Read two bytes out of every five, until EOF */
- for (p = 0; ; p += 5) {
+ for (long p = 0; ; p += 5) {
if (fseek(stream, p, SEEK_SET) == \-1) {
perror("fseek");
exit(EXIT_FAILURE);
diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 70e6b4cc05..c9a4b3e432 100644
--- a/man3/getaddrinfo.3
+++ b/man3/getaddrinfo.3
@@ -763,7 +763,7 @@ main(int argc, char *argv[])
{
struct addrinfo hints;
struct addrinfo *result, *rp;
- int sfd, s, j;
+ int sfd, s;
size_t len;
ssize_t nread;
char buf[BUF_SIZE];
@@ -814,7 +814,7 @@ main(int argc, char *argv[])
/* Send remaining command\-line arguments as separate
datagrams, and read responses from server */
- for (j = 3; j < argc; j++) {
+ for (int j = 3; j < argc; j++) {
len = strlen(argv[j]) + 1;
/* +1 for terminating null byte */
diff --git a/man3/getaddrinfo_a.3 b/man3/getaddrinfo_a.3
index cd4cad0dc5..3a8ddc98ea 100644
--- a/man3/getaddrinfo_a.3
+++ b/man3/getaddrinfo_a.3
@@ -359,7 +359,7 @@ Here is the program source code
int
main(int argc, char *argv[])
{
- int i, ret;
+ int ret;
struct gaicb *reqs[argc \- 1];
char host[NI_MAXHOST];
struct addrinfo *res;
@@ -369,7 +369,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- for (i = 0; i < argc \- 1; i++) {
+ for (int i = 0; i < argc \- 1; i++) {
reqs[i] = malloc(sizeof(*reqs[0]));
if (reqs[i] == NULL) {
perror("malloc");
@@ -386,7 +386,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- for (i = 0; i < argc \- 1; i++) {
+ for (int i = 0; i < argc \- 1; i++) {
printf("%s: ", reqs[i]\->ar_name);
ret = gai_error(reqs[i]);
if (ret == 0) {
diff --git a/man3/getdate.3 b/man3/getdate.3
index 83f0dcc983..188e98012c 100644
--- a/man3/getdate.3
+++ b/man3/getdate.3
@@ -290,9 +290,8 @@ int
main(int argc, char *argv[])
{
struct tm *tmp;
- int j;
- for (j = 1; j < argc; j++) {
+ for (int j = 1; j < argc; j++) {
tmp = getdate(argv[j]);
if (tmp == NULL) {
diff --git a/man3/getgrent_r.3 b/man3/getgrent_r.3
index 394ccabc4f..81d81a851a 100644
--- a/man3/getgrent_r.3
+++ b/man3/getgrent_r.3
@@ -190,10 +190,10 @@ main(void)
if (i)
break;
printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
- for (i = 0; ; i++) {
- if (grpp\->gr_mem[i] == NULL)
+ for (int j = 0; ; j++) {
+ if (grpp\->gr_mem[j] == NULL)
break;
- printf(" %s", grpp\->gr_mem[i]);
+ printf(" %s", grpp\->gr_mem[j]);
}
printf("\en");
}
diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index 36a134949c..e2bbe790e8 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -152,7 +152,7 @@ ngroups = 3
int
main(int argc, char *argv[])
{
- int j, ngroups;
+ int ngroups;
struct passwd *pw;
struct group *gr;
@@ -188,7 +188,7 @@ main(int argc, char *argv[])
/* Display list of retrieved groups, along with group names */
fprintf(stderr, "ngroups = %d\en", ngroups);
- for (j = 0; j < ngroups; j++) {
+ for (int j = 0; j < ngroups; j++) {
printf("%d", groups[j]);
gr = getgrgid(groups[j]);
if (gr != NULL)
diff --git a/man3/getifaddrs.3 b/man3/getifaddrs.3
index ebdf6dc4ab..c781043ebe 100644
--- a/man3/getifaddrs.3
+++ b/man3/getifaddrs.3
@@ -263,7 +263,7 @@ wlp3s0 AF_INET6 (10)
int main(int argc, char *argv[])
{
- struct ifaddrs *ifaddr, *ifa;
+ struct ifaddrs *ifaddr;
int family, s;
char host[NI_MAXHOST];
@@ -275,7 +275,8 @@ int main(int argc, char *argv[])
/* Walk through linked list, maintaining head pointer so we
can free list later */
- for (ifa = ifaddr; ifa != NULL; ifa = ifa\->ifa_next) {
+ for (struct ifaddrs *ifa = ifaddr; ifa != NULL;
+ ifa = ifa\->ifa_next) {
if (ifa\->ifa_addr == NULL)
continue;
diff --git a/man3/getprotoent_r.3 b/man3/getprotoent_r.3
index 08c0d94dcb..fc7b4ff6f4 100644
--- a/man3/getprotoent_r.3
+++ b/man3/getprotoent_r.3
@@ -197,7 +197,6 @@ main(int argc, char *argv[])
struct protoent result_buf;
struct protoent *result;
char buf[MAX_BUF];
- char **p;
if (argc < 2) {
printf("Usage: %s proto\-name [buflen]\en", argv[0]);
@@ -245,7 +244,7 @@ main(int argc, char *argv[])
printf("p_name=%s; p_proto=%d; aliases=",
result_buf.p_name, result_buf.p_proto);
- for (p = result_buf.p_aliases; *p != NULL; p++)
+ for (char **p = result_buf.p_aliases; *p != NULL; p++)
printf("%s ", *p);
printf("\en");
diff --git a/man3/getservent_r.3 b/man3/getservent_r.3
index 42f2159f22..803ce5bcc6 100644
--- a/man3/getservent_r.3
+++ b/man3/getservent_r.3
@@ -195,7 +195,6 @@ main(int argc, char *argv[])
struct servent *result;
char buf[MAX_BUF];
char *protop;
- char **p;
if (argc < 3) {
printf("Usage: %s port\-num proto\-name [buflen]\en", argv[0]);
@@ -248,7 +247,7 @@ main(int argc, char *argv[])
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 (p = result_buf.s_aliases; *p != NULL; p++)
+ for (char **p = result_buf.s_aliases; *p != NULL; p++)
printf("%s ", *p);
printf("\en");
diff --git a/man3/hsearch.3 b/man3/hsearch.3
index f839e38256..2fd2dc2cd6 100644
--- a/man3/hsearch.3
+++ b/man3/hsearch.3
@@ -316,11 +316,10 @@ int
main(void)
{
ENTRY e, *ep;
- int i;
hcreate(30);
- for (i = 0; i < 24; i++) {
+ for (int i = 0; i < 24; i++) {
e.key = data[i];
/* data is just an integer, instead of a
pointer to something */
@@ -333,7 +332,7 @@ main(void)
}
}
- for (i = 22; i < 26; i++) {
+ for (int i = 22; i < 26; i++) {
/* print two entries from the table, and
show that two are not in the table */
e.key = data[i];
diff --git a/man3/mallinfo.3 b/man3/mallinfo.3
index ceb62d365a..70cea83205 100644
--- a/man3/mallinfo.3
+++ b/man3/mallinfo.3
@@ -263,7 +263,7 @@ main(int argc, char *argv[])
{
#define MAX_ALLOCS 2000000
char *alloc[MAX_ALLOCS];
- int numBlocks, j, freeBegin, freeEnd, freeStep;
+ int numBlocks, freeBegin, freeEnd, freeStep;
size_t blockSize;
if (argc < 3 || strcmp(argv[1], "\-\-help") == 0) {
@@ -281,7 +281,7 @@ main(int argc, char *argv[])
printf("============== Before allocating blocks ==============\en");
display_mallinfo();
- for (j = 0; j < numBlocks; j++) {
+ for (int j = 0; j < numBlocks; j++) {
if (numBlocks >= MAX_ALLOCS) {
fprintf(stderr, "Too many allocations\en");
exit(EXIT_FAILURE);
@@ -297,7 +297,7 @@ main(int argc, char *argv[])
printf("\en============== After allocating blocks ==============\en");
display_mallinfo();
- for (j = freeBegin; j < freeEnd; j += freeStep)
+ for (int j = freeBegin; j < freeEnd; j += freeStep)
free(alloc[j]);
printf("\en============== After freeing blocks ==============\en");
diff --git a/man3/malloc_info.3 b/man3/malloc_info.3
index a5a3195580..2a03cf4f19 100644
--- a/man3/malloc_info.3
+++ b/man3/malloc_info.3
@@ -194,13 +194,12 @@ static int numThreads, numBlocks;
static void *
thread_func(void *arg)
{
- int j;
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 (j = 0; j < numBlocks; j++)
+ for (int j = 0; j < numBlocks; j++)
if (malloc(blockSize * (2 + tn)) == NULL)
errExit("malloc\-thread");
@@ -211,7 +210,7 @@ thread_func(void *arg)
int
main(int argc, char *argv[])
{
- int j, tn, sleepTime;
+ int sleepTime;
if (argc < 4) {
fprintf(stderr,
@@ -234,7 +233,7 @@ main(int argc, char *argv[])
/* Create threads that allocate different amounts of memory */
- for (tn = 0; tn < numThreads; tn++) {
+ for (int tn = 0; tn < numThreads; tn++) {
errno = pthread_create(&thr[tn], NULL, thread_func,
(void *) tn);
if (errno != 0)
@@ -251,7 +250,7 @@ main(int argc, char *argv[])
/* The main thread also allocates some memory */
- for (j = 0; j < numBlocks; j++)
+ for (int j = 0; j < numBlocks; j++)
if (malloc(blockSize) == NULL)
errExit("malloc");
diff --git a/man3/mbstowcs.3 b/man3/mbstowcs.3
index 2f9fbc17c3..ad5a5780d8 100644
--- a/man3/mbstowcs.3
+++ b/man3/mbstowcs.3
@@ -154,7 +154,6 @@ main(int argc, char *argv[])
{
size_t mbslen; /* Number of multibyte characters in source */
wchar_t *wcs; /* Pointer to converted wide character string */
- wchar_t *wp;
if (argc < 3) {
fprintf(stderr, "Usage: %s <locale> <string>\en", argv[0]);
@@ -206,7 +205,7 @@ main(int argc, char *argv[])
/* Now do some inspection of the classes of the characters in
the wide character string */
- for (wp = wcs; *wp != 0; wp++) {
+ for (wchar_t *wp = wcs; *wp != 0; wp++) {
printf(" %lc ", (wint_t) *wp);
if (!iswalpha(*wp))
diff --git a/man3/mtrace.3 b/man3/mtrace.3
index e68ada6d0f..353cfd96ab 100644
--- a/man3/mtrace.3
+++ b/man3/mtrace.3
@@ -145,11 +145,9 @@ The demonstration uses the following program:
int
main(int argc, char *argv[])
{
- int j;
-
mtrace();
- for (j = 0; j < 2; j++)
+ for (int j = 0; j < 2; j++)
malloc(100); /* Never freed\-\-a memory leak */
calloc(16, 16); /* Never freed\-\-a memory leak */
diff --git a/man3/pthread_create.3 b/man3/pthread_create.3
index 9df8cfcda9..c1c4c2ff51 100644
--- a/man3/pthread_create.3
+++ b/man3/pthread_create.3
@@ -305,7 +305,7 @@ static void *
thread_start(void *arg)
{
struct thread_info *tinfo = arg;
- char *uargv, *p;
+ char *uargv;
printf("Thread %d: top of stack near %p; argv_string=%s\en",
tinfo\->thread_num, &p, tinfo\->argv_string);
@@ -314,7 +314,7 @@ thread_start(void *arg)
if (uargv == NULL)
handle_error("strdup");
- for (p = uargv; *p != \(aq\e0\(aq; p++)
+ for (char *p = uargv; *p != \(aq\e0\(aq; p++)
*p = toupper(*p);
return uargv;
@@ -323,7 +323,7 @@ thread_start(void *arg)
int
main(int argc, char *argv[])
{
- int s, tnum, opt, num_threads;
+ int s, opt, num_threads;
pthread_attr_t attr;
int stack_size;
void *res;
@@ -366,7 +366,7 @@ main(int argc, char *argv[])
/* Create one thread for each command\-line argument */
- for (tnum = 0; tnum < num_threads; tnum++) {
+ for (int tnum = 0; tnum < num_threads; tnum++) {
tinfo[tnum].thread_num = tnum + 1;
tinfo[tnum].argv_string = argv[optind + tnum];
@@ -388,7 +388,7 @@ main(int argc, char *argv[])
/* Now join with each thread, and display its returned value */
- for (tnum = 0; tnum < num_threads; tnum++) {
+ for (int tnum = 0; tnum < num_threads; tnum++) {
s = pthread_join(tinfo[tnum].thread_id, &res);
if (s != 0)
handle_error_en(s, "pthread_join");
diff --git a/man3/pthread_getcpuclockid.3 b/man3/pthread_getcpuclockid.3
index 8b4aebc1d4..703735b915 100644
--- a/man3/pthread_getcpuclockid.3
+++ b/man3/pthread_getcpuclockid.3
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
{
pthread_t thread;
clockid_t cid;
- int j, s;
+ int s;
s = pthread_create(&thread, NULL, thread_start, NULL);
if (s != 0)
@@ -161,7 +161,7 @@ main(int argc, char *argv[])
sleep(1);
printf("Main thread consuming some CPU time...\en");
- for (j = 0; j < 2000000; j++)
+ for (int j = 0; j < 2000000; j++)
getppid();
pclock("Process total CPU time: ", CLOCK_PROCESS_CPUTIME_ID);
diff --git a/man3/pthread_setaffinity_np.3 b/man3/pthread_setaffinity_np.3
index 57aaf12515..d85d837e98 100644
--- a/man3/pthread_setaffinity_np.3
+++ b/man3/pthread_setaffinity_np.3
@@ -182,7 +182,7 @@ to check the resulting CPU affinity mask of the thread.
int
main(int argc, char *argv[])
{
- int s, j;
+ int s;
cpu_set_t cpuset;
pthread_t thread;
@@ -191,7 +191,7 @@ main(int argc, char *argv[])
/* Set affinity mask to include CPUs 0 to 7 */
CPU_ZERO(&cpuset);
- for (j = 0; j < 8; j++)
+ for (int j = 0; j < 8; j++)
CPU_SET(j, &cpuset);
s = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
@@ -205,7 +205,7 @@ main(int argc, char *argv[])
handle_error_en(s, "pthread_getaffinity_np");
printf("Set returned by pthread_getaffinity_np() contained:\en");
- for (j = 0; j < CPU_SETSIZE; j++)
+ for (int j = 0; j < CPU_SETSIZE; j++)
if (CPU_ISSET(j, &cpuset))
printf(" CPU %d\en", j);
diff --git a/man3/qsort.3 b/man3/qsort.3
index b49c2a9d34..37c4fa1976 100644
--- a/man3/qsort.3
+++ b/man3/qsort.3
@@ -143,8 +143,6 @@ cmpstringp(const void *p1, const void *p2)
int
main(int argc, char *argv[])
{
- int j;
-
if (argc < 2) {
fprintf(stderr, "Usage: %s <string>...\en", argv[0]);
exit(EXIT_FAILURE);
@@ -152,7 +150,7 @@ main(int argc, char *argv[])
qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
- for (j = 1; j < argc; j++)
+ for (int j = 1; j < argc; j++)
puts(argv[j]);
exit(EXIT_SUCCESS);
}
diff --git a/man3/rand.3 b/man3/rand.3
index 36b96e933e..21b03198b8 100644
--- a/man3/rand.3
+++ b/man3/rand.3
@@ -213,7 +213,7 @@ when given a particular seed.
int
main(int argc, char *argv[])
{
- int j, r, nloops;
+ int r, nloops;
unsigned int seed;
if (argc != 3) {
@@ -225,7 +225,7 @@ main(int argc, char *argv[])
nloops = atoi(argv[2]);
srand(seed);
- for (j = 0; j < nloops; j++) {
+ for (int j = 0; j < nloops; j++) {
r = rand();
printf("%d\en", r);
}
diff --git a/man3/strcat.3 b/man3/strcat.3
index dce33bae52..1d8fb73157 100644
--- a/man3/strcat.3
+++ b/man3/strcat.3
@@ -208,14 +208,13 @@ int
main(int argc, char *argv[])
{
#define LIM 4000000
- int j;
char p[LIM + 1]; /* +1 for terminating null byte */
time_t base;
base = time(NULL);
p[0] = \(aq\e0\(aq;
- for (j = 0; j < LIM; j++) {
+ for (int j = 0; j < LIM; j++) {
if ((j % 10000) == 0)
printf("%d %ld\en", j, (long) (time(NULL) \- base));
strcat(p, "a");
diff --git a/man3/strtok.3 b/man3/strtok.3
index bef49f17a6..fa6a0e1084 100644
--- a/man3/strtok.3
+++ b/man3/strtok.3
@@ -250,7 +250,6 @@ 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",
@@ -258,7 +257,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
+ for (int j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
token = strtok_r(str1, argv[2], &saveptr1);
if (token == NULL)
break;
diff --git a/man3/tsearch.3 b/man3/tsearch.3
index b34ef516c3..eec9979aee 100644
--- a/man3/tsearch.3
+++ b/man3/tsearch.3
@@ -322,11 +322,10 @@ action(const void *nodep, VISIT which, int depth)
int
main(void)
{
- int i;
void *val;
srand(time(NULL));
- for (i = 0; i < 12; i++) {
+ for (int i = 0; i < 12; i++) {
int *ptr = xmalloc(sizeof(*ptr));
*ptr = rand() & 0xff;
val = tsearch((void *) ptr, &root, compare);
diff --git a/man3/wordexp.3 b/man3/wordexp.3
index d9805e1dcc..9749b1b78e 100644
--- a/man3/wordexp.3
+++ b/man3/wordexp.3
@@ -234,11 +234,10 @@ main(int argc, char **argv)
{
wordexp_t p;
char **w;
- int i;
wordexp("[a\-c]*.c", &p, 0);
w = p.we_wordv;
- for (i = 0; i < p.we_wordc; i++)
+ for (int i = 0; i < p.we_wordc; i++)
printf("%s\en", w[i]);
wordfree(&p);
exit(EXIT_SUCCESS);
diff --git a/man5/core.5 b/man5/core.5
index fb0dc22196..a87ebbaf46 100644
--- a/man5/core.5
+++ b/man5/core.5
@@ -654,7 +654,7 @@ Total bytes in core dump: 282624
int
main(int argc, char *argv[])
{
- int tot, j;
+ int tot;
ssize_t nread;
char buf[BUF_SIZE];
FILE *fp;
@@ -676,7 +676,7 @@ main(int argc, char *argv[])
pipe program */
fprintf(fp, "argc=%d\en", argc);
- for (j = 0; j < argc; j++)
+ for (int j = 0; j < argc; j++)
fprintf(fp, "argc[%d]=<%s>\en", j, argv[j]);
/* Count bytes in standard input (the core dump) */
diff --git a/man7/aio.7 b/man7/aio.7
index a9586a6943..ff099885ef 100644
--- a/man7/aio.7
+++ b/man7/aio.7
@@ -295,7 +295,7 @@ int
main(int argc, char *argv[])
{
struct sigaction sa;
- int s, j;
+ int s;
int numReqs; /* Total number of queued I/O requests */
int openReqs; /* Number of I/O requests still in progress */
@@ -334,7 +334,7 @@ main(int argc, char *argv[])
/* Open each file specified on the command line, and queue
a read request on the resulting file descriptor */
- for (j = 0; j < numReqs; j++) {
+ for (int j = 0; j < numReqs; j++) {
ioList[j].reqNum = j;
ioList[j].status = EINPROGRESS;
ioList[j].aiocbp = &aiocbList[j];
@@ -377,7 +377,7 @@ main(int argc, char *argv[])
printf("got SIGQUIT; canceling I/O requests: \en");
- for (j = 0; j < numReqs; j++) {
+ for (int j = 0; j < numReqs; j++) {
if (ioList[j].status == EINPROGRESS) {
printf(" Request %d on descriptor %d:", j,
ioList[j].aiocbp\->aio_fildes);
@@ -401,7 +401,7 @@ main(int argc, char *argv[])
in progress */
printf("aio_error():\en");
- for (j = 0; j < numReqs; j++) {
+ for (int j = 0; j < numReqs; j++) {
if (ioList[j].status == EINPROGRESS) {
printf(" for request %d (descriptor %d): ",
j, ioList[j].aiocbp\->aio_fildes);
@@ -433,7 +433,7 @@ main(int argc, char *argv[])
/* Check status return of all I/O requests */
printf("aio_return():\en");
- for (j = 0; j < numReqs; j++) {
+ for (int j = 0; j < numReqs; j++) {
ssize_t s;
s = aio_return(ioList[j].aiocbp);
diff --git a/man7/inotify.7 b/man7/inotify.7
index 9b2d7a4e5a..2414409457 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -942,9 +942,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
char buf[4096]
__attribute__ ((aligned(__alignof__(struct inotify_event))));
const struct inotify_event *event;
- int i;
ssize_t len;
- char *ptr;
/* Loop while events can be read from inotify file descriptor. */
@@ -967,7 +965,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
/* Loop over all events in the buffer */
- for (ptr = buf; ptr < buf + len;
+ for (char *ptr = buf; ptr < buf + len;
ptr += sizeof(struct inotify_event) + event\->len) {
event = (const struct inotify_event *) ptr;
@@ -983,7 +981,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
/* Print the name of the watched directory */
- for (i = 1; i < argc; ++i) {
+ for (int i = 1; i < argc; ++i) {
if (wd[i] == event\->wd) {
printf("%s/", argv[i]);
break;
diff --git a/man7/sock_diag.7 b/man7/sock_diag.7
index a5816ceca5..89d4b404ae 100644
--- a/man7/sock_diag.7
+++ b/man7/sock_diag.7
@@ -711,13 +711,12 @@ print_diag(const struct unix_diag_msg *diag, unsigned int len)
return \-1;
}
- struct rtattr *attr;
unsigned int rta_len = len \- NLMSG_LENGTH(sizeof(*diag));
unsigned int peer = 0;
size_t path_len = 0;
char path[sizeof(((struct sockaddr_un *) 0)\->sun_path) + 1];
- for (attr = (struct rtattr *) (diag + 1);
+ for (struct rtattr *attr = (struct rtattr *) (diag + 1);
RTA_OK(attr, rta_len); attr = RTA_NEXT(attr, rta_len)) {
switch (attr\->rta_type) {
case UNIX_DIAG_NAME:
diff --git a/man7/unix.7 b/man7/unix.7
index 30b0e754d4..f61b514240 100644
--- a/man7/unix.7
+++ b/man7/unix.7
@@ -1063,7 +1063,6 @@ int
main(int argc, char *argv[])
{
struct sockaddr_un addr;
- int i;
int ret;
int data_socket;
char buffer[BUFFER_SIZE];
@@ -1098,7 +1097,7 @@ main(int argc, char *argv[])
/* Send arguments. */
- for (i = 1; i < argc; ++i) {
+ for (int i = 1; i < argc; ++i) {
ret = write(data_socket, argv[i], strlen(argv[i]) + 1);
if (ret == \-1) {
perror("write");
diff --git a/man7/user_namespaces.7 b/man7/user_namespaces.7
index 954a508871..2e3db5fbfd 100644
--- a/man7/user_namespaces.7
+++ b/man7/user_namespaces.7
@@ -1149,13 +1149,13 @@ usage(char *pname)
static void
update_map(char *mapping, char *map_file)
{
- int fd, j;
+ int fd;
size_t map_len; /* Length of \(aqmapping\(aq */
/* Replace commas in mapping string with newlines */
map_len = strlen(mapping);
- for (j = 0; j < map_len; j++)
+ for (int j = 0; j < map_len; j++)
if (mapping[j] == \(aq,\(aq)
mapping[j] = \(aq\en\(aq;