num_files: opendir() returns a directory stream
authorplanet36 <planet36@users.noreply.github.com>
Wed, 12 May 2021 02:45:34 +0000 (22:45 -0400)
committerdrkhsh <me@drkhsh.at>
Mon, 19 Dec 2022 01:44:21 +0000 (02:44 +0100)
opendir() returns a directory stream, not a file descriptor

Co-authored-by: drkhsh <me@drkhsh.at>
Signed-off-by: drkhsh <me@drkhsh.at>
components/num_files.c

index e4b428170d0e39586e794fc9d4e4ebf35ed24dbd..df0acd1f8f6e52b6d5ee1a0d6f6df0e43470a4f6 100644 (file)
@@ -10,23 +10,23 @@ const char *
 num_files(const char *path)
 {
        struct dirent *dp;
-       DIR *fd;
+       DIR *dir;
        int num;
 
-       if (!(fd = opendir(path))) {
+       if (!(dir = opendir(path))) {
                warn("opendir '%s':", path);
                return NULL;
        }
 
        num = 0;
-       while ((dp = readdir(fd))) {
+       while ((dp = readdir(dir))) {
                if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
                        continue; /* skip self and parent */
 
                num++;
        }
 
-       closedir(fd);
+       closedir(dir);
 
        return bprintf("%d", num);
 }