X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=error.h;h=010af4559bcb9b0a4e3ca5f329dd35629be762a7;hp=7c3f4aada972651ec60c9a862b609b12b842a7c6;hb=59e83bcfc11c56094c3d02c78c36556ac1fca5ae;hpb=e21355c5755fb738dd08b3a9e2d3c66af4b9a355 diff --git a/error.h b/error.h index 7c3f4aa..010af45 100644 --- a/error.h +++ b/error.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2008 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + +/** \file error.h \brief Error handling functions and macros. */ + /** * 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 @@ -11,6 +19,7 @@ /** Set the system error bit for the given number. */ #define ERRNO_TO_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT)) +/** The list of all adu error codes with descriptions. */ #define ALL_ERRORS \ _ERROR(SUCCESS, "success") \ _ERROR(SYNTAX, "syntax error") \ @@ -24,7 +33,17 @@ _ERROR(EMPTY, "file empty") \ _ERROR(MMAP, "mmap error") \ _ERROR(OSL, "osl error") \ - _ERROR(SIGNAL_SIG_ERR, "signal() returned SIG_ERR") \ + _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") /** @@ -33,46 +52,43 @@ */ #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 *adu_errlist[] = {ALL_ERRORS} +/** \endcond */ extern int osl_errno; + +/** Contains the description of all adu error codes. */ extern char *adu_errlist[]; - -/** - * adu's version of strerror(3). - * - * \param num The error number. - * - * \return The error text of \a num. - */ -static inline const char *adu_strerror(int num) -{ - assert(num > 0); - if (num == E_OSL) { - assert(osl_errno > 0); - return osl_strerror((osl_errno)); - } - if (IS_SYSTEM_ERROR(num)) - return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1)); - return adu_errlist[num]; -} +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) +_static_inline_ int osl(int ret) { if (ret >= 0) return ret;