BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 4f75471c50029ee76c328c9413ea055d67cb3ac0 / lib

// Related

Nucleus

Barry File system type object 4f75471 (3 years, 3 months ago)
diff --git a/lib/string.c b/lib/string.c
new file mode 100644
index 0000000..5b9506e
--- /dev/null
+++ b/lib/string.c
@@ -0,0 +1,51 @@
+#include <stddef.h>
+
+/* Compare two strings */
+int
+strcmp(char *s1, char *s2)
+{
+	for (; *s1 == *s2 && *s1 && *s2; s1++, s2++);
+	return *(unsigned char *) s1 - *(unsigned char *) s2;
+}
+
+/* Compare two limited strings */
+int
+strncmp(char *s1, char *s2, size_t n)
+{
+	if (!n--) return 0;
+	for (; *s1 == *s2 && *s1 && *s2 && n; s1++, s2++, n--);
+	return *(unsigned char *) s1 - *(unsigned char *) s2;
+}
+
+/* Copy a string */
+char *
+strcpy(char *dest, const char *src)
+{
+	char *ret = dest;
+	while (*src)
+		*dest++ = *src++;
+	*dest = '\0';
+	return ret;
+}
+
+/* Copy a limited string */
+char *
+strncpy(char *dest, const char *src, size_t n)
+{
+	char *ret = dest;
+	while (*src && n--)
+		*dest++ = *src++;
+	*dest = '\0';
+	return ret;
+}
+
+/* Find length of string */
+size_t
+strlen(const char *str)
+{
+	if (!str)
+		return 0;
+	size_t i;
+	for (i = 0; str[i]; i++);
+	return i;
+}