5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/SILC Errno
24 * Error codes and routines for accessing the error codes in case of
25 * error condition. SILC Runtime toolkit contains a global silc_errno
26 * that contains the error code that occurred. Each thread has their own
29 * Each silc_errno error code can be mapped to a string that can be used
30 * to display the error for user. Some routines may also provide detailed
31 * reason why the error occurred. The reason string can be retrieved for
32 * the last error by using silc_errno_reason.
37 * buf = silc_file_readfile(filename, &buf_len, NULL);
39 * fprintf(stderr, "Error reading file %s: %s (%d)", filename,
40 * silc_errno_string(silc_errno), silc_errno);
44 * // Get the detailed reason for the error too
45 * if (silc_some_routine() == FALSE) {
46 * fprintf(stderr, "%s (%d) (%s)", silc_errno_string(silc_errno),
47 * silc_errno, silc_errno_reason);
56 /****d* silcutil/SilcErrnoAPI/SilcResult
60 * typedef enum { ... } SilcResult;
69 SILC_OK = 0, /* Ok, no error */
72 SILC_ERR = 1, /* General error */
73 SILC_ERR_OUT_OF_MEMORY = 2, /* Out of memory */
74 SILC_ERR_ZERO_ALLOCATION = 3, /* Allocation by zero */
75 SILC_ERR_TOO_LARGE_ALLOCATION = 4, /* Too large allocation */
76 SILC_ERR_OVERFLOW = 5, /* Would overflow */
77 SILC_ERR_UNDERFLOW = 6, /* Would underflow */
78 SILC_ERR_NOT_SUPPORTED = 7, /* Feature not supported */
79 SILC_ERR_NOT_PERMITTED = 8, /* Operation not permitted */
80 SILC_ERR_TRY_AGAIN = 9, /* Try again */
81 SILC_ERR_PERMISSION_DENIED = 10, /* Permission denied */
82 SILC_ERR_INVALID_ARGUMENT = 11, /* Invalid argument */
83 SILC_ERR_BAD_TIME = 12, /* Bad time value */
84 SILC_ERR_TIMEOUT = 13, /* Timeout occurred */
85 SILC_ERR_ASSERT = 14, /* Assertion failed */
86 SILC_ERR_NOT_FOUND = 15, /* Item/entry not found */
87 SILC_ERR_UNKNOWN_CHAR = 16, /* Unknown character */
88 SILC_ERR_PROHIBITED_CHAR = 17, /* Prohibited character */
89 SILC_ERR_BAD_CHAR_ENCODING = 18, /* Bad character encoding */
90 SILC_ERR_UNSUPPORTED_CHAR_ENCODING = 19, /* Unsupported char encoding */
91 SILC_ERR_BAD_VERSION = 20, /* Bad/unsupported version */
92 SILC_ERR_BAD_ADDRESS = 21, /* Bad memory address */
93 SILC_ERR_BAD_ENCODING = 22, /* Bad data encoding */
94 SILC_ERR_INTERRUPTED = 23, /* Interrupted */
95 SILC_ERR_NOT_VALID = 24, /* Not valid */
96 SILC_ERR_LIMIT = 25, /* Limit reached */
98 /* File, directory and device errors */
99 SILC_ERR_NO_SUCH_FILE = 40, /* No such file */
100 SILC_ERR_ALREADY_EXISTS = 41, /* File already exists */
101 SILC_ERR_NOT_DIRECTORY = 42, /* Not a directory */
102 SILC_ERR_IS_DIRECTORY = 43, /* Is a directory */
103 SILC_ERR_NOT_EMPTY = 44, /* Directory not empty */
104 SILC_ERR_BUSY = 45, /* Device or resource busy */
105 SILC_ERR_NO_SUCH_DEVICE = 46, /* No such device */
106 SILC_ERR_NO_SPACE_LEFT = 47, /* No space left on device */
107 SILC_ERR_BROKEN_PIPE = 48, /* Broken pipe */
108 SILC_ERR_READ_ONLY = 49, /* Read only */
109 SILC_ERR_IO = 50, /* I/O error */
110 SILC_ERR_BAD_FD = 51, /* Bad file descriptor */
111 SILC_ERR_EOF = 52, /* End of file */
114 SILC_ERR_BAD_IP = 70, /* Bad IP address */
115 SILC_ERR_UNKNOWN_IP = 71, /* Unknown IP address */
116 SILC_ERR_UNKNOWN_HOST = 72, /* Unknown host name */
117 SILC_ERR_UNREACHABLE = 73, /* Destination unreachable */
118 SILC_ERR_REFUSED = 74, /* Connection refused */
119 SILC_ERR_ABORTED = 75, /* Connection aborted */
120 SILC_ERR_RESET = 76, /* Connection reset by peer */
121 SILC_ERR_WOULD_BLOCK = 77, /* Would block */
122 SILC_ERR_HOST_DOWN = 78, /* Host is down */
123 SILC_ERR_BAD_SOCKET = 79, /* Bad socket */
124 SILC_ERR_BAD_STREAM = 80, /* Bad stream */
125 SILC_ERR_ADDR_IN_USE = 81, /* Address already in use */
126 SILC_ERR_NET_DOWN = 82, /* Network is down */
127 SILC_ERR_EOS = 83, /* End of stream */
133 /****d* silcutil/SilcErrnoAPI/silc_errno
137 * SilcResult silc_errno;
141 * Returns the error code of the last error. To map the error code to a
142 * string call silc_errno_string.
145 #define silc_errno silc_get_errno()
147 /****f* silcutil/SilcErrnoAPI/silc_errno_string
151 * const char *silc_errno_string(SilcResult error);
155 * Returns the string of the error `errno'. This routine never returns
159 const char *silc_errno_string(SilcResult error);
161 /****d* silcutil/SilcErrnoAPI/silc_errno_string
165 * const char *silc_errno_reason(void);
169 * Returns additional reason string for the last occurred error or ""
170 * if the additional information is not available. This routine never
174 const char *silc_errno_reason(void);
176 /* Low-level routines for the error handling. */
178 /* Return last error */
179 SilcResult silc_get_errno(void);
182 void silc_set_errno(SilcResult error);
184 /* Set error, cannot fail. */
185 void silc_set_errno_nofail(SilcResult error);
187 /* Set error and reason string. */
188 void silc_set_errno_reason(SilcResult error, const char *format, ...);
190 /* Set error and reason string, cannot fail. */
191 void silc_set_errno_reason_nofail(SilcResult error, const char *format, ...);
193 /* Set error from POSIX errno */
194 void silc_set_errno_posix(int error);
196 #endif /* SILCERRNO_H */