Skip to content

Commit 8045c65

Browse files
committed
Re-enable _LARGEFILE64_SOURCE when _GNU_SOURCE is defined
When we updated to the latest version of musl it broke some codebases that were using LFS functions (e.g. `stat64`) and assuming those functions would be defined when `_GNU_SOURCE` is defined. See bminor/musl@25e6fee This change effectively reverts the above one by defining _LARGEFILE64_SOURCE whenever _GNU_SOURCE is defined. This is what glibc does: https://github.com/lattera/glibc/blob/895ef79e04a953cac1493863bcae29ad85657ee1/include/features.h#L206
1 parent 10d156e commit 8045c65

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

system/lib/libc/musl/include/features.h

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
#define _XOPEN_SOURCE 700
1717
#endif
1818

19+
#if defined(__EMSCRIPTEN__) && defined(_GNU_SOURCE)
20+
// In emscripten the LFS functions are kept around when _GNU_SOURCE is
21+
// defined, for increased compatabiliy. This is also what glibc does.
22+
#undef _LARGEFILE64_SOURCE
23+
#define _LARGEFILE64_SOURCE 1
24+
#endif
25+
1926
#if __STDC_VERSION__ >= 199901L
2027
#define __restrict restrict
2128
#elif !defined(__GNUC__)

test/stat/test_stat.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* found in the LICENSE file.
66
*/
77

8+
// For LFS functions (e.g. stat64)
9+
#define _GNU_SOURCE 1
10+
811
#include <assert.h>
912
#include <dirent.h>
1013
#include <errno.h>
@@ -60,6 +63,12 @@ void test() {
6063
assert(err == -1);
6164
assert(errno == ENOENT);
6265

66+
// test stat64 LFS functions
67+
struct stat64 s64;
68+
err = stat("does_not_exist", &s64);
69+
assert(err == -1);
70+
assert(errno == ENOENT);
71+
6372
// stat a folder
6473
memset(&s, 0, sizeof(s));
6574
err = stat("folder", &s);
@@ -208,7 +217,7 @@ void test() {
208217
);
209218

210219
symlink("folder/file", "folder/symlinkfile");
211-
220+
212221
EM_ASM(
213222
var linkStats = FS.lstat("folder/symlinkfile");
214223
assert(linkStats.dev == 1);
@@ -224,7 +233,7 @@ void test() {
224233
assert(linkStats.atime);
225234
assert(linkStats.mtime);
226235
assert(linkStats.ctime);
227-
236+
228237
var ex;
229238
try {
230239
FS.stat("nonexistent");

0 commit comments

Comments
 (0)