diff options
author | Anton Kling <anton@kling.gg> | 2023-11-16 01:36:38 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-16 01:36:38 +0100 |
commit | f4cf0cac3fbefce2454a0e96ab32000a12b54253 (patch) | |
tree | 6341fbb6abfa7bcdf27509c840711c69461dae2c | |
parent | 7c115f97f16ba1d26adf9b477520002cedc05c09 (diff) |
LibC: Add error checking to scandir
-rw-r--r-- | userland/libc/dirent/scandir.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/userland/libc/dirent/scandir.c b/userland/libc/dirent/scandir.c index 1520140..945bc1f 100644 --- a/userland/libc/dirent/scandir.c +++ b/userland/libc/dirent/scandir.c @@ -22,6 +22,8 @@ int scandir(const char *dir, struct dirent ***namelist, compar = nop_compar; DIR *d = opendir(dir); + if (!d) + return -1; struct dirent **list = NULL; struct dirent *e; int rc = 0; @@ -34,10 +36,7 @@ int scandir(const char *dir, struct dirent ***namelist, list[rc] = p; rc++; } - // struct dirent **new_list; - // compar((const struct dirent **)list, (const struct dirent **)new_list); - // *namelist = new_list; *namelist = list; - // closedir(d); + closedir(d); return rc; } |