-extern char *__errlist[];
-extern char *__error_txt;
+/*
+ * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
-//__printf_2_3 void __log(int ll, const char* fmt,...);
+/** \file error.h \brief Error handling functions and macros. */
/**
- * This bit indicates whether a number is considered a system error number
+ * This bit indicates whether a number is considered a system error code.
* If yes, the system errno is just the result of clearing this bit from
* the given number.
*/
/** Set the system error bit for the given number. */
#define ERRNO_TO_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
-/** Check whether a given number is a system error number.
- *
- * \param num The value to be checked.
- * \param _errno The system error number.
- *
- * \return True if \a num is the representation of the system
- * error identified by \a _errno.
- */
-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];
-}
-
+/** The list of all adu error codes with descriptions. */
#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 OSL") \
- _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(SYNTAX, "syntax error") \
+ _ERROR(LOOP_COMPLETE, "loop complete") \
+ _ERROR(HASH_TABLE_OVERFLOW, "hash table too small") \
+ _ERROR(BAD_UID, "uid not found in hash table") \
_ERROR(ATOI_OVERFLOW, "value too large") \
_ERROR(STRTOLL, "unknown strtoll error") \
_ERROR(ATOI_NO_DIGITS, "no digits found in string") \
_ERROR(ATOI_JUNK_AT_END, "further characters after number") \
- _ERROR(FGETS, "fgets error") \
_ERROR(EMPTY, "file empty") \
_ERROR(MMAP, "mmap error") \
- _ERROR(SYNTAX, "syntax error") \
- _ERROR(LOOP_COMPLETE, "loop complete") \
- _ERROR(HASH_TABLE_OVERFLOW, "hash table too small") \
- _ERROR(BAD_UID, "uid not found in hash table")
+ _ERROR(OSL, "osl error") \
+ _ERROR(SIGACTION, "could not install signal handler") \
+ _ERROR(OUTPUT, "error writing output") \
+ _ERROR(MALFORMED_FORMAT, "malformed format string") \
+ _ERROR(BAD_ALIGN_SPEC, "bad alignment specifier") \
+ _ERROR(TRAILING_GARBAGE, "trailing garbage after specifier") \
+ _ERROR(UNIT, "no unit allowed here") \
+ _ERROR(BAD_UNIT, "invalid unit specifier") \
+ _ERROR(BAD_ATOM, "invalid atom") \
+ _ERROR(BAD_OUTPUT_ARG, "invalid name for output") \
+ _ERROR(REGEX, "regular expression error") \
+ _ERROR(MKDIR, "could not create directory")
/**
*/
#define _ERROR(err, msg) E_ ## err,
+/**
+ * \cond (doxygen can not handle multiple definitions of the same macro).
+ *
+ * This just creates an enum consisting of the first argument of the above
+ * error list.
+ */
enum error_codes {
ALL_ERRORS
};
#undef _ERROR
+
+/*
+ * Here we define the array of error texts used by adu_strerror().
+ */
#define _ERROR(err, msg) msg,
-#define DEFINE_ERRLIST char *__errlist[] = {ALL_ERRORS}
+#define DEFINE_ERRLIST char *adu_errlist[] = {ALL_ERRORS}
+/** \endcond */
+
+extern int osl_errno;
+
+/** Contains the description of all adu error codes. */
+extern char *adu_errlist[];
+
+extern const char *adu_strerror(int num);
+
+/**
+ * Wrapper for osl library calls.
+ *
+ * \param ret The return value of an osl library function.
+ *
+ * This should be used for all calls to osl functions that return an osl error
+ * code. It changes the return value to \p -E_OSL appropriately so that it can
+ * be used for printing the correct error message.
+ *
+ * \return \a ret if \a ret >= 0, \p -E_OSL otherwise.
+ */
+_static_inline_ int osl(int ret)
+{
+ if (ret >= 0)
+ return ret;
+ osl_errno = -ret;
+ return -E_OSL;
+}