Do not export para_lseek() and para_write_file().
[osl.git] / error.h
1 extern char *__errlist[];
2 extern char *__error_txt;
3
4 /**
5  * This bit indicates whether a number is considered a system error number
6  * If yes, the system errno is just the result of clearing this bit from
7  * the given number.
8  */
9 #define SYSTEM_ERROR_BIT 30
10
11 /** Check whether the system error bit is set. */
12 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
13
14 /** Set the system error bit for the given number. */
15 #define ERRNO_TO_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
16
17 /**
18  * Check whether a given number is a system error number.
19  *
20  * \param num The value to be checked.
21  * \param _errno The system error number.
22  *
23  * \return True if \a num is the representation of the system
24  * error identified by \a _errno.
25  */
26 static inline int is_errno(int num, int _errno)
27 {
28         assert(num > 0 && _errno > 0);
29         return ERRNO_TO_ERROR(_errno) == num;
30 }
31
32 /**
33  * version of strerror(3).
34  *
35  * \param num The error number.
36  *
37  * \return The error text of \a num.
38  */
39 static inline char *error_txt(int num)
40 {
41         assert(num > 0);
42         if (IS_SYSTEM_ERROR(num))
43                 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
44         else
45                 return __errlist[num];
46 }
47
48 #define ALL_ERRORS \
49         _ERROR(SUCCESS, "success") \
50         _ERROR(BAD_DB_DIR, "invalid database directory") \
51         _ERROR(NO_COLUMN_DESC, "missing column description") \
52         _ERROR(BAD_NAME, "invalid name for a column/table") \
53         _ERROR(BAD_STORAGE_TYPE, "invalid storage type") \
54         _ERROR(BAD_STORAGE_FLAGS, "invalid storage flags") \
55         _ERROR(NO_COLUMN_NAME, "missing column name") \
56         _ERROR(NO_COLUMNS, "at least one column required") \
57         _ERROR(BAD_COLUMN_NAME, "invalid name for a table column") \
58         _ERROR(NO_UNIQUE_RBTREE_COLUMN, "need at least one mapped column with OSL_UNIQE and OSL_RBTREE") \
59         _ERROR(NO_RBTREE_COL, "at least one column needs an rbtree") \
60         _ERROR(DUPLICATE_COL_NAME, "column name given twice") \
61         _ERROR(BAD_STORAGE_SIZE, "invalid storage size") \
62         _ERROR(NO_COMPARE_FUNC, "missing compare function") \
63         _ERROR(BAD_DATA_SIZE, "wrong data size for fixed-size column") \
64         _ERROR(NOT_MAPPED, "file not mapped") \
65         _ERROR(ALREADY_MAPPED, "file already mapped") \
66         _ERROR(BAD_SIZE, "invalid size specified") \
67         _ERROR(TRUNC, "failed to truncate file") \
68         _ERROR(BAD_TABLE, "table not open") \
69         _ERROR(BAD_TABLE_DESC, "invalid table description") \
70         _ERROR(RB_KEY_EXISTS, "key already exists in rbtree") \
71         _ERROR(RB_KEY_NOT_FOUND, "key not found in rbtree") \
72         _ERROR(BAD_ROW_NUM, "invalid row number") \
73         _ERROR(INDEX_CORRUPTION, "index corruption detected") \
74         _ERROR(INVALID_OBJECT, "reference to invalid object") \
75         _ERROR(STAT, "can not stat file") \
76         _ERROR(WRITE, "write error") \
77         _ERROR(LSEEK, "lseek error") \
78         _ERROR(BUSY, "table is busy") \
79         _ERROR(SHORT_TABLE, "table too short") \
80         _ERROR(NO_MAGIC, "missing table header magic") \
81         _ERROR(VERSION_MISMATCH, "table version not supported") \
82         _ERROR(BAD_COLUMN_NUM, "invalid column number") \
83         _ERROR(BAD_TABLE_FLAGS, "invalid flags in table description") \
84         _ERROR(BAD_ROW, "invalid row") \
85         _ERROR(EMPTY, "file empty") \
86         _ERROR(MMAP, "mmap error") \
87
88
89 /**
90  * This is temporarily defined to expand to its first argument (prefixed by
91  * 'E_') and gets later redefined to expand to the error text only
92  */
93 #define _ERROR(err, msg) E_ ## err,
94
95 enum error_codes {
96         ALL_ERRORS
97 };
98 #undef _ERROR
99 #define _ERROR(err, msg) msg,
100 #define DEFINE_ERRLIST char *__errlist[] = {ALL_ERRORS}