From 33e92ff899ca76809d8e826bd885a746264fa4e8 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 26 Nov 2014 17:15:07 +0000 Subject: Fix error enum to not conflict and add monotonic time implementation --- Makefile | 1 + include/nsutils/base64.h | 16 +++++++------- include/nsutils/errors.h | 56 ++++++++++++++++++++++++------------------------ include/nsutils/time.h | 2 +- src/base64.c | 12 +++++------ src/time.c | 15 +++++++++---- 6 files changed, 55 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index f76e305..be20bdd 100644 --- a/Makefile +++ b/Makefile @@ -33,5 +33,6 @@ include $(NSBUILD)/Makefile.top I := /include/nsutils INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nsutils/errors.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nsutils/base64.h +INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nsutils/time.h INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT) diff --git a/include/nsutils/base64.h b/include/nsutils/base64.h index 2bb10e4..672b69c 100644 --- a/include/nsutils/base64.h +++ b/include/nsutils/base64.h @@ -28,10 +28,10 @@ * \param output_length The length of data placed in \a output * \return NSERROR_OK on success and \a output updated else error code. */ -nserror nsu_base64_encode_alloc(const uint8_t *input, - size_t input_length, - uint8_t **output, - size_t *output_length); +nsuerror nsu_base64_encode_alloc(const uint8_t *input, + size_t input_length, + uint8_t **output, + size_t *output_length); /** * Base 64 decode data. @@ -44,9 +44,9 @@ nserror nsu_base64_encode_alloc(const uint8_t *input, * \param output_length The length of data placed in \a output * \return NSERROR_OK on success and \a output updated else error code. */ -nserror nsu_base64_decode_alloc(const uint8_t *input, - size_t input_length, - uint8_t **output, - size_t *output_length); +nsuerror nsu_base64_decode_alloc(const uint8_t *input, + size_t input_length, + uint8_t **output, + size_t *output_length); #endif diff --git a/include/nsutils/errors.h b/include/nsutils/errors.h index 0da38d9..ed459bc 100644 --- a/include/nsutils/errors.h +++ b/include/nsutils/errors.h @@ -19,60 +19,60 @@ * Enumeration of error codes */ typedef enum { - NSERROR_OK, /**< No error */ + NSUERROR_OK, /**< No error */ - NSERROR_UNKNOWN, /**< Unknown error - DO *NOT* USE */ + NSUERROR_UNKNOWN, /**< Unknown error - DO *NOT* USE */ - NSERROR_NOMEM, /**< Memory exhaustion */ + NSUERROR_NOMEM, /**< Memory exhaustion */ - NSERROR_NO_FETCH_HANDLER, /**< No fetch handler for URL scheme */ + NSUERROR_NO_FETCH_HANDLER, /**< No fetch handler for URL scheme */ - NSERROR_NOT_FOUND, /**< Requested item not found */ + NSUERROR_NOT_FOUND, /**< Requested item not found */ - NSERROR_NOT_DIRECTORY, /**< Missing directory */ + NSUERROR_NOT_DIRECTORY, /**< Missing directory */ - NSERROR_SAVE_FAILED, /**< Failed to save data */ + NSUERROR_SAVE_FAILED, /**< Failed to save data */ - NSERROR_CLONE_FAILED, /**< Failed to clone handle */ + NSUERROR_CLONE_FAILED, /**< Failed to clone handle */ - NSERROR_INIT_FAILED, /**< Initialisation failed */ + NSUERROR_INIT_FAILED, /**< Initialisation failed */ - NSERROR_MNG_ERROR, /**< An MNG error occurred */ + NSUERROR_MNG_ERROR, /**< An MNG error occurred */ - NSERROR_BAD_ENCODING, /**< The character set is unknown */ + NSUERROR_BAD_ENCODING, /**< The character set is unknown */ - NSERROR_NEED_DATA, /**< More data needed */ + NSUERROR_NEED_DATA, /**< More data needed */ - NSERROR_ENCODING_CHANGE, /**< The character changed */ + NSUERROR_ENCODING_CHANGE, /**< The character changed */ - NSERROR_BAD_PARAMETER, /**< Bad Parameter */ + NSUERROR_BAD_PARAMETER, /**< Bad Parameter */ - NSERROR_INVALID, /**< Invalid data */ + NSUERROR_INVALID, /**< Invalid data */ - NSERROR_BOX_CONVERT, /**< Box conversion failed */ + NSUERROR_BOX_CONVERT, /**< Box conversion failed */ - NSERROR_STOPPED, /**< Content conversion stopped */ + NSUERROR_STOPPED, /**< Content conversion stopped */ - NSERROR_DOM, /**< DOM call returned error */ + NSUERROR_DOM, /**< DOM call returned error */ - NSERROR_CSS, /**< CSS call returned error */ + NSUERROR_CSS, /**< CSS call returned error */ - NSERROR_CSS_BASE, /**< CSS base sheet failed */ + NSUERROR_CSS_BASE, /**< CSS base sheet failed */ - NSERROR_BAD_URL, /**< Bad URL */ + NSUERROR_BAD_URL, /**< Bad URL */ - NSERROR_BAD_CONTENT, /**< Bad Content */ + NSUERROR_BAD_CONTENT, /**< Bad Content */ - NSERROR_FRAME_DEPTH, /**< Exceeded frame depth */ + NSUERROR_FRAME_DEPTH, /**< Exceeded frame depth */ - NSERROR_PERMISSION, /**< Permission error */ + NSUERROR_PERMISSION, /**< Permission error */ - NSERROR_NOSPACE, /**< Insufficient space */ + NSUERROR_NOSPACE, /**< Insufficient space */ - NSERROR_BAD_SIZE, /**< Bad size */ + NSUERROR_BAD_SIZE, /**< Bad size */ - NSERROR_NOT_IMPLEMENTED, /**< Functionality is not implemented */ -} nserror; + NSUERROR_NOT_IMPLEMENTED, /**< Functionality is not implemented */ +} nsuerror; #endif diff --git a/include/nsutils/time.h b/include/nsutils/time.h index e07a670..bfc9490 100644 --- a/include/nsutils/time.h +++ b/include/nsutils/time.h @@ -26,6 +26,6 @@ * \param current The current value of the counter. * \return NSERROR_OK on success else error code. */ -nserror nsu_nsu_getmonotonic_ms(uint64_t *current); +nsuerror nsu_nsu_getmonotonic_ms(uint64_t *current); #endif diff --git a/src/base64.c b/src/base64.c index c299955..c11364f 100644 --- a/src/base64.c +++ b/src/base64.c @@ -33,7 +33,7 @@ static uint8_t encoding_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', static unsigned int mod_table[] = {0, 2, 1}; /* exported interface documented in nsutils/base64.h */ -nserror nsu_base64_encode_alloc(const uint8_t *input, +nsuerror nsu_base64_encode_alloc(const uint8_t *input, size_t input_length, uint8_t **output, size_t *output_length) @@ -47,7 +47,7 @@ nserror nsu_base64_encode_alloc(const uint8_t *input, encoded = malloc(encoded_len); if (encoded == NULL) { - return NSERROR_NOMEM; + return NSUERROR_NOMEM; } for (i = 0, j = 0; i < input_length;) { @@ -71,12 +71,12 @@ nserror nsu_base64_encode_alloc(const uint8_t *input, *output = encoded; *output_length = encoded_len; - return NSERROR_OK; + return NSUERROR_OK; } /* exported interface documented in nsutils/base64.h */ -nserror nsu_base64_decode_alloc(const uint8_t *input, +nsuerror nsu_base64_decode_alloc(const uint8_t *input, size_t input_length, uint8_t **output, size_t *output_length) @@ -104,7 +104,7 @@ nserror nsu_base64_decode_alloc(const uint8_t *input, decoded = malloc(decoded_len); if (decoded == NULL) { - return NSERROR_NOMEM; + return NSUERROR_NOMEM; } sextet_idx = 0; @@ -177,5 +177,5 @@ nserror nsu_base64_decode_alloc(const uint8_t *input, *output = decoded; *output_length = opidx; - return NSERROR_OK; + return NSUERROR_OK; } diff --git a/src/time.c b/src/time.c index c0a5dff..2b83f3f 100644 --- a/src/time.c +++ b/src/time.c @@ -14,12 +14,19 @@ #include #include -#include -#include +#include #include "nsutils/time.h" -nserror nsu_nsu_getmonotonic_ms(uint64_t *current) +/* exported interface documented in nsutils/time.h */ +nsuerror nsu_nsu_getmonotonic_ms(uint64_t *current) { - return NSERROR_NOT_IMPLEMENTED; + /** \todo Implement this properly! */ + struct timeval tv; + + gettimeofday(&tv, NULL); + + *current = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); + + return NSUERROR_OK; } -- cgit v1.2.3