From 11e607a5a50bde8ef07378261250b2782cbbf046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= <b@bpiotrowski.pl> Date: Wed, 10 Dec 2014 23:32:24 +0100 Subject: [PATCH] Reduce the scope of for loops iterator variables --- fanout.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fanout.c b/fanout.c index d220063..5f4a14e 100644 --- a/fanout.c +++ b/fanout.c @@ -152,7 +152,7 @@ int main (int argc, char *argv[]) hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; int e; - int epollfd, efd, n, res; + int epollfd, efd, res; int portno = 1986; int optval; socklen_t optlen = sizeof(optval); @@ -376,7 +376,7 @@ xit\n"); if((epollfd = epoll_create (nfds)) < 0) fanout_error ("ERROR creating epoll instance"); - for (n=0; n < nfds; n++) { + for (int n = 0; n < nfds; n++) { if (epoll_ctl (epollfd, EPOLL_CTL_ADD, fds[n].data.fd, &fds[n]) == -1) { fanout_error ("epoll_ctl: srvsock"); exit (EXIT_FAILURE); @@ -510,7 +510,7 @@ xit\n"); continue; } - for (n = 0; n < nevents; n++) { + for (int n = 0; n < nevents; n++) { // new connection efd = events[n].data.fd; fanout_debug (3, "processing event %d of %d\n", (n+1), @@ -518,8 +518,8 @@ xit\n"); fanout_debug (3, "current event fd %d\n", efd); int newconnection = 0; - for (n=0; n < nfds; n++) { - if (efd == fds[n].data.fd) { + for (int m = 0; m < nfds; m++) { + if (efd == fds[m].data.fd) { newconnection = 1; break; } @@ -636,7 +636,7 @@ resetting counter\n"); }//end for }//end while (1) - for (n=0; n < nfds; n++) { + for (int n = 0; n < nfds; n++) { close (fds[n].data.fd); } return 0; @@ -656,8 +656,7 @@ int is_numeric (char *str) int strcpos (const char *haystack, const char c) { - int i; - for (i = 0; i <= strlen (haystack); i++) { + for (int i = 0; i <= strlen (haystack); i++) { if (haystack[i] == c) return i; } -- GitLab