-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibc.c
59 lines (46 loc) · 1008 Bytes
/
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
/*
* libc.c
*/
#include <libc.h>
#include <types.h>
int errno;
//int write(int fd, char *buffer, int size);
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(void){
switch (errno) {
case 1: write(1, EPERM_msg, sizeof(EPERM_msg)); break;
case 3: write(1, ESRCH_msg, sizeof(ESRCH_msg)); break;
case 9: write(1, EBADF_msg, sizeof(EBADF_msg)); break;
case 11: write(1, EAGAIN_msg, sizeof(EAGAIN_msg)); break;
case 12: write(1, ENOMEM_msg, sizeof(ENOMEM_msg)); break;
case 14: write(1, EFAULT_msg, sizeof(EFAULT_msg)); break;
case 16: write(1, EBUSY_msg, sizeof(EBUSY_msg)); break;
case 22: write(1, EINVAL_msg, sizeof(EINVAL_msg)); break;
}
}