summaryrefslogtreecommitdiff
path: root/src/lib/string.c
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2026-02-28 12:48:48 +0100
committerCarlos Maiolino <[email protected]>2026-02-28 13:11:41 +0100
commit7b3f6a5a507a59b613998ef9ad2f14252d993d42 (patch)
treea9cf5c8a1ab84fbd55e38d75ed01d3f5efb4b3f6 /src/lib/string.c
parent50905cb31b16d39a9e9e640b9e5978826a03f920 (diff)
add strnlen and isdigit helpers
This is missing and will come in handy for path parsing. Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'src/lib/string.c')
-rw-r--r--src/lib/string.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/string.c b/src/lib/string.c
index e5b6972..365381b 100644
--- a/src/lib/string.c
+++ b/src/lib/string.c
@@ -1,4 +1,10 @@
#include <stddef.h>
+#include <stdbool.h>
+
+bool isdigit(char c)
+{
+ return c >= 48 && c <= 57;
+}
size_t strlen(const char *s)
{
@@ -10,6 +16,16 @@ size_t strlen(const char *s)
return c;
}
+size_t strnlen(const char *s, size_t maxlen)
+{
+ size_t c = 0;
+
+ while (c <= maxlen && s[c])
+ c++;
+
+ return c;
+}
+
char *strcpy(char *restrict dst, const char *restrict src)
{
size_t pos = 0;