Usermode/libc - Changes to get NASM/irssi/bash ... compiling
[tpg/acess2.git] / Usermode / Libraries / libc.so_src / string.c
index 1c05236..86ecb6f 100644 (file)
@@ -5,6 +5,7 @@
 #include <acess/sys.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <ctype.h>
 #include "lib.h"
 
 /**
@@ -32,6 +33,25 @@ EXPORT int strncmp(const char *s1, const char *s2, size_t n)
        return (int)*s1 - (int)*s2;
 }
 
+EXPORT int strcasecmp(const char *s1, const char *s2)
+{
+        int    rv;
+       while( (rv = toupper(*s1) - toupper(*s2)) == 0 && *s1 != '\0' && *s2 != '\0' ) {
+               s1++; s2++;
+       }
+       return rv;
+}
+
+EXPORT int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+        int    rv = 0;
+       if( n == 0 )    return 0;
+       while(n -- && (rv = toupper(*s1) - toupper(*s2)) == 0 && *s1 != '\0' && *s2 != '\0') {
+               s1++; s2++;
+       }
+       return rv;
+}
+
 /**
  * \fn EXPORT char *strcpy(char *dst, const char *src)
  * \brief Copy a string to another
@@ -253,3 +273,31 @@ EXPORT void *memchr(const void *ptr, int value, size_t num)
        }
        return NULL;
 }
+
+EXPORT size_t strcspn(const char *haystack, const char *reject)
+{
+       size_t  ret = 0;
+        int    i;
+       while( *haystack )
+       {
+               for( i = 0; reject[i] && reject[i] == *haystack; i ++ );
+
+               if( reject[i] ) return ret;
+               ret ++;
+       }
+       return ret;
+}
+
+EXPORT size_t strspn(const char *haystack, const char *accept)
+{
+       size_t  ret = 0;
+        int    i;
+       while( *haystack )
+       {
+               for( i = 0; accept[i] && accept[i] == *haystack; i ++ );
+
+               if( !accept[i] )        return ret;
+               ret ++;
+       }
+       return ret;
+}

UCC git Repository :: git.ucc.asn.au