Skip to content
Snippets Groups Projects
Commit 4350d597 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Use different offset for mapped errno to Knot error codes.

It would otherwise clash with TSIG errors, which are required to
be inverted TSIG RCODEs.
parent b7031075
Branches
Tags
1 merge request!23Clashing error codes
......@@ -30,6 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common/errors.h"
/* errno -> Knot error mapping.
* \note offset is required, otherwise it would interfere with TSIG errors.
*/
#define ERRBASE 100
#define err2code(x) (-(ERRBASE + (x)))
/*! \brief Error codes used in the library. */
enum knot_error {
KNOT_EOK = 0, /*!< OK */
......@@ -40,17 +46,17 @@ enum knot_error {
KNOT_TSIG_EBADTIME = -18, /*!< TSIG signing time out of range. */
/* Directly mapped error codes. */
KNOT_ENOMEM = -ENOMEM, /*!< Out of memory. */
KNOT_EINVAL = -EINVAL, /*!< Invalid parameter passed. */
KNOT_ENOTSUP = -ENOTSUP, /*!< Parameter not supported. */
KNOT_EBUSY = -EBUSY, /*!< Requested resource is busy. */
KNOT_EAGAIN = -EAGAIN, /*!< OS lacked necessary resources. */
KNOT_EACCES = -EACCES, /*!< Permission is denied. */
KNOT_ECONNREFUSED = -ECONNREFUSED, /*!< Connection is refused. */
KNOT_EISCONN = -EISCONN, /*!< Already connected. */
KNOT_EADDRINUSE = -EADDRINUSE, /*!< Address already in use. */
KNOT_ENOENT = -ENOENT, /*!< Resource not found. */
KNOT_ERANGE = -ERANGE, /*!< Value is out of range. */
KNOT_ENOMEM = err2code(ENOMEM), /*!< Out of memory. */
KNOT_EINVAL = err2code(EINVAL), /*!< Invalid parameter passed. */
KNOT_ENOTSUP = err2code(ENOTSUP), /*!< Parameter not supported. */
KNOT_EBUSY = err2code(EBUSY), /*!< Requested resource is busy. */
KNOT_EAGAIN = err2code(EAGAIN), /*!< OS lacked necessary resources. */
KNOT_EACCES = err2code(EACCES), /*!< Permission is denied. */
KNOT_ECONNREFUSED = err2code(ECONNREFUSED), /*!< Connection is refused. */
KNOT_EISCONN = err2code(EISCONN), /*!< Already connected. */
KNOT_EADDRINUSE = err2code(EADDRINUSE), /*!< Address already in use. */
KNOT_ENOENT = err2code(ENOENT), /*!< Resource not found. */
KNOT_ERANGE = err2code(ERANGE), /*!< Value is out of range. */
/* General errors. */
KNOT_ERROR = -10000, /*!< General error. */
......
......@@ -20,6 +20,7 @@
#include <stdlib.h>
#include "common/errors.h"
#include "common/errcode.h"
/*!
* \brief Looks up the given id in the lookup table.
......@@ -66,7 +67,7 @@ int _map_errno(int fallback_value, int arg0, ...)
if (c == errno) {
/* Return negative value of the code. */
va_end(ap);
return -abs(c);
return err2code(abs(c));
}
}
va_end(ap);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment