From 929f54e13c65d9120d6902b02ad1c9a3f9108218 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 12 Jan 2017 10:25:30 +0100 Subject: [PATCH] Clarify format of error codes --- src/gmio_amf/amf_error.h | 2 +- src/gmio_core/error.h | 36 ++++++++++++++++++------------ src/gmio_core/internal/zip_utils.h | 4 ++-- src/gmio_stl/stl_error.h | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/gmio_amf/amf_error.h b/src/gmio_amf/amf_error.h index 2e50854..de56522 100644 --- a/src/gmio_amf/amf_error.h +++ b/src/gmio_amf/amf_error.h @@ -39,7 +39,7 @@ /*! \c GMIO_AMF_ERROR_TAG * Byte-mask to tag(identify) AMF-specific error codes */ -enum { GMIO_AMF_ERROR_TAG = 0x12000000 }; +enum { GMIO_AMF_ERROR_TAG = 0x02000000 }; /*! Specific error codes reported by AMF read/write functions */ enum gmio_amf_error diff --git a/src/gmio_core/error.h b/src/gmio_core/error.h index 45d5f58..a329997 100644 --- a/src/gmio_core/error.h +++ b/src/gmio_core/error.h @@ -39,17 +39,20 @@ #include "global.h" -enum { - /*! \c GMIO_ZLIB_ERROR_TAG - * Byte-mask to tag(identify) zlib-specific error codes */ - GMIO_ZLIB_ERROR_TAG = 0x01000000, - - /*! \c GMIO_ZIP_ERROR_TAG - * Byte-mask to tag(identify) ZIP-specific error codes */ - GMIO_ZIP_ERROR_TAG = 0x02000000 -}; - -/*! Common errors */ +/*! Common errors + * + * Format: + * + * 4-bytes signed integer (ISO C restricts enumerator value to 'int') + * max value: 0x7FFFFFFF + * bits 0x00FFFFFF..0x7FFFFFFF: tag identifying the error category + * bits 0x001FFFFF..0x00FFFFFF: tag identifying an error sub-category + * bits 0x00000000..0x000FFFFF: error value in the (sub)category + * Max count of categories : 128 (2^7) + * Max count of sub-categories : 15 (2^4 - 1) + * Max count of error values : 1048576 (2^20) + * + */ enum gmio_error { /*! No error occurred, success */ @@ -80,7 +83,7 @@ enum gmio_error /* zlib */ /*! See \c Z_ERRNO (file operation error) */ - GMIO_ERROR_ZLIB_ERRNO = GMIO_ZLIB_ERROR_TAG + 0x01, + GMIO_ERROR_ZLIB_ERRNO, /*! See \c Z_STREAM_ERROR */ GMIO_ERROR_ZLIB_STREAM, @@ -105,14 +108,19 @@ enum gmio_error * gmio_zlib_compress_options::memory_usage */ GMIO_ERROR_ZLIB_INVALID_COMPRESS_MEMORY_USAGE, + /* ZIP */ /*! Zip64 format requires the compiler to provide a 64b integer type */ - GMIO_ERROR_ZIP_INT64_TYPE_REQUIRED = GMIO_ZIP_ERROR_TAG + 0x01, + GMIO_ERROR_ZIP_INT64_TYPE_REQUIRED, /*! The size of some ZIP file entry exceeds 32b limit and so requires Zip64 * format */ - GMIO_ERROR_ZIP64_FORMAT_REQUIRED = GMIO_ZIP_ERROR_TAG + 0x02 + GMIO_ERROR_ZIP64_FORMAT_REQUIRED }; +/*! \c GMIO_CORE_ERROR_TAG + * Byte-mask to tag(identify) gmio_core error codes */ +enum { GMIO_CORE_ERROR_TAG = 0x00 }; + /*! Returns true if code == GMIO_NO_ERROR */ GMIO_INLINE bool gmio_no_error(int code) { return code == GMIO_ERROR_OK ? true : false; } diff --git a/src/gmio_core/internal/zip_utils.h b/src/gmio_core/internal/zip_utils.h index 29a1b7c..48217e7 100644 --- a/src/gmio_core/internal/zip_utils.h +++ b/src/gmio_core/internal/zip_utils.h @@ -252,9 +252,9 @@ struct gmio_zip_write_result { size_t written_len; }; -enum { GMIO_ZIP_UTILS_ERROR_TAG = 0xAA000000 }; +enum { GMIO_ZIP_UTILS_ERROR_TAG = 0x00100000 }; enum gmio_zip_utils_error { - GMIO_ZIP_UTILS_ERROR_BAD_MAGIC = GMIO_ZIP_UTILS_ERROR_TAG + 0x01 + GMIO_ZIP_UTILS_ERROR_BAD_MAGIC = GMIO_ZIP_UTILS_ERROR_TAG + 1 }; /*! Reads ZIP local file header from \p stream */ diff --git a/src/gmio_stl/stl_error.h b/src/gmio_stl/stl_error.h index 7c4ff03..6af020b 100644 --- a/src/gmio_stl/stl_error.h +++ b/src/gmio_stl/stl_error.h @@ -39,7 +39,7 @@ /*! \c GMIO_STL_ERROR_TAG * Byte-mask to tag(identify) STL-specific error codes */ -enum { GMIO_STL_ERROR_TAG = 0x11000000 }; +enum { GMIO_STL_ERROR_TAG = 0x01000000 }; /*! Specific error codes reported by STL read/write functions */ enum gmio_stl_error