diff options
| author | Ian C <ianc@noddybox.co.uk> | 2010-11-09 08:32:19 +0000 | 
|---|---|---|
| committer | Ian C <ianc@noddybox.co.uk> | 2010-11-09 08:32:19 +0000 | 
| commit | 07ad92f856c98327f2219a4211516257dcf88f23 (patch) | |
| tree | 00865ebce0a23c3bd7f31e6a851c940f3bd7ad9b /err.c | |
| parent | 8c47b8879a1623d11509b18296a7ba285c01417f (diff) | |
Tidied up err.c
Diffstat (limited to 'err.c')
| -rw-r--r-- | err.c | 55 | 
1 files changed, 37 insertions, 18 deletions
@@ -1,36 +1,55 @@  /* Report Unix errors */ +#include <stdlib.h>  #include <stdio.h> +#include <string.h>  #include <errno.h> -#if 0 -extern int sys_nerr; -extern char *sys_errlist[]; -#endif - -main(argc,argv) -int argc; -char *argv[]; - +int main(int argc, char *argv[])  {      int f,n; +    char *p; -    if (argc==1) -	{ +    if (argc == 1) +    {  	fprintf(stderr,"%s:usage %s -t|err1 [.. errn]\n",argv[0],argv[0]); -	exit(1); -	} +	exit(EXIT_FAILURE); +    }      if (!strcmp(argv[1],"-t")) -	for(f=0;f<sys_nerr;f++) -	    printf("%3d : %s\n",f,sys_errlist[f]); +    { +	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); -	    if(n>=sys_nerr) +	    errno = 0; + +	    p = strerror(n); + +	    if (errno == EINVAL) +	    {  		fprintf(stderr,"%s:errcode %d invalid!\n",argv[0],n); +	    }  	    else -		printf("%3d : %s\n",n,sys_errlist[n]); +	    { +		printf("%3d : %s\n",n,p);  	    } +	} +    } + +    return EXIT_SUCCESS;  }  | 
