From f09abdf6e236198e6dbf7d049dc99534d9f8af01 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 28 Jan 2025 12:52:23 +0100 Subject: Fix a compilation error on C99 Add some ifdef guards around `getlogin_r`. --- include/unistd.h | 4 +++- tests/Makefile | 2 +- tests/test_getlogin_r_dynamic.c | 3 +++ tests/test_getlogin_r_static.c | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index 69095d5..f6d4e87 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -33,7 +33,6 @@ extern "C" { #undef getcwd #undef getgroups #undef gethostname -#undef getlogin_r #undef pread #undef read #undef readlink @@ -109,6 +108,8 @@ _FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) return __orig_gethostname(__s, __l); } +#if _REENTRANT || _POSIX_C_SOURCE >= 199506L +#undef getlogin_r __fh_access(write_only, 1, 2) #if __has_builtin(__builtin_getlogin_r) __diagnose_as_builtin(__builtin_getlogin_r, 1, 2) @@ -121,6 +122,7 @@ _FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) __builtin_trap(); return __orig_getlogin_r(__s, __l); } +#endif #if __has_builtin(__builtin_pread) __diagnose_as_builtin(__builtin_pread, 1, 2, 3, 4) diff --git a/tests/Makefile b/tests/Makefile index a8c7ac5..740fe4d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -150,7 +150,7 @@ RUNTIME_TARGETS= \ .SILENT: -gcc: CC=../x86_64-linux-musl-native/bin/gcc +gcc: CC=../aarch64-linux-musl-native/bin/gcc gcc: $(RUNTIME_TARGETS) clang: CC=clang diff --git a/tests/test_getlogin_r_dynamic.c b/tests/test_getlogin_r_dynamic.c index 33156ee..b1e66f7 100644 --- a/tests/test_getlogin_r_dynamic.c +++ b/tests/test_getlogin_r_dynamic.c @@ -3,6 +3,7 @@ #include int main(int argc, char** argv) { +#if _REENTRANT || _POSIX_C_SOURCE >= 199506L char buffer[8] = {0}; getlogin_r(buffer, 6); @@ -13,4 +14,6 @@ int main(int argc, char** argv) { puts(buffer); return ret; +#endif + return 0; } diff --git a/tests/test_getlogin_r_static.c b/tests/test_getlogin_r_static.c index 64f76c5..52638b9 100644 --- a/tests/test_getlogin_r_static.c +++ b/tests/test_getlogin_r_static.c @@ -3,6 +3,7 @@ #include int main(int argc, char** argv) { +#if _REENTRANT || _POSIX_C_SOURCE >= 199506L char buffer[12] = {0}; getlogin_r(buffer, 10); @@ -13,4 +14,6 @@ int main(int argc, char** argv) { puts(buffer); return ret; +#endif + return 0; } -- cgit v1.3