diff options
| author | rimio <vasi.vilvoiu@gmail.com> | 2018-03-02 01:42:43 +0200 |
|---|---|---|
| committer | rimio <vasi.vilvoiu@gmail.com> | 2018-03-03 01:39:53 +0200 |
| commit | d31766d827c085dea004ebf7209ab45eddaad02b (patch) | |
| tree | c52e09cbf927f4d59eadff04510e84c6a630c86f /src/ecbor_internal.h | |
| parent | f2397db2cab21c9db06e8f7b69981f7eb2ca8cd5 (diff) | |
Various fixes and refactoring.
Diffstat (limited to 'src/ecbor_internal.h')
| -rw-r--r-- | src/ecbor_internal.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/ecbor_internal.h b/src/ecbor_internal.h index abeaf97..8013fcb 100644 --- a/src/ecbor_internal.h +++ b/src/ecbor_internal.h @@ -9,9 +9,9 @@ #define _ECBOR_INTERNAL_H_ #include <stdint.h> +#include <stddef.h> -/* Don't rely on <stddef.h> for this */ -#define NULL 0 +/* Don't rely on <stdbool.h> for this */ #define false 0 #define true 1 @@ -38,6 +38,36 @@ enum { ECBOR_SIMPLE_UNDEFINED = 23 }; +/* Internal checks. Most of these macros rely on the function returning an + error code, and a 'rc' value being declared locally */ +#define ECBOR_INTERNAL_CHECK_ITEM_PTR(i) \ + { \ + if (!(i)) { \ + return ECBOR_ERR_NULL_ITEM; \ + } \ + } + +#define ECBOR_INTERNAL_CHECK_VALUE_PTR(v) \ + { \ + if (!(v)) { \ + return ECBOR_ERR_NULL_VALUE; \ + } \ + } + +#define ECBOR_INTERNAL_CHECK_TYPE(t1, ref) \ + { \ + if ((t1) != (ref)) { \ + return ECBOR_ERR_INVALID_TYPE; \ + } \ + } + +#define ECBOR_INTERNAL_CHECK_BOUNDS(index, limit) \ + { \ + if ((index) >= (limit)) { \ + return ECBOR_ERR_INDEX_OUT_OF_BOUNDS; \ + } \ + } + /* * Endianness */ |
