-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use `constructor` to eliminate them if unnecessary
- Loading branch information
Showing
5 changed files
with
50 additions
and
43 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
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,20 @@ | ||
#include "../wasi.h" | ||
|
||
int __max_preopen_fd = 3; | ||
|
||
__attribute__((constructor)) | ||
static void find_preopens(void) { | ||
for (int fd = 3; ; ++fd) { | ||
Prestat prestat; | ||
int result = fd_prestat_get(fd, &prestat); | ||
if (result != 0) { | ||
__max_preopen_fd = fd; | ||
return; | ||
} | ||
|
||
// char buf[256]; | ||
// fd_prestat_dir_name(fd, buf, prestat.u.dir.pr_name_len); // TODO: Confirm prestat.u.dir.pr_name_len < sizeof(buf) | ||
// buf[prestat.u.dir.pr_name_len] = '\0'; | ||
// fprintf(stderr, "preopens: %d, %s\n", fd, buf); | ||
} | ||
} |
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,27 @@ | ||
#include "sys/stat.h" | ||
#include "../wasi.h" | ||
|
||
void _set_stat(Filestat *fs, struct stat *st) { | ||
mode_t mode = 0; | ||
switch (fs->filetype) { | ||
case FILETYPE_BLOCK_DEVICE: mode = S_IFBLK; break; | ||
case FILETYPE_CHARACTER_DEVICE: mode = S_IFCHR; break; | ||
case FILETYPE_DIRECTORY: mode = S_IFDIR; break; | ||
case FILETYPE_REGULAR_FILE: mode = S_IFREG; break; | ||
case FILETYPE_SOCKET_DGRAM: mode = S_IFSOCK; break; | ||
case FILETYPE_SOCKET_STREAM: mode = S_IFSOCK; break; | ||
case FILETYPE_SYMBOLIC_LINK: mode = S_IFLNK; break; | ||
} | ||
|
||
st->st_dev = fs->dev; | ||
st->st_ino = fs->ino; | ||
st->st_mode = mode; | ||
st->st_nlink = fs->nlink; | ||
st->st_uid = 0; | ||
st->st_gid = 0; | ||
st->st_rdev = 0; | ||
st->st_size = fs->size; | ||
st->st_blksize = 0; | ||
st->st_blocks = 0; | ||
// TODO: atim, mtim, ctim | ||
} |
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
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