1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
3 // SPDX-License-Identifier: BSD-2-Clause
10 #ifdef __wasilibc_unmodified_upstream
11 // Translates ENOTCAPABLE to ENOTDIR if not a directory.
12 static inline __wasi_errno_t
errno_fixup_directory(__wasi_fd_t fd
,
13 __wasi_errno_t error
) {
14 if (error
== __WASI_ENOTCAPABLE
) {
16 if (__wasi_fd_stat_get(fd
, &fds
) == 0 &&
17 fds
.fs_filetype
!= __WASI_FILETYPE_DIRECTORY
)
18 return __WASI_ENOTDIR
;
23 // WASI syscalls should just return ENOTDIR if that's what the problem is.
24 static inline __wasi_errno_t
errno_fixup_directory(__wasi_fd_t fd
,
25 __wasi_errno_t error
) {
30 #ifdef __wasilibc_unmodified_upstream // posix_spawn etc.
31 // Translates ENOTCAPABLE to EBADF if a regular file or EACCES otherwise.
32 static inline __wasi_errno_t
errno_fixup_executable(__wasi_fd_t fd
,
33 __wasi_errno_t error
) {
34 if (error
== __WASI_ENOTCAPABLE
) {
36 if (__wasi_fd_stat_get(fd
, &fds
) == 0)
37 return fds
.fs_filetype
== __WASI_FILETYPE_REGULAR_FILE
45 #ifdef __wasilibc_unmodified_upstream // process file descriptors
46 // Translates ENOTCAPABLE to EINVAL if not a process.
47 static inline __wasi_errno_t
errno_fixup_process(__wasi_fd_t fd
,
48 __wasi_errno_t error
) {
49 if (error
== __WASI_ENOTCAPABLE
) {
51 if (__wasi_fd_stat_get(fd
, &fds
) == 0 &&
52 fds
.fs_filetype
!= __WASI_FILETYPE_PROCESS
)
59 #ifdef __wasilibc_unmodified_upstream
60 // Translates ENOTCAPABLE to ENOTSOCK if not a socket.
61 static inline __wasi_errno_t
errno_fixup_socket(__wasi_fd_t fd
,
62 __wasi_errno_t error
) {
63 if (error
== __WASI_ENOTCAPABLE
) {
65 if (__wasi_fd_stat_get(fd
, &fds
) == 0 &&
66 #ifdef __wasilibc_unmodified_upstream // don't hard-code magic numbers
67 (fds
.fs_filetype
& 0xf0) != 0x80)
69 (fds
.fs_filetype
!= __WASI_FILETYPE_SOCKET_STREAM
&&
70 fds
.fs_filetype
!= __WASI_FILETYPE_SOCKET_DGRAM
))
72 return __WASI_ENOTSOCK
;
77 // WASI syscalls should just return ENOTSOCK if that's what the problem is.
78 static inline __wasi_errno_t
errno_fixup_socket(__wasi_fd_t fd
,
79 __wasi_errno_t error
) {