Skip to content

Commit

Permalink
Re-enable _LARGEFILE64_SOURCE when _GNU_SOURCE is defined
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbc100 committed Aug 30, 2023
1 parent 10d156e commit 8045c65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions system/lib/libc/musl/include/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
13 changes: 11 additions & 2 deletions test/stat/test_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* found in the LICENSE file.
*/

// For LFS functions (e.g. stat64)
#define _GNU_SOURCE 1

#include <assert.h>
#include <dirent.h>
#include <errno.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -208,7 +217,7 @@ void test() {
);

symlink("folder/file", "folder/symlinkfile");

EM_ASM(
var linkStats = FS.lstat("folder/symlinkfile");
assert(linkStats.dev == 1);
Expand All @@ -224,7 +233,7 @@ void test() {
assert(linkStats.atime);
assert(linkStats.mtime);
assert(linkStats.ctime);

var ex;
try {
FS.stat("nonexistent");
Expand Down

0 comments on commit 8045c65

Please sign in to comment.