#include <malloc.h>
-#ifndef __HAVE_ARCH_STRNICMP
+#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */
/**
* strnicmp - Case insensitive, length-limited string comparison
* @s1: One string
{
const char *p = s + strlen(s);
do {
- if (*p == (char)c)
- return (char *)p;
+ if (*p == (char)c)
+ return (char *)p;
} while (--p >= s);
return NULL;
}
#ifndef __HAVE_ARCH_STRSPN
/**
* strspn - Calculate the length of the initial substring of @s which only
- * contain letters in @accept
+ * contain letters in @accept
* @s: The string to be searched
* @accept: The string to search for
*/
}
#endif
+#ifndef __HAVE_ARCH_STRSWAB
+/**
+ * strswab - swap adjacent even and odd bytes in %NUL-terminated string
+ * s: address of the string
+ *
+ * returns the address of the swapped string or NULL on error. If
+ * string length is odd, last byte is untouched.
+ */
+char *strswab(const char *s)
+{
+ char *p, *q;
+
+ if ((NULL == s) || ('\0' == *s)) {
+ return (NULL);
+ }
+
+ for (p=(char *)s, q=p+1; (*p != '\0') && (*q != '\0'); p+=2, q+=2) {
+ char tmp;
+
+ tmp = *p;
+ *p = *q;
+ *q = tmp;
+ }
+
+ return (char *) s;
+}
+#endif
+
#ifndef __HAVE_ARCH_MEMSET
/**
* memset - Fill a region of memory with the given value
*/
void * memset(void * s,int c,size_t count)
{
- char *xs = (char *) s;
-
+ unsigned long *sl = (unsigned long *) s;
+ unsigned long cl = 0;
+ char *s8;
+ int i;
+
+ /* do it one word at a time (32 bits or 64 bits) while possible */
+ if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
+ for (i = 0; i < sizeof(*sl); i++) {
+ cl <<= 8;
+ cl |= c & 0xff;
+ }
+ while (count >= sizeof(*sl)) {
+ *sl++ = cl;
+ count -= sizeof(*sl);
+ }
+ }
+ /* fill 8 bits at a time */
+ s8 = (char *)sl;
while (count--)
- *xs++ = c;
+ *s8++ = c;
return s;
}
* You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead.
*/
-void * memcpy(void * dest,const void *src,size_t count)
+void * memcpy(void *dest, const void *src, size_t count)
{
- char *tmp = (char *) dest, *s = (char *) src;
-
+ unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
+ char *d8, *s8;
+
+ /* while all data is aligned (common case), copy a word at a time */
+ if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
+ while (count >= sizeof(*dl)) {
+ *dl++ = *sl++;
+ count -= sizeof(*dl);
+ }
+ }
+ /* copy the reset one byte at a time */
+ d8 = (char *)dl;
+ s8 = (char *)sl;
while (count--)
- *tmp++ = *s++;
+ *d8++ = *s8++;
return dest;
}
p++;
size--;
}
- return (void *) p;
+ return (void *) p;
}
#endif
{
const unsigned char *p = s;
while (n-- != 0) {
- if ((unsigned char)c == *p++) {
+ if ((unsigned char)c == *p++) {
return (void *)(p-1);
}
}