summaryrefslogtreecommitdiff
path: root/filesystem-posix.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-06 18:52:47 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-06 18:52:47 -0500
commitf9092e361420a44e6ed8e5a1fa13d3fad9f3d7de (patch)
treefa6fb3760fafb594de3b6d4c5b2979681ad8806b /filesystem-posix.c
parent132dcb648981050990e34a44925e6b54d0dc008c (diff)
fix fs_list_directory
Diffstat (limited to 'filesystem-posix.c')
-rw-r--r--filesystem-posix.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/filesystem-posix.c b/filesystem-posix.c
index 4913e30..e2ff82e 100644
--- a/filesystem-posix.c
+++ b/filesystem-posix.c
@@ -12,7 +12,7 @@ static bool fs_file_exists(char const *path) {
return S_ISREG(statbuf.st_mode);
}
-// Returns a NULL-terminated array of the files in this directory, or NULL if the directory does not exist.
+// Returns a NULL-terminated array of the files/directories in this directory, or NULL if the directory does not exist.
// When you're done with the file names, call free on each one, then on the array.
// NOTE: The files aren't returned in any particular order!
static char **fs_list_directory(char const *dirname) {
@@ -29,15 +29,13 @@ static char **fs_list_directory(char const *dirname) {
filenames = (char **)calloc(nentries+1, sizeof *filenames);
while ((ent = readdir(dir))) {
- if (ent->d_type == DT_REG) {
- char const *filename = ent->d_name;
- size_t len = strlen(filename);
- char *filename_copy = (char *)malloc(len+1);
- if (!filename_copy) break;
- strcpy(filename_copy, filename);
- if (filename_idx < nentries) // this could actually fail if someone creates files between calculating nentries and here.
- filenames[filename_idx++] = filename_copy;
- }
+ char const *filename = ent->d_name;
+ size_t len = strlen(filename);
+ char *filename_copy = (char *)malloc(len+1);
+ if (!filename_copy) break;
+ strcpy(filename_copy, filename);
+ if (filename_idx < nentries) // this could actually fail if someone creates files between calculating nentries and here.
+ filenames[filename_idx++] = filename_copy;
}
ret = filenames;
closedir(dir);