6 void *memcpy(void *dest, const void *src, size_t n)
10 const char *sptr = src;
18 void *memmove(void *dest, const void *src, size_t n)
33 dptr = (char*)dest + n - 1;
34 sptr = (const char*)src + n - 1;
43 int memcmp(void *aptr, void *bptr, size_t n)
45 int i, startoffs, diff;
47 unsigned char *a = aptr;
48 unsigned char *b = bptr;
50 a32 = (uint32_t*)((intptr_t)(a + 3) & 0xfffffffc);
51 b32 = (uint32_t*)((intptr_t)(b + 3) & 0xfffffffc);
53 /* if both are aligned the same way... */
54 if((startoffs = (unsigned char*)a32 - a) == (unsigned char*)b32 - b) {
55 /* catch-up to the 32bit alignment */
56 for(i=0; i<startoffs; i++) {
57 if((diff = *a++ - *b++) != 0 || --n <= 0) {
62 /* compare 32bit at once */
64 if(*a32 != *b32) break;
70 /* update byte pointers to contine with the tail */
71 a = (unsigned char*)a32;
72 b = (unsigned char*)b32;
75 /* we're here both for the tail-end of same-alignment buffers, or for the
76 * whole length of mis-aligned buffers.
79 if((diff = *a++ - *b++) != 0) {
86 size_t strlen(const char *s)
93 char *strchr(const char *s, int c)
104 char *strrchr(const char *s, int c)
111 /* go back checking for c */
120 char *strstr(const char *str, const char *substr)
123 const char *s1 = str;
124 const char *s2 = substr;
126 while(*s1 && *s1 == *s2) {
138 char *strcasestr(const char *str, const char *substr)
141 const char *s1 = str;
142 const char *s2 = substr;
144 while(*s1 && tolower(*s1) == tolower(*s2)) {
156 int strcmp(const char *s1, const char *s2)
158 while(*s1 && *s1 == *s2) {
165 int strcasecmp(const char *s1, const char *s2)
167 while(*s1 && tolower(*s1) == tolower(*s2)) {
171 return tolower(*s1) - tolower(*s2);
174 int strncmp(const char *s1, const char *s2, int n)
178 while(n-- > 0 && *s1 && *s2 && *s1 == *s2) {
187 int strncasecmp(const char *s1, const char *s2, int n)
191 while(n-- > 0 && *s1 && *s2 && tolower(*s1) == tolower(*s2)) {
197 return tolower(*s1) - tolower(*s2);
200 char *strcpy(char *dest, const char *src)
203 while((*dptr++ = *src++));
207 char *strcat(char *dest, const char *src)
209 strcpy(dest + strlen(dest), src);
213 char *strncpy(char *dest, const char *src, int n)
216 while(n-- > 0 && (*dptr++ = *src++));