return 0;
}
+
+//
+// Lame implementation just for use by strcasecmp/strncasecmp
+//
+static int
+tolower(unsigned char ch)
+{
+ if (ch >= 'A' && ch <= 'Z')
+ ch = 'a' + (ch - 'A');
+
+ return ch;
+}
+
+int
+strcasecmp(const char *s1, const char *s2)
+{
+ const unsigned char *us1 = (const u_char *)s1,
+ *us2 = (const u_char *)s2;
+
+ while (tolower(*us1) == tolower(*us2++))
+ if (*us1++ == '\0')
+ return (0);
+ return (tolower(*us1) - tolower(*--us2));
+}
+
+int
+strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ if (n != 0) {
+ const unsigned char *us1 = (const u_char *)s1,
+ *us2 = (const u_char *)s2;
+
+ do {
+ if (tolower(*us1) != tolower(*us2++))
+ return (tolower(*us1) - tolower(*--us2));
+ if (*us1++ == '\0')
+ break;
+ } while (--n != 0);
+ }
+ return (0);
+}
+
+
/*
* Abstract:
* strcpy copies the contents of the string "from" including
return (os1);
}
-
-#if !defined(__alpha)
-
-/*
- * Abstract:
- * strlen returns the number of characters in "string" preceeding
- * the terminating null character.
- */
-
-size_t
-strlen(
- register const char *string)
-{
- register const char *ret = string;
-
- while (*string++ != '\0')
- continue;
- return string - 1 - ret;
-}
-#endif /* !defined(__alpha) */
-
/*
* atoi:
*
return(f? -n: n);
}
+/*
+ * Does the same thing as strlen, except only looks up
+ * to max chars inside the buffer.
+ * Taken from archive/kern-stuff/sbf_machine.c in
+ * seatbelt.
+ * inputs:
+ * s string whose length is to be measured
+ * max maximum length of string to search for null
+ * outputs:
+ * length of s or max; whichever is smaller
+ */
+size_t
+strnlen(const char *s, size_t max) {
+ const char *es = s + max, *p = s;
+ while(*p && p != es)
+ p++;
+
+ return p - s;
+}
+
+
+
/*
* convert an integer to an ASCII string.
* inputs: