diff --git a/libc-bottom-half/headers/public/wasi/libc-find-relpath.h b/libc-bottom-half/headers/public/wasi/libc-find-relpath.h index 32dbb035..705ccf6d 100644 --- a/libc-bottom-half/headers/public/wasi/libc-find-relpath.h +++ b/libc-bottom-half/headers/public/wasi/libc-find-relpath.h @@ -57,6 +57,10 @@ int __wasilibc_find_abspath(const char *abspath, * `relative` as a malloc'd buffer that will be `realloc`'d to the appropriate * size to contain the relative path. * + * This used to be a weak function for WASI, but since WASIX has a host-side + * CWD that can be set, we always need this. The rest of this comment block is + * the documentation for the original weak WASI version of it. + * * Note that this is a weak symbol and if it's not defined you can use * `__wasilibc_find_relpath`. The weak-nature of this symbols means that if it's * not otherwise included in the compilation then `chdir` wasn't used an there's @@ -70,7 +74,7 @@ int __wasilibc_find_relpath_alloc( char **relative, size_t *relative_len, int can_realloc -) __attribute__((__weak__)); +); #ifdef __cplusplus } diff --git a/libc-bottom-half/sources/chdir.c b/libc-bottom-half/sources/chdir.c index 87c66a8b..e62a634b 100644 --- a/libc-bottom-half/sources/chdir.c +++ b/libc-bottom-half/sources/chdir.c @@ -197,7 +197,10 @@ int chdir(const char *path) { // we run the legacy chdir function that emulates real // current directory functionality for backwards compatibility reasons - chdir_legacy(path); + if (chdir_legacy(path) != 0) { + // chdir_legacy already sets errno + return -1; + } // otherwise we let the operating system know we are changing the current path __wasi_errno_t error = __wasi_chdir(path); diff --git a/libc-bottom-half/sources/posix.c b/libc-bottom-half/sources/posix.c index 06e9dbe0..3c75a69f 100644 --- a/libc-bottom-half/sources/posix.c +++ b/libc-bottom-half/sources/posix.c @@ -17,11 +17,8 @@ static int find_relpath2( char **relative, size_t *relative_len ) { - // See comments in `preopens.c` for what this trick is doing. const char *abs; - if (__wasilibc_find_relpath_alloc) - return __wasilibc_find_relpath_alloc(path, &abs, relative, relative_len, 1); - return __wasilibc_find_relpath(path, &abs, relative, *relative_len); + return __wasilibc_find_relpath_alloc(path, &abs, relative, relative_len, 1); } // Helper to call `__wasilibc_find_relpath` and return an already-managed diff --git a/libc-bottom-half/sources/preopens.c b/libc-bottom-half/sources/preopens.c index a5daf5f4..991ed44e 100644 --- a/libc-bottom-half/sources/preopens.c +++ b/libc-bottom-half/sources/preopens.c @@ -160,12 +160,7 @@ int __wasilibc_find_relpath(const char *path, const char **abs_prefix, char **relative_path, size_t relative_path_len) { - // If `chdir` is linked, whose object file defines this symbol, then we - // call that. Otherwise if the program can't `chdir` then `path` is - // absolute (or relative to the root dir), so we delegate to `find_abspath` - if (__wasilibc_find_relpath_alloc) - return __wasilibc_find_relpath_alloc(path, abs_prefix, relative_path, &relative_path_len, 0); - return __wasilibc_find_abspath(path, abs_prefix, (const char**) relative_path); + return __wasilibc_find_relpath_alloc(path, abs_prefix, relative_path, &relative_path_len, 0); } // See the documentation in libc-find-relpath.h.