-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibc.c
76 lines (62 loc) · 1.01 KB
/
libc.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
/*
* libc.c
*/
#include <libc.h>
#include <errno.h>
#include <types.h>
int errno;
void itoa(int a, char *b)
{
int i, i1;
char c;
if (a==0) { b[0]='0'; b[1]=0; return ;}
i=0;
while (a>0)
{
b[i]=(a%10)+'0';
a=a/10;
i++;
}
for (i1=0; i1<i/2; i1++)
{
c=b[i1];
b[i1]=b[i-i1-1];
b[i-i1-1]=c;
}
b[i]=0;
}
int strlen(char *a)
{
int i;
i=0;
while (a[i]!=0) i++;
return i;
}
void perror()
{
char buff[3];
switch(errno)
{
case ENOSYS:
write(1, "Syscall not implemented\n", 24);
break;
case EFAULT:
write(1, "Bad address\n", 12);
break;
case EINVAL:
write(1, "Invalid argument\n", 17);
break;
case EACCES:
write(1, "Permission denied\n", 18);
break;
case EBADF:
write(1, "Bad file number\n", 16);
break;
default:
itoa(errno, buff);
write(1, "Message for error ", 18);
write(1, buff, strlen (buff));
write(1, " not found\n", 11);
break;
}
}