Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/dirent/test_readdir_empty.c
4133 views
1
/*
2
* Copyright 2014 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
8
#include <stdio.h>
9
#include <dirent.h>
10
#include <sys/stat.h>
11
#include <string.h>
12
#include <errno.h>
13
14
15
int main(int argc, char** argv) {
16
if (mkdir("/tmp", S_IRWXG) != 0 && errno != EEXIST) {
17
printf("Unable to create dir '/tmp'\n");
18
return 1;
19
}
20
21
if (mkdir("/tmp/foo", S_IRWXG) != 0 && errno != EEXIST) {
22
printf("Unable to create dir '/tmp/foo'\n");
23
return 1;
24
}
25
26
if (mkdir("/tmp/foo/", S_IRWXG) != 0 && errno != EEXIST) {
27
printf("Unable to create dir '/tmp/foo/'\n");
28
return 1;
29
}
30
31
DIR *dir = opendir("/tmp");
32
33
if (!dir) {
34
printf("Unable to open dir '/tmp'\n");
35
return 2;
36
}
37
38
struct dirent *dirent;
39
40
while ((dirent = readdir(dir)) != 0) {
41
printf("Found '%s'\n", dirent->d_name);
42
43
if (strlen(dirent->d_name) == 0) {
44
printf("Found empty path!\n");
45
return 3;
46
}
47
}
48
49
closedir(dir);
50
51
printf("success\n");
52
53
return 0;
54
}
55
56
57