From 46305b75b9a4ec8f0e4a93e3efb1b8e12ff2f390 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 4 Feb 2017 16:12:32 +0000 Subject: error: Improve error header. --- include/libnslayout/error.h | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h index 0e2321f..5e7b87a 100644 --- a/include/libnslayout/error.h +++ b/include/libnslayout/error.h @@ -16,6 +16,11 @@ extern "C" { #endif +/** + * Number of bits in an `nslayout_error` that indicate the source of the error. + */ +#define NSLAYOUT_ERROR_PROV 8 + /** * Libnslayout return codes * @@ -23,18 +28,30 @@ extern "C" */ typedef enum nslayout_error { /** No error code */ - NSLAYOUT_OK = 0, + NSLAYOUT_OK = 0, - /** Error provenance */ - NSLAYOUT_NSLAYOUT = (1 << 0), - NSLAYOUT_LIBDOM = (1 << 1), - NSLAYOUT_LIBCSS = (1 << 2), + /** Error provenance (bits 0..7) */ + NSLAYOUT_NSLAYOUT = (1 << 0), + NSLAYOUT_LIBDOM = (1 << 1), + NSLAYOUT_LIBCSS = (1 << 2), - /** LibNSLayout errors */ - NSLAYOUT_NO_MEM = (1 << 8) + NSLAYOUT_NSLAYOUT, + /** LibNSLayout errors (bits 8..31) */ + NSLAYOUT_NO_MEM = (1 << NSLAYOUT_ERROR_PROV) | NSLAYOUT_NSLAYOUT, } nslayout_error; +/** + * Get error provenance. + * + * \param[in] err Error code to test + * \return error provenance + */ +static inline nslayout_error nslayout_error_provenance(nslayout_error err) +{ + return err & ((1 << NSLAYOUT_ERROR_PROV) - 1); +} + + /** * Check if error is from libnslayout * -- cgit v1.2.3