From cab0ec601e0d3b1b6eb1be9d76f36aad5507998b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 4 Feb 2021 16:36:38 -0800 Subject: [PATCH] Remove __wasilibc_unmodified_upstream markers from libc-bottom-half. We've already started removing this; this just removes all remaining ones under the libc-bottom-half directory. These markers were originally intended to help track upstream changes, however in practice they created a lot of clutter and weren't that helpful. And now, upstream cloudlibc is no longer active. --- libc-bottom-half/cloudlibc/src/common/errno.h | 62 ------ .../cloudlibc/src/include/stdlib.h | 205 ------------------ .../cloudlibc/src/libc/dirent/fdopendir.c | 4 - .../cloudlibc/src/libc/dirent/opendirat.c | 4 - .../cloudlibc/src/libc/dirent/readdir.c | 4 - .../cloudlibc/src/libc/dirent/scandirat.c | 8 - .../cloudlibc/src/libc/fcntl/fcntl.c | 23 -- .../cloudlibc/src/libc/fcntl/openat.c | 95 -------- .../cloudlibc/src/libc/fcntl/posix_fadvise.c | 4 - .../src/libc/fcntl/posix_fallocate.c | 4 - .../cloudlibc/src/libc/sched/sched_yield.c | 4 - .../cloudlibc/src/libc/stdio/renameat.c | 6 +- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 20 -- .../src/libc/sys/resource/getrusage.c | 4 - .../cloudlibc/src/libc/sys/select/select.c | 8 - .../src/libc/sys/socket/getsockopt.c | 8 - .../cloudlibc/src/libc/sys/socket/recv.c | 22 -- .../cloudlibc/src/libc/sys/socket/send.c | 16 -- .../cloudlibc/src/libc/sys/socket/shutdown.c | 5 - .../cloudlibc/src/libc/sys/stat/fstat.c | 4 - .../cloudlibc/src/libc/sys/stat/fstatat.c | 12 - .../cloudlibc/src/libc/sys/stat/futimens.c | 10 - .../cloudlibc/src/libc/sys/stat/mkdirat.c | 9 - .../cloudlibc/src/libc/sys/stat/stat_impl.h | 58 ----- .../cloudlibc/src/libc/sys/stat/utimensat.c | 18 -- .../src/libc/sys/time/gettimeofday.c | 8 - .../cloudlibc/src/libc/sys/times/times.c | 8 - .../cloudlibc/src/libc/time/CLOCK_MONOTONIC.c | 4 - .../src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c | 4 - .../cloudlibc/src/libc/time/CLOCK_REALTIME.c | 4 - .../src/libc/time/CLOCK_THREAD_CPUTIME_ID.c | 4 - .../cloudlibc/src/libc/time/clock.c | 4 - .../cloudlibc/src/libc/time/clock_gettime.c | 7 - .../cloudlibc/src/libc/time/clock_nanosleep.c | 13 -- .../cloudlibc/src/libc/time/nanosleep.c | 11 +- .../cloudlibc/src/libc/time/time.c | 4 - .../cloudlibc/src/libc/unistd/faccessat.c | 29 --- .../cloudlibc/src/libc/unistd/ftruncate.c | 10 - .../cloudlibc/src/libc/unistd/linkat.c | 14 +- .../cloudlibc/src/libc/unistd/lseek.c | 7 - .../cloudlibc/src/libc/unistd/pread.c | 8 - .../cloudlibc/src/libc/unistd/pwrite.c | 8 - .../cloudlibc/src/libc/unistd/readlinkat.c | 5 - .../cloudlibc/src/libc/unistd/sleep.c | 4 - .../cloudlibc/src/libc/unistd/symlinkat.c | 4 - .../cloudlibc/src/libc/unistd/unlinkat.c | 16 -- .../cloudlibc/src/libc/unistd/usleep.c | 4 - 47 files changed, 3 insertions(+), 794 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/common/errno.h b/libc-bottom-half/cloudlibc/src/common/errno.h index ebc1734..7d178fb 100644 --- a/libc-bottom-half/cloudlibc/src/common/errno.h +++ b/libc-bottom-half/cloudlibc/src/common/errno.h @@ -7,78 +7,16 @@ #include -#ifdef __wasilibc_unmodified_upstream -// Translates ENOTCAPABLE to ENOTDIR if not a directory. -static inline __wasi_errno_t errno_fixup_directory(__wasi_fd_t fd, - __wasi_errno_t error) { - if (error == __WASI_ENOTCAPABLE) { - __wasi_fdstat_t fds; - if (__wasi_fd_stat_get(fd, &fds) == 0 && - fds.fs_filetype != __WASI_FILETYPE_DIRECTORY) - return __WASI_ENOTDIR; - } - return error; -} -#else // WASI syscalls should just return ENOTDIR if that's what the problem is. static inline __wasi_errno_t errno_fixup_directory(__wasi_fd_t fd, __wasi_errno_t error) { return error; } -#endif - -#ifdef __wasilibc_unmodified_upstream // posix_spawn etc. -// Translates ENOTCAPABLE to EBADF if a regular file or EACCES otherwise. -static inline __wasi_errno_t errno_fixup_executable(__wasi_fd_t fd, - __wasi_errno_t error) { - if (error == __WASI_ENOTCAPABLE) { - __wasi_fdstat_t fds; - if (__wasi_fd_stat_get(fd, &fds) == 0) - return fds.fs_filetype == __WASI_FILETYPE_REGULAR_FILE - ? __WASI_EBADF - : __WASI_EACCES; - } - return error; -} -#endif -#ifdef __wasilibc_unmodified_upstream // process file descriptors -// Translates ENOTCAPABLE to EINVAL if not a process. -static inline __wasi_errno_t errno_fixup_process(__wasi_fd_t fd, - __wasi_errno_t error) { - if (error == __WASI_ENOTCAPABLE) { - __wasi_fdstat_t fds; - if (__wasi_fd_stat_get(fd, &fds) == 0 && - fds.fs_filetype != __WASI_FILETYPE_PROCESS) - return __WASI_EINVAL; - } - return error; -} -#endif - -#ifdef __wasilibc_unmodified_upstream -// Translates ENOTCAPABLE to ENOTSOCK if not a socket. -static inline __wasi_errno_t errno_fixup_socket(__wasi_fd_t fd, - __wasi_errno_t error) { - if (error == __WASI_ENOTCAPABLE) { - __wasi_fdstat_t fds; - if (__wasi_fd_stat_get(fd, &fds) == 0 && -#ifdef __wasilibc_unmodified_upstream // don't hard-code magic numbers - (fds.fs_filetype & 0xf0) != 0x80) -#else - (fds.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM && - fds.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM)) -#endif - return __WASI_ENOTSOCK; - } - return error; -} -#else // WASI syscalls should just return ENOTSOCK if that's what the problem is. static inline __wasi_errno_t errno_fixup_socket(__wasi_fd_t fd, __wasi_errno_t error) { return error; } -#endif #endif diff --git a/libc-bottom-half/cloudlibc/src/include/stdlib.h b/libc-bottom-half/cloudlibc/src/include/stdlib.h index e30b8de..ff48afb 100644 --- a/libc-bottom-half/cloudlibc/src/include/stdlib.h +++ b/libc-bottom-half/cloudlibc/src/include/stdlib.h @@ -69,223 +69,18 @@ #include <_/limits.h> #include <_/types.h> -#ifdef __wasilibc_unmodified_upstream -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -#define RAND_MAX _INT_MAX - -#define NULL _NULL - -typedef struct { - int quot; - int rem; -} div_t; - -typedef struct { - long quot; - long rem; -} ldiv_t; - -typedef struct { - long long quot; - long long rem; -} lldiv_t; - -#ifndef _SIZE_T_DECLARED -typedef __size_t size_t; -#define _SIZE_T_DECLARED -#endif -#ifndef _WCHAR_T_DECLARED -typedef __wchar_t wchar_t; -#define _WCHAR_T_DECLARED -#endif - -#ifdef __wasilibc_unmodified_upstream -// Process wide locale always uses ASCII. -#define MB_CUR_MAX ((size_t)1) -#endif - -// Keep existing code happy that assumes that MB_CUR_MAX_L is a macro. -#define MB_CUR_MAX_L MB_CUR_MAX_L - -#define alloca(size) __builtin_alloca(size) -#endif - __BEGIN_DECLS _Noreturn void _Exit(int); -#ifdef __wasilibc_unmodified_upstream -size_t MB_CUR_MAX_L(__locale_t); -long a64l(const char *); -#endif _Noreturn void abort(void); -#ifdef __wasilibc_unmodified_upstream -int abs(int) __pure2; -int at_quick_exit(void (*)(void)); -int atexit(void (*)(void)); -void *aligned_alloc(size_t, size_t); -__uint32_t arc4random(void); -void arc4random_buf(void *, size_t); -__uint32_t arc4random_uniform(__uint32_t); -double atof(const char *); -int atoi(const char *); -long atol(const char *); -long long atoll(const char *); -void *bsearch(const void *, const void *, size_t, size_t, - int (*)(const void *, const void *)); -#endif void *calloc(size_t, size_t); -#ifdef __wasilibc_unmodified_upstream -div_t div(int, int) __pure2; -double drand48(void); -double erand48(__uint16_t *); -#endif _Noreturn void exit(int); void free(void *); -#ifdef __wasilibc_unmodified_upstream -char *getenv(const char *); -int getsubopt(char **, char *const *, char **); -long jrand48(__uint16_t *); -int l64a_r(long, char *, int); -long labs(long) __pure2; -ldiv_t ldiv(long, long) __pure2; -long long llabs(long long) __pure2; -lldiv_t lldiv(long long, long long) __pure2; -long lrand48(void); -#endif void *malloc(size_t); -#ifdef __wasilibc_unmodified_upstream -int mblen(const char *, size_t); -int mblen_l(const char *, size_t, __locale_t); -size_t mbstowcs(wchar_t *__restrict, const char *__restrict, size_t); -size_t mbstowcs_l(wchar_t *__restrict, const char *__restrict, size_t, - __locale_t); -int mbtowc(wchar_t *__restrict, const char *__restrict, size_t); -int mbtowc_l(wchar_t *__restrict, const char *__restrict, size_t, __locale_t); -long mrand48(void); -long nrand48(__uint16_t *); -int posix_memalign(void **, size_t, size_t); -#endif void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); -#ifdef __wasilibc_unmodified_upstream -void qsort_r(void *, size_t, size_t, - int (*)(const void *, const void *, void *), void *); -_Noreturn void quick_exit(int); -int rand(void); -long random(void); -#endif void *realloc(void *, size_t); -#ifdef __wasilibc_unmodified_upstream -void *reallocarray(void *, size_t, size_t); -double strtod(const char *__restrict, char **__restrict); -double strtod_l(const char *__restrict, char **__restrict, __locale_t); -float strtof(const char *__restrict, char **__restrict); -float strtof_l(const char *__restrict, char **__restrict, __locale_t); -long strtol(const char *__restrict, char **__restrict, int); -long strtol_l(const char *__restrict, char **__restrict, int, __locale_t); -long double strtold(const char *__restrict, char **__restrict); -long double strtold_l(const char *__restrict, char **__restrict, __locale_t); -long long strtoll(const char *__restrict, char **__restrict, int); -long long strtoll_l(const char *__restrict, char **__restrict, int, __locale_t); -unsigned long strtoul(const char *__restrict, char **__restrict, int); -unsigned long strtoul_l(const char *__restrict, char **__restrict, int, - __locale_t); -unsigned long long strtoull(const char *__restrict, char **__restrict, int); -unsigned long long strtoull_l(const char *__restrict, char **__restrict, int, - __locale_t); -size_t wcstombs(char *__restrict, const wchar_t *__restrict, size_t); -size_t wcstombs_l(char *__restrict, const wchar_t *__restrict, size_t, - __locale_t); -int wctomb(char *, wchar_t); -int wctomb_l(char *, wchar_t, __locale_t); -#endif __END_DECLS #if _CLOUDLIBC_INLINE_FUNCTIONS -#ifdef __wasilibc_unmodified_upstream -static __inline double __atof(const char *__str) { - return strtod(__str, NULL); -} -#define atof(str) __atof(str) - -static __inline int __atoi(const char *__str) { - return (int)strtol(__str, NULL, 10); -} -#define atoi(str) __atoi(str) - -static __inline long __atol(const char *__str) { - return strtol(__str, NULL, 10); -} -#define atol(str) __atol(str) - -static __inline long long __atoll(const char *__str) { - return strtoll(__str, NULL, 10); -} -#define atoll(str) __atoll(str) - -static __inline int __abs(int __i) { - return __i < 0 ? -__i : __i; -} -#define abs(i) __abs(i) - -static __inline long __labs(long __i) { - return __i < 0 ? -__i : __i; -} -#define labs(i) __labs(i) - -static __inline long long __llabs(long long __i) { - return __i < 0 ? -__i : __i; -} -#define llabs(i) __llabs(i) - -static __inline div_t __div(int __numer, int __denom) { - div_t __res = {__numer / __denom, __numer % __denom}; - return __res; -} -#define div(numer, denom) __div(numer, denom) - -static __inline ldiv_t __ldiv(long __numer, long __denom) { - ldiv_t __res = {__numer / __denom, __numer % __denom}; - return __res; -} -#define ldiv(numer, denom) __ldiv(numer, denom) - -static __inline lldiv_t __lldiv(long long __numer, long long __denom) { - lldiv_t __res = {__numer / __denom, __numer % __denom}; - return __res; -} -#define lldiv(numer, denom) __lldiv(numer, denom) - -static __inline void *__bsearch(const void *__key, const void *__base, - size_t __nel, size_t __width, - int (*__compar)(const void *, const void *)) { - const char *__basep, *__obj; - size_t __mid, __skip; - int __cmp; - - __basep = (const char *)__base; - while (__nel > 0) { - // Pick pivot. - __mid = __nel / 2; - __obj = __basep + __mid * __width; - __cmp = __compar(__key, (const void *)__obj); - if (__cmp < 0) { - // key < obj. Restrict search to top of the list. - __nel = __mid; - } else if (__cmp > 0) { - // key > obj. Restrict search to bottom of the list. - __skip = __mid + 1; - __basep += __skip * __width; - __nel -= __skip; - } else { - return (void *)__obj; - } - } - return NULL; -} -#define bsearch(key, base, nel, width, compar) \ - __preserve_const(void, __bsearch, base, key, base, nel, width, compar) -#endif // qsort_r() implementation from Bentley and McIlroy's // "Engineering a Sort Function". diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c index 325093f..59fc027 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c @@ -25,12 +25,8 @@ DIR *fdopendir(int fd) { // Ensure that this is really a directory by already loading the first // chunk of data. __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream - __wasi_file_readdir(fd, dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE, -#else // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support. __wasi_fd_readdir(fd, (uint8_t *)dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE, -#endif __WASI_DIRCOOKIE_START, &dirp->buffer_used); if (error != 0) { free(dirp->buffer); diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c b/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c index c940d5f..1465004 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c @@ -10,11 +10,7 @@ DIR *opendirat(int dir, const char *dirname) { // Open directory. -#ifdef __wasilibc_unmodified_upstream // avoid making a varargs call - int fd = openat(dir, dirname, O_RDONLY | O_NONBLOCK | O_DIRECTORY); -#else int fd = __wasilibc_openat_nomode(dir, dirname, O_RDONLY | O_NONBLOCK | O_DIRECTORY); -#endif if (fd == -1) return NULL; diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c index c4a2013..b5650d6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c @@ -91,12 +91,8 @@ struct dirent *readdir(DIR *dirp) { // Load more directory entries and continue. __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream - __wasi_file_readdir(dirp->fd, dirp->buffer, dirp->buffer_size, -#else // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support. __wasi_fd_readdir(dirp->fd, (uint8_t *)dirp->buffer, dirp->buffer_size, -#endif dirp->cookie, &dirp->buffer_used); if (error != 0) { errno = error; diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c b/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c index 83cdeb9..a77a1d3 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c @@ -25,11 +25,7 @@ int scandirat(int dirfd, const char *dir, struct dirent ***namelist, sel = sel_true; // Open the directory. -#ifdef __wasilibc_unmodified_upstream // avoid making a varargs call - int fd = openat(dirfd, dir, O_RDONLY | O_NONBLOCK | O_DIRECTORY); -#else int fd = __wasilibc_openat_nomode(dirfd, dir, O_RDONLY | O_NONBLOCK | O_DIRECTORY); -#endif if (fd == -1) return -1; @@ -119,12 +115,8 @@ int scandirat(int dirfd, const char *dir, struct dirent ***namelist, read_entries:; // Load more directory entries and continue. -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_file_readdir(fd, buffer, buffer_size, -#else // TODO: Remove the cast on `buffer` once the witx is updated with char8 support. __wasi_errno_t error = __wasi_fd_readdir(fd, (uint8_t *)buffer, buffer_size, -#endif cookie, &buffer_used); if (error != 0) { errno = error; diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c index d4e5597..5d4055d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c @@ -18,11 +18,7 @@ int fcntl(int fildes, int cmd, ...) { case F_GETFL: { // Obtain the flags and the rights of the descriptor. __wasi_fdstat_t fds; -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_fd_stat_get(fildes, &fds); -#else __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); -#endif if (error != 0) { errno = error; return -1; @@ -31,26 +27,13 @@ int fcntl(int fildes, int cmd, ...) { // Roughly approximate the access mode by converting the rights. int oflags = fds.fs_flags; if ((fds.fs_rights_base & -#ifdef __wasilibc_unmodified_upstream - (__WASI_RIGHT_FD_READ | __WASI_RIGHT_FILE_READDIR)) != 0) { - if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) != 0) -#else (__WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR)) != 0) { if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) -#endif oflags |= O_RDWR; else oflags |= O_RDONLY; -#ifdef __wasilibc_unmodified_upstream - } else if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) != 0) { -#else } else if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) { -#endif oflags |= O_WRONLY; -#ifdef __wasilibc_unmodified_upstream - } else if ((fds.fs_rights_base & __WASI_RIGHT_PROC_EXEC) != 0) { - oflags |= O_EXEC; -#endif } else { oflags |= O_SEARCH; } @@ -63,15 +46,9 @@ int fcntl(int fildes, int cmd, ...) { int flags = va_arg(ap, int); va_end(ap); -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_fdstat_t fds = {.fs_flags = flags & 0xfff}; - __wasi_errno_t error = - __wasi_fd_stat_put(fildes, &fds, __WASI_FDSTAT_FLAGS); -#else __wasi_fdflags_t fs_flags = flags & 0xfff; __wasi_errno_t error = __wasi_fd_fdstat_set_flags(fildes, fs_flags); -#endif if (error != 0) { errno = error; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c index 12d62b7..da54a72 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c @@ -11,98 +11,44 @@ #include #include -#ifdef __wasilibc_unmodified_upstream // fstat -static_assert(O_APPEND == __WASI_FDFLAG_APPEND, "Value mismatch"); -static_assert(O_DSYNC == __WASI_FDFLAG_DSYNC, "Value mismatch"); -static_assert(O_NONBLOCK == __WASI_FDFLAG_NONBLOCK, "Value mismatch"); -static_assert(O_RSYNC == __WASI_FDFLAG_RSYNC, "Value mismatch"); -static_assert(O_SYNC == __WASI_FDFLAG_SYNC, "Value mismatch"); -#else static_assert(O_APPEND == __WASI_FDFLAGS_APPEND, "Value mismatch"); static_assert(O_DSYNC == __WASI_FDFLAGS_DSYNC, "Value mismatch"); static_assert(O_NONBLOCK == __WASI_FDFLAGS_NONBLOCK, "Value mismatch"); static_assert(O_RSYNC == __WASI_FDFLAGS_RSYNC, "Value mismatch"); static_assert(O_SYNC == __WASI_FDFLAGS_SYNC, "Value mismatch"); -#endif -#ifdef __wasilibc_unmodified_upstream // fstat -static_assert(O_CREAT >> 12 == __WASI_O_CREAT, "Value mismatch"); -static_assert(O_DIRECTORY >> 12 == __WASI_O_DIRECTORY, "Value mismatch"); -static_assert(O_EXCL >> 12 == __WASI_O_EXCL, "Value mismatch"); -static_assert(O_TRUNC >> 12 == __WASI_O_TRUNC, "Value mismatch"); -#else static_assert(O_CREAT >> 12 == __WASI_OFLAGS_CREAT, "Value mismatch"); static_assert(O_DIRECTORY >> 12 == __WASI_OFLAGS_DIRECTORY, "Value mismatch"); static_assert(O_EXCL >> 12 == __WASI_OFLAGS_EXCL, "Value mismatch"); static_assert(O_TRUNC >> 12 == __WASI_OFLAGS_TRUNC, "Value mismatch"); -#endif int openat(int fd, const char *path, int oflag, ...) { -#ifdef __wasilibc_unmodified_upstream // fstat -#else return __wasilibc_openat_nomode(fd, path, oflag); } int __wasilibc_openat_nomode(int fd, const char *path, int oflag) { -#endif // Compute rights corresponding with the access modes provided. // Attempt to obtain all rights, except the ones that contradict the // access mode provided to openat(). -#ifdef __wasilibc_unmodified_upstream // Let the WASI implementation check this instead. - __wasi_rights_t min = 0; -#endif __wasi_rights_t max = -#ifdef __wasilibc_unmodified_upstream // fstat - ~(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | - __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FILE_ALLOCATE | - __WASI_RIGHT_FILE_READDIR | __WASI_RIGHT_FILE_STAT_FPUT_SIZE | -#else ~(__WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_WRITE | __WASI_RIGHTS_FD_ALLOCATE | __WASI_RIGHTS_FD_READDIR | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE | -#endif -#ifdef __wasilibc_unmodified_upstream // RIGHT_MEM_MAP_EXEC - __WASI_RIGHT_MEM_MAP_EXEC); -#else 0); -#endif switch (oflag & O_ACCMODE) { case O_RDONLY: case O_RDWR: case O_WRONLY: if ((oflag & O_RDONLY) != 0) { -#ifdef __wasilibc_unmodified_upstream // Let the WASI implementation check this instead. - min |= (oflag & O_DIRECTORY) == 0 ? __WASI_RIGHT_FD_READ - : __WASI_RIGHT_FILE_READDIR; -#endif -#ifdef __wasilibc_unmodified_upstream // RIGHT_MEM_MAP_EXEC - max |= __WASI_RIGHT_FD_READ | __WASI_RIGHT_FILE_READDIR | - __WASI_RIGHT_MEM_MAP_EXEC; -#else max |= __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR; -#endif } if ((oflag & O_WRONLY) != 0) { -#ifdef __wasilibc_unmodified_upstream // Let the WASI implementation check this instead. - min |= __WASI_RIGHT_FD_WRITE; - if ((oflag & O_APPEND) == 0) - min |= __WASI_RIGHT_FD_SEEK; -#endif -#ifdef __wasilibc_unmodified_upstream // fstat - max |= __WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE | - __WASI_RIGHT_FILE_ALLOCATE | - __WASI_RIGHT_FILE_STAT_FPUT_SIZE; -#else max |= __WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_WRITE | __WASI_RIGHTS_FD_ALLOCATE | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE; -#endif } break; case O_EXEC: -#ifdef __wasilibc_unmodified_upstream // RIGHT_PROC_EXEC - min |= __WASI_RIGHT_PROC_EXEC; -#endif break; case O_SEARCH: break; @@ -110,57 +56,21 @@ int __wasilibc_openat_nomode(int fd, const char *path, int oflag) { errno = EINVAL; return -1; } -#ifdef __wasilibc_unmodified_upstream // Let the WASI implementation check this instead. - assert((min & max) == min && - "Minimal rights should be a subset of the maximum"); -#endif // Ensure that we can actually obtain the minimal rights needed. __wasi_fdstat_t fsb_cur; -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_fd_stat_get(fd, &fsb_cur); -#else __wasi_errno_t error = __wasi_fd_fdstat_get(fd, &fsb_cur); -#endif if (error != 0) { errno = error; return -1; } -#ifdef __wasilibc_unmodified_upstream // Let the WASI implementation check this instead. - if (fsb_cur.fs_filetype != __WASI_FILETYPE_DIRECTORY) { - errno = ENOTDIR; - return -1; - } - if ((min & fsb_cur.fs_rights_inheriting) != min) { - errno = ENOTCAPABLE; - return -1; - } -#endif // Path lookup properties. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_lookup_t lookup = {.fd = fd, .flags = 0}; -#else __wasi_lookupflags_t lookup_flags = 0; -#endif if ((oflag & O_NOFOLLOW) == 0) -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW; -#else lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; -#endif // Open file with appropriate rights. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t and __wasi_fdstat_t - __wasi_fdstat_t fsb_new = { - .fs_flags = oflag & 0xfff, - .fs_rights_base = max & fsb_cur.fs_rights_inheriting, - .fs_rights_inheriting = fsb_cur.fs_rights_inheriting, - }; - __wasi_fd_t newfd; - error = __wasi_file_open(lookup, path, strlen(path), - (oflag >> 12) & 0xfff, &fsb_new, &newfd); -#else __wasi_fdflags_t fs_flags = oflag & 0xfff; __wasi_rights_t fs_rights_base = max & fsb_cur.fs_rights_inheriting; __wasi_rights_t fs_rights_inheriting = fsb_cur.fs_rights_inheriting; @@ -169,13 +79,8 @@ int __wasilibc_openat_nomode(int fd, const char *path, int oflag) { (oflag >> 12) & 0xfff, fs_rights_base, fs_rights_inheriting, fs_flags, &newfd); -#endif if (error != 0) { -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - errno = errno_fixup_directory(lookup.fd, error); -#else errno = errno_fixup_directory(fd, error); -#endif return -1; } return newfd; diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c index af8d7e1..d683d39 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c @@ -20,9 +20,5 @@ static_assert(POSIX_FADV_WILLNEED == __WASI_ADVICE_WILLNEED, int posix_fadvise(int fd, off_t offset, off_t len, int advice) { if (offset < 0 || len < 0) return EINVAL; -#ifdef __wasilibc_unmodified_upstream - return __wasi_file_advise(fd, offset, len, advice); -#else return __wasi_fd_advise(fd, offset, len, advice); -#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c index 44e1842..4b41c4b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c @@ -9,9 +9,5 @@ int posix_fallocate(int fd, off_t offset, off_t len) { if (offset < 0 || len < 0) return EINVAL; -#ifdef __wasilibc_unmodified_upstream - return __wasi_file_allocate(fd, offset, len); -#else return __wasi_fd_allocate(fd, offset, len); -#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c index e48e3c7..6100ea5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c +++ b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c @@ -7,11 +7,7 @@ #include int sched_yield(void) { -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_thread_yield(); -#else __wasi_errno_t error = __wasi_sched_yield(); -#endif if (error != 0) { errno = error; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c b/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c index f5e4d96..da9b5c5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c +++ b/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c @@ -10,12 +10,8 @@ #include int renameat(int oldfd, const char *old, int newfd, const char *new) { -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_file_rename(oldfd, old, strlen(old), -#else __wasi_errno_t error = __wasi_path_rename(oldfd, old, strlen(old), -#endif - newfd, new, strlen(new)); + newfd, new, strlen(new)); if (error != 0) { errno = errno_fixup_directory(oldfd, errno_fixup_directory(newfd, error)); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c index e464d88..7d03cc6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -24,11 +24,7 @@ int ioctl(int fildes, int request, ...) { }; __wasi_event_t events[__arraycount(subscriptions)]; size_t nevents; -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_poll( -#else __wasi_errno_t error = __wasi_poll_oneoff( -#endif subscriptions, events, __arraycount(subscriptions), &nevents); if (error != 0) { errno = error; @@ -61,11 +57,7 @@ int ioctl(int fildes, int request, ...) { case FIONBIO: { // Obtain the current file descriptor flags. __wasi_fdstat_t fds; -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_fd_stat_get(fildes, &fds); -#else __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); -#endif if (error != 0) { errno = error; return -1; @@ -75,25 +67,13 @@ int ioctl(int fildes, int request, ...) { va_list ap; va_start(ap, request); if (*va_arg(ap, const int *) != 0) -#ifdef __wasilibc_unmodified_upstream // generated constant names - fds.fs_flags |= __WASI_FDFLAG_NONBLOCK; -#else fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; -#endif else -#ifdef __wasilibc_unmodified_upstream // generated constant names - fds.fs_flags &= ~__WASI_FDFLAG_NONBLOCK; -#else fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; -#endif va_end(ap); // Update the file descriptor flags. -#ifdef __wasilibc_unmodified_upstream // fstat - error = __wasi_fd_stat_put(fildes, &fds, __WASI_FDSTAT_FLAGS); -#else error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); -#endif if (error != 0) { errno = error; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/resource/getrusage.c b/libc-bottom-half/cloudlibc/src/libc/sys/resource/getrusage.c index be1a078..bd059c4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/resource/getrusage.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/resource/getrusage.c @@ -13,11 +13,7 @@ int getrusage(int who, struct rusage *r_usage) { switch (who) { case RUSAGE_SELF: { __wasi_timestamp_t usertime = 0; -#ifdef __wasilibc_unmodified_upstream // generated constant names - (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 1000, -#else (void)__wasi_clock_time_get(__WASI_CLOCKID_PROCESS_CPUTIME_ID, 1000, -#endif &usertime); *r_usage = (struct rusage){ .ru_utime = timestamp_to_timeval(usertime), diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c index 5d4bc93..ebe5e8c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c @@ -17,17 +17,9 @@ int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, } struct timespec ts = {.tv_sec = timeout->tv_sec, .tv_nsec = (long)timeout->tv_usec * 1000}; -#ifdef __wasilibc_unmodified_upstream - return pselect(nfds, readfds, writefds, errorfds, &ts); -#else return pselect(nfds, readfds, writefds, errorfds, &ts, NULL); -#endif } else { // No timeout specified. -#ifdef __wasilibc_unmodified_upstream - return pselect(nfds, readfds, writefds, errorfds, NULL); -#else return pselect(nfds, readfds, writefds, errorfds, NULL, NULL); -#endif } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c index 61af183..1fe41c4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c @@ -9,11 +9,7 @@ #include int getsockopt(int socket, int level, int option_name, -#ifdef __wasilibc_unmodified_upstream - void *restrict option_value, size_t *restrict option_len) { -#else void *restrict option_value, socklen_t *restrict option_len) { -#endif // Only support SOL_SOCKET options for now. if (level != SOL_SOCKET) { errno = ENOPROTOOPT; @@ -26,11 +22,7 @@ int getsockopt(int socket, int level, int option_name, // Return the type of the socket. This information can simply be // obtained by looking at the file descriptor type. __wasi_fdstat_t fsb; -#ifdef __wasilibc_unmodified_upstream - if (__wasi_fd_stat_get(socket, &fsb) != 0) { -#else if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { -#endif errno = EBADF; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 57e0370..49c09d0 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -11,13 +11,8 @@ #include #include -#ifdef __wasilibc_unmodified_upstream -static_assert(MSG_PEEK == __WASI_SOCK_RECV_PEEK, "Value mismatch"); -static_assert(MSG_WAITALL == __WASI_SOCK_RECV_WAITALL, "Value mismatch"); -#else static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); -#endif ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { // Validate flags. @@ -28,37 +23,20 @@ ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { // Prepare input parameters. __wasi_iovec_t iov = {.buf = buffer, .buf_len = length}; -#ifdef __wasilibc_unmodified_upstream // send/recv - __wasi_recv_in_t ri = { - .ri_data = &iov, - .ri_data_len = 1, - .ri_flags = flags, - }; -#else __wasi_iovec_t *ri_data = &iov; size_t ri_data_len = 1; __wasi_riflags_t ri_flags = flags; -#endif // Perform system call. -#ifdef __wasilibc_unmodified_upstream // send/recv - __wasi_recv_out_t ro; - __wasi_errno_t error = __wasi_sock_recv(socket, &ri, &ro); -#else size_t ro_datalen; __wasi_roflags_t ro_flags; __wasi_errno_t error = __wasi_sock_recv(socket, ri_data, ri_data_len, ri_flags, &ro_datalen, &ro_flags); -#endif if (error != 0) { errno = errno_fixup_socket(socket, error); return -1; } -#ifdef __wasilibc_unmodified_upstream // send/recv - return ro.ro_datalen; -#else return ro_datalen; -#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 626110c..0759abf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -19,32 +19,16 @@ ssize_t send(int socket, const void *buffer, size_t length, int flags) { // Prepare input parameters. __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; -#ifdef __wasilibc_unmodified_upstream // send/recv - __wasi_send_in_t si = { - .si_data = &iov, - .si_data_len = 1, - }; -#else __wasi_ciovec_t *si_data = &iov; size_t si_data_len = 1; __wasi_siflags_t si_flags = 0; -#endif // Perform system call. -#ifdef __wasilibc_unmodified_upstream // send/recv - __wasi_send_out_t so; - __wasi_errno_t error = __wasi_sock_send(socket, &si, &so); -#else size_t so_datalen; __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); -#endif if (error != 0) { errno = errno_fixup_socket(socket, error); return -1; } -#ifdef __wasilibc_unmodified_upstream // send/recv - return so.so_datalen; -#else return so_datalen; -#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c index 560f53c..883b551 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c @@ -10,13 +10,8 @@ #include #include -#ifdef __wasilibc_unmodified_upstream // generated constant names -static_assert(SHUT_RD == __WASI_SHUT_RD, "Value mismatch"); -static_assert(SHUT_WR == __WASI_SHUT_WR, "Value mismatch"); -#else static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); -#endif int shutdown(int socket, int how) { // Validate shutdown flags. diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c index ff590d1..b8ffdb5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c @@ -11,11 +11,7 @@ int fstat(int fildes, struct stat *buf) { __wasi_filestat_t internal_stat; -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_errno_t error = __wasi_file_stat_fget(fildes, &internal_stat); -#else __wasi_errno_t error = __wasi_fd_filestat_get(fildes, &internal_stat); -#endif if (error != 0) { errno = error; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c index 375d59d..6f31ddb 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c @@ -16,26 +16,14 @@ int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag) { // Create lookup properties. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_lookup_t lookup = {.fd = fd, .flags = 0}; -#else __wasi_lookupflags_t lookup_flags = 0; -#endif if ((flag & AT_SYMLINK_NOFOLLOW) == 0) -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW; -#else lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; -#endif // Perform system call. __wasi_filestat_t internal_stat; __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_file_stat_get(lookup, path, strlen(path), &internal_stat); -#else __wasi_path_filestat_get(fd, lookup_flags, path, strlen(path), &internal_stat); -#endif if (error != 0) { errno = errno_fixup_directory(fd, error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c index 1ae43dd..13357fc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c @@ -11,26 +11,16 @@ int futimens(int fd, const struct timespec *times) { // Convert timestamps and extract NOW/OMIT flags. -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_filestat_t fs; - __wasi_fsflags_t flags; - if (!utimens_get_timestamps(times, &fs, &flags)) { -#else __wasi_timestamp_t st_atim; __wasi_timestamp_t st_mtim; __wasi_fstflags_t flags; if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { -#endif errno = EINVAL; return -1; } // Perform system call. -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_errno_t error = __wasi_file_stat_fput(fd, &fs, flags); -#else __wasi_errno_t error = __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, flags); -#endif if (error != 0) { errno = error; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c index 75f47a4..df79f76 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c @@ -10,18 +10,9 @@ #include #include -#ifdef __wasilibc_unmodified_upstream -int mkdirat(int fd, const char *path, ...) { -#else int mkdirat(int fd, const char *path, mode_t mode) { -#endif -#ifdef __wasilibc_unmodified_upstream // __wasi_path_create_directory - __wasi_errno_t error = __wasi_file_create( - fd, path, strlen(path), __WASI_FILETYPE_DIRECTORY); -#else __wasi_errno_t error = __wasi_path_create_directory( fd, path, strlen(path)); -#endif if (error != 0) { errno = errno_fixup_directory(fd, error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h index d1a26fd..c649d3b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h @@ -24,43 +24,17 @@ static_assert(S_ISSOCK(S_IFSOCK), "Value mismatch"); static inline void to_public_stat(const __wasi_filestat_t *in, struct stat *out) { // Ensure that we don't truncate any values. -#ifdef __wasilibc_unmodified_upstream - static_assert(sizeof(in->st_dev) == sizeof(out->st_dev), "Size mismatch"); - static_assert(sizeof(in->st_ino) == sizeof(out->st_ino), "Size mismatch"); - static_assert(sizeof(in->st_filetype) == sizeof(out->__st_filetype), - "Size mismatch"); -#else static_assert(sizeof(in->dev) == sizeof(out->st_dev), "Size mismatch"); static_assert(sizeof(in->ino) == sizeof(out->st_ino), "Size mismatch"); /* * The non-standard __st_filetype field appears to only be used for shared * memory, which we don't currently support. */ -#endif -#ifdef __wasilibc_unmodified_upstream - static_assert(sizeof(in->st_nlink) == sizeof(out->st_nlink), "Size mismatch"); - static_assert(sizeof(in->st_size) == sizeof(out->st_size), "Size mismatch"); -#else /* nlink_t is 64-bit on wasm32, following the x32 ABI. */ static_assert(sizeof(in->nlink) <= sizeof(out->st_nlink), "Size shortfall"); static_assert(sizeof(in->size) == sizeof(out->st_size), "Size mismatch"); -#endif *out = (struct stat){ -#ifdef __wasilibc_unmodified_upstream -#define COPY_FIELD(field) .field = in->field - COPY_FIELD(st_dev), - COPY_FIELD(st_ino), - .__st_filetype = in->st_filetype, - COPY_FIELD(st_nlink), - COPY_FIELD(st_size), -#undef COPY_FIELD -#define COPY_TIMESPEC(field) .field = timestamp_to_timespec(in->field) - COPY_TIMESPEC(st_atim), - COPY_TIMESPEC(st_mtim), - COPY_TIMESPEC(st_ctim), -#undef COPY_TIMESPEC -#else .st_dev = in->dev, .st_ino = in->ino, .st_nlink = in->nlink, @@ -68,15 +42,10 @@ static inline void to_public_stat(const __wasi_filestat_t *in, .st_atim = timestamp_to_timespec(in->atim), .st_mtim = timestamp_to_timespec(in->mtim), .st_ctim = timestamp_to_timespec(in->ctim), -#endif }; // Convert file type to legacy types encoded in st_mode. -#ifdef __wasilibc_unmodified_upstream - switch (in->st_filetype) { -#else switch (in->filetype) { -#endif case __WASI_FILETYPE_BLOCK_DEVICE: out->st_mode |= S_IFBLK; break; @@ -100,64 +69,37 @@ static inline void to_public_stat(const __wasi_filestat_t *in, } static inline bool utimens_get_timestamps(const struct timespec *times, -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_filestat_t *fs, - __wasi_fsflags_t *flags) { -#else __wasi_timestamp_t *st_atim, __wasi_timestamp_t *st_mtim, __wasi_fstflags_t *flags) { -#endif if (times == NULL) { // Update both timestamps. -#ifdef __wasilibc_unmodified_upstream // fstat - *flags = __WASI_FILESTAT_ATIM_NOW | __WASI_FILESTAT_MTIM_NOW; -#else *flags = __WASI_FSTFLAGS_ATIM_NOW | __WASI_FSTFLAGS_MTIM_NOW; -#endif } else { // Set individual timestamps. *flags = 0; switch (times[0].tv_nsec) { case UTIME_NOW: -#ifdef __wasilibc_unmodified_upstream // fstat - *flags |= __WASI_FILESTAT_ATIM_NOW; -#else *flags |= __WASI_FSTFLAGS_ATIM_NOW; -#endif break; case UTIME_OMIT: break; default: -#ifdef __wasilibc_unmodified_upstream // fstat - *flags |= __WASI_FILESTAT_ATIM; - if (!timespec_to_timestamp_exact(×[0], &fs->st_atim)) -#else *flags |= __WASI_FSTFLAGS_ATIM; if (!timespec_to_timestamp_exact(×[0], st_atim)) -#endif return false; break; } switch (times[1].tv_nsec) { case UTIME_NOW: -#ifdef __wasilibc_unmodified_upstream // fstat - *flags |= __WASI_FILESTAT_MTIM_NOW; -#else *flags |= __WASI_FSTFLAGS_MTIM_NOW; -#endif break; case UTIME_OMIT: break; default: -#ifdef __wasilibc_unmodified_upstream // fstat - *flags |= __WASI_FILESTAT_MTIM; - if (!timespec_to_timestamp_exact(×[1], &fs->st_mtim)) -#else *flags |= __WASI_FSTFLAGS_MTIM; if (!timespec_to_timestamp_exact(×[1], st_mtim)) -#endif return false; break; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c index f27b67d..0a8e61b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c @@ -16,40 +16,22 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag) { // Convert timestamps and extract NOW/OMIT flags. -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_filestat_t fs; - __wasi_fsflags_t flags; - if (!utimens_get_timestamps(times, &fs, &flags)) { -#else __wasi_timestamp_t st_atim; __wasi_timestamp_t st_mtim; __wasi_fstflags_t flags; if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { -#endif errno = EINVAL; return -1; } // Create lookup properties. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_lookup_t lookup = {.fd = fd, .flags = 0}; -#else __wasi_lookupflags_t lookup_flags = 0; -#endif if ((flag & AT_SYMLINK_NOFOLLOW) == 0) -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW; -#else lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; -#endif // Perform system call. __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t, fstat - __wasi_file_stat_put(lookup, path, strlen(path), &fs, flags); -#else __wasi_path_filestat_set_times(fd, lookup_flags, path, strlen(path), st_atim, st_mtim, flags); -#endif if (error != 0) { errno = errno_fixup_directory(fd, error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c index 9d33386..d58cbb9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c @@ -8,17 +8,9 @@ #include -#ifdef __wasilibc_unmodified_upstream -int gettimeofday(struct timeval *restrict tp, ...) { -#else int gettimeofday(struct timeval *restrict tp, void *tz) { -#endif __wasi_timestamp_t ts = 0; -#ifdef __wasilibc_unmodified_upstream // generated constant names - (void)__wasi_clock_time_get(__WASI_CLOCK_REALTIME, 1000, &ts); -#else (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); -#endif *tp = timestamp_to_timeval(ts); return 0; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/times/times.c b/libc-bottom-half/cloudlibc/src/libc/sys/times/times.c index 19dc42a..fdb1a38 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/times/times.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/times/times.c @@ -15,19 +15,11 @@ static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC, clock_t times(struct tms *buffer) { // Obtain user time. __wasi_timestamp_t usertime = 0; -#ifdef __wasilibc_unmodified_upstream // generated constant names - (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 0, &usertime); -#else (void)__wasi_clock_time_get(__WASI_CLOCKID_PROCESS_CPUTIME_ID, 0, &usertime); -#endif *buffer = (struct tms){.tms_utime = usertime}; // Obtain real time. __wasi_timestamp_t realtime = 0; -#ifdef __wasilibc_unmodified_upstream // generated constant names - (void)__wasi_clock_time_get(__WASI_CLOCK_MONOTONIC, 0, &realtime); -#else (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &realtime); -#endif return realtime; } diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c index bf87ea9..a4c4a62 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c @@ -8,9 +8,5 @@ #include const struct __clockid _CLOCK_MONOTONIC = { -#ifdef __wasilibc_unmodified_upstream // generated constant names - .id = __WASI_CLOCK_MONOTONIC, -#else .id = __WASI_CLOCKID_MONOTONIC, -#endif }; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c index ce87214..901fd73 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c @@ -8,9 +8,5 @@ #include const struct __clockid _CLOCK_PROCESS_CPUTIME_ID = { -#ifdef __wasilibc_unmodified_upstream - .id = __WASI_CLOCK_PROCESS_CPUTIME_ID, -#else .id = __WASI_CLOCKID_PROCESS_CPUTIME_ID, -#endif }; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c index 9bbcc6e..9523754 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c @@ -8,9 +8,5 @@ #include const struct __clockid _CLOCK_REALTIME = { -#ifdef __wasilibc_unmodified_upstream // generated constant names - .id = __WASI_CLOCK_REALTIME, -#else .id = __WASI_CLOCKID_REALTIME, -#endif }; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_THREAD_CPUTIME_ID.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_THREAD_CPUTIME_ID.c index 4cfd3ee..de58c51 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_THREAD_CPUTIME_ID.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_THREAD_CPUTIME_ID.c @@ -8,9 +8,5 @@ #include const struct __clockid _CLOCK_THREAD_CPUTIME_ID = { -#ifdef __wasilibc_unmodified_upstream // generated constant names - .id = __WASI_CLOCK_THREAD_CPUTIME_ID, -#else .id = __WASI_CLOCKID_THREAD_CPUTIME_ID, -#endif }; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock.c b/libc-bottom-half/cloudlibc/src/libc/time/clock.c index d0748f3..cc4b6db 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock.c @@ -13,10 +13,6 @@ static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC, clock_t clock(void) { __wasi_timestamp_t ts = 0; -#ifdef __wasilibc_unmodified_upstream // generated constant names - (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 0, &ts); -#else (void)__wasi_clock_time_get(__WASI_CLOCKID_PROCESS_CPUTIME_ID, 0, &ts); -#endif return ts; } diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c index 412b613..dbb36a7 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c @@ -9,11 +9,7 @@ #include #include -#ifdef __wasilibc_unmodified_upstream -int clock_gettime(clockid_t clock_id, struct timespec *tp) { -#else int __clock_gettime(clockid_t clock_id, struct timespec *tp) { -#endif __wasi_timestamp_t ts; __wasi_errno_t error = __wasi_clock_time_get(clock_id->id, 1, &ts); if (error != 0) { @@ -23,7 +19,4 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) { *tp = timestamp_to_timespec(ts); return 0; } -#ifdef __wasilibc_unmodified_upstream -#else extern __typeof(__clock_gettime) clock_gettime __attribute__((weak, alias("__clock_gettime"))); -#endif diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c index cd8ecfc..52b577a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c @@ -10,20 +10,11 @@ #include #include -#ifdef __wasilibc_unmodified_upstream // generated constant names -static_assert(TIMER_ABSTIME == __WASI_SUBSCRIPTION_CLOCK_ABSTIME, -#else static_assert(TIMER_ABSTIME == __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME, -#endif "Value mismatch"); -#ifdef __wasilibc_unmodified_upstream -int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, - ...) { -#else int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp) { -#endif if ((flags & ~TIMER_ABSTIME) != 0) return EINVAL; @@ -39,10 +30,6 @@ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, // Block until polling event is triggered. size_t nevents; __wasi_event_t ev; -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_poll(&sub, &ev, 1, &nevents); -#else __wasi_errno_t error = __wasi_poll_oneoff(&sub, &ev, 1, &nevents); -#endif return error == 0 && ev.error == 0 ? 0 : ENOTSUP; } diff --git a/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c b/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c index 0cba5ac..9ffa1be 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c @@ -6,16 +6,8 @@ #include #include -#ifdef __wasilibc_unmodified_upstream -int nanosleep(const struct timespec *rqtp, ...) { -#else int nanosleep(const struct timespec *rqtp, struct timespec *rem) { -#endif -#ifdef __wasilibc_unmodified_upstream - int error = clock_nanosleep(CLOCK_REALTIME, 0, rqtp); -#else int error = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rem); -#endif if (error != 0) { errno = error; return -1; @@ -23,7 +15,6 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rem) { return 0; } -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) +#if defined(_REENTRANT) __strong_reference(nanosleep, thrd_sleep); -#else #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/time/time.c b/libc-bottom-half/cloudlibc/src/libc/time/time.c index 2c0ba9a..52bc0e4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/time.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/time.c @@ -9,11 +9,7 @@ time_t time(time_t *tloc) { __wasi_timestamp_t ts = 0; -#ifdef __wasilibc_unmodified_upstream - (void)__wasi_clock_time_get(__WASI_CLOCK_REALTIME, NSEC_PER_SEC, &ts); -#else (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts); -#endif if (tloc != NULL) *tloc = ts / NSEC_PER_SEC; return ts / NSEC_PER_SEC; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c index 2c8ee84..2ccecb8 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c @@ -19,21 +19,10 @@ int faccessat(int fd, const char *path, int amode, int flag) { } // Check for target file existence and obtain the file type. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_lookup_t lookup = { - .fd = fd, - .flags = __WASI_LOOKUP_SYMLINK_FOLLOW, - }; -#else __wasi_lookupflags_t lookup_flags = __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; -#endif __wasi_filestat_t file; __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_file_stat_get(lookup, path, strlen(path), &file); -#else __wasi_path_filestat_get(fd, lookup_flags, path, strlen(path), &file); -#endif if (error != 0) { errno = errno_fixup_directory(fd, error); return -1; @@ -43,11 +32,7 @@ int faccessat(int fd, const char *path, int amode, int flag) { // directory file descriptor. if (amode != 0) { __wasi_fdstat_t directory; -#ifdef __wasilibc_unmodified_upstream - error = __wasi_fd_stat_get(fd, &directory); -#else error = __wasi_fd_fdstat_get(fd, &directory); -#endif if (error != 0) { errno = error; return -1; @@ -55,25 +40,11 @@ int faccessat(int fd, const char *path, int amode, int flag) { __wasi_rights_t min = 0; if ((amode & R_OK) != 0) -#ifdef __wasilibc_unmodified_upstream - min |= file.st_filetype == __WASI_FILETYPE_DIRECTORY - ? __WASI_RIGHT_FILE_READDIR - : __WASI_RIGHT_FD_READ; -#else min |= file.filetype == __WASI_FILETYPE_DIRECTORY ? __WASI_RIGHTS_FD_READDIR : __WASI_RIGHTS_FD_READ; -#endif if ((amode & W_OK) != 0) -#ifdef __wasilibc_unmodified_upstream // generated constant names - min |= __WASI_RIGHT_FD_WRITE; -#else min |= __WASI_RIGHTS_FD_WRITE; -#endif -#ifdef __wasilibc_unmodified_upstream // RIGHT_PROC_EXEC - if ((amode & X_OK) != 0 && file.st_filetype != __WASI_FILETYPE_DIRECTORY) - min |= __WASI_RIGHT_PROC_EXEC; -#endif if ((min & directory.fs_rights_inheriting) != min) { errno = EACCES; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c b/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c index c00ccdd..7792597 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c @@ -11,19 +11,9 @@ int ftruncate(int fildes, off_t length) { errno = EINVAL; return -1; } -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_filestat_t fs = { - .st_size = length, - }; -#else __wasi_filesize_t st_size = length; -#endif __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream // fstat - __wasi_file_stat_fput(fildes, &fs, __WASI_FILESTAT_SIZE); -#else __wasi_fd_filestat_set_size(fildes, st_size); -#endif if (error != 0) { errno = error; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c index f0ec72b..eaaf274 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c @@ -12,25 +12,13 @@ int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) { // Create lookup properties. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_lookup_t lookup1 = {.fd = fd1, .flags = 0}; -#else __wasi_lookupflags_t lookup1_flags = 0; -#endif if ((flag & AT_SYMLINK_FOLLOW) != 0) -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - lookup1.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW; -#else lookup1_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; -#endif // Perform system call. -#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t - __wasi_errno_t error = __wasi_file_link(lookup1, path1, strlen(path1), -#else __wasi_errno_t error = __wasi_path_link(fd1, lookup1_flags, path1, strlen(path1), -#endif - fd2, path2, strlen(path2)); + fd2, path2, strlen(path2)); if (error != 0) { errno = errno_fixup_directory(fd1, errno_fixup_directory(fd2, error)); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c b/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c index cb5d995..0dfc49e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c @@ -11,11 +11,7 @@ static_assert(SEEK_CUR == __WASI_WHENCE_CUR, "Value mismatch"); static_assert(SEEK_END == __WASI_WHENCE_END, "Value mismatch"); static_assert(SEEK_SET == __WASI_WHENCE_SET, "Value mismatch"); -#ifdef __wasilibc_unmodified_upstream // Provide an __lseek entry point -off_t lseek(int fildes, off_t offset, int whence) { -#else off_t __lseek(int fildes, off_t offset, int whence) { -#endif __wasi_filesize_t new_offset; __wasi_errno_t error = __wasi_fd_seek(fildes, offset, whence, &new_offset); @@ -26,7 +22,4 @@ off_t __lseek(int fildes, off_t offset, int whence) { return new_offset; } -#ifdef __wasilibc_unmodified_upstream // Provide an __lseek entry point -#else extern __typeof(__lseek) lseek __attribute__((weak, alias("__lseek"))); -#endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c b/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c index 9520867..c9944bc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c @@ -17,17 +17,9 @@ ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset) { __wasi_fd_pread(fildes, &iov, 1, offset, &bytes_read); if (error != 0) { __wasi_fdstat_t fds; -#ifdef __wasilibc_unmodified_upstream - if (error == ENOTCAPABLE && __wasi_fd_stat_get(fildes, &fds) == 0) { -#else if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) { -#endif // Determine why we got ENOTCAPABLE. -#ifdef __wasilibc_unmodified_upstream // generated constant names - if ((fds.fs_rights_base & __WASI_RIGHT_FD_READ) == 0) -#else if ((fds.fs_rights_base & __WASI_RIGHTS_FD_READ) == 0) -#endif error = EBADF; else error = ESPIPE; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c b/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c index 56672e5..f80bc40 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c @@ -17,17 +17,9 @@ ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) { __wasi_fd_pwrite(fildes, &iov, 1, offset, &bytes_written); if (error != 0) { __wasi_fdstat_t fds; -#ifdef __wasilibc_unmodified_upstream - if (error == ENOTCAPABLE && __wasi_fd_stat_get(fildes, &fds) == 0) { -#else if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) { -#endif // Determine why we got ENOTCAPABLE. -#ifdef __wasilibc_unmodified_upstream // generated constant names - if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) == 0) -#else if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) == 0) -#endif error = EBADF; else error = ESPIPE; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c index 1ebffc6..82a9939 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c @@ -12,14 +12,9 @@ ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) { size_t bufused; -#ifdef __wasilibc_unmodified_upstream - __wasi_errno_t error = __wasi_file_readlink(fd, path, strlen(path), - buf, bufsize, &bufused); -#else // TODO: Remove the cast on `buf` once the witx is updated with char8 support. __wasi_errno_t error = __wasi_path_readlink(fd, path, strlen(path), (uint8_t*)buf, bufsize, &bufused); -#endif if (error != 0) { errno = errno_fixup_directory(fd, error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c b/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c index f6a1d89..970287b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c @@ -7,11 +7,7 @@ unsigned int sleep(unsigned int seconds) { struct timespec ts = {.tv_sec = seconds, .tv_nsec = 0}; -#ifdef __wasilibc_unmodified_upstream - if (clock_nanosleep(CLOCK_REALTIME, 0, &ts) != 0) -#else if (clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL) != 0) -#endif return seconds; return 0; } diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c index 9ad06b7..ec7cc94 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c @@ -11,11 +11,7 @@ int symlinkat(const char *path1, int fd, const char *path2) { __wasi_errno_t error = -#ifdef __wasilibc_unmodified_upstream - __wasi_file_symlink(path1, strlen(path1), fd, path2, strlen(path2)); -#else __wasi_path_symlink(path1, strlen(path1), fd, path2, strlen(path2)); -#endif if (error != 0) { errno = errno_fixup_directory(fd, error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c index d970ad1..ea795c2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c @@ -5,31 +5,15 @@ #include #include -#ifdef __wasilibc_unmodified_upstream // unlink -#else #include -#endif #include #include #include #include int unlinkat(int fd, const char *path, int flag) { -#ifdef __wasilibc_unmodified_upstream // unlink - __wasi_ulflags_t ulflags = 0; - if ((flag & AT_REMOVEDIR) != 0) - ulflags |= __WASI_UNLINK_REMOVEDIR; - __wasi_errno_t error = - __wasi_file_unlink(fd, path, strlen(path), ulflags); - if (error != 0) { - errno = errno_fixup_directory(fd, error); - return -1; - } - return 0; -#else if ((flag & AT_REMOVEDIR) != 0) { return __wasilibc_rmdirat(fd, path); } return __wasilibc_unlinkat(fd, path); -#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c b/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c index 51ee5cb..8005f17 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c @@ -9,11 +9,7 @@ int usleep(useconds_t useconds) { struct timespec ts = {.tv_sec = useconds / 1000000, .tv_nsec = useconds % 1000000 * 1000}; -#ifdef __wasilibc_unmodified_upstream - int error = clock_nanosleep(CLOCK_REALTIME, 0, &ts); -#else int error = clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); -#endif if (error != 0) { errno = error; return -1; -- 2.39.5