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