mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
musl: make strtoll() accept strings start with dot
glibc accepts strings start with '.' and returns 0, but musl refuses them. Let's accept them, as our code assumes the function accept such strings.
This commit is contained in:
7
src/include/musl/stdlib.h
Normal file
7
src/include/musl/stdlib.h
Normal file
@@ -0,0 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include_next <stdlib.h>
|
||||
|
||||
long long strtoll_fallback(const char *nptr, char **endptr, int base);
|
||||
#define strtoll strtoll_fallback
|
||||
@@ -6,5 +6,6 @@ endif
|
||||
|
||||
libc_wrapper_sources += files(
|
||||
'stdio.c',
|
||||
'stdlib.c',
|
||||
'string.c',
|
||||
)
|
||||
|
||||
19
src/libc/musl/stdlib.c
Normal file
19
src/libc/musl/stdlib.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* The header stdlib.h overrides strtoll with strtoll_fallback, hence we need to undef it here. */
|
||||
#undef strtoll
|
||||
|
||||
long long strtoll_fallback(const char *nptr, char **endptr, int base) {
|
||||
/* glibc returns 0 if the first character is '.' without error, but musl returns as an error.
|
||||
* As our code assumes the glibc behavior, let's accept strings start with '.'. */
|
||||
if (nptr && *nptr == '.') {
|
||||
if (endptr)
|
||||
*endptr = (char*) nptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Otherwise, use the native strtoll(). */
|
||||
return strtoll(nptr, endptr, base);
|
||||
}
|
||||
Reference in New Issue
Block a user