Skip to content

Commit d4efc3f

Browse files
committed
Fix stale magic numbers in libc-bottom-half's errno_fixup_socket.
1 parent 350ea74 commit d4efc3f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • libc-bottom-half/cloudlibc/src/common

libc-bottom-half/cloudlibc/src/common/errno.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static inline __wasi_errno_t errno_fixup_directory(__wasi_fd_t fd,
1919
return error;
2020
}
2121

22+
#ifdef __wasilibc_unmodified_upstream // posix_spawn etc.
2223
// Translates ENOTCAPABLE to EBADF if a regular file or EACCES otherwise.
2324
static inline __wasi_errno_t errno_fixup_executable(__wasi_fd_t fd,
2425
__wasi_errno_t error) {
@@ -31,6 +32,7 @@ static inline __wasi_errno_t errno_fixup_executable(__wasi_fd_t fd,
3132
}
3233
return error;
3334
}
35+
#endif
3436

3537
#ifdef __wasilibc_unmodified_upstream // process file descriptors
3638
// Translates ENOTCAPABLE to EINVAL if not a process.
@@ -52,7 +54,12 @@ static inline __wasi_errno_t errno_fixup_socket(__wasi_fd_t fd,
5254
if (error == __WASI_ENOTCAPABLE) {
5355
__wasi_fdstat_t fds;
5456
if (__wasi_fd_stat_get(fd, &fds) == 0 &&
57+
#ifdef __wasilibc_unmodified_upstream // don't hard-code magic numbers
5558
(fds.fs_filetype & 0xf0) != 0x80)
59+
#else
60+
(fds.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM &&
61+
fds.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM))
62+
#endif
5663
return __WASI_ENOTSOCK;
5764
}
5865
return error;

0 commit comments

Comments
 (0)