diff options
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/read_file.c | 12 | ||||
-rw-r--r-- | src/io/read_file.h | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/io/read_file.c b/src/io/read_file.c index 219a395..22e0286 100644 --- a/src/io/read_file.c +++ b/src/io/read_file.c @@ -60,18 +60,20 @@ static void *fd_to_mmap(const int fd, struct stat sb) { return addr; } -struct filebuf *file_to_filebuf(char *fname, int openOptions) { +struct filebuf *file_to_filebuf(char *fname, int openOptions, bool *isdir) { const int fd = open(fname, O_RDONLY); if (fd == -1) { return NULL; } - if (openOptions & O_NOALLOWMAP) { - goto sponge; - } - struct stat sb; if (fstat(fd, &sb) == -1) { + return NULL; + } + + if (isdir != NULL) *isdir = S_ISDIR(sb.st_mode); + + if (openOptions & O_NOALLOWMAP) { goto sponge; } diff --git a/src/io/read_file.h b/src/io/read_file.h index 89f738b..d097c05 100644 --- a/src/io/read_file.h +++ b/src/io/read_file.h @@ -1,5 +1,6 @@ #pragma once +#include <stdbool.h> #include <stddef.h> #include <stdio.h> @@ -20,5 +21,5 @@ struct filebuf { }; struct filebuf *stream_to_filebuf(FILE *restrict stream, int openOptions); -struct filebuf *file_to_filebuf(char *fname, int openOptions); +struct filebuf *file_to_filebuf(char *fname, int openOptions, bool *isdir); void free_filebuf(struct filebuf *filebuf); |