diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | include/nsutils/assert.h | 24 | ||||
-rw-r--r-- | include/nsutils/endian.h | 4 | ||||
-rw-r--r-- | src/time.c | 4 |
4 files changed, 31 insertions, 6 deletions
@@ -2,11 +2,11 @@ # # Makefile for libnsutils # -# Copyright 2014-1015 Vincent Sanders <vince@netsurf-browser.org> +# Copyright 2014-2020 Vincent Sanders <vince@netsurf-browser.org> # Component settings COMPONENT := nsutils -COMPONENT_VERSION := 0.0.5 +COMPONENT_VERSION := 0.1.1 # Default to a static library COMPONENT_TYPE ?= lib-static @@ -49,6 +49,7 @@ include $(NSBUILD)/Makefile.top # Extra installation rules I := /$(INCLUDEDIR)/nsutils +INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/nsutils/assert.h 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/endian.h diff --git a/include/nsutils/assert.h b/include/nsutils/assert.h new file mode 100644 index 0000000..7f59f2f --- /dev/null +++ b/include/nsutils/assert.h @@ -0,0 +1,24 @@ +/* + * This file is part of LibNSUtils. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2022 Michael Drake <tlsa@netsurf-browser.org> + */ + +/** + * \file + * Static assertion macro. + */ + +#ifndef NSUTILS_ASSERT_H__ +#define NSUTILS_ASSERT_H__ + +/** Compile time assertion macro. */ +#define ns_static_assert(e) \ +{ \ + enum { \ + ns_static_assert_check = 1 / (!!(e)) \ + }; \ +} + +#endif diff --git a/include/nsutils/endian.h b/include/nsutils/endian.h index 0e4bad0..a15c7e2 100644 --- a/include/nsutils/endian.h +++ b/include/nsutils/endian.h @@ -23,9 +23,9 @@ */ static inline bool endian_host_is_le(void) { - static uint32_t magic = 0x10000002; + const uint16_t test = 1; - return (((uint8_t *) &magic)[0] == 0x02); + return ((const uint8_t *) &test)[0]; } /** @@ -20,7 +20,7 @@ #include <time.h> #elif defined(__riscos) #include <oslib/os.h> -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) #include <mach/mach.h> #include <mach/clock.h> #include <mach/mach_time.h> @@ -51,7 +51,7 @@ nsuerror nsu_getmonotonic_ms(uint64_t *current_out) time = os_read_monotonic_time(); current = time * 10; -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) clock_serv_t cclock; mach_timespec_t mts; |