| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
|
| 5 |
/* The header stdlib.h overrides strtoll with strtoll_fallback, hence we need to undef it here. */ |
| 6 |
#undef strtoll |
| 7 |
|
| 8 |
long long strtoll_fallback(const char *nptr, char **endptr, int base) { |
| 9 |
/* glibc returns 0 if the first character is '.' without error, but musl returns as an error. |
| 10 |
* As our code assumes the glibc behavior, let's accept strings start with '.'. */ |
| 11 |
if (nptr && *nptr == '.') { |
| 12 |
if (endptr) |
| 13 |
*endptr = (char*) nptr; |
| 14 |
return 0; |
| 15 |
} |
| 16 |
|
| 17 |
/* Otherwise, use the native strtoll(). */ |
| 18 |
return strtoll(nptr, endptr, base); |
| 19 |
} |