-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathulib.c
67 lines (57 loc) · 1.07 KB
/
ulib.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
extern void panic(const char *message, const char *file, int line)
{
// We encountered a massive problem and have to stop.
asm volatile("cli"); // Disable interrupts.
printf("PANIC(");
printf(message);
printf(") at ");
printf(file);
printf(":");
printf(line);
printf("\n");
// trigger Bochs debug mode (magic instruction)
asm volatile("xchg %bx, %bx");
}
void* memmove(void *dst, const void *src, unsigned int n)
{
const char *s;
char *d;
s = src;
d = dst;
if(s < d && s + n > d){
s += n;
d += n;
while(n-- > 0)
*--d = *--s;
} else
while(n-- > 0)
*d++ = *s++;
return dst;
}
char* strchr(const char *s, char c)
{
printf(0, "strchr: s is %s", s);
for(; *s; s++)
if(*s == c) {
return (char*)s;
}
return 0;
}
int strlen(char *s)
{
int n;
for ( n = 0 ; s[n]>0 ; n++ )
;
return n;
}
char* gets(char *buf, int max)
{
int n, i;
n = read(0, buf, max);
printf(0,"gets: read returned: %d", n);
for(i = 0; i <=n; i++)
if(buf[i] = '\n')
break;
buf[i] = '\0';
return buf;
}