]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/ctype/strtoascii/: strtolower(): Add API
authorAlejandro Colomar <alx@kernel.org>
Mon, 17 Feb 2025 11:26:41 +0000 (12:26 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 30 May 2025 20:32:09 +0000 (15:32 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/ctype/strtoascii/strtolower.c [new file with mode: 0644]
lib/string/ctype/strtoascii/strtolower.h [new file with mode: 0644]

index 0c0284a9b1390c0dc7756b7d21db0306e6c76c4f..279971bdabd48f539009c33e559d28c9382febe6 100644 (file)
@@ -183,6 +183,8 @@ libshadow_la_SOURCES = \
        sssd.h \
        string/ctype/strisascii/strisdigit.c \
        string/ctype/strisascii/strisdigit.h \
+       string/ctype/strtoascii/strtolower.c \
+       string/ctype/strtoascii/strtolower.h \
        string/memset/memzero.c \
        string/memset/memzero.h \
        string/sprintf/snprintf.c \
diff --git a/lib/string/ctype/strtoascii/strtolower.c b/lib/string/ctype/strtoascii/strtolower.c
new file mode 100644 (file)
index 0000000..b46e19a
--- /dev/null
@@ -0,0 +1,10 @@
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "string/ctype/strtoascii/strtolower.h"
+
+
+extern inline char *strtolower(char *str);
diff --git a/lib/string/ctype/strtoascii/strtolower.h b/lib/string/ctype/strtoascii/strtolower.h
new file mode 100644 (file)
index 0000000..a19e851
--- /dev/null
@@ -0,0 +1,34 @@
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRTOASCII_STRTOLOWER_H_
+#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRTOASCII_STRTOLOWER_H_
+
+
+#include <config.h>
+
+#include <ctype.h>
+
+#include "string/strcmp/streq.h"
+
+
+inline char *strtolower(char *str);
+
+
+// string convert-to lower-case
+// Like tolower(3), but convert all characters in the string.
+// Returns the input pointer.
+inline char *
+strtolower(char *str)
+{
+       for (char *s = str; !streq(s, ""); s++) {
+               unsigned char  c = *s;
+
+               *s = tolower(c);
+       }
+       return str;
+}
+
+
+#endif  // include guard