string.c (618B)
1 #include "string.h" 2 3 void * 4 memset(void *dst, int v, size_t len) 5 { 6 unsigned char *dst0; 7 8 dst0 = dst; 9 while (len--) 10 *dst0++ = v; 11 return dst; 12 } 13 14 void * 15 memcpy(void *dst, const void *src, size_t len) 16 { 17 const unsigned char *src0; 18 unsigned char *dst0; 19 20 src0 = src; 21 dst0 = dst; 22 23 while (len--) 24 *dst0++ = *src0++; 25 return dst; 26 } 27 28 size_t 29 strlen(const char *str) 30 { 31 const char *s; 32 33 for (s = str; *s != '\0'; s++) 34 ; 35 return (s - str); 36 } 37 38 int 39 strcmp(const char *s1, const char *s2) 40 { 41 while (*s1 == *s2++) 42 if (*s1++ == '\0') 43 return 0; 44 return *(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1); 45 }