mirror of git://git.suckless.org/slstatus
num_files: opendir() returns a directory stream
opendir() returns a directory stream, not a file descriptor Co-authored-by: drkhsh <me@drkhsh.at> Signed-off-by: drkhsh <me@drkhsh.at>
This commit is contained in:
parent
c432c981df
commit
984f45719e
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue