From fb83de1869826d475c8318524c3f768bcd43b7a2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 2 Apr 2014 19:01:06 -0700 Subject: add missing test file for #2263 / #2258 --- tests/dirent/test_readdir_empty.c | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/dirent/test_readdir_empty.c (limited to 'tests/dirent/test_readdir_empty.c') diff --git a/tests/dirent/test_readdir_empty.c b/tests/dirent/test_readdir_empty.c new file mode 100644 index 00000000..00102733 --- /dev/null +++ b/tests/dirent/test_readdir_empty.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + + +int main(int argc, char** argv) { + if (mkdir("/tmp", S_IRWXG) != 0 && errno != EEXIST) { + printf("Unable to create dir '/tmp'\n"); + return -1; + } + + if (mkdir("/tmp/1", S_IRWXG) != 0 && errno != EEXIST) { + printf("Unable to create dir '/tmp/1'\n"); + return -1; + } + + if (mkdir("/tmp/1/", S_IRWXG) != 0 && errno != EEXIST) { + printf("Unable to create dir '/tmp/1/'\n"); + return -1; + } + + DIR *dir = opendir("/tmp"); + + if (!dir) { + printf("Unable to open dir '/tmp'\n"); + return -2; + } + + struct dirent *dirent; + + while ((dirent = readdir(dir)) != 0) { + printf("Found '%s'\n", dirent->d_name); + + if (strlen(dirent->d_name) == 0) { + printf("Found empty path!\n"); + return -3; + } + } + + closedir(dir); + + printf("success\n"); + return 0; +} + -- cgit v1.2.3-70-g09d2