summaryrefslogtreecommitdiff
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
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]>
-rw-r--r--src/include/toxic/string.h4
-rw-r--r--src/lib/string.c16
2 files changed, 20 insertions, 0 deletions
diff --git a/src/include/toxic/string.h b/src/include/toxic/string.h
index 69d8bd2..3cb4a30 100644
--- a/src/include/toxic/string.h
+++ b/src/include/toxic/string.h
@@ -3,7 +3,11 @@
#include <stddef.h>
+#define NULL ((void *)0)
+
+bool isdigit(char c);
size_t strlen(const char *s);
+size_t strnlen(const char *s, size_t maxlen);
char *strcpy(char *restrict dst, const char *restrict src);
void *memset(void *s, int c, size_t n);
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;