-
Notifications
You must be signed in to change notification settings - Fork 0
/
errno.c
67 lines (54 loc) · 1.89 KB
/
errno.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
/*
*
* Copyright (C) 2013 eXactLab and GC3, University of Zurich.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Moreno Baricevic <[email protected]>
*/
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#define MAX_KNOWN_STRERROR 132 // 132 found resolved by gnu's "%m" as of 2013-11-02
static int isint ( const register char * string , long int * result );
int main( int argc , char * const * argv )
{
long int i = 0;
if ( argc == 2 )
{
if ( isint( argv[1] , &i ) )
errno = i , printf( "Error code %3d: %m\n" , errno ) , exit(0);
fprintf( stderr , "*** %s: invalid non numerical argument %s\n" , argv[0] , argv[1] );
exit(1);
}
while( ( errno = i++ ) <= MAX_KNOWN_STRERROR )
printf( "Error code %3d: %m\n" , errno );
return 0;
} /* main */
static int isint ( const register char * string , long int * result )
{
int i;
char junk = '\0';
for ( i = 0 ; i < strlen( string ) ; i++ )
if ( ! isdigit( string[i] ) )
return 0;
if ( ( sscanf( string , "%ld%c" , result , &junk ) == 1 ) || junk != '\0' )
return 1;
else
return 0;
} /* isint */
/*********************** E N D O F F I L E ************************/