-extern char *__errlist[];
-extern char *__error_txt;
-
/**
* This bit indicates whether a number is considered a system error number
* If yes, the system errno is just the result of clearing this bit from
assert(num > 0 && _errno > 0);
return ERRNO_TO_ERROR(_errno) == num;
}
-
-/**
- * version of strerror(3).
- *
- * \param num The error number.
- *
- * \return The error text of \a num.
- */
-static inline char *error_txt(int num)
-{
- assert(num > 0);
- if (IS_SYSTEM_ERROR(num))
- return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
- else
- return __errlist[num];
-}
-
-#define ALL_ERRORS \
- _ERROR(SUCCESS, "success") \
- _ERROR(BAD_DB_DIR, "invalid database directory") \
- _ERROR(NO_COLUMN_DESC, "missing column description") \
- _ERROR(BAD_NAME, "invalid name for a column/table") \
- _ERROR(BAD_STORAGE_TYPE, "invalid storage type") \
- _ERROR(BAD_STORAGE_FLAGS, "invalid storage flags") \
- _ERROR(NO_COLUMN_NAME, "missing column name") \
- _ERROR(NO_COLUMNS, "at least one column required") \
- _ERROR(BAD_COLUMN_NAME, "invalid name for a table column") \
- _ERROR(NO_UNIQUE_RBTREE_COLUMN, "need at least one mapped column with OSL_UNIQE and OSL_RBTREE") \
- _ERROR(NO_RBTREE_COL, "at least one column needs an rbtree") \
- _ERROR(DUPLICATE_COL_NAME, "column name given twice") \
- _ERROR(BAD_STORAGE_SIZE, "invalid storage size") \
- _ERROR(NO_COMPARE_FUNC, "missing compare function") \
- _ERROR(BAD_DATA_SIZE, "wrong data size for fixed-size column") \
- _ERROR(NOT_MAPPED, "file not mapped") \
- _ERROR(ALREADY_MAPPED, "file already mapped") \
- _ERROR(BAD_SIZE, "invalid size specified") \
- _ERROR(TRUNC, "failed to truncate file") \
- _ERROR(BAD_TABLE, "table not open") \
- _ERROR(BAD_TABLE_DESC, "invalid table description") \
- _ERROR(RB_KEY_EXISTS, "key already exists in rbtree") \
- _ERROR(RB_KEY_NOT_FOUND, "key not found in rbtree") \
- _ERROR(BAD_ROW_NUM, "invalid row number") \
- _ERROR(INDEX_CORRUPTION, "index corruption detected") \
- _ERROR(INVALID_OBJECT, "reference to invalid object") \
- _ERROR(STAT, "can not stat file") \
- _ERROR(WRITE, "write error") \
- _ERROR(LSEEK, "lseek error") \
- _ERROR(BUSY, "table is busy") \
- _ERROR(SHORT_TABLE, "table too short") \
- _ERROR(NO_MAGIC, "missing table header magic") \
- _ERROR(VERSION_MISMATCH, "table version not supported") \
- _ERROR(BAD_COLUMN_NUM, "invalid column number") \
- _ERROR(BAD_TABLE_FLAGS, "invalid flags in table description") \
- _ERROR(BAD_ROW, "invalid row") \
- _ERROR(EMPTY, "file empty") \
- _ERROR(MMAP, "mmap error") \
-
-
-/**
- * This is temporarily defined to expand to its first argument (prefixed by
- * 'E_') and gets later redefined to expand to the error text only
- */
-#define _ERROR(err, msg) E_ ## err,
-
-enum error_codes {
- ALL_ERRORS
-};
-#undef _ERROR
-#define _ERROR(err, msg) msg,
-#define DEFINE_ERRLIST char *__errlist[] = {ALL_ERRORS}
#include "log.h"
+#include "osl.h"
#include "error.h"
#include "fd.h"
#include "list.h"
return p;
}
+/* Taken from Drepper: How to write shared libraries, Appendix B. */
+#include <stddef.h>
+#define MSGSTRFIELD(line) MSGSTRFIELD1(line)
+#define MSGSTRFIELD1(line) str##line
+static const union msgstr_t {
+ struct {
+#define _S(n, s) char MSGSTRFIELD(__LINE__)[sizeof(s)];
+#include "errtab.h"
+#undef _S
+ };
+ char str[0];
+} msgstr = { {
+#define _S(n, s) s,
+#include "errtab.h"
+#undef _S
+} };
+static const unsigned int errmsgidx[] = {
+#define _S(n, s) [n] = offsetof(union msgstr_t, MSGSTRFIELD(__LINE__)),
+#include "errtab.h"
+#undef _S
+};
+__export const char *osl_strerror(int num)
+{
+ if (IS_SYSTEM_ERROR(num))
+ return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
+ return msgstr.str + errmsgidx[num];
+}
+
/**
* The log function.
*