| 50 | }; |
| 51 | |
| 52 | constexpr int openFlags(__wasi_oflags_t OpenFlags, __wasi_fdflags_t FdFlags, |
| 53 | VFS::Flags VFSFlags) noexcept { |
| 54 | int Flags = O_NOFOLLOW; |
| 55 | #ifdef O_CLOEXEC |
| 56 | Flags |= O_CLOEXEC; |
| 57 | #endif |
| 58 | |
| 59 | if (VFSFlags & VFS::Read) { |
| 60 | if (VFSFlags & VFS::Write) { |
| 61 | Flags |= O_RDWR; |
| 62 | } else { |
| 63 | Flags |= O_RDONLY; |
| 64 | } |
| 65 | } else if (VFSFlags & VFS::Write) { |
| 66 | Flags |= O_WRONLY; |
| 67 | } else { |
| 68 | #ifdef O_PATH |
| 69 | if (OpenFlags == __WASI_OFLAGS_DIRECTORY) { |
| 70 | Flags |= O_PATH; |
| 71 | } else { |
| 72 | Flags |= O_RDONLY; |
| 73 | } |
| 74 | #else |
| 75 | Flags |= O_RDONLY; |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | if (OpenFlags & __WASI_OFLAGS_CREAT) { |
| 80 | Flags |= O_CREAT; |
| 81 | } |
| 82 | if (OpenFlags & __WASI_OFLAGS_DIRECTORY) { |
| 83 | Flags |= O_DIRECTORY; |
| 84 | } |
| 85 | if (OpenFlags & __WASI_OFLAGS_EXCL) { |
| 86 | Flags |= O_EXCL; |
| 87 | } |
| 88 | if ((OpenFlags & __WASI_OFLAGS_TRUNC) && (VFSFlags & VFS::Write)) { |
| 89 | Flags |= O_TRUNC; |
| 90 | } |
| 91 | |
| 92 | // Convert file descriptor flags. |
| 93 | if ((FdFlags & __WASI_FDFLAGS_APPEND) != 0) { |
| 94 | Flags |= O_APPEND; |
| 95 | } |
| 96 | if ((FdFlags & __WASI_FDFLAGS_DSYNC) != 0) { |
| 97 | #ifdef O_DSYNC |
| 98 | Flags |= O_DSYNC; |
| 99 | #else |
| 100 | Flags |= O_SYNC; |
| 101 | #endif |
| 102 | } |
| 103 | if ((FdFlags & __WASI_FDFLAGS_NONBLOCK) != 0) { |
| 104 | Flags |= O_NONBLOCK; |
| 105 | } |
| 106 | if ((FdFlags & __WASI_FDFLAGS_RSYNC) != 0) { |
| 107 | #ifdef O_RSYNC |
| 108 | Flags |= O_RSYNC; |
| 109 | #else |