]> git.tuebingen.mpg.de Git - osl.git/commitdiff
Switch to the new error code handling.
authorAndre Noll <maan@systemlinux.org>
Sat, 31 May 2008 14:17:27 +0000 (16:17 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 31 May 2008 14:17:27 +0000 (16:17 +0200)
error.h
fd.c
osl.c
osl.h.in
osl_core.h

diff --git a/error.h b/error.h
index e311807668b4a47d7e5ab65ad3dc3b54de72ee73..5652e9a4556241ab4d9090f7e6797b2c0fdf2001 100644 (file)
--- a/error.h
+++ b/error.h
@@ -1,6 +1,3 @@
-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
@@ -28,73 +25,3 @@ static inline int is_errno(int num, int _errno)
        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}
diff --git a/fd.c b/fd.c
index b0089d3051c0676d4171bcc80c6ed15338e73f2e..13708ac64f3e4b490703408dd371fcd504eb5f43 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -13,6 +13,7 @@
 #include <sys/select.h>
 
 #include "log.h"
+#include "osl.h"
 #include "error.h"
 
 /**
@@ -197,14 +198,14 @@ int mmap_full_file(const char *path, int open_mode, void **map,
                goto out;
        }
        *size = file_status.st_size;
-       ret = -E_EMPTY;
+       ret = -E_OSL_EMPTY;
        DEBUG_LOG("%s: size %zu\n", path, *size);
        if (!*size)
                goto out;
        *map = mmap(NULL, *size, mmap_prot, mmap_flags, fd, 0);
        if (*map == MAP_FAILED) {
                *map = NULL;
-               ret = -E_MMAP;
+               ret = -E_OSL_MMAP;
                goto out;
        }
        ret = 1;
diff --git a/osl.c b/osl.c
index 957e9a7edefa7fb7ebda9ab2eff424482fcc4d77..cce01aac4dc7c7fc6be09d47f274e12a5e0209fb 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -10,6 +10,7 @@
 
 
 #include "log.h"
+#include "osl.h"
 #include "error.h"
 #include "fd.h"
 #include "list.h"
@@ -60,6 +61,34 @@ static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ..
        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.
  *
index 8c386c7bcd809d4053128b0943a98b2c90eaa66f..a586be293ac228382fc7413b508539bc425a2808 100644 (file)
--- a/osl.h.in
+++ b/osl.h.in
@@ -178,3 +178,4 @@ int osl_get_nth_row(const struct osl_table *t, unsigned col_num,
        unsigned n, struct osl_row **result);
 int osl_get_rank(const struct osl_table *t, struct osl_row *r,
        unsigned col_num, unsigned *rank);
+const char *osl_strerror(int nr);
index b6d1f8222878de726dfadeced976fc1f9c99799f..a6342f8e74db1aa5174e0bfea2a6e128de1b8add 100644 (file)
@@ -7,7 +7,6 @@
 /** \file osl_core.h Object storage layer details, not visible to users. */
 
 #include "rbtree.h"
-#include "osl.h"
 #include "hash.h"
 
 static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...);
@@ -261,7 +260,7 @@ _static_inline_ int get_row_index(const struct osl_table *t, uint32_t row_num,
        index_offset = t->index_header_size + t->row_index_size * row_num;
        if (index_offset + 8 > t->index_map.size) {
                *row_index = NULL;
-               return -E_INDEX_CORRUPTION;
+               return -E_OSL_INDEX_CORRUPTION;
        }
        *row_index = (char *)(t->index_map.data) + index_offset;
        return 1;