5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2007 - 2008 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 */
97 SILC_ERR_SYNTAX = 26, /* Syntax error */
99 /* File, directory and device errors */
100 SILC_ERR_NO_SUCH_FILE = 40, /* No such file */
101 SILC_ERR_ALREADY_EXISTS = 41, /* File already exists */
102 SILC_ERR_NOT_DIRECTORY = 42, /* Not a directory */
103 SILC_ERR_IS_DIRECTORY = 43, /* Is a directory */
104 SILC_ERR_NOT_EMPTY = 44, /* Directory not empty */
105 SILC_ERR_BUSY = 45, /* Device or resource busy */
106 SILC_ERR_NO_SUCH_DEVICE = 46, /* No such device */
107 SILC_ERR_NO_SPACE_LEFT = 47, /* No space left on device */
108 SILC_ERR_BROKEN_PIPE = 48, /* Broken pipe */
109 SILC_ERR_READ_ONLY = 49, /* Read only */
110 SILC_ERR_IO = 50, /* I/O error */
111 SILC_ERR_BAD_FD = 51, /* Bad file descriptor */
112 SILC_ERR_EOF = 52, /* End of file */
115 SILC_ERR_BAD_IP = 70, /* Bad IP address */
116 SILC_ERR_UNKNOWN_IP = 71, /* Unknown IP address */
117 SILC_ERR_UNKNOWN_HOST = 72, /* Unknown host name */
118 SILC_ERR_UNREACHABLE = 73, /* Destination unreachable */
119 SILC_ERR_REFUSED = 74, /* Connection refused */
120 SILC_ERR_ABORTED = 75, /* Connection aborted */
121 SILC_ERR_RESET = 76, /* Connection reset by peer */
122 SILC_ERR_WOULD_BLOCK = 77, /* Would block */
123 SILC_ERR_HOST_DOWN = 78, /* Host is down */
124 SILC_ERR_BAD_SOCKET = 79, /* Bad socket */
125 SILC_ERR_BAD_STREAM = 80, /* Bad stream */
126 SILC_ERR_ADDR_IN_USE = 81, /* Address already in use */
127 SILC_ERR_NET_DOWN = 82, /* Network is down */
128 SILC_ERR_EOS = 83, /* End of stream */
130 /* Regular expression errors */
131 SILC_ERR_REGEX_PAREN = 100, /* Unmatched parenthesis */
132 SILC_ERR_REGEX_HEX = 101, /* Bad hex number */
133 SILC_ERR_REGEX_REG = 102, /* Bad register number */
134 SILC_ERR_REGEX_SPECIAL = 103, /* Unmatched special character */
135 SILC_ERR_REGEX_TOO_COMPLEX = 104, /* Too complex expression */
136 SILC_ERR_REGEX_OPCODE = 105, /* Bad regex opcode */
137 SILC_ERR_REGEX_REPEAT = 106, /* Bad repeat value */
143 /****d* silcutil/SilcErrnoAPI/silc_errno
147 * SilcResult silc_errno;
151 * Returns the error code of the last error. To map the error code to a
152 * string call silc_errno_string.
155 #define silc_errno silc_get_errno()
157 /****f* silcutil/SilcErrnoAPI/silc_errno_string
161 * const char *silc_errno_string(SilcResult error);
165 * Returns the string of the error `errno'. This routine never returns
169 const char *silc_errno_string(SilcResult error);
171 /****d* silcutil/SilcErrnoAPI/silc_errno_string
175 * const char *silc_errno_reason(void);
179 * Returns additional reason string for the last occurred error or ""
180 * if the additional information is not available. This routine never
184 const char *silc_errno_reason(void);
186 /* Low-level routines for the error handling. */
188 /* Return last error */
189 SilcResult silc_get_errno(void);
192 void silc_set_errno(SilcResult error);
194 /* Set error, cannot fail. */
195 void silc_set_errno_nofail(SilcResult error);
197 /* Set error and reason string. */
198 void silc_set_errno_reason(SilcResult error, const char *format, ...);
200 /* Set error and reason string, cannot fail. */
201 void silc_set_errno_reason_nofail(SilcResult error, const char *format, ...);
203 /* Set error from POSIX errno */
204 void silc_set_errno_posix(int error);
206 #endif /* SILCERRNO_H */