summaryrefslogtreecommitdiff
path: root/src/strfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/strfuncs.c')
-rw-r--r--src/strfuncs.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/strfuncs.c b/src/strfuncs.c
new file mode 100644
index 0000000..08b43b2
--- /dev/null
+++ b/src/strfuncs.c
@@ -0,0 +1,37 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "strfuncs.h"
+
+char *strdup(const char *s)
+{
+ size_t len = strlen(s);
+ char *new = malloc(len + 1);
+ if (!new)
+ return 0;
+ memcpy(new, s, len);
+ new[len] = '\0';
+ return new;
+}
+
+char *strndup(const char *s, size_t n)
+{
+ size_t len = strlen(s);
+ if (n < len)
+ len = n;
+ char *new = malloc(len + 1);
+ if (!new)
+ return 0;
+ memcpy(new, s, len);
+ new[len] = '\0';
+ return new;
+}
+
+int strcasecmp(const char *s1, const char *s2)
+{
+ int i;
+ while ((i = tolower(*s1)) && i == tolower(*s2))
+ s1++, s2++;
+ return ((unsigned char) tolower(*s1) - (unsigned char) tolower(*s2));
+}