On Mon, 2003-11-24 at 11:36, Martin Hicks wrote:> Hi,
>
> Here are some new library functions for klibc. Some of them are
> required for udev, which currently has a klibc_fixups.c file that
> implements these functions.
Crap. My mail client mangled that one...
here it is again.
mh
--
Martin Hicks Wild Open Source Inc.
mort@wildopensource.com 613-266-2296
# This is a BitKeeper generated patch for the following project:
# Project Name: The kernel C library
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.247 -> 1.248
# klibc/Makefile 1.102 -> 1.103
# klibc/include/string.h 1.8 -> 1.9
# (new) -> 1.1 klibc/strncasecmp.c
# (new) -> 1.1 klibc/strcasecmp.c
# (new) -> 1.1 klibc/strndup.c
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/11/24 mort@green.i.bork.org 1.248
# Add a few new library functions:
# -strcasecmp
# -strncasecmp
# -strndup
# -Enable strerror() in the Makefile. It was already there, but it wasn't
being compiled.
# --------------------------------------------
#
diff -Nru a/klibc/Makefile b/klibc/Makefile
--- a/klibc/Makefile Mon Nov 24 11:33:52 2003
+++ b/klibc/Makefile Mon Nov 24 11:33:52 2003
@@ -27,6 +27,7 @@
brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
memmove.o \
+ strcasecmp.o strncasecmp.o strndup.o strerror.o \
strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o \
strncat.o strstr.o strncmp.o strncpy.o strrchr.o strspn.o \
strsep.o strtok.o \
diff -Nru a/klibc/include/string.h b/klibc/include/string.h
--- a/klibc/include/string.h Mon Nov 24 11:33:52 2003
+++ b/klibc/include/string.h Mon Nov 24 11:33:52 2003
@@ -16,12 +16,15 @@
__extern void *memset(void *, int, size_t);
__extern void *memmem(const void *, size_t, const void *, size_t);
__extern void memswap(void *, void *, size_t);
+__extern int strcasecmp(const char *, const char *);
+__extern int strncasecmp(const char *, const char *, size_t);
__extern char *strcat(char *, const char *);
__extern char *strchr(const char *, int);
__extern int strcmp(const char *, const char *);
__extern char *strcpy(char *, const char *);
__extern size_t strcspn(const char *, const char *);
__extern char *strdup(const char *);
+__extern char *strndup(const char *, size_t);
__extern char *strerror(int);
__extern size_t strlen(const char *);
__extern char *strncat(char *, const char *, size_t);
diff -Nru a/klibc/strcasecmp.c b/klibc/strcasecmp.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/klibc/strcasecmp.c Mon Nov 24 11:33:52 2003
@@ -0,0 +1,25 @@
+/*
+ * strcasecmp.c
+ *
+ */
+
+#include <string.h>
+#include <ctype.h>
+
+int strcasecmp(const char *s1, const char *s2)
+{
+ char *n1, *n2;
+ int i, retval;
+
+ n1 = strdup(s1);
+ n2 = strdup(s2);
+
+ for (i = 0; i < strlen(n1); i++)
+ n1[i] = toupper(n1[i]);
+ for (i = 0; i < strlen(n2); i++)
+ n2[i] = toupper(n2[i]);
+ retval = strcmp(n1, n2);
+ free(n1);
+ free(n2);
+ return retval;
+}
diff -Nru a/klibc/strncasecmp.c b/klibc/strncasecmp.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/klibc/strncasecmp.c Mon Nov 24 11:33:52 2003
@@ -0,0 +1,24 @@
+/*
+ * strncasecmp.c
+ */
+
+#include <string.h>
+#include <ctype.h>
+
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ char *n1, *n2;
+ int i, retval;
+
+ n1 = strndup(s1, n);
+ n2 = strndup(s2, n);
+
+ for (i = 0; i < strlen(n1); i++)
+ n1[i] = toupper(n1[i]);
+ for (i = 0; i < strlen(n2); i++)
+ n2[i] = toupper(n2[i]);
+ retval = strcmp(n1, n2);
+ free(n1);
+ free(n2);
+ return retval;
+}
diff -Nru a/klibc/strndup.c b/klibc/strndup.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/klibc/strndup.c Mon Nov 24 11:33:52 2003
@@ -0,0 +1,17 @@
+/*
+ * strndup.c
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+char *strndup(const char *s, size_t n)
+{
+ int l = n > strlen(s) ? strlen(s)+1 : n+1;
+ char *d = malloc(l);
+
+ if (d)
+ memcpy(d, s, l);
+ d[n] = '\0';
+ return d;
+}