libc.c (998B)
1#include "vof.h" 2 3int strlen(const char *s) 4{ 5 int len = 0; 6 7 while (*s != 0) { 8 len += 1; 9 s += 1; 10 } 11 12 return len; 13} 14 15int strcmp(const char *s1, const char *s2) 16{ 17 while (*s1 != 0 && *s2 != 0) { 18 if (*s1 != *s2) { 19 break; 20 } 21 s1 += 1; 22 s2 += 1; 23 } 24 25 return *s1 - *s2; 26} 27 28void *memcpy(void *dest, const void *src, size_t n) 29{ 30 char *cdest; 31 const char *csrc = src; 32 33 cdest = dest; 34 while (n-- > 0) { 35 *cdest++ = *csrc++; 36 } 37 38 return dest; 39} 40 41int memcmp(const void *ptr1, const void *ptr2, size_t n) 42{ 43 const unsigned char *p1 = ptr1; 44 const unsigned char *p2 = ptr2; 45 46 while (n-- > 0) { 47 if (*p1 != *p2) { 48 return *p1 - *p2; 49 } 50 p1 += 1; 51 p2 += 1; 52 } 53 54 return 0; 55} 56 57void *memset(void *dest, int c, size_t size) 58{ 59 unsigned char *d = (unsigned char *)dest; 60 61 while (size-- > 0) { 62 *d++ = (unsigned char)c; 63 } 64 65 return dest; 66}