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
|
/* Report Unix errors */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
int f,n;
char *p;
if (argc == 1)
{
fprintf(stderr,"%s:usage %s -t|err1 [.. errn]\n",argv[0],argv[0]);
exit(EXIT_FAILURE);
}
if (!strcmp(argv[1],"-t"))
{
errno = 0;
for(f = 0; errno != EINVAL && f < 256; f++)
{
errno = 0;
p = strerror(f);
if (errno != EINVAL)
{
printf("%3d : %s\n",f,p);
}
}
}
else
{
for(f=1;f<argc;f++)
{
n=strtol(argv[f],(char **)NULL,0);
errno = 0;
p = strerror(n);
if (errno == EINVAL)
{
fprintf(stderr,"%s:errcode %d invalid!\n",argv[0],n);
}
else
{
printf("%3d : %s\n",n,p);
}
}
}
return EXIT_SUCCESS;
}
|