diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2019-06-23 10:07:49 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2019-06-25 01:18:47 -0400 |
commit | c8f7eca0eb6327e8b8ea066af55183a135818fe1 (patch) | |
tree | cffd779c202fe52cfe0b603372a33b77721214c9 /util.c | |
parent | 8d393a4e1a37a78bccb3928379693529f78ff20e (diff) | |
download | bfs-c8f7eca0eb6327e8b8ea066af55183a135818fe1.tar.xz |
util: Filter out . and .. in xreaddir()
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -41,12 +41,20 @@ #endif int xreaddir(DIR *dir, struct dirent **de) { - errno = 0; - *de = readdir(dir); - if (!*de && errno != 0) { - return -1; - } else { - return 0; + while (true) { + errno = 0; + *de = readdir(dir); + + if (*de) { + const char *name = (*de)->d_name; + if (name[0] != '.' || (name[1] != '\0' && (name[1] != '.' || name[2] != '\0'))) { + return 0; + } + } else if (errno != 0) { + return -1; + } else { + return 0; + } } } |