File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <assert.h>
2+ #include <dirent.h>
3+ #include <errno.h>
4+ #include <stdio.h>
5+ #include <stdlib.h>
6+ #include <string.h>
7+
8+ int main () {
9+ DIR * dir ;
10+ struct dirent * entry ;
11+ char * platform ;
12+ int cnt ;
13+ int has_d_type ;
14+
15+ platform = getenv ("NODE_PLATFORM" );
16+ assert (platform != NULL );
17+ has_d_type = (0 != strcmp (platform , "aix" ) && 0 != strcmp (platform , "sunos" ));
18+
19+ dir = opendir ("/sandbox" );
20+ assert (dir != NULL );
21+
22+ cnt = 0 ;
23+ errno = 0 ;
24+ while (NULL != (entry = readdir (dir ))) {
25+ if (strcmp (entry -> d_name , "input.txt" ) == 0 ||
26+ strcmp (entry -> d_name , "input2.txt" ) == 0 ||
27+ strcmp (entry -> d_name , "notadir" ) == 0 ) {
28+ if (has_d_type ) {
29+ assert (entry -> d_type == DT_REG );
30+ } else {
31+ assert (entry -> d_type == DT_UNKNOWN );
32+ }
33+ } else if (strcmp (entry -> d_name , "subdir" ) == 0 ) {
34+ if (has_d_type ) {
35+ assert (entry -> d_type == DT_DIR );
36+ } else {
37+ assert (entry -> d_type == DT_UNKNOWN );
38+ }
39+ } else {
40+ assert ("unexpected file" );
41+ }
42+
43+ cnt ++ ;
44+ }
45+
46+ assert (errno == 0 );
47+ assert (cnt == 4 );
48+ closedir (dir );
49+ return 0 ;
50+ }
Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ if (process.argv[2] === 'wasi-child') {
8484 runWASI ( { test : 'notdir' } ) ;
8585 runWASI ( { test : 'poll' } ) ;
8686 runWASI ( { test : 'preopen_populates' } ) ;
87+
88+ if ( ! common . isWindows && process . platform !== 'android' ) {
89+ runWASI ( { test : 'readdir' } ) ;
90+ }
91+
8792 runWASI ( { test : 'read_file' , stdout : `hello from input.txt${ EOL } ` } ) ;
8893 runWASI ( {
8994 test : 'read_file_twice' ,
You can’t perform that action at this time.
0 commit comments