|
41 | 41 | #include <cstdio>
|
42 | 42 | #include <cstdlib>
|
43 | 43 | #include <cstring>
|
44 |
| -#if defined(__CYGWIN__) || defined(_WIN32) || defined(__HAIKU__) |
| 44 | +#if defined(__OpenBSD__) || defined(__ANDROID__) || defined(__linux__) || defined(__wasi__) |
| 45 | +#include <locale.h> |
| 46 | +#elif defined(__CYGWIN__) || defined(__HAIKU__) || defined(_WIN32) |
45 | 47 | #include <sstream>
|
46 | 48 | #include <cmath>
|
47 |
| -#elif defined(__OpenBSD__) |
48 |
| -#include <locale.h> |
49 |
| - |
50 |
| -static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) { |
51 |
| - return strtod(nptr, endptr); |
52 |
| -} |
53 |
| - |
54 |
| -static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) { |
55 |
| - return strtof(nptr, endptr); |
56 |
| -} |
57 |
| - |
58 |
| -static long double swift_strtold_l(const char *nptr, char **endptr, |
59 |
| - locale_t loc) { |
60 |
| - return strtold(nptr, endptr); |
61 |
| -} |
62 |
| - |
63 |
| -#define strtod_l swift_strtod_l |
64 |
| -#define strtof_l swift_strtof_l |
65 |
| -#define strtold_l swift_strtold_l |
66 |
| -#elif defined(__ANDROID__) |
67 |
| -#include <locale.h> |
68 |
| - |
69 |
| -#include <android/api-level.h> |
70 |
| - |
71 |
| -#if __ANDROID_API__ < 21 // Introduced in Android API 21 - L |
72 |
| -static inline long double swift_strtold_l(const char *nptr, char **endptr, |
73 |
| - locale_t) { |
74 |
| - return strtod(nptr, endptr); |
75 |
| -} |
76 |
| -#define strtold_l swift_strtold_l |
77 |
| -#endif |
78 |
| - |
79 |
| -#if __ANDROID_API__ < 26 // Introduced in Android API 26 - O |
80 |
| -static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) { |
81 |
| - return strtod(nptr, endptr); |
82 |
| -} |
83 |
| -static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) { |
84 |
| - return strtof(nptr, endptr); |
85 |
| -} |
86 |
| -#define strtod_l swift_strtod_l |
87 |
| -#define strtof_l swift_strtof_l |
88 |
| -#endif |
89 |
| -#elif defined(__linux__) || defined(__wasi__) |
90 |
| -#include <locale.h> |
91 | 49 | #else
|
92 | 50 | #include <xlocale.h>
|
93 | 51 | #endif
|
94 | 52 | #include <limits>
|
95 | 53 | #include <thread>
|
| 54 | + |
| 55 | +#if defined(__ANDROID__) |
| 56 | +#include <android/api-level.h> |
| 57 | +#endif |
| 58 | + |
96 | 59 | #include "swift/Runtime/Debug.h"
|
97 | 60 | #include "swift/Runtime/SwiftDtoa.h"
|
98 | 61 | #include "swift/Basic/Lazy.h"
|
@@ -388,6 +351,44 @@ static bool swift_stringIsSignalingNaN(const char *nptr) {
|
388 | 351 | return strcasecmp(nptr, "snan") == 0;
|
389 | 352 | }
|
390 | 353 |
|
| 354 | +#if defined(__OpenBSD__) |
| 355 | +static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) { |
| 356 | + return strtod(nptr, endptr); |
| 357 | +} |
| 358 | + |
| 359 | +static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) { |
| 360 | + return strtof(nptr, endptr); |
| 361 | +} |
| 362 | + |
| 363 | +static long double swift_strtold_l(const char *nptr, char **endptr, |
| 364 | + locale_t loc) { |
| 365 | + return strtold(nptr, endptr); |
| 366 | +} |
| 367 | + |
| 368 | +#define strtod_l swift_strtod_l |
| 369 | +#define strtof_l swift_strtof_l |
| 370 | +#define strtold_l swift_strtold_l |
| 371 | +#elif defined(__ANDROID__) |
| 372 | +#if __ANDROID_API__ < 21 // Introduced in Android API 21 - L |
| 373 | +static inline long double swift_strtold_l(const char *nptr, char **endptr, |
| 374 | + locale_t) { |
| 375 | + return strtod(nptr, endptr); |
| 376 | +} |
| 377 | +#define strtold_l swift_strtold_l |
| 378 | +#endif |
| 379 | + |
| 380 | +#if __ANDROID_API__ < 26 // Introduced in Android API 26 - O |
| 381 | +static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) { |
| 382 | + return strtod(nptr, endptr); |
| 383 | +} |
| 384 | +static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) { |
| 385 | + return strtof(nptr, endptr); |
| 386 | +} |
| 387 | +#define strtod_l swift_strtod_l |
| 388 | +#define strtof_l swift_strtof_l |
| 389 | +#endif |
| 390 | +#endif |
| 391 | + |
391 | 392 | #if defined(__CYGWIN__) || defined(_WIN32) || defined(__HAIKU__)
|
392 | 393 | // Cygwin does not support uselocale(), but we can use the locale feature
|
393 | 394 | // in stringstream object.
|
|
0 commit comments