aboutsummaryrefslogtreecommitdiffstats
path: root/man2
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 /man2
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 'man2')
-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
8 files changed, 18 insertions, 22 deletions
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 */