-
Notifications
You must be signed in to change notification settings - Fork 0
/
_clib.c
66 lines (50 loc) · 1.07 KB
/
_clib.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// clib-mimic
#include "_clib.h"
void _strcpy(char *d,const char *s)
{
for (; *s!=0; ++s, ++d) *d=*s;
*d=0;
}
void _strcat(char *d,const char *s)
{
for (; *d!=0; ++d) ;
for (; *s!=0; ++s, ++d) *d=*s;
*d=0;
}
void _strncpy(char *d,const char *s,int n)
{
for (; *s!=0 && n>0; ++s, ++d, --n) *d=*s;
*d=0;
}
char *_strchr(const char *_s, int c)
{
char *s=(char *)_s;
for (; *s!=0; s++) {
if (*s==(char)c) return s;
}
return NULL;
}
unsigned int _strlen(const char *s)
{
unsigned int r=0;
for (; *s!=0; ++s, ++r) ;
return r;
}
void _memset(void *d, const long s, unsigned long n)
{
for (; n>0; n--) *(((char *)d)++)=s;
}
int _memcmp(const void *s1, const void *s2, unsigned long n)
{
for (; n>0; n--) {
if (*(((unsigned char *)s1))>*(((unsigned char *)s2))) return 1;
if (*(((unsigned char *)s1)++)<*(((unsigned char *)s2)++)) return -1;
}
return 0;
}
void _memcpy(void *d, const void *s, unsigned long n)
{
for (; n>0; n--) {
(*(((unsigned char *)d)++)=*(((unsigned char *)s)++));
}
}