-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.c
194 lines (80 loc) · 1.43 KB
/
lib.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdlib.h"
void * memcpy(void *dst, const void *src, size_t count)
{
int i;
char *d = (char*)dst;
char *s = (char*)src;
for (i=0;i<count;i++)
d[i] = s[i];
return (void*)src;
}
void * memset(void *p, int value, size_t count)
{
int i;
char *ptr = (char*)p;
for (i=0;i<count;i++)
ptr[i] = value;
return p;
}
int tolower(int a)
{
if (a>='A' && a<='Z')
return a-'A'+'a';
return a;
}
int strlen(const char *s)
{
int i;
for (i=0;;i++)
{
if (s[i] == 0)
return i;
}
}
int strcmp(const char *a, const char *b)
{
int i;
for (i=0;;i++)
{
if (a[i] == 0 && b[i] == 0)
return 0;
if (a[i] == 0)
return -1;
if (b[i] == 0)
return 1;
if (a[i]>b[i])
return 1;
if (a[i]<b[i])
return -1;
}
}
int strncasecmp(char *a, char *b, int n)
{
int i;
for (i=0;;i++)
{
char x = tolower(a[i]);
char y = tolower(b[i]);
if (x == 0 && y == 0)
return 0;
if (x == 0)
return -1;
if (y == 0)
return 1;
if (x>y)
return 1;
if (x<y)
return -1;
}
}
char * strchr(const char *a, int b)
{
int i = 0;
for (i=0;;i++)
{
if (a[i]==0)
return NULL;
if (a[i] == b)
return (char*)&a[i];
}
}