diff options
Diffstat (limited to 'src/libc/dirent.c')
-rw-r--r-- | src/libc/dirent.c | 20 |
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) { |