diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-11-14 22:40:40 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-11-14 22:40:40 -0500 |
commit | a7e08e893eb796637ca2c53cd32a529f453ace12 (patch) | |
tree | 73f6bdc3e00baab465b5b90e963af94391f6d984 /util.c | |
parent | 196cf9f617ca17acec75eafbcd9e5e7989752dcb (diff) | |
download | bfs-a7e08e893eb796637ca2c53cd32a529f453ace12.tar.xz |
Check for readdir() errors everywhere.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -17,6 +17,16 @@ #include <sys/types.h> #include <unistd.h> +int xreaddir(DIR *dir, struct dirent **de) { + errno = 0; + *de = readdir(dir); + if (!*de && errno != 0) { + return -1; + } else { + return 0; + } +} + bool isopen(int fd) { return fcntl(fd, F_GETFD) >= 0 || errno != EBADF; } |