diff --git a/cutils.c b/cutils.c index 5ad14eba8..65f23d077 100644 --- a/cutils.c +++ b/cutils.c @@ -1282,7 +1282,7 @@ int js_exepath(char *buffer, size_t *size) { return 0; } -#elif defined(__linux__) +#elif defined(__linux__) || defined(__GNU__) int js_exepath(char *buffer, size_t *size) { ssize_t n; diff --git a/cutils.h b/cutils.h index 50fee11a1..ec1fa886a 100644 --- a/cutils.h +++ b/cutils.h @@ -43,7 +43,7 @@ extern "C" { #endif #if defined(__APPLE__) #include -#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) +#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) || defined(__GLIBC__) #include #elif defined(__FreeBSD__) #include @@ -586,7 +586,7 @@ static inline size_t js__malloc_usable_size(const void *ptr) return malloc_size(ptr); #elif defined(_WIN32) return _msize((void *)ptr); -#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) || defined(__FreeBSD__) +#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__GLIBC__) return malloc_usable_size((void *)ptr); #else return 0; diff --git a/quickjs-libc.c b/quickjs-libc.c index d08ff7f74..1c49ecb55 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -728,7 +728,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val, bool use_realpath, bool is_main) { JSModuleDef *m; - char buf[PATH_MAX + 16]; + char buf[JS__PATH_MAX + 16]; JSValue meta_obj; JSAtom module_name_atom; const char *module_name; @@ -1321,7 +1321,7 @@ static JSValue js_std_file_tell(JSContext *ctx, JSValueConst this_val, int64_t pos; if (!f) return JS_EXCEPTION; -#if defined(__linux__) +#if defined(__linux__) || defined(__GLIBC__) pos = ftello(f); #else pos = ftell(f); @@ -1344,7 +1344,7 @@ static JSValue js_std_file_seek(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; if (JS_ToInt32(ctx, &whence, argv[1])) return JS_EXCEPTION; -#if defined(__linux__) +#if defined(__linux__) || defined(__GLIBC__) ret = fseeko(f, pos, whence); #else ret = fseek(f, pos, whence); @@ -2756,7 +2756,7 @@ static JSValue make_string_error(JSContext *ctx, static JSValue js_os_getcwd(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - char buf[PATH_MAX]; + char buf[JS__PATH_MAX]; int err; if (!getcwd(buf, sizeof(buf))) { @@ -3039,7 +3039,7 @@ static JSValue js_os_realpath(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { const char *path; - char buf[PATH_MAX], *res; + char buf[JS__PATH_MAX], *res; int err; path = JS_ToCString(ctx, argv[0]); @@ -3083,7 +3083,7 @@ static JSValue js_os_readlink(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { const char *path; - char buf[PATH_MAX]; + char buf[JS__PATH_MAX]; int err; ssize_t res; @@ -3165,7 +3165,7 @@ static char **build_envp(JSContext *ctx, JSValue obj) static int my_execvpe(const char *filename, char **argv, char **envp) { char *path, *p, *p_next, *p1; - char buf[PATH_MAX]; + char buf[JS__PATH_MAX]; size_t filename_len, path_len; bool eacces_error; @@ -3192,7 +3192,7 @@ static int my_execvpe(const char *filename, char **argv, char **envp) path_len = p1 - p; } /* path too long */ - if ((path_len + 1 + filename_len + 1) > PATH_MAX) + if ((path_len + 1 + filename_len + 1) > JS__PATH_MAX) continue; memcpy(buf, p, path_len); buf[path_len] = '/'; @@ -4029,6 +4029,8 @@ void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt)) #define OS_PLATFORM "freebsd" #elif defined(__wasi__) #define OS_PLATFORM "wasi" +#elif defined(__GNU__) +#define OS_PLATFORM "hurd" #else #define OS_PLATFORM "unknown" #endif