1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
3 // SPDX-License-Identifier: BSD-2-Clause
10 #include "dirent_impl.h"
12 DIR *fdopendir(int fd
) {
13 // Allocate new directory object and read buffer.
14 DIR *dirp
= malloc(sizeof(*dirp
));
17 dirp
->buffer
= malloc(DIRENT_DEFAULT_BUFFER_SIZE
);
18 if (dirp
->buffer
== NULL
) {
23 // Ensure that this is really a directory by already loading the first
25 __wasi_errno_t error
=
26 // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support.
27 __wasi_fd_readdir(fd
, (uint8_t *)dirp
->buffer
, DIRENT_DEFAULT_BUFFER_SIZE
,
28 __WASI_DIRCOOKIE_START
, &dirp
->buffer_used
);
35 // Initialize other members.
37 dirp
->cookie
= __WASI_DIRCOOKIE_START
;
38 dirp
->buffer_processed
= 0;
39 dirp
->buffer_size
= DIRENT_DEFAULT_BUFFER_SIZE
;
41 dirp
->dirent_size
= 1;