summaryrefslogtreecommitdiff
path: root/src/libc/dirent.c
diff options
context:
space:
mode:
authordzwdz2023-09-02 17:45:35 +0200
committerdzwdz2023-09-02 17:45:35 +0200
commit48d6aa11451f6e4ee0c3716b1c4be3c11287dd3b (patch)
tree775219a4501957ed8bf52d76291817eb9dfa11ef /src/libc/dirent.c
parentfd7be968dd3bce84e31d62e1faecef9cf5ea14c1 (diff)
libc: opendir_f; make httpd use it
Diffstat (limited to 'src/libc/dirent.c')
-rw-r--r--src/libc/dirent.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/libc/dirent.c b/src/libc/dirent.c
index c2d1b9c..61d8a48 100644
--- a/src/libc/dirent.c
+++ b/src/libc/dirent.c
@@ -4,22 +4,20 @@
#include <stdlib.h>
DIR *opendir(const char *name) {
- FILE *fp = NULL;
- DIR *dir = NULL;
- fp = fopen(name, "r");
- if (!fp) {
- goto err;
- }
+ return opendir_f(fopen(name, "r"));
+}
+
+DIR *opendir_f(FILE *fp) {
+ if (!fp) return NULL;
+
+ DIR *dir;
dir = calloc(1, sizeof *dir);
if (!dir) {
- goto err;
+ fclose(fp);
+ return NULL;
}
dir->fp = fp;
return dir;
-err:
- if (fp) fclose(fp);
- free(dir);
- return NULL;
}
int closedir(DIR *dir) {