@@ -439,17 +439,24 @@ os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags,
439439 return __WASI_ENOMEM ;
440440 }
441441
442- int zmode =
443- wasi_flags_to_zephyr (oflags , fd_flags , lookup_flags , access_mode );
444-
445- ptr = zephyr_fs_alloc_obj (false, abs_path , & index );
442+ ptr = zephyr_fs_alloc_obj (oflags & __WASI_O_DIRECTORY , abs_path , & index );
446443 if (!ptr && (index < 0 )) {
447444 BH_FREE (* out );
448445 return __WASI_EMFILE ;
449446 }
450447
451- fs_file_t_init (& ptr -> file );
452- rc = fs_open (& ptr -> file , abs_path , zmode );
448+ if (oflags & __WASI_O_DIRECTORY ) {
449+ // Is a directory
450+ fs_dir_t_init (& ptr -> dir );
451+ rc = fs_opendir (& ptr -> dir , abs_path );
452+ }
453+ else {
454+ // Is a file
455+ int zmode = wasi_flags_to_zephyr (oflags , fd_flags , lookup_flags , access_mode );
456+ fs_file_t_init (& ptr -> file );
457+ rc = fs_open (& ptr -> file , abs_path , zmode );
458+ }
459+
453460 if (rc < 0 ) {
454461 zephyr_fs_free_obj (ptr );
455462 BH_FREE (* out );
@@ -474,9 +481,15 @@ os_file_get_access_mode(os_file_handle handle,
474481 * access_mode = WASI_LIBC_ACCESS_MODE_READ_WRITE ;
475482 return __WASI_ESUCCESS ;
476483 }
477-
484+
478485 GET_FILE_SYSTEM_DESCRIPTOR (handle -> fd , ptr );
479486
487+ if (ptr -> is_dir ) {
488+ // DSK: is this actually the correct mode for a dir?
489+ * access_mode = WASI_LIBC_ACCESS_MODE_READ_WRITE ;
490+ return __WASI_ESUCCESS ;
491+ }
492+
480493 if ((ptr -> file .flags & FS_O_RDWR ) != 0 ) {
481494 * access_mode = WASI_LIBC_ACCESS_MODE_READ_WRITE ;
482495 }
0 commit comments