diff --git a/system/lib/libc/musl/include/features.h b/system/lib/libc/musl/include/features.h index 85cfb72a0d42..952ffd968592 100644 --- a/system/lib/libc/musl/include/features.h +++ b/system/lib/libc/musl/include/features.h @@ -16,6 +16,13 @@ #define _XOPEN_SOURCE 700 #endif +#if defined(__EMSCRIPTEN__) && defined(_GNU_SOURCE) +// In emscripten the LFS functions are kept around when _GNU_SOURCE is +// defined, for increased compatabiliy. This is also what glibc does. +#undef _LARGEFILE64_SOURCE +#define _LARGEFILE64_SOURCE 1 +#endif + #if __STDC_VERSION__ >= 199901L #define __restrict restrict #elif !defined(__GNUC__) diff --git a/test/stat/test_stat.c b/test/stat/test_stat.c index d5b2bd9d6362..d1c3a07650cc 100644 --- a/test/stat/test_stat.c +++ b/test/stat/test_stat.c @@ -5,6 +5,9 @@ * found in the LICENSE file. */ +// For LFS functions (e.g. stat64) +#define _GNU_SOURCE 1 + #include #include #include @@ -60,6 +63,12 @@ void test() { assert(err == -1); assert(errno == ENOENT); + // test stat64 LFS functions + struct stat64 s64; + err = stat("does_not_exist", &s64); + assert(err == -1); + assert(errno == ENOENT); + // stat a folder memset(&s, 0, sizeof(s)); err = stat("folder", &s); @@ -208,7 +217,7 @@ void test() { ); symlink("folder/file", "folder/symlinkfile"); - + EM_ASM( var linkStats = FS.lstat("folder/symlinkfile"); assert(linkStats.dev == 1); @@ -224,7 +233,7 @@ void test() { assert(linkStats.atime); assert(linkStats.mtime); assert(linkStats.ctime); - + var ex; try { FS.stat("nonexistent");