-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit provides coverage for __wasi_fd_readdir(). PR-URL: #35202 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
- Loading branch information
1 parent
884755f
commit c3e1bf7
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#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); | ||
has_d_type = (0 != strcmp(platform, "aix") && 0 != strcmp(platform, "sunos")); | ||
|
||
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) { | ||
if (has_d_type) { | ||
assert(entry->d_type == DT_REG); | ||
} else { | ||
assert(entry->d_type == DT_UNKNOWN); | ||
} | ||
} else if (strcmp(entry->d_name, "subdir") == 0) { | ||
if (has_d_type) { | ||
assert(entry->d_type == DT_DIR); | ||
} else { | ||
assert(entry->d_type == DT_UNKNOWN); | ||
} | ||
} else { | ||
assert("unexpected file"); | ||
} | ||
|
||
cnt++; | ||
} | ||
|
||
assert(errno == 0); | ||
assert(cnt == 4); | ||
closedir(dir); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.