forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaddir.c
More file actions
41 lines (35 loc) · 834 Bytes
/
Copy pathreaddir.c
File metadata and controls
41 lines (35 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
DIR* dir;
struct dirent* entry;
char* platform;
int cnt;
int has_d_type;
platform = getenv("NODE_PLATFORM");
assert(platform != NULL);
dir = opendir("/sandbox");
assert(dir != NULL);
cnt = 0;
errno = 0;
while (NULL != (entry = readdir(dir))) {
if (strcmp(entry->d_name, "input.txt") == 0 ||
strcmp(entry->d_name, "input2.txt") == 0 ||
strcmp(entry->d_name, "notadir") == 0) {
assert(entry->d_type == DT_REG);
} else if (strcmp(entry->d_name, "subdir") == 0) {
assert(entry->d_type == DT_DIR);
} else {
assert("unexpected file");
}
cnt++;
}
assert(errno == 0);
assert(cnt == 4);
closedir(dir);
return 0;
}