#include <acess/sys.h>
#include <stdlib.h>
#include <stdio.h>
+#include <ctype.h>
#include "lib.h"
/**
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
}
/**
- * \fn EXPORT int strlen(const char *str)
* \brief Get the length of a string
*/
-EXPORT int strlen(const char *str)
+EXPORT size_t strlen(const char *str)
{
- int retval;
- for(retval = 0; *str != '\0'; str++)
- retval++;
+ size_t retval;
+ for(retval = 0; *str != '\0'; str++, retval++);
return retval;
}
+/**
+ * \brief Get the length of a string, with a maximum of \a maxlen
+ *
+ * Gets the length of a string (excluding the terminating \0 byte)
+ */
+EXPORT size_t strnlen(const char *str, size_t maxlen)
+{
+ size_t len;
+ for( len = 0; maxlen -- && *str; str ++, len ++ );
+ return len;
+}
+
/**
* \fn EXPORT char *strdup(const char *str)
* \brief Duplicate a string using heap memory
}
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;
+}