mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.6 KiB

# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
#
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
#
# ROCK Linux: rock-src/package/base/dietlibc/strnlen.patch
# ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
#
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
#
# --- ROCK-COPYRIGHT-NOTE-END ---
--- /dev/null Thu Jan 1 00:00:00 1970
+++ ./lib/strnlen.c Fri Jan 10 23:54:35 2003
@@ -0,0 +1,57 @@
+#include <endian.h>
+#include "dietfeatures.h"
+#include <string.h>
+
+#ifdef WANT_SMALL_STRING_ROUTINES
+size_t strnlen(const char *s, size_t maxlen) {
+ register size_t i;
+ if (!maxlen) return 0;
+ if (!s) return 0;
+ for (i=0; *s && i<maxlen; ++s) ++i;
+ return i;
+}
+#else
+static const unsigned long magic = 0x01010101;
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *t = s;
+ const char *u = s + maxlen;
+ unsigned long word;
+
+ if (!s) return 0;
+
+ /* Byte compare up until word boundary */
+ for (; ((unsigned long) t & 3); t++)
+ if (!*t) {
+ if (t>u) t = u;
+ return t - s;
+ }
+
+ /* Word compare */
+ do {
+ if (t>u) return maxlen;
+ word = *((unsigned long *) t); t += 4;
+ word = (word - magic) &~ word;
+ word &= (magic << 7);
+ } while (word == 0);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* word & 0x80808080 == word */
+ word = (word - 1) & (magic << 10);
+ word += (word << 8) + (word << 16);
+ t += word >> 26;
+#else
+ if ((word & 0x80800000) == 0) {
+ word <<= 16;
+ t += 2;
+ }
+ if ((word & 0x80000000) == 0) t += 1;
+#endif
+ if (t-4 > u) {
+ return maxlen;
+ } else {
+ return ((const char *) t) - 4 - s;
+ }
+}
+#endif
--- ./include/string.h~ Mon Jul 8 20:30:53 2002
+++ ./include/string.h Sat Jan 11 00:03:10 2003
@@ -35,6 +35,7 @@
int strncasecmp(const char *s1, const char *s2, size_t n) __THROW __pure__;
size_t strlen(const char *s) __THROW __pure__;
+size_t strnlen(const char *s, size_t maxlen) __THROW __pure__;
char *strstr(const char *haystack, const char *needle) __THROW __pure__;