Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define DTTOIF and IFTODT. #279

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions expected/wasm32-wasi/defined-symbols.txt
Original file line number Diff line number Diff line change
@@ -307,6 +307,7 @@ __wasi_sock_shutdown
__wasilibc_access
__wasilibc_cwd
__wasilibc_deinitialize_environ
__wasilibc_dttoif
__wasilibc_ensure_environ
__wasilibc_environ
__wasilibc_environ
@@ -315,6 +316,7 @@ __wasilibc_find_abspath
__wasilibc_find_relpath
__wasilibc_find_relpath_alloc
__wasilibc_get_environ
__wasilibc_iftodt
__wasilibc_initialize_environ
__wasilibc_link
__wasilibc_link_newat
2 changes: 2 additions & 0 deletions expected/wasm32-wasi/predefined-macros.txt
Original file line number Diff line number Diff line change
@@ -176,6 +176,7 @@
#define DO 253
#define DONT 254
#define DOUBLEBITS (sizeof(double) * 8)
#define DTTOIF(x) (__wasilibc_dttoif(x))
#define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE
#define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE
#define DT_DIR __WASI_FILETYPE_DIRECTORY
@@ -547,6 +548,7 @@
#define ICMP_UNREACH_SRCFAIL 5
#define ICMP_UNREACH_TOSHOST 12
#define ICMP_UNREACH_TOSNET 11
#define IFTODT(x) (__wasilibc_iftodt(x))
#define IGMP_AWAKENING_MEMBER 5
#define IGMP_DELAYING_MEMBER 1
#define IGMP_DVMRP 0x13
6 changes: 6 additions & 0 deletions libc-bottom-half/headers/public/__header_dirent.h
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@
#define DT_REG __WASI_FILETYPE_REGULAR_FILE
#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN

#define IFTODT(x) (__wasilibc_iftodt(x))
#define DTTOIF(x) (__wasilibc_dttoif(x))

int __wasilibc_iftodt(int x);
int __wasilibc_dttoif(int x);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had forgotten to git add these. Fixed now!


#include <__struct_dirent.h>
#include <__typedef_DIR.h>

34 changes: 34 additions & 0 deletions libc-bottom-half/sources/__wasilibc_dt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <__header_dirent.h>
#include <__mode_t.h>

int __wasilibc_iftodt(int x) {
switch (x) {
case S_IFDIR: return DT_DIR;
case S_IFCHR: return DT_CHR;
case S_IFBLK: return DT_BLK;
case S_IFREG: return DT_REG;
case S_IFIFO: return DT_FIFO;
case S_IFLNK: return DT_LNK;
#ifdef DT_SOCK
case S_IFSOCK: return DT_SOCK;
#endif
default: return DT_UNKNOWN;
}
}

int __wasilibc_dttoif(int x) {
switch (x) {
case DT_DIR: return S_IFDIR;
case DT_CHR: return S_IFCHR;
case DT_BLK: return S_IFBLK;
case DT_REG: return S_IFREG;
case DT_FIFO: return S_IFIFO;
case DT_LNK: return S_IFLNK;
#ifdef DT_SOCK
case DT_SOCK: return S_IFSOCK;
#endif
case DT_UNKNOWN:
default:
return S_IFSOCK;
}
}