Skip to content
Snippets Groups Projects
Commit 11e607a5 authored by Bartłomiej Piotrowski's avatar Bartłomiej Piotrowski
Browse files

Reduce the scope of for loops iterator variables

parent c0943c91
Branches
No related tags found
No related merge requests found
...@@ -152,7 +152,7 @@ int main (int argc, char *argv[]) ...@@ -152,7 +152,7 @@ int main (int argc, char *argv[])
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
int e; int e;
int epollfd, efd, n, res; int epollfd, efd, res;
int portno = 1986; int portno = 1986;
int optval; int optval;
socklen_t optlen = sizeof(optval); socklen_t optlen = sizeof(optval);
...@@ -376,7 +376,7 @@ xit\n"); ...@@ -376,7 +376,7 @@ xit\n");
if((epollfd = epoll_create (nfds)) < 0) if((epollfd = epoll_create (nfds)) < 0)
fanout_error ("ERROR creating epoll instance"); 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) { if (epoll_ctl (epollfd, EPOLL_CTL_ADD, fds[n].data.fd, &fds[n]) == -1) {
fanout_error ("epoll_ctl: srvsock"); fanout_error ("epoll_ctl: srvsock");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
...@@ -510,7 +510,7 @@ xit\n"); ...@@ -510,7 +510,7 @@ xit\n");
continue; continue;
} }
for (n = 0; n < nevents; n++) { for (int n = 0; n < nevents; n++) {
// new connection // new connection
efd = events[n].data.fd; efd = events[n].data.fd;
fanout_debug (3, "processing event %d of %d\n", (n+1), fanout_debug (3, "processing event %d of %d\n", (n+1),
...@@ -518,8 +518,8 @@ xit\n"); ...@@ -518,8 +518,8 @@ xit\n");
fanout_debug (3, "current event fd %d\n", efd); fanout_debug (3, "current event fd %d\n", efd);
int newconnection = 0; int newconnection = 0;
for (n=0; n < nfds; n++) { for (int m = 0; m < nfds; m++) {
if (efd == fds[n].data.fd) { if (efd == fds[m].data.fd) {
newconnection = 1; newconnection = 1;
break; break;
} }
...@@ -636,7 +636,7 @@ resetting counter\n"); ...@@ -636,7 +636,7 @@ resetting counter\n");
}//end for }//end for
}//end while (1) }//end while (1)
for (n=0; n < nfds; n++) { for (int n = 0; n < nfds; n++) {
close (fds[n].data.fd); close (fds[n].data.fd);
} }
return 0; return 0;
...@@ -656,8 +656,7 @@ int is_numeric (char *str) ...@@ -656,8 +656,7 @@ int is_numeric (char *str)
int strcpos (const char *haystack, const char c) int strcpos (const char *haystack, const char c)
{ {
int i; for (int i = 0; i <= strlen (haystack); i++) {
for (i = 0; i <= strlen (haystack); i++) {
if (haystack[i] == c) if (haystack[i] == c)
return i; return i;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment