Skip to content

Commit aa2a7f4

Browse files
[libc++] Fix the locale base API on Linux with musl (#167980)
This pull request addresses an issue encountered when building **libcxx** with certain configurations (`-D_LIBCPP_HAS_MUSL_LIBC` & `-D__linux__`) that lack the `_GNU_SOURCE` definition. Specifically, this issue arises if the system **musl libc** is built with `_BSD_SOURCE` instead of `_GNU_SOURCE`. The resultant configuration leads to problems with the "Strtonum functions" in the file [libcxx/include/__locale_dir/support/linux.h](https://github.com/llvm/llvm-project/tree/master/libcxx/include/__locale_dir/support/linux.h), affecting the following functions: - `__strtof` - `__strtod` - `__strtold` **Error messages displayed include**: ```console error: no member named 'strtof_l' in the global namespace ``` ```console error: no member named 'strtod_l' in the global namespace ``` ```console error: no member named 'strtold_l' in the global namespace ``` For more insight, relevant code can be accessed [here](https://github.com/llvm/llvm-project/blob/79cd1b7a25cdbf42c7234999ae9bc51db30af1f0/libcxx/include/__locale_dir/support/linux.h#L85-L95).
1 parent 583fba3 commit aa2a7f4

File tree

1 file changed

+15
-0
lines changed
  • libcxx/include/__locale_dir/support

1 file changed

+15
-0
lines changed

libcxx/include/__locale_dir/support/linux.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,30 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
8383
// Strtonum functions
8484
//
8585
inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
86+
#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
8687
return ::strtof_l(__nptr, __endptr, __loc);
88+
#else
89+
(void)__loc;
90+
return ::strtof(__nptr, __endptr);
91+
#endif
8792
}
8893

8994
inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
95+
#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
9096
return ::strtod_l(__nptr, __endptr, __loc);
97+
#else
98+
(void)__loc;
99+
return ::strtod(__nptr, __endptr);
100+
#endif
91101
}
92102

93103
inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
104+
#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
94105
return ::strtold_l(__nptr, __endptr, __loc);
106+
#else
107+
(void)__loc;
108+
return ::strtold(__nptr, __endptr);
109+
#endif
95110
}
96111

97112
//

0 commit comments

Comments
 (0)