aboutsummaryrefslogtreecommitdiffstats
path: root/man3
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2020-09-05 17:18:10 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2020-09-05 17:20:12 +0200
commit88893a773cbd219f08cc3ae34fffe079d89a120d (patch)
tree990eaeb2aef511d3e0c211b7eb4757ef25334edc /man3
parent3b27ce1573535e0585b83b83a8b3828af70afe67 (diff)
downloadman-pages-88893a773cbd219f08cc3ae34fffe079d89a120d.tar.gz
sprof.1, eventfd.2, execve.2, futex.2, getdents.2, mprotect.2, open_by_handle_at.2, recvmmsg.2, sched_setaffinity.2, CPU_SET.3, backtrace.3, bsearch.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, envz_add.3, fopencookie.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrent_r.3, getgrouplist.3, getifaddrs.3, getprotoent_r.3, getservent_r.3, hsearch.3, mallinfo.3, malloc_info.3, mbstowcs.3, mtrace.3, pthread_create.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, qsort.3, rand.3, strcat.3, strtok.3, tsearch.3, wordexp.3, core.5, aio.7, inotify.7, sock_diag.7, unix.7, user_namespaces.7: Use C99 style to declare loop counter variables
Rather than: sometype x; for (x = ....; ...) use for (sometype x = ...; ...) This brings the declaration and use closer together (thus aiding readability) and also clearly indicates the scope of the loop counter variable. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man3')
-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
31 files changed, 64 insertions, 84 deletions
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);