3 * Copyright (C) 2001 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
22 * Print error code MACRO and messages
24 * Author: Simone Piccardi
27 * Usage: errcode -h give all info's
29 * $Id: ErrCode.c,v 1.4 2001/10/14 15:05:33 piccardi Exp $
31 ****************************************************************/
33 * Include needed headers
35 #include <errno.h> /* error definitions and routines */
36 #include <stdlib.h> /* C standard library */
37 #include <unistd.h> /* unix standard library */
38 #include <stdio.h> /* standard I/O library */
39 #include <string.h> /* string functions */
41 /* Help printing routine */
44 /* Array for code number <=> code macro name */
46 "SUCCESS ", /* 0 Success */
47 "EPERM ", /* 1 Operation not permitted */
48 "ENOENT ", /* 2 No such file or directory */
49 "ESRCH ", /* 3 No such process */
50 "EINTR ", /* 4 Interrupted system call */
51 "EIO ", /* 5 I/O error */
52 "ENXIO ", /* 6 No such device or address */
53 "E2BIG ", /* 7 Arg list too long */
54 "ENOEXEC ", /* 8 Exec format error */
55 "EBADF ", /* 9 Bad file number */
56 "ECHILD ", /* 10 No child processes */
57 "EAGAIN ", /* 11 Try again */
58 "ENOMEM ", /* 12 Out of memory */
59 "EACCES ", /* 13 Permission denied */
60 "EFAULT ", /* 14 Bad address */
61 "ENOTBLK ", /* 15 Block device required */
62 "EBUSY ", /* 16 Device or resource busy */
63 "EEXIST ", /* 17 File exists */
64 "EXDEV ", /* 18 Cross-device link */
65 "ENODEV ", /* 19 No such device */
66 "ENOTDIR ", /* 20 Not a directory */
67 "EISDIR ", /* 21 Is a directory */
68 "EINVAL ", /* 22 Invalid argument */
69 "ENFILE ", /* 23 File table overflow */
70 "EMFILE ", /* 24 Too many open files */
71 "ENOTTY ", /* 25 Not a typewriter */
72 "ETXTBSY ", /* 26 Text file busy */
73 "EFBIG ", /* 27 File too large */
74 "ENOSPC ", /* 28 No space left on device */
75 "ESPIPE ", /* 29 Illegal seek */
76 "EROFS ", /* 30 Read-only file system */
77 "EMLINK ", /* 31 Too many links */
78 "EPIPE ", /* 32 Broken pipe */
79 "EDOM ", /* 33 Math argument out of domain of func */
80 "ERANGE ", /* 34 Math result not representable */
81 "EDEADLK ", /* 35 Resource deadlock would occur */
82 "ENAMETOOLONG ", /* 36 File name too long */
83 "ENOLCK ", /* 37 No record locks available */
84 "ENOSYS ", /* 38 Function not implemented */
85 "ENOTEMPTY ", /* 39 Directory not empty */
86 "ELOOP ", /* 40 Too many symbolic links encountered */
87 "EWOULDBLOCK ", /* EAGAIN Operation would block */
88 "ENOMSG ", /* 42 No message of desired type */
89 "EIDRM ", /* 43 Identifier removed */
90 "ECHRNG ", /* 44 Channel number out of range */
91 "EL2NSYNC ", /* 45 Level 2 not synchronized */
92 "EL3HLT ", /* 46 Level 3 halted */
93 "EL3RST ", /* 47 Level 3 reset */
94 "ELNRNG ", /* 48 Link number out of range */
95 "EUNATCH ", /* 49 Protocol driver not attached */
96 "ENOCSI ", /* 50 No CSI structure available */
97 "EL2HLT ", /* 51 Level 2 halted */
98 "EBADE ", /* 52 Invalid exchange */
99 "EBADR ", /* 53 Invalid request descriptor */
100 "EXFULL ", /* 54 Exchange full */
101 "ENOANO ", /* 55 No anode */
102 "EBADRQC ", /* 56 Invalid request code */
103 "EBADSLT ", /* 57 Invalid slot */
104 "EDEADLOCK ", /* EDEADLK */
105 "EBFONT ", /* 59 Bad font file format */
106 "ENOSTR ", /* 60 Device not a stream */
107 "ENODATA ", /* 61 No data available */
108 "ETIME ", /* 62 Timer expired */
109 "ENOSR ", /* 63 Out of streams resources */
110 "ENONET ", /* 64 Machine is not on the network */
111 "ENOPKG ", /* 65 Package not installed */
112 "EREMOTE ", /* 66 Object is remote */
113 "ENOLINK ", /* 67 Link has been severed */
114 "EADV ", /* 68 Advertise error */
115 "ESRMNT ", /* 69 Srmount error */
116 "ECOMM ", /* 70 Communication error on send */
117 "EPROTO ", /* 71 Protocol error */
118 "EMULTIHOP ", /* 72 Multihop attempted */
119 "EDOTDOT ", /* 73 RFS specific error */
120 "EBADMSG ", /* 74 Not a data message */
121 "EOVERFLOW ", /* 75 Value too large for defined data type */
122 "ENOTUNIQ ", /* 76 Name not unique on network */
123 "EBADFD ", /* 77 File descriptor in bad state */
124 "EREMCHG ", /* 78 Remote address changed */
125 "ELIBACC ", /* 79 Can not access a needed shared library */
126 "ELIBBAD ", /* 80 Accessing a corrupted shared library */
127 "ELIBSCN ", /* 81 .lib section in a.out corrupted */
128 "ELIBMAX ", /* 82 Attempting to link in too many shared libraries */
129 "ELIBEXEC ", /* 83 Cannot exec a shared library directly */
130 "EILSEQ ", /* 84 Illegal byte sequence */
131 "ERESTART ", /* 85 Interrupted system call should be restarted */
132 "ESTRPIPE ", /* 86 Streams pipe error */
133 "EUSERS ", /* 87 Too many users */
134 "ENOTSOCK ", /* 88 Socket operation on non-socket */
135 "EDESTADDRREQ ", /* 89 Destination address required */
136 "EMSGSIZE ", /* 90 Message too long */
137 "EPROTOTYPE ", /* 91 Protocol wrong type for socket */
138 "ENOPROTOOPT ", /* 92 Protocol not available */
139 "EPROTONOSUPPORT", /* 93 Protocol not supported */
140 "ESOCKTNOSUPPORT", /* 94 Socket type not supported */
141 "EOPNOTSUPP ", /* 95 Operation not supported on transport endpoint */
142 "EPFNOSUPPORT ", /* 96 Protocol family not supported */
143 "EAFNOSUPPORT ", /* 97 Address family not supported by protocol */
144 "EADDRINUSE ", /* 98 Address already in use */
145 "EADDRNOTAVAIL ", /* 99 Cannot assign requested address */
146 "ENETDOWN ", /* 100 Network is down */
147 "ENETUNREACH ", /* 101 Network is unreachable */
148 "ENETRESET ", /* 102 Network dropped connection because of reset */
149 "ECONNABORTED ", /* 103 Software caused connection abort */
150 "ECONNRESET ", /* 104 Connection reset by peer */
151 "ENOBUFS ", /* 105 No buffer space available */
152 "EISCONN ", /* 106 Transport endpoint is already connected */
153 "ENOTCONN ", /* 107 Transport endpoint is not connected */
154 "ESHUTDOWN ", /* 108 Cannot send after transport endpoint shutdown */
155 "ETOOMANYREFS ", /* 109 Too many references: cannot splice */
156 "ETIMEDOUT ", /* 110 Connection timed out */
157 "ECONNREFUSED ", /* 111 Connection refused */
158 "EHOSTDOWN ", /* 112 Host is down */
159 "EHOSTUNREACH ", /* 113 No route to host */
160 "EALREADY ", /* 114 Operation already in progress */
161 "EINPROGRESS ", /* 115 Operation now in progress */
162 "ESTALE ", /* 116 Stale NFS file handle */
163 "EUCLEAN ", /* 117 Structure needs cleaning */
164 "ENOTNAM ", /* 118 Not a XENIX named type file */
165 "ENAVAIL ", /* 119 No XENIX semaphores available */
166 "EISNAM ", /* 120 Is a named type file */
167 "EREMOTEIO ", /* 121 Remote I/O error */
168 "EDQUOT ", /* 122 Quota exceeded */
169 "ENOMEDIUM ", /* 123 No medium found */
170 "EMEDIUMTYPE " /* 124 Wrong medium type */
172 int main(int argc, char *argv[])
175 * Variables definition
181 * Input section: decode parameters passed in the calling
182 * Use getopt function
184 opterr = 0; /* don't want writing to stderr */
185 while ( (i = getopt(argc, argv, "hlm")) != -1) {
191 printf("Wrong -h option use\n");
195 case 'l': /* unrecognized options */
196 printf("Label printing\n");
199 case 'm': /* unrecognized options */
200 printf("Message printing\n");
203 case '?': /* unrecognized options */
204 printf("Unrecognized options -%c\n",optopt);
206 default: /* should not reached */
210 /* ***********************************************************
212 * Options processing completed
214 * Main code beginning
216 * ***********************************************************/
217 if (optind == argc) {
220 /* convert string to number */
221 err = strtol(argv[optind], NULL, 10);
222 /* testing error condition on conversion */
224 perror("Underflow on error code");
226 } else if (err==LONG_MIN) {
227 perror("Overflow on error code");
230 /* conversion is fine */
232 printf("Error message for %d is %s\n", err, strerror(err));
235 printf("Error label for %d is %s\n", err, err_code[err]);
237 if ( (!label)&&(!message) ) {
244 * routine to print usage info and exit
247 printf("Print error code message or macro label \n");
249 printf(" daytime [-h] [-l] [-m] error code \n");
250 printf(" -m print error messages\n");
251 printf(" -l print error code label\n");
252 printf(" -h print this help\n");