0
|
1 #include "types.h"
|
|
2 #include "stat.h"
|
|
3 #include "fcntl.h"
|
|
4 #include "user.h"
|
|
5
|
|
6 char*
|
|
7 strcpy(char *s, char *t)
|
|
8 {
|
|
9 char *os;
|
|
10
|
|
11 os = s;
|
|
12 while((*s++ = *t++) != 0)
|
|
13 ;
|
|
14 return os;
|
|
15 }
|
|
16
|
|
17 int
|
|
18 strcmp(const char *p, const char *q)
|
|
19 {
|
|
20 while(*p && *p == *q)
|
|
21 p++, q++;
|
|
22 return (uchar)*p - (uchar)*q;
|
|
23 }
|
|
24
|
|
25 uint
|
|
26 strlen(char *s)
|
|
27 {
|
|
28 int n;
|
|
29
|
|
30 for(n = 0; s[n]; n++)
|
|
31 ;
|
|
32 return n;
|
|
33 }
|
|
34
|
|
35 void*
|
|
36 memset(void *dst, int v, uint n)
|
|
37 {
|
|
38 uint8 *p;
|
|
39 uint8 c;
|
|
40 uint32 val;
|
|
41 uint32 *p4;
|
|
42
|
|
43 p = dst;
|
|
44 c = v & 0xff;
|
|
45 val = (c << 24) | (c << 16) | (c << 8) | c;
|
|
46
|
|
47 // set bytes before whole uint32
|
|
48 for (; (n > 0) && ((uint)p % 4); n--, p++){
|
|
49 *p = c;
|
|
50 }
|
|
51
|
|
52 // set memory 4 bytes a time
|
|
53 p4 = (uint*)p;
|
|
54
|
|
55 for (; n >= 4; n -= 4, p4++) {
|
|
56 *p4 = val;
|
|
57 }
|
|
58
|
|
59 // set leftover one byte a time
|
|
60 p = (uint8*)p4;
|
|
61
|
|
62 for (; n > 0; n--, p++) {
|
|
63 *p = c;
|
|
64 }
|
|
65
|
|
66 return dst;
|
|
67 }
|
|
68
|
|
69 char*
|
|
70 strchr(const char *s, char c)
|
|
71 {
|
|
72 for(; *s; s++)
|
|
73 if(*s == c)
|
|
74 return (char*)s;
|
|
75 return 0;
|
|
76 }
|
|
77
|
|
78 char*
|
|
79 gets(char *buf, int max)
|
|
80 {
|
|
81 int i, cc;
|
|
82 char c;
|
|
83
|
|
84 for(i=0; i+1 < max; ){
|
|
85 cc = read(0, &c, 1);
|
|
86 if(cc < 1)
|
|
87 break;
|
|
88 buf[i++] = c;
|
|
89 if(c == '\n' || c == '\r')
|
|
90 break;
|
|
91 }
|
|
92 buf[i] = '\0';
|
|
93 return buf;
|
|
94 }
|
|
95
|
|
96 int
|
|
97 stat(char *n, struct stat *st)
|
|
98 {
|
|
99 int fd;
|
|
100 int r;
|
|
101
|
|
102 fd = open(n, O_RDONLY);
|
|
103 if(fd < 0)
|
|
104 return -1;
|
|
105 r = fstat(fd, st);
|
|
106 close(fd);
|
|
107 return r;
|
|
108 }
|
|
109
|
|
110 int
|
|
111 atoi(const char *s)
|
|
112 {
|
|
113 int n;
|
|
114
|
|
115 n = 0;
|
|
116 while('0' <= *s && *s <= '9')
|
|
117 n = n*10 + *s++ - '0';
|
|
118 return n;
|
|
119 }
|
|
120
|
|
121 void*
|
|
122 memmove(void *vdst, void *vsrc, int n)
|
|
123 {
|
|
124 char *dst, *src;
|
|
125
|
|
126 dst = vdst;
|
|
127 src = vsrc;
|
|
128 while(n-- > 0)
|
|
129 *dst++ = *src++;
|
|
130 return vdst;
|
|
131 }
|
6
|
132
|
|
133 void
|
|
134 raise()
|
|
135 {}
|