File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 27
27
#include <string.h>
28
28
#include <unistd.h>
29
29
#include <limits.h>
30
+ #include <locale.h> // Make C locale for strerror_l()
30
31
#include <errno.h>
31
32
#include <math.h>
32
33
#include <time.h>
@@ -175,14 +176,26 @@ INLINE int us_flock_timedwait_monotonic(int fd, ldf timeout) {
175
176
}
176
177
177
178
INLINE char * us_errno_to_string (int error ) {
179
+ # if (_POSIX_C_SOURCE >= 200112L ) && !defined(_GNU_SOURCE ) // XSI
178
180
char buf [2048 ];
179
181
const uz max_len = sizeof (buf ) - 1 ;
180
- # if (_POSIX_C_SOURCE >= 200112L ) && ! _GNU_SOURCE
181
182
if (strerror_r (error , buf , max_len ) != 0 ) {
182
183
US_SNPRINTF (buf , max_len , "Errno = %d" , error );
183
184
}
184
185
return us_strdup (buf );
185
- # else
186
+
187
+ # elif defined(__GLIBC__ ) && defined(_GNU_SOURCE ) // GNU
188
+ char buf [2048 ];
189
+ const uz max_len = sizeof (buf ) - 1 ;
186
190
return us_strdup (strerror_r (error , buf , max_len ));
191
+
192
+ # else // BSD
193
+ locale_t locale = newlocale (LC_MESSAGES_MASK , "C" , NULL );
194
+ if (locale ) {
195
+ char * ptr = us_strdup (strerror_l (error , locale ));
196
+ freelocale (locale );
197
+ return ptr ;
198
+ }
199
+ return us_strdup ("!!! newlocale() error !!!" );
187
200
# endif
188
201
}
You can’t perform that action at this time.
0 commit comments