Xinqi Bao's Git

num_files: Variable declarations at top of block
authorAaron Marcher <[email protected]>
Mon, 7 May 2018 10:17:13 +0000 (12:17 +0200)
committerAaron Marcher <[email protected]>
Mon, 7 May 2018 10:17:13 +0000 (12:17 +0200)
components/num_files.c

index ab43694..327a64d 100644 (file)
@@ -11,13 +11,14 @@ num_files(const char *dir)
 {
        struct dirent *dp;
        DIR *fd;
-       int num = 0;
+       int num;
 
        if (!(fd = opendir(dir))) {
                fprintf(stderr, "opendir '%s': %s\n", dir, strerror(errno));
                return NULL;
        }
 
+       num = 0;
        while ((dp = readdir(fd))) {
                if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
                        continue; /* skip self and parent */