6 void *memset(void *s, int c, size_t n)
13 void *memcpy(void *dest, const void *src, size_t n)
16 const char *sptr = src;
17 while(n--) *dptr++ = *sptr++;
21 void *memmove(void *dest, const void *src, size_t n)
36 dptr = (char*)dest + n - 1;
37 sptr = (const char*)src + n - 1;
46 int memcmp(void *aptr, void *bptr, size_t n)
48 int i, startoffs, diff;
50 unsigned char *a = aptr;
51 unsigned char *b = bptr;
53 a32 = (uint32_t*)((intptr_t)(a + 3) & 0xfffffffc);
54 b32 = (uint32_t*)((intptr_t)(b + 3) & 0xfffffffc);
56 /* if both are aligned the same way... */
57 if((startoffs = (unsigned char*)a32 - a) == (unsigned char*)b32 - b) {
58 /* catch-up to the 32bit alignment */
59 for(i=0; i<startoffs; i++) {
60 if((diff = *a++ - *b++) != 0 || --n <= 0) {
65 /* compare 32bit at once */
67 if(*a32 != *b32) break;
73 /* update byte pointers to contine with the tail */
74 a = (unsigned char*)a32;
75 b = (unsigned char*)b32;
78 /* we're here both for the tail-end of same-alignment buffers, or for the
79 * whole length of mis-aligned buffers.
82 if((diff = *a++ - *b++) != 0) {
89 size_t strlen(const char *s)
96 char *strchr(const char *s, int c)
107 char *strrchr(const char *s, int c)
114 /* go back checking for c */
123 char *strstr(const char *str, const char *substr)
126 const char *s1 = str;
127 const char *s2 = substr;
129 while(*s1 && *s1 == *s2) {
141 char *strcasestr(const char *str, const char *substr)
144 const char *s1 = str;
145 const char *s2 = substr;
147 while(*s1 && tolower(*s1) == tolower(*s2)) {
159 int strcmp(const char *s1, const char *s2)
161 while(*s1 && *s1 == *s2) {
168 int strcasecmp(const char *s1, const char *s2)
170 while(*s1 && tolower(*s1) == tolower(*s2)) {
174 return tolower(*s1) - tolower(*s2);
177 int strncmp(const char *s1, const char *s2, int n)
181 while(n-- > 0 && *s1 && *s2 && *s1 == *s2) {
190 int strncasecmp(const char *s1, const char *s2, int n)
194 while(n-- > 0 && *s1 && *s2 && tolower(*s1) == tolower(*s2)) {
200 return tolower(*s1) - tolower(*s2);
203 char *strcpy(char *dest, const char *src)
206 while((*dptr++ = *src++));
210 char *strcat(char *dest, const char *src)
212 strcpy(dest + strlen(dest), src);
216 char *strncpy(char *dest, const char *src, int n)
219 while(n-- > 0 && (*dptr++ = *src++));