9ffb5ecfd738c94a728b4283e88423c9a881a0fb
[rpikern] / src / libc / string.c
1 #include "string.h"
2
3 void *memset(void *ptr, int val, int size)
4 {
5         unsigned char *p = ptr;
6         while(size--) {
7                 *p++ = val;
8         }
9         return ptr;
10 }
11
12 void *memcpy(void *dest, void *src, int size)
13 {
14         unsigned char *d = dest;
15         unsigned char *s = src;
16         while(size--) {
17                 *d++ = *s++;
18         }
19         return dest;
20 }
21
22 int strcmp(const char *a, const char *b)
23 {
24         while(*a && *a == *b) {
25                 a++;
26                 b++;
27         }
28
29         if(!*a && !*b) return 0;
30
31         if(!*a) return -1;
32         if(!*b) return 1;
33         return *a - *b > 0 ? 1 : -1;
34 }