diff --git a/lib/Makefile.am b/lib/Makefile.am index e76e7446a..7eb2ee296 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -176,6 +176,8 @@ libshadow_la_SOURCES = \ spawn.c \ sssd.c \ sssd.h \ + string/ctype/strisascii_c/strisdigit_c.c \ + string/ctype/strisascii_c/strisdigit_c.h \ string/memset/memzero.c \ string/memset/memzero.h \ string/sprintf/snprintf.c \ diff --git a/lib/string/ctype/strisascii_c/strisdigit_c.c b/lib/string/ctype/strisascii_c/strisdigit_c.c new file mode 100644 index 000000000..65562593b --- /dev/null +++ b/lib/string/ctype/strisascii_c/strisdigit_c.c @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "string/ctype/strisascii_c/strisdigit_c.h" + +#include + + +extern inline bool strisdigit_c(const char *s); diff --git a/lib/string/ctype/strisascii_c/strisdigit_c.h b/lib/string/ctype/strisascii_c/strisdigit_c.h new file mode 100644 index 000000000..fe7e496c3 --- /dev/null +++ b/lib/string/ctype/strisascii_c/strisdigit_c.h @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_C_STRISDIGIT_C_H_ +#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_C_STRISDIGIT_C_H_ + + +#include + +#include + +#include "string/strchr/stpspn.h" +#include "string/strcmp/streq.h" + + +inline bool strisdigit_c(const char *s); + + +// Like isdigit(3), +// but check all characters in the string, and use the C locale. +inline bool +strisdigit_c(const char *s) +{ + if (streq(s, "")) + return false; + + return streq(stpspn(s, "0123456789"), ""); +} + + +#endif // include guard