Actually implement strnlen()
authorH. Peter Anvin <hpa@zytor.com>
Mon, 18 Feb 2008 23:58:01 +0000 (15:58 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 20 Feb 2008 00:51:23 +0000 (16:51 -0800)
Actually implement strnlen(), which was in the header files but not in
the library.

com32/lib/Makefile
com32/lib/strnlen.c [new file with mode: 0644]

index def1729..d8fb30d 100644 (file)
@@ -12,6 +12,7 @@ LIBOBJS = \
        perror.o printf.o puts.o qsort.o realloc.o seed48.o snprintf.o  \
        sprintf.o srand48.o sscanf.o stack.o strcasecmp.o strcat.o      \
        strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o         \
+       strnlen.o                                                       \
        strncasecmp.o strncat.o strncmp.o strncpy.o stpncpy.o strndup.o \
        strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o  \
        strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o    \
diff --git a/com32/lib/strnlen.c b/com32/lib/strnlen.c
new file mode 100644 (file)
index 0000000..d073561
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * strnlen()
+ */
+
+#include <string.h>
+
+size_t strnlen(const char *s, size_t n)
+{
+  const char *ss = s;
+  while ( n-- && *ss )
+    ss++;
+  return ss-s;
+}