blob: 92fdec28c04a64a4d1cbb4eac660eeada1b26a10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include "stdlib.h"
void *memset(void *s, int c, size_t n)
{
char *p = (char *) s;
for (size_t i = 0; i < n; i++, p++)
*p = (char) c;
return s;
}
/* overlap is not handled */
void *memcpy(void *dest, void *src, size_t n)
{
char *s = (char *) src;
char *d = (char *) dest;
for (size_t i = 0; i < n; i++, s++, d++)
*d = *s;
return dest;
}
int strncmp(const char *s1, const char *s2, size_t n)
{
for (size_t i = 0; i < n; i++, s1++, s2++) {
if (*s1 < *s2) return -1;
if (*s1 > *s2) return 1;
}
return 0;
}
|