From 5d2bbca39c79dcc73060ac480a4e229affef0a14 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 10 Jun 2022 19:34:11 +0200 Subject: Add strto[u]{hh,h,z}, strto{i,u}{,8,16,32,64} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index cc1c5c9..cc583ab 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ SUBHDR =\ libsimple/strdup.h\ libsimple/strn.h\ libsimple/strndup.h\ + libsimple/strtoint.h\ libsimple/time.h\ libsimple/valloc.h\ libsimple/vallocz.h\ @@ -192,8 +193,24 @@ OBJ =\ strrnstr.o\ strrstr.o\ strstarts.o\ + strtoh.o\ + strtohh.o\ + strtoi.o\ + strtoi16.o\ + strtoi32.o\ + strtoi64.o\ + strtoi8.o\ strtotimespec.o\ strtotimeval.o\ + strtou.o\ + strtou16.o\ + strtou32.o\ + strtou64.o\ + strtou8.o\ + strtouh.o\ + strtouhh.o\ + strtouz.o\ + strtoz.o\ sumtimespec.o\ sumtimeval.o\ timespec2timeval.o\ -- cgit v1.2.3-70-g09d2 From 056c5fe698f194c3187b9eec5378c441930c005b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 10 Jun 2022 20:34:32 +0200 Subject: Remove `static` from some `static inline` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 19 +++++++++++ close.c | 18 ++++++++++ ealigned_memdup.c | 41 +++++++++++++++++++++++ ealigned_strndup.c | 71 +++++++++++++++++++++++++++++++++++++++ ealigned_wcsndup.c | 71 +++++++++++++++++++++++++++++++++++++++ ealigned_wmemdup.c | 41 +++++++++++++++++++++++ ememdup.c | 40 ++++++++++++++++++++++ enaligned_memdup.c | 18 ---------- enaligned_strndup.c | 48 -------------------------- enaligned_wcsndup.c | 48 -------------------------- enaligned_wmemdup.c | 18 ---------- enmemdup.c | 17 ---------- enputenvf.c | 41 +++++++++++++++++++++++ enstrdup.c | 18 ---------- enstrndup.c | 54 ----------------------------- envputenvf.c | 47 +------------------------- enwcsdup.c | 18 ---------- enwcsndup.c | 54 ----------------------------- enwmemdup.c | 23 ------------- eputenvf.c | 42 +++++++++++++++++++++++ estrdup.c | 41 +++++++++++++++++++++++ estrndup.c | 77 ++++++++++++++++++++++++++++++++++++++++++ evputenvf.c | 18 ++++++++++ ewcsdup.c | 41 +++++++++++++++++++++++ ewcsndup.c | 77 ++++++++++++++++++++++++++++++++++++++++++ ewmemdup.c | 46 +++++++++++++++++++++++++ getenv_e.c | 28 ++++++++++++++++ getenv_ne.c | 28 ++++++++++++++++ libsimple.c | 82 --------------------------------------------- libsimple.h | 4 +-- libsimple/aligned_memdup.h | 7 ++-- libsimple/aligned_strndup.h | 7 ++-- libsimple/aligned_wcsndup.h | 7 ++-- libsimple/aligned_wmemdup.h | 7 ++-- libsimple/env.h | 17 ++++++---- libsimple/memdup.h | 7 ++-- libsimple/memelem.h | 8 +++-- libsimple/strdup.h | 7 ++-- libsimple/strndup.h | 7 ++-- libsimple/strtoint.h | 23 ++++++++++--- libsimple/wcsdup.h | 7 ++-- libsimple/wcsndup.h | 7 ++-- libsimple/wmemdup.h | 7 ++-- memsetelem.c | 50 +++++++++++++++++++++++++++ putenvf.c | 38 +++++++++++++++++++++ strtouz.c | 2 +- strtoz.c | 2 +- unlist.c | 50 +++++++++++++++++++++++++++ vputenvf.c | 22 +----------- 49 files changed, 969 insertions(+), 502 deletions(-) create mode 100644 close.c create mode 100644 ealigned_memdup.c create mode 100644 ealigned_strndup.c create mode 100644 ealigned_wcsndup.c create mode 100644 ealigned_wmemdup.c create mode 100644 ememdup.c create mode 100644 enputenvf.c create mode 100644 eputenvf.c create mode 100644 estrdup.c create mode 100644 estrndup.c create mode 100644 evputenvf.c create mode 100644 ewcsdup.c create mode 100644 ewcsndup.c create mode 100644 ewmemdup.c create mode 100644 getenv_e.c create mode 100644 getenv_ne.c create mode 100644 memsetelem.c create mode 100644 putenvf.c create mode 100644 unlist.c (limited to 'Makefile') diff --git a/Makefile b/Makefile index cc583ab..88f2130 100644 --- a/Makefile +++ b/Makefile @@ -55,10 +55,15 @@ OBJ =\ aligned_wmemdup.o\ allocn.o\ asprintf.o\ + close.o\ difftimespec.o\ difftimeval.o\ doubletotimespec.o\ doubletotimeval.o\ + ealigned_memdup.o\ + ealigned_strndup.o\ + ealigned_wcsndup.o\ + ealigned_wmemdup.o\ enaligned_allocz.o\ enaligned_memdup.o\ enaligned_realloc.o\ @@ -74,6 +79,7 @@ OBJ =\ enmalloc.o\ enmemdup.o\ enposix_memalignz.o\ + enputenvf.o\ enrealloc.o\ enreallocarray.o\ enstrdup.o\ @@ -88,6 +94,16 @@ OBJ =\ enwcsdup.o\ enwcsndup.o\ enwmemdup.o\ + ememdup.o\ + eputenvf.o\ + estrdup.o\ + estrndup.o\ + evputenvf.o\ + ewcsdup.o\ + ewcsndup.o\ + ewmemdup.o\ + getenv_e.o\ + getenv_ne.o\ gmtime.o\ localtime.o\ memcasechr.o\ @@ -126,12 +142,14 @@ OBJ =\ memreplaceelem.o\ memreqlen.o\ memrmem.o\ + memsetelem.o\ memscan.o\ memscan_inv.o\ memstarts.o\ minimise_number_string.o\ multimespec.o\ multimeval.o\ + putenvf.o\ rawmemcasechr.o\ rawmemcasechr_inv.o\ rawmemchr.o\ @@ -216,6 +234,7 @@ OBJ =\ timespec2timeval.o\ timespectostr.o\ timevaltostr.o\ + unlist.o\ vasprintf.o\ vmemalloc.o\ vputenvf.o\ diff --git a/close.c b/close.c new file mode 100644 index 0000000..6ddcb1f --- /dev/null +++ b/close.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_close(int *); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_memdup.c b/ealigned_memdup.c new file mode 100644 index 0000000..4209a77 --- /dev/null +++ b/ealigned_memdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_memdup(const void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_memdup("test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_memdup("test", 8, 2)); + assert(exit_status == 55); + assert_stderr("%s: aligned_memdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_strndup.c b/ealigned_strndup.c new file mode 100644 index 0000000..1d8cc1d --- /dev/null +++ b/ealigned_strndup.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_ealigned_strndup(const char *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_strndup("test", 8, SIZE_MAX))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + assert((s = libsimple_ealigned_strndup("test", 8, 100))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + assert((s = libsimple_ealigned_strndup("test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + assert((s = libsimple_ealigned_strndup("test", 8, 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_strndup("test", 8, 10)); + assert(exit_status == 55); + assert_stderr("%s: aligned_strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_wcsndup.c b/ealigned_wcsndup.c new file mode 100644 index 0000000..2f70be3 --- /dev/null +++ b/ealigned_wcsndup.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ealigned_wcsndup(const wchar_t *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, SIZE_MAX))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, 100))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_wcsndup(L"test", 8, 10)); + assert(exit_status == 55); + assert_stderr("%s: aligned_wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_wmemdup.c b/ealigned_wmemdup.c new file mode 100644 index 0000000..dae7c33 --- /dev/null +++ b/ealigned_wmemdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ealigned_wmemdup(const wchar_t *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_wmemdup(L"test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_wmemdup(L"test", 8, 2)); + assert(exit_status == 55); + assert_stderr("%s: aligned_wmemdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ememdup.c b/ememdup.c new file mode 100644 index 0000000..50295e3 --- /dev/null +++ b/ememdup.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ememdup(const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ememdup("test", 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ememdup("test", 2)); + assert(exit_status == 55); + assert_stderr("%s: memdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/enaligned_memdup.c b/enaligned_memdup.c index ac94746..ae8589f 100644 --- a/enaligned_memdup.c +++ b/enaligned_memdup.c @@ -32,30 +32,12 @@ main(void) assert(!memcmp(s, "hello", 5)); free(s); - assert((s = libsimple_ealigned_memdup("test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_memdup(44, "hello", 2, 2)); assert(exit_status == 44); assert_stderr("%s: aligned_memdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_memdup("test", 8, 2)); - assert(exit_status == 55); - assert_stderr("%s: aligned_memdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enaligned_strndup.c b/enaligned_strndup.c index 6812d1c..91825fd 100644 --- a/enaligned_strndup.c +++ b/enaligned_strndup.c @@ -32,16 +32,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, SIZE_MAX))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 100))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, 100))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 6))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 5))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -92,16 +62,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 4))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -118,14 +78,6 @@ main(void) assert(exit_status == 44); assert_stderr("%s: aligned_strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_strndup("test", 8, 10)); - assert(exit_status == 55); - assert_stderr("%s: aligned_strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enaligned_wcsndup.c b/enaligned_wcsndup.c index 32cce57..840d180 100644 --- a/enaligned_wcsndup.c +++ b/enaligned_wcsndup.c @@ -32,16 +32,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, SIZE_MAX))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 100))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, 100))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 6))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 5))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -92,16 +62,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 4))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -118,14 +78,6 @@ main(void) assert(exit_status == 44); assert_stderr("%s: aligned_wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_wcsndup(L"test", 8, 10)); - assert(exit_status == 55); - assert_stderr("%s: aligned_wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enaligned_wmemdup.c b/enaligned_wmemdup.c index ad36238..657b644 100644 --- a/enaligned_wmemdup.c +++ b/enaligned_wmemdup.c @@ -32,30 +32,12 @@ main(void) assert(!wmemcmp(s, L"hello", 5)); free(s); - assert((s = libsimple_ealigned_wmemdup(L"test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_wmemdup(44, L"hello", 2, 2)); assert(exit_status == 44); assert_stderr("%s: aligned_wmemdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_wmemdup(L"test", 8, 2)); - assert(exit_status == 55); - assert_stderr("%s: aligned_wmemdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enmemdup.c b/enmemdup.c index 0761f86..6863733 100644 --- a/enmemdup.c +++ b/enmemdup.c @@ -31,29 +31,12 @@ main(void) assert(!memcmp(s, "hello", 5)); free(s); - assert((s = libsimple_ememdup("test", 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enmemdup(44, "hello", 2)); assert(exit_status == 44); assert_stderr("%s: memdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ememdup("test", 2)); - assert(exit_status == 55); - assert_stderr("%s: memdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enputenvf.c b/enputenvf.c new file mode 100644 index 0000000..8447eae --- /dev/null +++ b/enputenvf.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_enputenvf(int, const char *, ...); + + +#else +#include "test.h" + +int +main(void) +{ + enputenvf(1, "X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + enputenvf(1, "Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + enputenvf(1, "X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + enputenvf(1, "Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + enputenvf(1, "X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + enputenvf(1, "Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit(enputenvf(100, "X=xyz")); + assert(exit_status == 100); + assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/enstrdup.c b/enstrdup.c index f330422..94160ef 100644 --- a/enstrdup.c +++ b/enstrdup.c @@ -34,30 +34,12 @@ main(void) assert(!strcmp(s, "hello")); free(s); - assert((s = libsimple_estrdup("test"))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "test")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrdup(14, "hello")); assert(exit_status == 14); assert_stderr("%s: strdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 15; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrdup("test")); - assert(exit_status == 15); - assert_stderr("%s: strdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enstrndup.c b/enstrndup.c index c02c0fd..755872d 100644 --- a/enstrndup.c +++ b/enstrndup.c @@ -32,16 +32,6 @@ main(void) assert(!strcmp(s, "hello")); free(s); - assert((s = libsimple_estrndup("test", 10))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "test")); - free(s); - assert((s = libsimple_enstrndup(1, "hello", 2))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!strcmp(s, "he")); free(s); - assert((s = libsimple_estrndup("test", 3))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 4); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "tes")); - free(s); - assert((s = libsimple_enstrndup(1, "hello", 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!strcmp(s, "")); free(s); - assert((s = libsimple_estrndup("test", 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 1); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrndup(14, "hello", 10)); @@ -89,41 +59,17 @@ main(void) assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 15; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrndup("test", 10)); - assert(exit_status == 15); - assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrndup(16, "hello", 1)); assert(exit_status == 16); assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 17; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrndup("test", 2)); - assert(exit_status == 17); - assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrndup(18, "hello", 0)); assert(exit_status == 18); assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 19; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrndup("test", 0)); - assert(exit_status == 19); - assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/envputenvf.c b/envputenvf.c index b4568fd..8b7fa72 100644 --- a/envputenvf.c +++ b/envputenvf.c @@ -17,52 +17,7 @@ libsimple_envputenvf(int status, const char *fmt, va_list ap) int main(void) { - eputenvf("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - eputenvf("Y=xyz"); - assert(!strcmpnul(getenv("Y"), "xyz")); - - eputenvf("X=x%sz", "abc"); - assert(!strcmpnul(getenv("X"), "xabcz")); - eputenvf("Y=x%sz", "abc"); - assert(!strcmpnul(getenv("Y"), "xabcz")); - - eputenvf("X=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("X"), "10xabcz-11")); - eputenvf("Y=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("Y"), "10xabcz-11")); - - enputenvf(1, "X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - enputenvf(1, "Y=xyz"); - assert(!strcmpnul(getenv("Y"), "xyz")); - - enputenvf(1, "X=x%sz", "abc"); - assert(!strcmpnul(getenv("X"), "xabcz")); - enputenvf(1, "Y=x%sz", "abc"); - assert(!strcmpnul(getenv("Y"), "xabcz")); - - enputenvf(1, "X=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("X"), "10xabcz-11")); - enputenvf(1, "Y=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("Y"), "10xabcz-11")); - - if (have_custom_malloc()) { - alloc_fail_in = 1; - assert_exit(enputenvf(100, "X=xyz")); - assert(exit_status == 100); - assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 102; - alloc_fail_in = 1; - assert_exit(eputenvf("X=xyz")); - assert(exit_status == 102); - assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - } - - return 0; + return 0; /* Tested via libsimple_enputenvf */ } #endif diff --git a/enwcsdup.c b/enwcsdup.c index 1fa27c0..ca3ad56 100644 --- a/enwcsdup.c +++ b/enwcsdup.c @@ -39,30 +39,12 @@ main(void) assert(!wcscmp(s, L"hello")); free(s); - assert((s = libsimple_ewcsdup(L"test"))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"test")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsdup(18, L"hello")); assert(exit_status == 18); assert_stderr("%s: wcsdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 5; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsdup(L"test")); - assert(exit_status == 5); - assert_stderr("%s: wcsdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enwcsndup.c b/enwcsndup.c index 105542c..04ff9fc 100644 --- a/enwcsndup.c +++ b/enwcsndup.c @@ -32,16 +32,6 @@ main(void) assert(!wcscmp(s, L"hello")); free(s); - assert((s = libsimple_ewcsndup(L"test", 10))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"test")); - free(s); - assert((s = libsimple_enwcsndup(1, L"hello", 2))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!wcscmp(s, L"he")); free(s); - assert((s = libsimple_ewcsndup(L"test", 3))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 4 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"tes")); - free(s); - assert((s = libsimple_enwcsndup(1, L"hello", 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!wcscmp(s, L"")); free(s); - assert((s = libsimple_ewcsndup(L"test", 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 1 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsndup(24, L"hello", 10)); @@ -89,41 +59,17 @@ main(void) assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 25; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsndup(L"test", 10)); - assert(exit_status == 25); - assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsndup(26, L"hello", 1)); assert(exit_status == 26); assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 27; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsndup(L"test", 2)); - assert(exit_status == 27); - assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsndup(28, L"hello", 0)); assert(exit_status == 28); assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 29; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsndup(L"test", 0)); - assert(exit_status == 29); - assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enwmemdup.c b/enwmemdup.c index 243c99e..19dc6be 100644 --- a/enwmemdup.c +++ b/enwmemdup.c @@ -31,15 +31,6 @@ main(void) assert(!wmemcmp(s, L"hello", 5)); free(s); - assert((s = libsimple_ewmemdup(L"test", 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t)); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enwmemdup(44, L"hello", 2)); @@ -47,23 +38,9 @@ main(void) assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewmemdup(L"test", 2)); - assert(exit_status == 55); - assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - assert_exit_ptr(libsimple_enwmemdup(41, NULL, SSIZE_MAX)); assert(exit_status == 41); assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); - - libsimple_default_failure_exit = 51; - assert_exit_ptr(libsimple_ewmemdup(NULL, SSIZE_MAX)); - assert(exit_status == 51); - assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); - libsimple_default_failure_exit = 1; } return 0; diff --git a/eputenvf.c b/eputenvf.c new file mode 100644 index 0000000..aee4d47 --- /dev/null +++ b/eputenvf.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_eputenvf(const char *, ...); + + +#else +#include "test.h" + +int +main(void) +{ + eputenvf("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + eputenvf("Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + eputenvf("X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + eputenvf("Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + eputenvf("X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + eputenvf("Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 102; + alloc_fail_in = 1; + assert_exit(eputenvf("X=xyz")); + assert(exit_status == 102); + assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/estrdup.c b/estrdup.c new file mode 100644 index 0000000..3a67e0a --- /dev/null +++ b/estrdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_estrdup(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + char *s; + + assert((s = libsimple_estrdup("test"))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "test")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 15; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrdup("test")); + assert(exit_status == 15); + assert_stderr("%s: strdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/estrndup.c b/estrndup.c new file mode 100644 index 0000000..3471db5 --- /dev/null +++ b/estrndup.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_estrndup(const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + char *s; + + assert((s = libsimple_estrndup("test", 10))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "test")); + free(s); + + assert((s = libsimple_estrndup("test", 3))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 4); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "tes")); + free(s); + + assert((s = libsimple_estrndup("test", 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 1); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 15; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrndup("test", 10)); + assert(exit_status == 15); + assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 17; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrndup("test", 2)); + assert(exit_status == 17); + assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 19; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrndup("test", 0)); + assert(exit_status == 19); + assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/evputenvf.c b/evputenvf.c new file mode 100644 index 0000000..b35aae3 --- /dev/null +++ b/evputenvf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_evputenvf(const char *, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_eputenvf */ +} + +#endif diff --git a/ewcsdup.c b/ewcsdup.c new file mode 100644 index 0000000..ca8e422 --- /dev/null +++ b/ewcsdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ewcsdup(const wchar_t *); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + wchar_t *s; + + assert((s = libsimple_ewcsdup(L"test"))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"test")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 5; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsdup(L"test")); + assert(exit_status == 5); + assert_stderr("%s: wcsdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ewcsndup.c b/ewcsndup.c new file mode 100644 index 0000000..239cca0 --- /dev/null +++ b/ewcsndup.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ewcsndup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + wchar_t *s; + + assert((s = libsimple_ewcsndup(L"test", 10))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"test")); + free(s); + + assert((s = libsimple_ewcsndup(L"test", 3))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 4 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"tes")); + free(s); + + assert((s = libsimple_ewcsndup(L"test", 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 1 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 25; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsndup(L"test", 10)); + assert(exit_status == 25); + assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 27; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsndup(L"test", 2)); + assert(exit_status == 27); + assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 29; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsndup(L"test", 0)); + assert(exit_status == 29); + assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ewmemdup.c b/ewmemdup.c new file mode 100644 index 0000000..0687fd5 --- /dev/null +++ b/ewmemdup.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ewmemdup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + wchar_t *s; + + assert((s = libsimple_ewmemdup(L"test", 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t)); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewmemdup(L"test", 2)); + assert(exit_status == 55); + assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 51; + assert_exit_ptr(libsimple_ewmemdup(NULL, SSIZE_MAX)); + assert(exit_status == 51); + assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/getenv_e.c b/getenv_e.c new file mode 100644 index 0000000..c09859d --- /dev/null +++ b/getenv_e.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline const char *libsimple_getenv_e(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + unsetenv("X"); + assert(!getenv("X")); + assert(!strcmpnul(libsimple_getenv_e("X"), "")); + putenv("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + assert(!strcmpnul(libsimple_getenv_e("X"), "xyz")); + putenv("X="); + assert(!strcmpnul(getenv("X"), "")); + assert(!strcmpnul(libsimple_getenv_e("X"), "")); + + return 0; +} + +#endif diff --git a/getenv_ne.c b/getenv_ne.c new file mode 100644 index 0000000..b502fc8 --- /dev/null +++ b/getenv_ne.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_getenv_ne(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + unsetenv("X"); + assert(!getenv("X")); + assert(!libsimple_getenv_ne("X")); + putenv("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + assert(!strcmpnul(libsimple_getenv_ne("X"), "xyz")); + putenv("X="); + assert(!strcmpnul(getenv("X"), "")); + assert(!libsimple_getenv_ne("X")); + + return 0; +} + +#endif diff --git a/libsimple.c b/libsimple.c index 5232833..1230b60 100644 --- a/libsimple.c +++ b/libsimple.c @@ -95,7 +95,6 @@ main(void) const wchar_t *cws; char buf[1024], *s; wchar_t *ws; - int intarray[10]; size_t i, j, n; DEFINE_PAGESIZE; DEFINE_CACHELINE; @@ -498,34 +497,6 @@ main(void) assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0); assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1); - for (i = 0, n = 10; i < n; i++) - buf[i] = i; - LIBSIMPLE_UNLIST(buf, 4, &n); - LIBSIMPLE_UNLIST(buf, 9 - 1, &n); - LIBSIMPLE_UNLIST(buf, 6 - 1, &n); - assert(n == 7); - assert(buf[0] == 0); - assert(buf[1] == 1); - assert(buf[2] == 2); - assert(buf[3] == 3); - assert(buf[4] == 5); - assert(buf[5] == 7); - assert(buf[6] == 8); - - for (i = 0, n = 10; i < n; i++) - intarray[i] = i; - LIBSIMPLE_UNLIST(intarray, 4, &n); - LIBSIMPLE_UNLIST(intarray, 9 - 1, &n); - LIBSIMPLE_UNLIST(intarray, 6 - 1, &n); - assert(n == 7); - assert(intarray[0] == 0); - assert(intarray[1] == 1); - assert(intarray[2] == 2); - assert(intarray[3] == 3); - assert(intarray[4] == 5); - assert(intarray[5] == 7); - assert(intarray[6] == 8); - assert(libsimple_strcmpnul(NULL, NULL) == 0); assert(libsimple_strcmpnul(NULL, "") < 0); assert(libsimple_strcmpnul("", NULL) > 0); @@ -967,26 +938,6 @@ main(void) fprintf(stderr, "warning: libsimple_aligned_wcsndupa missing\n"); #endif - unsetenv("X"); - assert(!getenv("X")); - assert(!libsimple_getenv_ne("X")); - putenv("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - assert(!strcmpnul(libsimple_getenv_ne("X"), "xyz")); - putenv("X="); - assert(!strcmpnul(getenv("X"), "")); - assert(!libsimple_getenv_ne("X")); - - unsetenv("X"); - assert(!getenv("X")); - assert(!strcmpnul(libsimple_getenv_e("X"), "")); - putenv("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - assert(!strcmpnul(libsimple_getenv_e("X"), "xyz")); - putenv("X="); - assert(!strcmpnul(getenv("X"), "")); - assert(!strcmpnul(libsimple_getenv_e("X"), "")); - assert(test_timespec(10.3000200010, 10, 300020001L, 10.300020001, "+10.300020001", "10.300020001")); assert(test_timespec(10.3000200014, 10, 300020001L, 10.300020001, "+10.300020001", "10.300020001")); assert(test_timespec(10.3000200015, 10, 300020002L, 10.300020002, "+10.300020002", "10.300020002")); @@ -2430,39 +2381,6 @@ main(void) assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); } - { - char p_[4096]; - char *p = p_; - - memset(p, 0, sizeof(p_)); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 10) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 1, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 2, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 4, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 8, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 16, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 3, 0) == p); - assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p); - assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p); - assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p); - assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p); - assert(libsimple_memsetelem(p, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == p); - - for (i = 0; i < 48; i++) - assert(p[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]); - for (; i < 800; i += 8) - assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL); - for (; i < 1200; i += 4) - assert(*(uint32_t *)&p[i] == 0x10203040UL); - for (; i < 2000; i += 2) - assert(*(uint16_t *)&p[i] == 0x0807); - for (; i < 3000; i++) - assert(p[i] == 0x09); - for (; i < sizeof(p_); i++) - assert(p[i] == 0); - } - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); assert(libsimple_strset(buf, 'x') == buf); diff --git a/libsimple.h b/libsimple.h index 6443dd4..2dda0c2 100644 --- a/libsimple.h +++ b/libsimple.h @@ -142,7 +142,7 @@ * -1 on error), 0 if `*fdp < 0` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline int +inline int libsimple_close(int *__fdp) { int __ret; @@ -180,7 +180,7 @@ libsimple_close(int *__fdp) * @param width The width, in bytes, of each item in the list */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline void +inline void libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width) { char *__lst = __list; diff --git a/libsimple/aligned_memdup.h b/libsimple/aligned_memdup.h index 0192a14..7c17375 100644 --- a/libsimple/aligned_memdup.h +++ b/libsimple/aligned_memdup.h @@ -72,8 +72,11 @@ void *libsimple_enaligned_memdup(int, const void *, size_t, size_t); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ealigned_memdup(const void *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_memdup(libsimple_default_failure_exit, __s, __alignment, __n); } +inline void * +libsimple_ealigned_memdup(const void *__s, size_t __alignment, size_t __n) +{ + return libsimple_enaligned_memdup(libsimple_default_failure_exit, __s, __alignment, __n); +} #ifndef ealigned_memdup # define ealigned_memdup libsimple_ealigned_memdup #endif diff --git a/libsimple/aligned_strndup.h b/libsimple/aligned_strndup.h index 16a3aac..68b9d00 100644 --- a/libsimple/aligned_strndup.h +++ b/libsimple/aligned_strndup.h @@ -72,8 +72,11 @@ char *libsimple_enaligned_strndup(int, const char *, size_t, size_t); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_ealigned_strndup(const char *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_strndup(libsimple_default_failure_exit, __s, __alignment, __n); } +inline char * +libsimple_ealigned_strndup(const char *__s, size_t __alignment, size_t __n) +{ + return libsimple_enaligned_strndup(libsimple_default_failure_exit, __s, __alignment, __n); +} #ifndef ealigned_strndup # define ealigned_strndup libsimple_ealigned_strndup #endif diff --git a/libsimple/aligned_wcsndup.h b/libsimple/aligned_wcsndup.h index 015d1dc..4e081ee 100644 --- a/libsimple/aligned_wcsndup.h +++ b/libsimple/aligned_wcsndup.h @@ -72,8 +72,11 @@ wchar_t *libsimple_enaligned_wcsndup(int, const wchar_t *, size_t, size_t); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ealigned_wcsndup(const wchar_t *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_wcsndup(libsimple_default_failure_exit, __s, __alignment, __n); } +inline wchar_t * +libsimple_ealigned_wcsndup(const wchar_t *__s, size_t __alignment, size_t __n) +{ + return libsimple_enaligned_wcsndup(libsimple_default_failure_exit, __s, __alignment, __n); +} #ifndef ealigned_wcsndup # define ealigned_wcsndup libsimple_ealigned_wcsndup #endif diff --git a/libsimple/aligned_wmemdup.h b/libsimple/aligned_wmemdup.h index 63a9d40..79b59dd 100644 --- a/libsimple/aligned_wmemdup.h +++ b/libsimple/aligned_wmemdup.h @@ -72,8 +72,11 @@ wchar_t *libsimple_enaligned_wmemdup(int, const wchar_t *, size_t, size_t); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ealigned_wmemdup(const wchar_t *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_wmemdup(libsimple_default_failure_exit, __s, __alignment, __n); } +inline wchar_t * +libsimple_ealigned_wmemdup(const wchar_t *__s, size_t __alignment, size_t __n) +{ + return libsimple_enaligned_wmemdup(libsimple_default_failure_exit, __s, __alignment, __n); +} #ifndef ealigned_wmemdup # define ealigned_wmemdup libsimple_ealigned_wmemdup #endif diff --git a/libsimple/env.h b/libsimple/env.h index dc58276..f9139c7 100644 --- a/libsimple/env.h +++ b/libsimple/env.h @@ -8,7 +8,7 @@ * @return The environment variable's value, `NULL` if empty or not defined */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__))) -static inline char * +inline char * libsimple_getenv_ne(const char *__name) { char *__env = getenv(__name); @@ -26,7 +26,7 @@ libsimple_getenv_ne(const char *__name) * @return The environment variable's value, "" if empty or not defined */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline const char * +inline const char * libsimple_getenv_e(const char *__name) { const char *__env = getenv(__name); @@ -71,7 +71,7 @@ int libsimple_vputenvf(const char *, va_list); * @return 0 on success, -1 on failure */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) -static inline int +inline int libsimple_putenvf(const char *__fmt, ...) { va_list __ap; @@ -126,7 +126,7 @@ void libsimple_envputenvf(int, const char *, va_list); * @param ap Format arguments, see vsprintf(3) */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 2, 3)))) -static inline void +inline void libsimple_enputenvf(int __status, const char *__fmt, ...) { va_list __ap; @@ -156,8 +156,11 @@ libsimple_enputenvf(int __status, const char *__fmt, ...) * @param ap Format arguments, see vsprintf(3) */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline void libsimple_evputenvf(const char *__fmt, va_list __ap) -{ libsimple_envputenvf(libsimple_default_failure_exit, __fmt, __ap); } +inline void +libsimple_evputenvf(const char *__fmt, va_list __ap) +{ + libsimple_envputenvf(libsimple_default_failure_exit, __fmt, __ap); +} #ifndef evputenvf # define evputenvf libsimple_evputenvf #endif @@ -180,7 +183,7 @@ static inline void libsimple_evputenvf(const char *__fmt, va_list __ap) * @param ap Format arguments, see vsprintf(3) */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) -static inline void +inline void libsimple_eputenvf(const char *__fmt, ...) { va_list __ap; diff --git a/libsimple/memdup.h b/libsimple/memdup.h index 75353b8..383b338 100644 --- a/libsimple/memdup.h +++ b/libsimple/memdup.h @@ -59,8 +59,11 @@ void *libsimple_enmemdup(int, const void *, size_t); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ememdup(const void *__s, size_t __n) -{ return libsimple_enmemdup(libsimple_default_failure_exit, __s, __n); } +inline void * +libsimple_ememdup(const void *__s, size_t __n) +{ + return libsimple_enmemdup(libsimple_default_failure_exit, __s, __n); +} #ifndef ememdup # define ememdup libsimple_ememdup #endif diff --git a/libsimple/memelem.h b/libsimple/memelem.h index 29570f6..ab4ffca 100644 --- a/libsimple/memelem.h +++ b/libsimple/memelem.h @@ -238,8 +238,12 @@ void *libsimple_mempsetelem(void *, const void *, size_t, size_t); * @return `buf` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) -static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __width, size_t __n) -{ return __item = libsimple_mempsetelem(__buf, __item, __width, __n), __buf; } +inline void * +libsimple_memsetelem(void *__buf, const void *__item, size_t __width, size_t __n) +{ + __item = libsimple_mempsetelem(__buf, __item, __width, __n); + return __buf; +} #ifndef memsetelem # define memsetelem libsimple_memsetelem #endif diff --git a/libsimple/strdup.h b/libsimple/strdup.h index 74e689e..a826414 100644 --- a/libsimple/strdup.h +++ b/libsimple/strdup.h @@ -42,8 +42,11 @@ char *libsimple_enstrdup(int, const char *); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_estrdup(const char *__s) -{ return libsimple_enstrdup(libsimple_default_failure_exit, __s); } +inline char * +libsimple_estrdup(const char *__s) +{ + return libsimple_enstrdup(libsimple_default_failure_exit, __s); +} #ifndef estrdup # define estrdup libsimple_estrdup #endif diff --git a/libsimple/strndup.h b/libsimple/strndup.h index 174a10a..6259a1e 100644 --- a/libsimple/strndup.h +++ b/libsimple/strndup.h @@ -48,8 +48,11 @@ char *libsimple_enstrndup(int, const char *, size_t); * @return Duplicate of `s` */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_estrndup(const char *__s, size_t __n) -{ return libsimple_enstrndup(libsimple_default_failure_exit, __s, __n); } +inline char * +libsimple_estrndup(const char *__s, size_t __n) +{ + return libsimple_enstrndup(libsimple_default_failure_exit, __s, __n); +} #ifndef estrndup # define estrndup libsimple_estrndup #endif diff --git a/libsimple/strtoint.h b/libsimple/strtoint.h index 34c2432..ba2c92e 100644 --- a/libsimple/strtoint.h +++ b/libsimple/strtoint.h @@ -23,6 +23,7 @@ signed char libsimple_strtohh(const char *restrict, char **restrict, int); # define strtohh libsimple_strtohh #endif + /** * Converts a string to a `unsigned char` * according to the rules of strtoul(3) @@ -45,6 +46,7 @@ unsigned char libsimple_strtouhh(const char *restrict, char **restrict, int); # define strtouhh libsimple_strtouhh #endif + /** * Converts a string to a `signed short int` * according to the rules of strtol(3) @@ -67,6 +69,7 @@ signed short int libsimple_strtoh(const char *restrict, char **restrict, int); # define strtoh libsimple_strtoh #endif + /** * Converts a string to a `unsigned short int` * according to the rules of strtoul(3) @@ -89,6 +92,7 @@ unsigned short int libsimple_strtouh(const char *restrict, char **restrict, int) # define strtouh libsimple_strtouh #endif + /** * Converts a string to a `signed int` * according to the rules of strtol(3) @@ -111,6 +115,7 @@ signed int libsimple_strtoi(const char *restrict, char **restrict, int); # define strtoi libsimple_strtoi #endif + /** * Converts a string to a `unsigned int` * according to the rules of strtoul(3) @@ -133,6 +138,7 @@ unsigned int libsimple_strtou(const char *restrict, char **restrict, int); # define strtou libsimple_strtou #endif + /** * Converts a string to a `ssize_t` * according to the rules of strtol(3) @@ -151,14 +157,15 @@ unsigned int libsimple_strtou(const char *restrict, char **restrict, int); */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) inline ssize_t -libsimple_strtoz(const char *restrict nptr, char **restrict endptr, int base) +libsimple_strtoz(const char *restrict __nptr, char **restrict __endptr, int __base) { - return (ssize_t)strtol(nptr, endptr, base); + return (ssize_t)strtol(__nptr, __endptr, __base); } #ifndef strtoz # define strtoz libsimple_strtoz #endif + /** * Converts a string to a `size_t` * according to the rules of strtol(3) @@ -177,14 +184,15 @@ libsimple_strtoz(const char *restrict nptr, char **restrict endptr, int base) */ _LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) inline size_t -libsimple_strtouz(const char *restrict nptr, char **restrict endptr, int base) +libsimple_strtouz(const char *restrict __nptr, char **restrict __endptr, int __base) { - return (size_t)strtoul(nptr, endptr, base); + return (size_t)strtoul(__nptr, __endptr, __base); } #ifndef strtouz # define strtouz libsimple_strtouz #endif + /** * Converts a string to a `int8_t` * according to the rules of strtol(3) @@ -207,6 +215,7 @@ int_least8_t libsimple_strtoi8(const char *restrict, char **restrict, int); # define strtoi8 libsimple_strtoi8 #endif + /** * Converts a string to a `uint8_t` * according to the rules of strtoul(3) @@ -229,6 +238,7 @@ uint_least8_t libsimple_strtou8(const char *restrict, char **restrict, int); # define strtou8 libsimple_strtou8 #endif + /** * Converts a string to a `int16_t` * according to the rules of strtol(3) @@ -251,6 +261,7 @@ int_least16_t libsimple_strtoi16(const char *restrict, char **restrict, int); # define strtoi16 libsimple_strtoi16 #endif + /** * Converts a string to a `uint16_t` * according to the rules of strtoul(3) @@ -273,6 +284,7 @@ uint_least16_t libsimple_strtou16(const char *restrict, char **restrict, int); # define strtou16 libsimple_strtou16 #endif + /** * Converts a string to a `int32_t` * according to the rules of strtol(3) @@ -295,6 +307,7 @@ int_least32_t libsimple_strtoi32(const char *restrict, char **restrict, int); # define strtoi32 libsimple_strtoi32 #endif + /** * Converts a string to a `uint32_t` * according to the rules of strtoul(3) @@ -317,6 +330,7 @@ uint_least32_t libsimple_strtou32(const char *restrict, char **restrict, int); # define strtou32 libsimple_strtou32 #endif + /** * Converts a string to a `int64_t` * according to the rules of strtol(3) @@ -339,6 +353,7 @@ int_least64_t libsimple_strtoi64(const char *restrict, char **restrict, int); # define strtoi64 libsimple_strtoi64 #endif + /** * Converts a string to a `uint64_t` * according to the rules of strtoul(3) diff --git a/libsimple/wcsdup.h b/libsimple/wcsdup.h index b85d265..8a2e8d2 100644 --- a/libsimple/wcsdup.h +++ b/libsimple/wcsdup.h @@ -44,8 +44,11 @@ wchar_t *libsimple_enwcsdup(int, const wchar_t *); */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ewcsdup(const wchar_t *__s) -{ return enwcsdup(libsimple_default_failure_exit, __s); } +inline wchar_t * +libsimple_ewcsdup(const wchar_t *__s) +{ + return enwcsdup(libsimple_default_failure_exit, __s); +} #ifndef ewcsdup # define ewcsdup libsimple_ewcsdup #endif diff --git a/libsimple/wcsndup.h b/libsimple/wcsndup.h index 31e9118..583ce65 100644 --- a/libsimple/wcsndup.h +++ b/libsimple/wcsndup.h @@ -65,8 +65,11 @@ wchar_t *libsimple_enwcsndup(int, const wchar_t *, size_t); */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ewcsndup(const wchar_t *__s, size_t __n) -{ return libsimple_enwcsndup(libsimple_default_failure_exit, __s, __n); } +inline wchar_t * +libsimple_ewcsndup(const wchar_t *__s, size_t __n) +{ + return libsimple_enwcsndup(libsimple_default_failure_exit, __s, __n); +} #ifndef ewcsndup # define ewcsndup libsimple_ewcsndup #endif diff --git a/libsimple/wmemdup.h b/libsimple/wmemdup.h index 2c1f899..9c63cbc 100644 --- a/libsimple/wmemdup.h +++ b/libsimple/wmemdup.h @@ -61,8 +61,11 @@ wchar_t *libsimple_enwmemdup(int, const wchar_t *, size_t); */ _LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ewmemdup(const wchar_t *__s, size_t __n) -{ return libsimple_enwmemdup(libsimple_default_failure_exit, __s, __n); } +inline wchar_t * +libsimple_ewmemdup(const wchar_t *__s, size_t __n) +{ + return libsimple_enwmemdup(libsimple_default_failure_exit, __s, __n); +} #ifndef ewmemdup # define ewmemdup libsimple_ewmemdup #endif diff --git a/memsetelem.c b/memsetelem.c new file mode 100644 index 0000000..6bcf021 --- /dev/null +++ b/memsetelem.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memsetelem(void *, const void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char p_[4096]; + char *p = p_; + size_t i; + + memset(p, 0, sizeof(p_)); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 10) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 1, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 2, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 4, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 8, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 16, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~0}, 3, 0) == p); + assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p); + assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p); + assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p); + assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p); + assert(libsimple_memsetelem(p, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == p); + + for (i = 0; i < 48; i++) + assert(p[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]); + for (; i < 800; i += 8) + assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL); + for (; i < 1200; i += 4) + assert(*(uint32_t *)&p[i] == 0x10203040UL); + for (; i < 2000; i += 2) + assert(*(uint16_t *)&p[i] == 0x0807); + for (; i < 3000; i++) + assert(p[i] == 0x09); + for (; i < sizeof(p_); i++) + assert(p[i] == 0); + + return 0; +} + +#endif diff --git a/putenvf.c b/putenvf.c new file mode 100644 index 0000000..45628ba --- /dev/null +++ b/putenvf.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_putenvf(const char *, ...); + + +#else +#include "test.h" + +int +main(void) +{ + unsetenv("X"); + assert(!getenv("X")); + unsetenv("Y"); + assert(!getenv("Y")); + + putenvf("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + putenvf("Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + putenvf("X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + putenvf("Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + putenvf("X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + putenvf("Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + return 0; +} + +#endif diff --git a/strtouz.c b/strtouz.c index 2885600..57d218d 100644 --- a/strtouz.c +++ b/strtouz.c @@ -3,7 +3,7 @@ #ifndef TEST -extern inline size_t libsimple_strtouz(const char *restrict nptr, char **restrict end, int base); /* TODO test, man */ +extern inline size_t libsimple_strtouz(const char *restrict, char **restrict, int); /* TODO test, man */ #else diff --git a/strtoz.c b/strtoz.c index dbaccad..d07be33 100644 --- a/strtoz.c +++ b/strtoz.c @@ -3,7 +3,7 @@ #ifndef TEST -extern inline ssize_t libsimple_strtoz(const char *restrict nptr, char **restrict end, int base); /* TODO test, man */ +extern inline ssize_t libsimple_strtoz(const char *restrict, char **restrict, int); /* TODO test, man */ #else diff --git a/unlist.c b/unlist.c new file mode 100644 index 0000000..192fad0 --- /dev/null +++ b/unlist.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_unlist(void *, size_t, size_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[10]; + int intarray[10]; + size_t i, n; + + for (i = 0, n = 10; i < n; i++) + buf[i] = i; + LIBSIMPLE_UNLIST(buf, 4, &n); + LIBSIMPLE_UNLIST(buf, 9 - 1, &n); + LIBSIMPLE_UNLIST(buf, 6 - 1, &n); + assert(n == 7); + assert(buf[0] == 0); + assert(buf[1] == 1); + assert(buf[2] == 2); + assert(buf[3] == 3); + assert(buf[4] == 5); + assert(buf[5] == 7); + assert(buf[6] == 8); + + for (i = 0, n = 10; i < n; i++) + intarray[i] = i; + LIBSIMPLE_UNLIST(intarray, 4, &n); + LIBSIMPLE_UNLIST(intarray, 9 - 1, &n); + LIBSIMPLE_UNLIST(intarray, 6 - 1, &n); + assert(n == 7); + assert(intarray[0] == 0); + assert(intarray[1] == 1); + assert(intarray[2] == 2); + assert(intarray[3] == 3); + assert(intarray[4] == 5); + assert(intarray[5] == 7); + assert(intarray[6] == 8); + + return 0; +} + +#endif diff --git a/vputenvf.c b/vputenvf.c index ee823f2..ea97ae6 100644 --- a/vputenvf.c +++ b/vputenvf.c @@ -36,27 +36,7 @@ libsimple_vputenvf(const char *fmt, va_list ap) int main(void) { - unsetenv("X"); - assert(!getenv("X")); - unsetenv("Y"); - assert(!getenv("Y")); - - putenvf("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - putenvf("Y=xyz"); - assert(!strcmpnul(getenv("Y"), "xyz")); - - putenvf("X=x%sz", "abc"); - assert(!strcmpnul(getenv("X"), "xabcz")); - putenvf("Y=x%sz", "abc"); - assert(!strcmpnul(getenv("Y"), "xabcz")); - - putenvf("X=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("X"), "10xabcz-11")); - putenvf("Y=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("Y"), "10xabcz-11")); - - return 0; + return 0; /* Tested via libsimple_putenvf */ } #endif -- cgit v1.2.3-70-g09d2 From fcfe59c1f2219408ac2a9cd84b386816ff252221 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 11 Jun 2022 16:37:09 +0200 Subject: Fix warnings, replace some static inline with inline + extern inline, and fix glibc support --- .gitignore | 1 + Makefile | 104 +++- aligned_strdup.c | 37 ++ aligned_wcsdup.c | 37 ++ allocn.c | 63 +-- asprintf.c | 5 +- cmptimespec.c | 133 +++++ cmptimeval.c | 248 ++++++++++ difftimeval.c | 102 ++-- doubletotimespec.c | 3 +- doubletotimeval.c | 3 +- ealigned_strdup.c | 41 ++ ealigned_wcsdup.c | 41 ++ egmtime.c | 18 + elocaltime.c | 18 + ememalloc.c | 18 + enaligned_strdup.c | 32 -- enaligned_wcsdup.c | 32 -- engmtime.c | 3 +- enlocaltime.c | 3 +- enmemalloc.c | 18 + enposix_memalign.c | 42 ++ enposix_memalignn.c | 45 ++ enposix_memalignz.c | 78 --- enposix_memalignzn.c | 68 +++ enprintf.c | 18 + enpvalloc.c | 42 ++ enpvallocn.c | 18 + enpvallocz.c | 59 +++ enpvalloczn.c | 18 + enrealloc.c | 29 -- enreallocarray.c | 62 --- enreallocn.c | 50 ++ envallocz.c | 59 +++ envalloczn.c | 18 + envposix_memalignn.c | 18 + envposix_memalignzn.c | 150 +----- envpvallocn.c | 18 + envpvalloczn.c | 18 + envreallocn.c | 63 +-- envvalloczn.c | 18 + eposix_memalign.c | 43 ++ eposix_memalignn.c | 47 ++ eposix_memalignz.c | 63 +++ eposix_memalignzn.c | 71 +++ eprintf.c | 18 + epvalloc.c | 44 ++ epvallocn.c | 18 + epvallocz.c | 63 +++ epvalloczn.c | 18 + erealloc.c | 52 ++ ereallocarray.c | 67 +++ ereallocn.c | 52 ++ evallocz.c | 63 +++ evalloczn.c | 18 + evmemalloc.c | 18 + evposix_memalignn.c | 18 + evposix_memalignzn.c | 18 + evpvallocn.c | 18 + evpvalloczn.c | 18 + evreallocn.c | 18 + evvalloczn.c | 18 + getenv_e.c | 7 +- getenv_ne.c | 7 +- libsimple-arg.c | 407 ++++++++-------- libsimple-arg.h | 2 +- libsimple.c | 867 +-------------------------------- libsimple.h | 93 ++-- libsimple/aligned_alloc.h | 81 +-- libsimple/aligned_allocz.h | 72 +-- libsimple/aligned_memdup.h | 11 +- libsimple/aligned_realloc.h | 151 +++--- libsimple/aligned_strdup.h | 43 +- libsimple/aligned_strndup.h | 39 +- libsimple/aligned_wcsdup.h | 43 +- libsimple/aligned_wcsndup.h | 39 +- libsimple/aligned_wmemdup.h | 37 +- libsimple/calloc.h | 77 +-- libsimple/env.h | 62 +-- libsimple/malloc.h | 77 +-- libsimple/mallocz.h | 86 ++-- libsimple/mem.h | 179 ++++--- libsimple/memalign.h | 90 ++-- libsimple/memalignz.h | 106 ++-- libsimple/memalloc.h | 55 ++- libsimple/memdup.h | 19 +- libsimple/memelem.h | 30 +- libsimple/posix_memalign.h | 87 ++-- libsimple/posix_memalignz.h | 80 +-- libsimple/printf.h | 114 ++--- libsimple/pvalloc.h | 96 ++-- libsimple/pvallocz.h | 102 ++-- libsimple/realloc.h | 143 +++--- libsimple/str.h | 247 ++++++---- libsimple/strdup.h | 17 +- libsimple/strn.h | 227 +++++---- libsimple/strndup.h | 23 +- libsimple/strtoint.h | 40 +- libsimple/time.h | 118 ++--- libsimple/valloc.h | 90 ++-- libsimple/vallocz.h | 102 ++-- libsimple/wcsdup.h | 17 +- libsimple/wcsndup.h | 25 +- libsimple/wmemdup.h | 19 +- man3/libsimple_aligned_allocz.3 | 4 +- man3/libsimple_aligned_memdup.3 | 2 +- man3/libsimple_aligned_realloc.3 | 4 +- man3/libsimple_aligned_reallocarray.3 | 4 +- man3/libsimple_aligned_reallocarrayf.3 | 2 +- man3/libsimple_aligned_reallocf.3 | 2 +- man3/libsimple_aligned_strdup.3 | 2 +- man3/libsimple_aligned_strndup.3 | 2 +- man3/libsimple_aligned_wcsdup.3 | 2 +- man3/libsimple_aligned_wcsndup.3 | 2 +- man3/libsimple_aligned_wmemdup.3 | 2 +- man3/libsimple_close.3 | 2 +- man3/libsimple_cmptimespec.3 | 4 +- man3/libsimple_enaligned_alloc.3 | 4 +- man3/libsimple_encalloc.3 | 2 +- man3/libsimple_enmalloc.3 | 2 +- man3/libsimple_enposix_memalign.3 | 4 +- man3/libsimple_enrealloc.3 | 2 +- man3/libsimple_enstrdup.3 | 2 +- man3/libsimple_enstrndup.3 | 2 +- man3/libsimple_enwcsdup.3 | 2 +- man3/libsimple_getenv_e.3 | 2 +- man3/libsimple_getenv_ne.3 | 2 +- man3/libsimple_gmtime.3 | 4 +- man3/libsimple_inchrset.3 | 4 +- man3/libsimple_localtime.3 | 4 +- man3/libsimple_mallocz.3 | 6 +- man3/libsimple_memalign.3 | 6 +- man3/libsimple_memalignz.3 | 6 +- man3/libsimple_memcasecmp.3 | 2 +- man3/libsimple_memcaseeq.3 | 2 +- man3/libsimple_memdup.3 | 2 +- man3/libsimple_memelemmove.3 | 4 +- man3/libsimple_memeq.3 | 2 +- man3/libsimple_mempcpy.3 | 2 +- man3/libsimple_mempmove.3 | 2 +- man3/libsimple_mempset.3 | 2 +- man3/libsimple_memreplace.3 | 2 +- man3/libsimple_memsetelem.3 | 2 +- man3/libsimple_memtolower.3 | 2 +- man3/libsimple_memtoupper.3 | 2 +- man3/libsimple_posix_memalignz.3 | 4 +- man3/libsimple_pvalloc.3 | 6 +- man3/libsimple_pvallocz.3 | 6 +- man3/libsimple_rawmemcmove.3 | 4 +- man3/libsimple_rawmemelemmove.3 | 4 +- man3/libsimple_reallocarray.3 | 6 +- man3/libsimple_reallocarrayf.3 | 2 +- man3/libsimple_reallocf.3 | 2 +- man3/libsimple_stpmove.3 | 2 +- man3/libsimple_stpnmove.3 | 2 +- man3/libsimple_strcasecmpnul.3 | 2 +- man3/libsimple_strcaseeq.3 | 2 +- man3/libsimple_strcaseeqnul.3 | 2 +- man3/libsimple_strcasestarts.3 | 2 +- man3/libsimple_strcmove.3 | 2 +- man3/libsimple_strcmpnul.3 | 2 +- man3/libsimple_strend.3 | 2 +- man3/libsimple_streq.3 | 2 +- man3/libsimple_streqnul.3 | 2 +- man3/libsimple_strisutf8.3 | 4 +- man3/libsimple_strmove.3 | 2 +- man3/libsimple_strncasecmpnul.3 | 2 +- man3/libsimple_strncaseeq.3 | 2 +- man3/libsimple_strncaseeqnul.3 | 2 +- man3/libsimple_strncmove.3 | 2 +- man3/libsimple_strncmpnul.3 | 2 +- man3/libsimple_strnend.3 | 2 +- man3/libsimple_strneq.3 | 2 +- man3/libsimple_strneqnul.3 | 2 +- man3/libsimple_strnmove.3 | 2 +- man3/libsimple_strnreplace.3 | 2 +- man3/libsimple_strnset.3 | 4 +- man3/libsimple_strntolower.3 | 2 +- man3/libsimple_strntoupper.3 | 2 +- man3/libsimple_strrcaseeqlen.3 | 2 +- man3/libsimple_strreplace.3 | 2 +- man3/libsimple_strreqlen.3 | 2 +- man3/libsimple_strrncaseeqlen.3 | 2 +- man3/libsimple_strrneqlen.3 | 2 +- man3/libsimple_strset.3 | 4 +- man3/libsimple_strtolower.3 | 2 +- man3/libsimple_strtoupper.3 | 2 +- man3/libsimple_timespectodouble.3 | 4 +- man3/libsimple_timeval2timespec.3 | 2 +- man3/libsimple_valigned_allocn.3 | 12 +- man3/libsimple_valigned_alloczn.3 | 8 +- man3/libsimple_valigned_reallocfn.3 | 4 +- man3/libsimple_valigned_reallocn.3 | 8 +- man3/libsimple_valloc.3 | 6 +- man3/libsimple_vallocz.3 | 6 +- man3/libsimple_vcallocn.3 | 12 +- man3/libsimple_vmallocn.3 | 12 +- man3/libsimple_vmalloczn.3 | 8 +- man3/libsimple_vmemalignn.3 | 12 +- man3/libsimple_vmemalignzn.3 | 12 +- man3/libsimple_vmemalloc.3 | 8 +- man3/libsimple_vposix_memalignn.3 | 12 +- man3/libsimple_vposix_memalignzn.3 | 8 +- man3/libsimple_vputenvf.3 | 8 +- man3/libsimple_vpvallocn.3 | 12 +- man3/libsimple_vpvalloczn.3 | 12 +- man3/libsimple_vreallocfn.3 | 4 +- man3/libsimple_vreallocn.3 | 8 +- man3/libsimple_vvallocn.3 | 12 +- man3/libsimple_vvalloczn.3 | 12 +- man3/libsimple_vweprintf.3 | 10 +- man3/libsimple_wcsndup.3 | 2 +- man3/libsimple_wmemdup.3 | 2 +- memalloc.c | 18 + memcaseends.c | 5 +- memcaseeq.c | 26 + memcasemem.c | 7 +- memcmove.c | 2 +- memelem.c | 26 +- memelem_inv.c | 24 +- memelemmove.c | 30 +- memelemscan.c | 28 +- memelemscan_inv.c | 28 +- memends.c | 5 +- memeq.c | 26 + memisutf8.c | 14 +- memmem.c | 6 +- mempcpy.c | 24 + mempmove.c | 35 ++ mempset.c | 24 + mempsetelem.c | 31 +- memptolower.c | 15 +- memptoupper.c | 15 +- memrcasechr.c | 2 +- memrcasechr_inv.c | 2 +- memrcaseeqlen.c | 10 +- memrcasemem.c | 7 +- memrchr.c | 2 +- memrchr_inv.c | 2 +- memrelem.c | 30 +- memrelem_inv.c | 28 +- memreplace.c | 28 ++ memreqlen.c | 3 +- memrmem.c | 6 +- memsetelem.c | 20 +- memtolower.c | 30 ++ memtoupper.c | 30 ++ posix_memalignn.c | 37 ++ posix_memalignz.c | 56 +++ posix_memalignzn.c | 49 ++ pvalloc.c | 45 ++ pvallocn.c | 50 ++ pvallocz.c | 110 +++++ pvalloczn.c | 75 +++ rawmemccpy.c | 28 ++ rawmemcmove.c | 52 ++ rawmemelem.c | 26 +- rawmemelem_inv.c | 24 +- rawmemelemmove.c | 28 +- rawmemrcasechr.c | 4 +- rawmemrcasechr_inv.c | 4 +- rawmemrelem.c | 30 +- rawmemrelem_inv.c | 28 +- reallocarray.c | 59 +++ reallocarrayf.c | 18 + reallocf.c | 18 + reallocfn.c | 18 + reallocn.c | 50 ++ stpntolower.c | 8 +- stpntoupper.c | 8 +- stptolower.c | 6 +- stptoupper.c | 6 +- strtoi.c | 2 +- strtotimespec.c | 27 +- strtou.c | 2 +- strtouh.c | 2 +- strtouhh.c | 2 +- sumtimeval.c | 60 ++- test.c | 4 +- test.h | 27 +- timespectodouble.c | 18 + timeval2timespec.c | 40 ++ timevaltodouble.c | 18 + unlist.c | 4 +- vallocz.c | 77 +++ valloczn.c | 75 +++ venprintf.c | 18 + veprintf.c | 18 + vmemalloc.c | 23 +- vposix_memalignn.c | 18 + vpvallocn.c | 18 + vpvalloczn.c | 18 + vreallocfn.c | 18 + vvalloczn.c | 18 + vweprintf.c | 103 +--- weprintf.c | 119 +++++ 296 files changed, 5894 insertions(+), 3540 deletions(-) create mode 100644 aligned_strdup.c create mode 100644 aligned_wcsdup.c create mode 100644 cmptimespec.c create mode 100644 cmptimeval.c create mode 100644 ealigned_strdup.c create mode 100644 ealigned_wcsdup.c create mode 100644 egmtime.c create mode 100644 elocaltime.c create mode 100644 ememalloc.c create mode 100644 enmemalloc.c create mode 100644 enposix_memalign.c create mode 100644 enposix_memalignn.c create mode 100644 enposix_memalignzn.c create mode 100644 enprintf.c create mode 100644 enpvalloc.c create mode 100644 enpvallocn.c create mode 100644 enpvallocz.c create mode 100644 enpvalloczn.c create mode 100644 enreallocn.c create mode 100644 envallocz.c create mode 100644 envalloczn.c create mode 100644 envposix_memalignn.c create mode 100644 envpvallocn.c create mode 100644 envpvalloczn.c create mode 100644 envvalloczn.c create mode 100644 eposix_memalign.c create mode 100644 eposix_memalignn.c create mode 100644 eposix_memalignz.c create mode 100644 eposix_memalignzn.c create mode 100644 eprintf.c create mode 100644 epvalloc.c create mode 100644 epvallocn.c create mode 100644 epvallocz.c create mode 100644 epvalloczn.c create mode 100644 erealloc.c create mode 100644 ereallocarray.c create mode 100644 ereallocn.c create mode 100644 evallocz.c create mode 100644 evalloczn.c create mode 100644 evmemalloc.c create mode 100644 evposix_memalignn.c create mode 100644 evposix_memalignzn.c create mode 100644 evpvallocn.c create mode 100644 evpvalloczn.c create mode 100644 evreallocn.c create mode 100644 evvalloczn.c create mode 100644 memalloc.c create mode 100644 memcaseeq.c create mode 100644 memeq.c create mode 100644 mempcpy.c create mode 100644 mempmove.c create mode 100644 mempset.c create mode 100644 memreplace.c create mode 100644 memtolower.c create mode 100644 memtoupper.c create mode 100644 posix_memalignn.c create mode 100644 posix_memalignz.c create mode 100644 posix_memalignzn.c create mode 100644 pvalloc.c create mode 100644 pvallocn.c create mode 100644 pvallocz.c create mode 100644 pvalloczn.c create mode 100644 rawmemccpy.c create mode 100644 rawmemcmove.c create mode 100644 reallocarray.c create mode 100644 reallocarrayf.c create mode 100644 reallocf.c create mode 100644 reallocfn.c create mode 100644 reallocn.c create mode 100644 timespectodouble.c create mode 100644 timeval2timespec.c create mode 100644 timevaltodouble.c create mode 100644 vallocz.c create mode 100644 valloczn.c create mode 100644 venprintf.c create mode 100644 veprintf.c create mode 100644 vposix_memalignn.c create mode 100644 vpvallocn.c create mode 100644 vpvalloczn.c create mode 100644 vreallocfn.c create mode 100644 vvalloczn.c create mode 100644 weprintf.c (limited to 'Makefile') diff --git a/.gitignore b/.gitignore index 9a3192c..99287d5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ *.gcno *.gcov *.lo +*.to diff --git a/Makefile b/Makefile index 88f2130..3299480 100644 --- a/Makefile +++ b/Makefile @@ -50,20 +50,30 @@ HDR =\ OBJ =\ aligned_memdup.o\ + aligned_strdup.o\ aligned_strndup.o\ + aligned_wcsdup.o\ aligned_wcsndup.o\ aligned_wmemdup.o\ allocn.o\ asprintf.o\ close.o\ + cmptimespec.o\ + cmptimeval.o\ difftimespec.o\ difftimeval.o\ doubletotimespec.o\ doubletotimeval.o\ ealigned_memdup.o\ + ealigned_strdup.o\ ealigned_strndup.o\ + ealigned_wcsdup.o\ ealigned_wcsndup.o\ ealigned_wmemdup.o\ + egmtime.o\ + elocaltime.o\ + ememalloc.o\ + ememdup.o\ enaligned_allocz.o\ enaligned_memdup.o\ enaligned_realloc.o\ @@ -77,28 +87,64 @@ OBJ =\ engmtime.o\ enlocaltime.o\ enmalloc.o\ + enmemalloc.o\ enmemdup.o\ + enposix_memalign.o\ + enposix_memalignn.o\ enposix_memalignz.o\ + enposix_memalignzn.o\ + enprintf.o\ enputenvf.o\ + enpvalloc.o\ + enpvallocn.o\ + enpvallocz.o\ + enpvalloczn.o\ enrealloc.o\ enreallocarray.o\ + enreallocn.o\ enstrdup.o\ enstrndup.o\ envaligned_alloczn.o\ envaligned_reallocn.o\ + envallocz.o\ + envalloczn.o\ envmalloczn.o\ envmemalloc.o\ + envposix_memalignn.o\ envposix_memalignzn.o\ envputenvf.o\ + envpvallocn.o\ + envpvalloczn.o\ envreallocn.o\ + envvalloczn.o\ enwcsdup.o\ enwcsndup.o\ enwmemdup.o\ - ememdup.o\ + eposix_memalign.o\ + eposix_memalignn.o\ + eposix_memalignz.o\ + eposix_memalignzn.o\ + eprintf.o\ eputenvf.o\ + epvalloc.o\ + epvallocn.o\ + epvallocz.o\ + epvalloczn.o\ + erealloc.o\ + ereallocarray.o\ + ereallocn.o\ estrdup.o\ estrndup.o\ + evallocz.o\ + evalloczn.o\ + evmemalloc.o\ + evposix_memalignn.o\ + evposix_memalignzn.o\ evputenvf.o\ + evpvallocn.o\ + evpvalloczn.o\ + evreallocn.o\ + evvalloczn.o\ ewcsdup.o\ ewcsndup.o\ ewmemdup.o\ @@ -106,10 +152,12 @@ OBJ =\ getenv_ne.o\ gmtime.o\ localtime.o\ + memalloc.o\ memcasechr.o\ memcasechr_inv.o\ memcasecmp.o\ memcaseends.o\ + memcaseeq.o\ memcaseeqlen.o\ memcasemem.o\ memcasescan.o\ @@ -125,9 +173,13 @@ OBJ =\ memelemscan.o\ memelemscan_inv.o\ memends.o\ + memeq.o\ memeqlen.o\ memisutf8.o\ memmem.o\ + mempcpy.o\ + mempmove.o\ + mempset.o\ mempsetelem.o\ memptolower.o\ memptoupper.o\ @@ -139,21 +191,33 @@ OBJ =\ memrchr_inv.o\ memrelem.o\ memrelem_inv.o\ + memreplace.o\ memreplaceelem.o\ memreqlen.o\ memrmem.o\ - memsetelem.o\ memscan.o\ memscan_inv.o\ + memsetelem.o\ memstarts.o\ + memtolower.o\ + memtoupper.o\ minimise_number_string.o\ multimespec.o\ multimeval.o\ + posix_memalignn.o\ + posix_memalignz.o\ + posix_memalignzn.o\ putenvf.o\ + pvalloc.o\ + pvallocn.o\ + pvallocz.o\ + pvalloczn.o\ rawmemcasechr.o\ rawmemcasechr_inv.o\ + rawmemccpy.o\ rawmemchr.o\ rawmemchr_inv.o\ + rawmemcmove.o\ rawmemelem.o\ rawmemelem_inv.o\ rawmemelemcpy.o\ @@ -164,6 +228,11 @@ OBJ =\ rawmemrchr_inv.o\ rawmemrelem.o\ rawmemrelem_inv.o\ + reallocarray.o\ + reallocarrayf.o\ + reallocf.o\ + reallocfn.o\ + reallocn.o\ stpntolower.o\ stpntoupper.o\ stptolower.o\ @@ -232,14 +301,27 @@ OBJ =\ sumtimespec.o\ sumtimeval.o\ timespec2timeval.o\ + timespectodouble.o\ timespectostr.o\ + timeval2timespec.o\ + timevaltodouble.o\ timevaltostr.o\ unlist.o\ + vallocz.o\ + valloczn.o\ vasprintf.o\ + venprintf.o\ + veprintf.o\ vmemalloc.o\ + vposix_memalignn.o\ vputenvf.o\ + vpvallocn.o\ + vpvalloczn.o\ + vreallocfn.o\ + vvalloczn.o\ vweprintf.o\ wcsndup.o\ + weprintf.o\ wmemdup.o\ libsimple.o @@ -255,21 +337,23 @@ MAN3 =\ TESTS = $(OBJ:.o=.test) libsimple-arg.test all: libsimple.a $(TESTS) -$(OBJ): $(@:.o=.c) $(HDR) -$(TESTS): $(@:=.o) test.o libsimple.a -$(TESTS:=.o): $(@:.test.o=.c) $(HDR) test.h +tests: $(TESTS) +$(OBJ): $(HDR) +$(TESTS): test.o libsimple.a +$(TESTS:.test=.to): $(HDR) test.h test.o: test.c $(HDR) test.h $(CC) -c -o $@ test.c $(CFLAGS) -DTEST -O0 -ffreestanding libsimple.a: $(OBJ) - $(AR) rc $@ $? + @rm -f -- $@ + $(AR) rc $@ $(OBJ) $(AR) -s $@ -.test.o.test: +.to.test: $(CC) -o $@ $< test.o libsimple.a $(LDFLAGS) -.c.test.o: +.c.to: $(CC) -c -o $@ $< $(CFLAGS) -DTEST -O0 check: $(TESTS) @@ -295,9 +379,9 @@ uninstall: -cd -- "$(DESTDIR)$(PREFIX)/share/man" && rm -f -- $(MAN0) $(MAN3) clean: - -rm -rf -- *.o *.su *.a *.so *.so.* *.gch *.gcda *.gcno *.gcov *.lo *.test + -rm -rf -- *.o *.su *.a *.so *.so.* *.gch *.gcda *.gcno *.gcov *.lo *.test *.to .SUFFIXES: -.SUFFIXES: .test .test.o .o .c +.SUFFIXES: .test .to .o .c .PHONY: all check install uninstall clean diff --git a/aligned_strdup.c b/aligned_strdup.c new file mode 100644 index 0000000..ed4ddf7 --- /dev/null +++ b/aligned_strdup.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_aligned_strdup(const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_aligned_strdup("test", 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 4); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_aligned_strdup("test", 16) && errno == ENOMEM); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/aligned_wcsdup.c b/aligned_wcsdup.c new file mode 100644 index 0000000..abb98e0 --- /dev/null +++ b/aligned_wcsdup.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_aligned_wcsdup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_aligned_wcsdup(L"test", 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (4 - 5 * sizeof(wchar_t) % 4) % 4); + assert(info->alignment == 4); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_aligned_wcsdup(L"test", 16) && errno == ENOMEM); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/allocn.c b/allocn.c index ce4fbad..540772e 100644 --- a/allocn.c +++ b/allocn.c @@ -78,7 +78,7 @@ int main(void) { struct allocinfo *info; - void *ptr, *old; + void *ptr; assert(!libsimple_malloczn(0, 0) && errno == EINVAL); errno = 0; @@ -88,17 +88,12 @@ main(void) errno = 0; assert(!libsimple_callocn(0) && errno == EINVAL); errno = 0; - assert(!libsimple_reallocn(NULL, 0) && errno == EINVAL); - errno = 0; assert(!libsimple_aligned_alloczn(0, 128, 0) && errno == EINVAL); errno = 0; assert(!libsimple_aligned_alloczn(1, 128, 0) && errno == EINVAL); errno = 0; assert(!libsimple_aligned_allocn(128, 0) && errno == EINVAL); errno = 0; - assert(libsimple_posix_memalignzn(&ptr, 0, 128, 0) == EINVAL && !errno); - assert(libsimple_posix_memalignzn(&ptr, 1, 128, 0) == EINVAL && !errno); - assert(libsimple_posix_memalignn(&ptr, 128, 0) == EINVAL && !errno); assert(!libsimple_malloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM); errno = 0; @@ -108,17 +103,12 @@ main(void) errno = 0; assert(!libsimple_callocn(SIZE_MAX, 2, 0) && errno == ENOMEM); errno = 0; - assert(!libsimple_reallocn(NULL, SIZE_MAX, 2, 0) && errno == ENOMEM); - errno = 0; assert(!libsimple_aligned_alloczn(0, 1024, SIZE_MAX, 2, 0) && errno == ENOMEM); errno = 0; assert(!libsimple_aligned_alloczn(1, 1024, SIZE_MAX, 2, 0) && errno == ENOMEM); errno = 0; assert(!libsimple_aligned_allocn(1024, SIZE_MAX, 2, 0) && errno == ENOMEM); errno = 0; - assert(libsimple_posix_memalignzn(&ptr, 0, 1024, SIZE_MAX, 2, 0) == ENOMEM && !errno); - assert(libsimple_posix_memalignzn(&ptr, 1, 1024, SIZE_MAX, 2, 0) == ENOMEM && !errno); - assert(libsimple_posix_memalignn(&ptr, 1024, SIZE_MAX, 2, 0) == ENOMEM && !errno); assert((ptr = libsimple_malloczn(0, 10, 10, 0))); if (have_custom_malloc()) { @@ -156,27 +146,6 @@ main(void) } free(ptr); - assert((ptr = libsimple_reallocn(NULL, 5, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5); - assert(!info->zeroed); - info->refcount += 1; - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - stpcpy(ptr, "test"); - assert((ptr = libsimple_reallocn(old = ptr, 10, 0))); - assert(!strcmp(ptr, "test")); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 10); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - assert(ptr != old); - free(old); - } - free(ptr); - assert((ptr = libsimple_aligned_alloczn(0, 8, 12, 12, 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -207,36 +176,6 @@ main(void) } free(ptr); - assert(!libsimple_posix_memalignzn(&ptr, 0, sizeof(void *), 12, 12, 0)); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 144); - assert(info->alignment == sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - - assert(!libsimple_posix_memalignzn(&ptr, 1, 2 * sizeof(void *), 12, 12, 2, 0)); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 288); - assert(info->alignment == 2 * sizeof(void *)); - assert(info->zeroed == 288); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - - assert(!libsimple_posix_memalignn(&ptr, 2 * sizeof(void *), 12, 12, 3, 0)); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 432); - assert(info->alignment == 2 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - assert(!errno); return 0; diff --git a/asprintf.c b/asprintf.c index 25bf07b..9c23204 100644 --- a/asprintf.c +++ b/asprintf.c @@ -21,10 +21,11 @@ libsimple_asprintf(char **strp, const char *fmt, ...) int main(void) { - char *s = ""; + char empty[1] = ""; + char *s = empty; char *old = s; - assert(libsimple_asprintf(&s, "%i %X", 99999, 255) == sizeof("99999 FF") - 1); + assert(libsimple_asprintf(&s, "%i %X", 99999, 255U) == sizeof("99999 FF") - 1); assert(s && s != old); assert(!strcmpnul(s, "99999 FF")); free(s); diff --git a/cmptimespec.c b/cmptimespec.c new file mode 100644 index 0000000..5a8463b --- /dev/null +++ b/cmptimespec.c @@ -0,0 +1,133 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_cmptimespec(const struct timespec *, const struct timespec *); + + +#else +#include "test.h" + +int +main(void) +{ + struct timespec ts1, ts2; + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; + ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = 1, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 1, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 1, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 1, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = 1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = 1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = 1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = 1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 1, ts1.tv_nsec = 0L; + ts2.tv_sec = 1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = 1, ts1.tv_nsec = 1L; + ts2.tv_sec = 1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 1, ts1.tv_nsec = 0L; + ts2.tv_sec = 1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 1, ts1.tv_nsec = 1L; + ts2.tv_sec = 1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = -1, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1, ts1.tv_nsec = 0L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1, ts1.tv_nsec = 1L; + ts2.tv_sec = 0, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = -1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = -1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = -1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = 0, ts1.tv_nsec = 1L; + ts2.tv_sec = -1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = -1, ts1.tv_nsec = 0L; + ts2.tv_sec = -1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = -1, ts1.tv_nsec = 1L; + ts2.tv_sec = -1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = -1, ts1.tv_nsec = 0L; + ts2.tv_sec = -1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1, ts1.tv_nsec = 1L; + ts2.tv_sec = -1, ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = 0, ts1.tv_nsec = 0L; + ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 1, ts1.tv_nsec = 0L; + ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = TIME_MAX, ts1.tv_nsec = 0L; + ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 0); + ts1.tv_sec = 1, ts1.tv_nsec = 0L; + ts2.tv_sec = -1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == 1); + ts1.tv_sec = -1, ts1.tv_nsec = 0L; + ts2.tv_sec = 1, ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + return 0; +} + +#endif diff --git a/cmptimeval.c b/cmptimeval.c new file mode 100644 index 0000000..7324988 --- /dev/null +++ b/cmptimeval.c @@ -0,0 +1,248 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_cmptimeval(const struct timeval *, const struct timeval *); + + +#else +#include "test.h" + +int +main(void) +{ + struct timeval tv1, tv2; + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 999999L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = 0; + tv1.tv_usec = 999999L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 999999L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 999999L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 999999L; + tv2.tv_sec = 0; + tv2.tv_usec = 999999L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = 1; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 1; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 1; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 1; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = 1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = 1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = 1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = 1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 1; + tv1.tv_usec = 0L; + tv2.tv_sec = 1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = 1; + tv1.tv_usec = 1L; + tv2.tv_sec = 1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 1; + tv1.tv_usec = 0L; + tv2.tv_sec = 1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 1; + tv1.tv_usec = 1L; + tv2.tv_sec = 1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = -1; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = -1; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = -1; + tv1.tv_usec = 0L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = -1; + tv1.tv_usec = 1L; + tv2.tv_sec = 0; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = -1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = -1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = -1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = 0; + tv1.tv_usec = 1L; + tv2.tv_sec = -1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = -1; + tv1.tv_usec = 0L; + tv2.tv_sec = -1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = -1; + tv1.tv_usec = 1L; + tv2.tv_sec = -1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = -1; + tv1.tv_usec = 0L; + tv2.tv_sec = -1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = -1; + tv1.tv_usec = 1L; + tv2.tv_sec = -1; + tv2.tv_usec = 1L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = 0; + tv1.tv_usec = 0L; + tv2.tv_sec = TIME_MAX; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = 1; + tv1.tv_usec = 0L; + tv2.tv_sec = TIME_MAX; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + tv1.tv_sec = TIME_MAX; + tv1.tv_usec = 0L; + tv2.tv_sec = TIME_MAX; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 0); + + tv1.tv_sec = 1; + tv1.tv_usec = 0L; + tv2.tv_sec = -1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == 1); + + tv1.tv_sec = -1; + tv1.tv_usec = 0L; + tv2.tv_sec = 1; + tv2.tv_usec = 0L; + assert(libsimple_cmptimeval(&tv1, &tv2) == -1); + + return 0; +} + +#endif diff --git a/difftimeval.c b/difftimeval.c index 2f633a2..e4c65e4 100644 --- a/difftimeval.c +++ b/difftimeval.c @@ -47,104 +47,138 @@ main(void) { struct timeval r, a, b; - a.tv_sec = 0, a.tv_usec = 0L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 100L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 100L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_usec == 100L); - a.tv_sec = 10, a.tv_usec = 100L; - b.tv_sec = 1, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 100L; + b.tv_sec = 1; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 9); assert(r.tv_usec == 100L); - a.tv_sec = 10, a.tv_usec = 100L; - b.tv_sec = 0, b.tv_usec = 1L; + a.tv_sec = 10; + a.tv_usec = 100L; + b.tv_sec = 0; + b.tv_usec = 1L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_usec == 99L); - a.tv_sec = -10, a.tv_usec = 100L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = -10; + a.tv_usec = 100L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_usec == 100L); - a.tv_sec = 10, a.tv_usec = 1L; - b.tv_sec = 1, b.tv_usec = 100L; + a.tv_sec = 10; + a.tv_usec = 1L; + b.tv_sec = 1; + b.tv_usec = 100L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 8); assert(r.tv_usec == 1000001L - 100L); - a.tv_sec = 10, a.tv_usec = 0L; - b.tv_sec = 20, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; + b.tv_sec = 20; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 10L; - b.tv_sec = 20, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 10L; + b.tv_sec = 20; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_usec == 10L); - a.tv_sec = 10, a.tv_usec = 10L; - b.tv_sec = 20, b.tv_usec = 20L; + a.tv_sec = 10; + a.tv_usec = 10L; + b.tv_sec = 20; + b.tv_usec = 20L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == -10 - 1); assert(r.tv_usec == 1000010L - 20L); - a.tv_sec = 10, a.tv_usec = 10L; - b.tv_sec = -20, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 10L; + b.tv_sec = -20; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 30); assert(r.tv_usec == 10L); - a.tv_sec = 0, a.tv_usec = 10L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 10L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_usec == 10L); - a.tv_sec = 0, a.tv_usec = 0L; - b.tv_sec = 0, b.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 0L; + b.tv_sec = 0; + b.tv_usec = 10L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == -1); assert(r.tv_usec == 1000000L - 10L); - a.tv_sec = TIME_MIN, a.tv_usec = 0L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = TIME_MIN; + a.tv_usec = 0L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 0L); - a.tv_sec = TIME_MIN, a.tv_usec = 0L; - b.tv_sec = 0, b.tv_usec = 1L; + a.tv_sec = TIME_MIN; + a.tv_usec = 0L; + b.tv_sec = 0; + b.tv_usec = 1L; assert(libsimple_difftimeval(&r, &a, &b) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 0L); - a.tv_sec = TIME_MIN, a.tv_usec = 0L; - b.tv_sec = -1, b.tv_usec = 1L; + a.tv_sec = TIME_MIN; + a.tv_usec = 0L; + b.tv_sec = -1; + b.tv_usec = 1L; assert(!libsimple_difftimeval(&r, &a, &b)); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; - b.tv_sec = -1, b.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; + b.tv_sec = -1; + b.tv_usec = 0L; assert(libsimple_difftimeval(&r, &a, &b) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); diff --git a/doubletotimespec.c b/doubletotimespec.c index a104b37..02f40e9 100644 --- a/doubletotimespec.c +++ b/doubletotimespec.c @@ -6,7 +6,8 @@ void libsimple_doubletotimespec(struct timespec *ts, double d) { - double ns = (long long int)d; + long long int d_integer = (long long int)d; + double ns = (double)d_integer; long int nsi; ns = d - ns; ns *= (double)1000000000L; diff --git a/doubletotimeval.c b/doubletotimeval.c index 03bacec..c603703 100644 --- a/doubletotimeval.c +++ b/doubletotimeval.c @@ -6,7 +6,8 @@ void libsimple_doubletotimeval(struct timeval *tv, double d) { - double ns = (long long int)d; + long long int d_integer = (long long int)d; + double ns = (double)d_integer; long int nsi; ns = d - ns; ns *= (double)1000000L; diff --git a/ealigned_strdup.c b/ealigned_strdup.c new file mode 100644 index 0000000..f0fd7e4 --- /dev/null +++ b/ealigned_strdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_ealigned_strdup(const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_strdup("test", 8))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_strdup("test", 8)); + assert(exit_status == 55); + assert_stderr("%s: aligned_strdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_wcsdup.c b/ealigned_wcsdup.c new file mode 100644 index 0000000..a73a261 --- /dev/null +++ b/ealigned_wcsdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ealigned_wcsdup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_wcsdup(L"test", 8))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_wcsdup(L"test", 8)); + assert(exit_status == 55); + assert_stderr("%s: aligned_wcsdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/egmtime.c b/egmtime.c new file mode 100644 index 0000000..85b62ee --- /dev/null +++ b/egmtime.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_egmtime(struct tm *, struct timespec *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/elocaltime.c b/elocaltime.c new file mode 100644 index 0000000..b3accdd --- /dev/null +++ b/elocaltime.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_elocaltime(struct tm *m, struct timespec *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalloc.c b/ememalloc.c new file mode 100644 index 0000000..79b2059 --- /dev/null +++ b/ememalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ememalloc(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_strdup.c b/enaligned_strdup.c index 533ff56..b2e505b 100644 --- a/enaligned_strdup.c +++ b/enaligned_strdup.c @@ -32,44 +32,12 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strdup("test", 8))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - - assert((s = libsimple_aligned_strdup("test", 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 4); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_strdup(44, "hello", 2)); assert(exit_status == 44); assert_stderr("%s: aligned_strdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_strdup("test", 8)); - assert(exit_status == 55); - assert_stderr("%s: aligned_strdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert(!libsimple_aligned_strdup("test", 16) && errno == ENOMEM); - assert(!alloc_fail_in); } return 0; diff --git a/enaligned_wcsdup.c b/enaligned_wcsdup.c index 10d9669..c048cc8 100644 --- a/enaligned_wcsdup.c +++ b/enaligned_wcsdup.c @@ -32,44 +32,12 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsdup(L"test", 8))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - - assert((s = libsimple_aligned_wcsdup(L"test", 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (4 - 5 * sizeof(wchar_t) % 4) % 4); - assert(info->alignment == 4); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_wcsdup(44, L"hello", 2)); assert(exit_status == 44); assert_stderr("%s: aligned_wcsdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_wcsdup(L"test", 8)); - assert(exit_status == 55); - assert_stderr("%s: aligned_wcsdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert(!libsimple_aligned_wcsdup(L"test", 16) && errno == ENOMEM); - assert(!alloc_fail_in); } return 0; diff --git a/engmtime.c b/engmtime.c index 55e6c9c..5cc9a55 100644 --- a/engmtime.c +++ b/engmtime.c @@ -4,7 +4,7 @@ void -libsimple_engmtime(int status, struct tm *tm, struct timespec *ts) +libsimple_engmtime(int status, struct tm *tm, struct timespec *ts) /* TODO test (also libsimple_egmtime) */ { if (libsimple_gmtime(tm, ts)) enprintf(status, "libsimple_gmtime:"); @@ -17,7 +17,6 @@ libsimple_engmtime(int status, struct tm *tm, struct timespec *ts) int main(void) { - /* TODO test */ return 0; } diff --git a/enlocaltime.c b/enlocaltime.c index af8907e..73fc99e 100644 --- a/enlocaltime.c +++ b/enlocaltime.c @@ -4,7 +4,7 @@ void -libsimple_enlocaltime(int status, struct tm *tm, struct timespec *ts) +libsimple_enlocaltime(int status, struct tm *tm, struct timespec *ts) /* TODO test (also libsimple_elocaltime) */ { if (libsimple_localtime(tm, ts)) enprintf(status, "libsimple_localtime:"); @@ -17,7 +17,6 @@ libsimple_enlocaltime(int status, struct tm *tm, struct timespec *ts) int main(void) { - /* TODO test */ return 0; } diff --git a/enmemalloc.c b/enmemalloc.c new file mode 100644 index 0000000..b81147b --- /dev/null +++ b/enmemalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalloc(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enposix_memalign.c b/enposix_memalign.c new file mode 100644 index 0000000..e2978e4 --- /dev/null +++ b/enposix_memalign.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_enposix_memalign(int, void **, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_enposix_memalign(1, &ptr, sizeof(void *), 8); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 8); + assert(info->alignment == sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit(libsimple_enposix_memalign(7, &ptr, sizeof(void *), 4)); + assert(exit_status == 7); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + + } + + return 0; +} + +#endif diff --git a/enposix_memalignn.c b/enposix_memalignn.c new file mode 100644 index 0000000..121d7c0 --- /dev/null +++ b/enposix_memalignn.c @@ -0,0 +1,45 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_enposix_memalignn(int, void **, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_enposix_memalignn(1, &ptr, 4 * sizeof(void *), 4, 3, 0); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 12); + assert(info->alignment == 4 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit(libsimple_enposix_memalignn(9, &ptr, 4 * sizeof(void *), 1, 0)); + assert(exit_status == 9); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + assert_exit(libsimple_enposix_memalignn(19, &ptr, sizeof(void *), SIZE_MAX, 2, 0)); + assert(exit_status == 19); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + + return 0; +} + +#endif diff --git a/enposix_memalignz.c b/enposix_memalignz.c index 64ae4f0..81844ea 100644 --- a/enposix_memalignz.c +++ b/enposix_memalignz.c @@ -35,18 +35,6 @@ main(void) free(ptr); ptr = NULL; - libsimple_eposix_memalignz(&ptr, 1, 2 * sizeof(void *), 8); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 8); - assert(info->alignment == 2 * sizeof(void *)); - assert(info->zeroed == 8); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - libsimple_enposix_memalignz(1, &ptr, 0, 2 * sizeof(void *), 8); assert(ptr); if (have_custom_malloc()) { @@ -59,42 +47,6 @@ main(void) free(ptr); ptr = NULL; - libsimple_eposix_memalignz(&ptr, 0, 4 * sizeof(void *), 4); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 4); - assert(info->alignment == 4 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - libsimple_enposix_memalign(1, &ptr, sizeof(void *), 8); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 8); - assert(info->alignment == sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - libsimple_eposix_memalign(&ptr, 8 * sizeof(void *), 4); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 4); - assert(info->alignment == 8 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit(libsimple_enposix_memalignz(3, &ptr, 1, sizeof(void *), 4)); @@ -102,41 +54,11 @@ main(void) assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 102; - alloc_fail_in = 1; - assert_exit(libsimple_eposix_memalignz(&ptr, 1, sizeof(void *), 4)); - assert(exit_status == 102); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit(libsimple_enposix_memalignz(5, &ptr, 0, sizeof(void *), 4)); assert(exit_status == 5); assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 103; - alloc_fail_in = 1; - assert_exit(libsimple_eposix_memalignz(&ptr, 0, sizeof(void *), 4)); - assert(exit_status == 103); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert_exit(libsimple_enposix_memalign(7, &ptr, sizeof(void *), 4)); - assert(exit_status == 7); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 104; - alloc_fail_in = 1; - assert_exit(libsimple_eposix_memalign(&ptr, sizeof(void *), 4)); - assert(exit_status == 104); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enposix_memalignzn.c b/enposix_memalignzn.c new file mode 100644 index 0000000..3606e74 --- /dev/null +++ b/enposix_memalignzn.c @@ -0,0 +1,68 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_enposix_memalignzn(int, void **, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_enposix_memalignzn(1, &ptr, 0, sizeof(void *), 5, 3, 0); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 15); + assert(info->alignment == sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + libsimple_enposix_memalignzn(1, &ptr, 1, 2 * sizeof(void *), 5, 4, 0); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 20); + assert(info->alignment == 2 * sizeof(void *)); + assert(info->zeroed == 20); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit(libsimple_enposix_memalignzn(3, &ptr, 0, 4 * sizeof(void *), 4, 0)); + assert(exit_status == 3); + stderr_buf[stderr_n] = 0; + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + assert_exit(libsimple_enposix_memalignzn(5, &ptr, 1, 4 * sizeof(void *), 2, 0)); + assert(exit_status == 5); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + assert_exit(libsimple_enposix_memalignzn(13, &ptr, 0, sizeof(void *), SIZE_MAX, 2, 0)); + assert(exit_status == 13); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + + assert_exit(libsimple_enposix_memalignzn(15, &ptr, 1, sizeof(void *), SIZE_MAX, 2, 0)); + assert(exit_status == 15); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + + return 0; +} + +#endif diff --git a/enprintf.c b/enprintf.c new file mode 100644 index 0000000..e896228 --- /dev/null +++ b/enprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_enprintf(int, const char *, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enpvalloc.c b/enpvalloc.c new file mode 100644 index 0000000..ab5df3a --- /dev/null +++ b/enpvalloc.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enpvalloc(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_enpvalloc(1, 127))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit_ptr(libsimple_enpvalloc(7, 4)); + assert(exit_status == 7); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/enpvallocn.c b/enpvallocn.c new file mode 100644 index 0000000..e4692ec --- /dev/null +++ b/enpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enpvallocn(int, size_t, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enpvallocz.c b/enpvallocz.c new file mode 100644 index 0000000..d20e6f6 --- /dev/null +++ b/enpvallocz.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enpvallocz(int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_enpvallocz(1, 1, 5 * pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_enpvallocz(1, 0, pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit_ptr(libsimple_enpvallocz(3, 1, 4)); + assert(exit_status == 3); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + assert_exit_ptr(libsimple_enpvallocz(5, 0, 4)); + assert(exit_status == 5); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/enpvalloczn.c b/enpvalloczn.c new file mode 100644 index 0000000..94d56bf --- /dev/null +++ b/enpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enpvalloczn(int, int, size_t, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enrealloc.c b/enrealloc.c index b27cb18..fd3fa31 100644 --- a/enrealloc.c +++ b/enrealloc.c @@ -43,41 +43,12 @@ main(void) } free(ptr); - assert((ptr = libsimple_erealloc(NULL, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - info->refcount += 1; - } - stpcpy(ptr, "test"); - assert((ptr = libsimple_erealloc(old = ptr, 10))); - assert(!strcmp(ptr, "test")); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 10); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - assert(ptr != old); - free(old); - } - free(ptr); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enrealloc(2, NULL, 1)); assert(exit_status == 2); assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 104; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_erealloc(NULL, 1)); - assert(exit_status == 104); - assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enreallocarray.c b/enreallocarray.c index c208626..48ac9bd 100644 --- a/enreallocarray.c +++ b/enreallocarray.c @@ -43,66 +43,12 @@ main(void) } free(ptr); - assert((ptr = libsimple_ereallocarray(NULL, 1, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - info->refcount += 1; - } - stpcpy(ptr, "test"); - assert((ptr = libsimple_ereallocarray(old = ptr, 10, 10))); - assert(!strcmp(ptr, "test")); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 100); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - assert(ptr != old); - free(old); - } - free(ptr); - - assert((ptr = libsimple_reallocarray(NULL, 1, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - info->refcount += 1; - } - stpcpy(ptr, "test"); - assert((ptr = libsimple_reallocarray(old = ptr, 10, 10))); - assert(!strcmp(ptr, "test")); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 100); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - assert(ptr != old); - free(old); - } - free(ptr); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enreallocarray(2, NULL, 1, 1)); assert(exit_status == 2); assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 104; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ereallocarray(NULL, 1, 1)); - assert(exit_status == 104); - assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert(!libsimple_reallocarray(NULL, 1, 1) && errno == ENOMEM); - assert(!alloc_fail_in); } #if defined(__GNUC__) && !defined(__clang) @@ -114,14 +60,6 @@ main(void) assert(exit_status == 3); assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); - libsimple_default_failure_exit = 4; - assert_exit_ptr(libsimple_ereallocarray(NULL, SIZE_MAX, SIZE_MAX)); - assert(exit_status == 4); - assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); - libsimple_default_failure_exit = 1; - - assert(!libsimple_reallocarray(NULL, SIZE_MAX, SIZE_MAX) && errno == ENOMEM); - #if defined(__GNUC__) && !defined(__clang) # pragma GCC diagnostic pop #endif diff --git a/enreallocn.c b/enreallocn.c new file mode 100644 index 0000000..c1817d9 --- /dev/null +++ b/enreallocn.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enreallocn(int, void *, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr, *old; + + assert((ptr = libsimple_enreallocn(1, NULL, 5, 3, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 15); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_enreallocn(1, old = ptr, 10, 2, 0))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 20); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + assert(ptr != old); + free(old); + } + free(ptr); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit_ptr(libsimple_enreallocn(2, NULL, 1, 0)); + assert(exit_status == 2); + assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/envallocz.c b/envallocz.c new file mode 100644 index 0000000..8e8d9b3 --- /dev/null +++ b/envallocz.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envallocz(int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_envallocz(1, 1, 5 * pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5 * pagesize - 1); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_envallocz(1, 0, pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize - 1); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit_ptr(libsimple_envallocz(3, 1, 4)); + assert(exit_status == 3); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + assert_exit_ptr(libsimple_envallocz(5, 0, 4)); + assert(exit_status == 5); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/envalloczn.c b/envalloczn.c new file mode 100644 index 0000000..c9a68fa --- /dev/null +++ b/envalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envalloczn(int, int, size_t, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envposix_memalignn.c b/envposix_memalignn.c new file mode 100644 index 0000000..d408e1a --- /dev/null +++ b/envposix_memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_envposix_memalignn(int, void **, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enposix_memalignn */ +} + +#endif diff --git a/envposix_memalignzn.c b/envposix_memalignzn.c index 62cc440..0693ac0 100644 --- a/envposix_memalignzn.c +++ b/envposix_memalignzn.c @@ -20,155 +20,7 @@ libsimple_envposix_memalignzn(int status, void **memptr, int clear, size_t align int main(void) { - struct allocinfo *info; - void *ptr = NULL; - - libsimple_enposix_memalignzn(1, &ptr, 0, sizeof(void *), 5, 3, 0); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 15); - assert(info->alignment == sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - libsimple_enposix_memalignzn(1, &ptr, 1, 2 * sizeof(void *), 5, 4, 0); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 20); - assert(info->alignment == 2 * sizeof(void *)); - assert(info->zeroed == 20); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - libsimple_enposix_memalignn(1, &ptr, 4 * sizeof(void *), 4, 3, 0); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 12); - assert(info->alignment == 4 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - if (have_custom_malloc()) { - alloc_fail_in = 1; - assert_exit(libsimple_enposix_memalignzn(3, &ptr, 0, 4 * sizeof(void *), 4, 0)); - assert(exit_status == 3); - stderr_buf[stderr_n] = 0; - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert_exit(libsimple_enposix_memalignzn(5, &ptr, 1, 4 * sizeof(void *), 2, 0)); - assert(exit_status == 5); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert_exit(libsimple_enposix_memalignn(9, &ptr, 4 * sizeof(void *), 1, 0)); - assert(exit_status == 9); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - } - - assert_exit(libsimple_enposix_memalignzn(13, &ptr, 0, sizeof(void *), SIZE_MAX, 2, 0)); - assert(exit_status == 13); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - - assert_exit(libsimple_enposix_memalignzn(15, &ptr, 1, sizeof(void *), SIZE_MAX, 2, 0)); - assert(exit_status == 15); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - - assert_exit(libsimple_enposix_memalignn(19, &ptr, sizeof(void *), SIZE_MAX, 2, 0)); - assert(exit_status == 19); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - - ptr = NULL; - - libsimple_eposix_memalignzn(&ptr, 0, 4 * sizeof(void *), 2, 5, 3, 0); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 30); - assert(info->alignment == 4 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - libsimple_eposix_memalignzn(&ptr, 1, sizeof(void *), 2, 5, 4, 0); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 40); - assert(info->alignment == sizeof(void *)); - assert(info->zeroed == 40); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - libsimple_eposix_memalignn(&ptr, 2 * sizeof(void *), 2, 4, 3, 0); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 24); - assert(info->alignment == 2 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - if (have_custom_malloc()) { - alloc_fail_in = 1; - libsimple_default_failure_exit = 23; - assert_exit(libsimple_eposix_memalignzn(&ptr, 0, sizeof(void *), 4, 0)); - assert(exit_status == 23); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - libsimple_default_failure_exit = 25; - assert_exit(libsimple_eposix_memalignzn(&ptr, 1, sizeof(void *), 2, 0)); - assert(exit_status == 25); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - libsimple_default_failure_exit = 29; - assert_exit(libsimple_eposix_memalignn(&ptr, sizeof(void *), 1, 0)); - assert(exit_status == 29); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - } - - libsimple_default_failure_exit = 33; - assert_exit(libsimple_eposix_memalignzn(&ptr, 0, sizeof(void *), SIZE_MAX, 2, 0)); - assert(exit_status == 33); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - - libsimple_default_failure_exit = 35; - assert_exit(libsimple_eposix_memalignzn(&ptr, 1, sizeof(void *), SIZE_MAX, 2, 0)); - assert(exit_status == 35); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - - libsimple_default_failure_exit = 39; - assert_exit(libsimple_eposix_memalignn(&ptr, sizeof(void *), SIZE_MAX, 2, 0)); - assert(exit_status == 39); - assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); - - return 0; + return 0; /* Tested via libsimple_enposix_memalignzn */ } #endif diff --git a/envpvallocn.c b/envpvallocn.c new file mode 100644 index 0000000..46a3acd --- /dev/null +++ b/envpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envpvallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enpvallocn */ +} + +#endif diff --git a/envpvalloczn.c b/envpvalloczn.c new file mode 100644 index 0000000..16bd5c4 --- /dev/null +++ b/envpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envpvalloczn(int, int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enpvalloczn */ +} + +#endif diff --git a/envreallocn.c b/envreallocn.c index 03394a1..7fdc82e 100644 --- a/envreallocn.c +++ b/envreallocn.c @@ -19,68 +19,7 @@ libsimple_envreallocn(int status, void *ptr, size_t n, va_list ap) int main(void) { - struct allocinfo *info; - void *ptr, *old; - - assert((ptr = libsimple_enreallocn(1, NULL, 5, 3, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 15); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - info->refcount += 1; - } - stpcpy(ptr, "test"); - assert((ptr = libsimple_enreallocn(1, old = ptr, 10, 2, 0))); - assert(!strcmp(ptr, "test")); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 20); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - assert(ptr != old); - free(old); - } - free(ptr); - - assert((ptr = libsimple_ereallocn(NULL, 5, 4, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 20); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - info->refcount += 1; - } - stpcpy(ptr, "test"); - assert((ptr = libsimple_ereallocn(old = ptr, 10, 11, 0))); - assert(!strcmp(ptr, "test")); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 110); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - assert(ptr != old); - free(old); - } - free(ptr); - - if (have_custom_malloc()) { - alloc_fail_in = 1; - assert_exit_ptr(libsimple_enreallocn(2, NULL, 1, 0)); - assert(exit_status == 2); - assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 104; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ereallocn(NULL, 1, 0)); - assert(exit_status == 104); - assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - } - - return 0; + return 0; /* Tested via libsimple_enreallocn */ } #endif diff --git a/envvalloczn.c b/envvalloczn.c new file mode 100644 index 0000000..f7e7886 --- /dev/null +++ b/envvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envvalloczn(int, int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_envalloczn */ +} + +#endif diff --git a/eposix_memalign.c b/eposix_memalign.c new file mode 100644 index 0000000..b471235 --- /dev/null +++ b/eposix_memalign.c @@ -0,0 +1,43 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_eposix_memalign(void **, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_eposix_memalign(&ptr, 8 * sizeof(void *), 4); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 4); + assert(info->alignment == 8 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 104; + alloc_fail_in = 1; + assert_exit(libsimple_eposix_memalign(&ptr, sizeof(void *), 4)); + assert(exit_status == 104); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/eposix_memalignn.c b/eposix_memalignn.c new file mode 100644 index 0000000..2845fe6 --- /dev/null +++ b/eposix_memalignn.c @@ -0,0 +1,47 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_eposix_memalignn(void **, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_eposix_memalignn(&ptr, 2 * sizeof(void *), 2, 4, 3, 0); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 24); + assert(info->alignment == 2 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + libsimple_default_failure_exit = 29; + assert_exit(libsimple_eposix_memalignn(&ptr, sizeof(void *), 1, 0)); + assert(exit_status == 29); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + libsimple_default_failure_exit = 39; + assert_exit(libsimple_eposix_memalignn(&ptr, sizeof(void *), SIZE_MAX, 2, 0)); + assert(exit_status == 39); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + + return 0; +} + +#endif diff --git a/eposix_memalignz.c b/eposix_memalignz.c new file mode 100644 index 0000000..c0ac5c1 --- /dev/null +++ b/eposix_memalignz.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_eposix_memalignz(void **, int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_eposix_memalignz(&ptr, 1, 2 * sizeof(void *), 8); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 8); + assert(info->alignment == 2 * sizeof(void *)); + assert(info->zeroed == 8); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + libsimple_eposix_memalignz(&ptr, 0, 4 * sizeof(void *), 4); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 4); + assert(info->alignment == 4 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 102; + alloc_fail_in = 1; + assert_exit(libsimple_eposix_memalignz(&ptr, 1, sizeof(void *), 4)); + assert(exit_status == 102); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 103; + alloc_fail_in = 1; + assert_exit(libsimple_eposix_memalignz(&ptr, 0, sizeof(void *), 4)); + assert(exit_status == 103); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/eposix_memalignzn.c b/eposix_memalignzn.c new file mode 100644 index 0000000..acb2153 --- /dev/null +++ b/eposix_memalignzn.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_eposix_memalignzn(void **, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr = NULL; + + libsimple_eposix_memalignzn(&ptr, 0, 4 * sizeof(void *), 2, 5, 3, 0); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 30); + assert(info->alignment == 4 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + libsimple_eposix_memalignzn(&ptr, 1, sizeof(void *), 2, 5, 4, 0); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 40); + assert(info->alignment == sizeof(void *)); + assert(info->zeroed == 40); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + libsimple_default_failure_exit = 23; + assert_exit(libsimple_eposix_memalignzn(&ptr, 0, sizeof(void *), 4, 0)); + assert(exit_status == 23); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + libsimple_default_failure_exit = 25; + assert_exit(libsimple_eposix_memalignzn(&ptr, 1, sizeof(void *), 2, 0)); + assert(exit_status == 25); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + libsimple_default_failure_exit = 33; + assert_exit(libsimple_eposix_memalignzn(&ptr, 0, sizeof(void *), SIZE_MAX, 2, 0)); + assert(exit_status == 33); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + + libsimple_default_failure_exit = 35; + assert_exit(libsimple_eposix_memalignzn(&ptr, 1, sizeof(void *), SIZE_MAX, 2, 0)); + assert(exit_status == 35); + assert_stderr("%s: posix_memalign: %s\n", argv0, strerror(ENOMEM)); + + return 0; +} + +#endif diff --git a/eprintf.c b/eprintf.c new file mode 100644 index 0000000..039a62f --- /dev/null +++ b/eprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_eprintf(const char *, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/epvalloc.c b/epvalloc.c new file mode 100644 index 0000000..e3e4788 --- /dev/null +++ b/epvalloc.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_epvalloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_epvalloc(3 * pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 3 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 104; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_epvalloc(4)); + assert(exit_status == 104); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/epvallocn.c b/epvallocn.c new file mode 100644 index 0000000..4fcf347 --- /dev/null +++ b/epvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_epvallocn(size_t, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/epvallocz.c b/epvallocz.c new file mode 100644 index 0000000..c9da7df --- /dev/null +++ b/epvallocz.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_epvallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_epvallocz(1, 3 * pagesize + 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 4 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_epvallocz(0, pagesize + 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 2 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 102; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_epvallocz(1, 4)); + assert(exit_status == 102); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 103; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_epvallocz(0, 4)); + assert(exit_status == 103); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/epvalloczn.c b/epvalloczn.c new file mode 100644 index 0000000..b6880c3 --- /dev/null +++ b/epvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_epvalloczn(int, size_t, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/erealloc.c b/erealloc.c new file mode 100644 index 0000000..1150ca2 --- /dev/null +++ b/erealloc.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_erealloc(void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr, *old; + + assert((ptr = libsimple_erealloc(NULL, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_erealloc(old = ptr, 10))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 10); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + assert(ptr != old); + free(old); + } + free(ptr); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 104; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_erealloc(NULL, 1)); + assert(exit_status == 104); + assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ereallocarray.c b/ereallocarray.c new file mode 100644 index 0000000..da022ae --- /dev/null +++ b/ereallocarray.c @@ -0,0 +1,67 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ereallocarray(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr, *old; + + assert((ptr = libsimple_ereallocarray(NULL, 1, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_ereallocarray(old = ptr, 10, 10))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 100); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + assert(ptr != old); + free(old); + } + free(ptr); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 104; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ereallocarray(NULL, 1, 1)); + assert(exit_status == 104); + assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + +#if defined(__GNUC__) && !defined(__clang) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Walloc-size-larger-than=" +#endif + + libsimple_default_failure_exit = 4; + assert_exit_ptr(libsimple_ereallocarray(NULL, SIZE_MAX, SIZE_MAX)); + assert(exit_status == 4); + assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); + libsimple_default_failure_exit = 1; + +#if defined(__GNUC__) && !defined(__clang) +# pragma GCC diagnostic pop +#endif + + return 0; +} + +#endif diff --git a/ereallocn.c b/ereallocn.c new file mode 100644 index 0000000..17b1f09 --- /dev/null +++ b/ereallocn.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ereallocn(void *, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr, *old; + + assert((ptr = libsimple_ereallocn(NULL, 5, 4, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 20); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_ereallocn(old = ptr, 10, 11, 0))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 110); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + assert(ptr != old); + free(old); + } + free(ptr); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 104; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ereallocn(NULL, 1, 0)); + assert(exit_status == 104); + assert_stderr("%s: realloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/evallocz.c b/evallocz.c new file mode 100644 index 0000000..1edd48c --- /dev/null +++ b/evallocz.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_evallocz(1, 3 * pagesize + 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 3 * pagesize + 1); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_evallocz(0, pagesize + 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize + 1); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 102; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_evallocz(1, 4)); + assert(exit_status == 102); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 103; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_evallocz(0, 4)); + assert(exit_status == 103); + assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/evalloczn.c b/evalloczn.c new file mode 100644 index 0000000..9be9c16 --- /dev/null +++ b/evalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evalloczn(int, size_t, ...); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evmemalloc.c b/evmemalloc.c new file mode 100644 index 0000000..2f04b4b --- /dev/null +++ b/evmemalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evmemalloc(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evposix_memalignn.c b/evposix_memalignn.c new file mode 100644 index 0000000..bd13743 --- /dev/null +++ b/evposix_memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_evposix_memalignn(void **, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_eposix_memalignn */ +} + +#endif diff --git a/evposix_memalignzn.c b/evposix_memalignzn.c new file mode 100644 index 0000000..71a5250 --- /dev/null +++ b/evposix_memalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_evposix_memalignzn(void **, int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_eposix_memalignzn */ +} + +#endif diff --git a/evpvallocn.c b/evpvallocn.c new file mode 100644 index 0000000..4ce9e69 --- /dev/null +++ b/evpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evpvallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_epvallocn */ +} + +#endif diff --git a/evpvalloczn.c b/evpvalloczn.c new file mode 100644 index 0000000..ddc593b --- /dev/null +++ b/evpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evpvalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_epvalloczn */ +} + +#endif diff --git a/evreallocn.c b/evreallocn.c new file mode 100644 index 0000000..5bddb0e --- /dev/null +++ b/evreallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evreallocn(void *, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ereallocn */ +} + +#endif diff --git a/evvalloczn.c b/evvalloczn.c new file mode 100644 index 0000000..dee0a1c --- /dev/null +++ b/evvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evvalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_evalloczn */ +} + +#endif diff --git a/getenv_e.c b/getenv_e.c index c09859d..95eb34e 100644 --- a/getenv_e.c +++ b/getenv_e.c @@ -12,13 +12,16 @@ extern inline const char *libsimple_getenv_e(const char *); int main(void) { + char env1[] = "X=xyz"; + char env2[] = "X="; + unsetenv("X"); assert(!getenv("X")); assert(!strcmpnul(libsimple_getenv_e("X"), "")); - putenv("X=xyz"); + putenv(env1); assert(!strcmpnul(getenv("X"), "xyz")); assert(!strcmpnul(libsimple_getenv_e("X"), "xyz")); - putenv("X="); + putenv(env2); assert(!strcmpnul(getenv("X"), "")); assert(!strcmpnul(libsimple_getenv_e("X"), "")); diff --git a/getenv_ne.c b/getenv_ne.c index b502fc8..e3b962a 100644 --- a/getenv_ne.c +++ b/getenv_ne.c @@ -12,13 +12,16 @@ extern inline char *libsimple_getenv_ne(const char *); int main(void) { + char env1[] = "X=xyz"; + char env2[] = "X="; + unsetenv("X"); assert(!getenv("X")); assert(!libsimple_getenv_ne("X")); - putenv("X=xyz"); + putenv(env1); assert(!strcmpnul(getenv("X"), "xyz")); assert(!strcmpnul(libsimple_getenv_ne("X"), "xyz")); - putenv("X="); + putenv(env2); assert(!strcmpnul(getenv("X"), "")); assert(!libsimple_getenv_ne("X")); diff --git a/libsimple-arg.c b/libsimple-arg.c index 95581bf..7fcb91a 100644 --- a/libsimple-arg.c +++ b/libsimple-arg.c @@ -4,25 +4,25 @@ #include #include #include -#include "test.h" #include "libsimple-arg.h" +#include "test.h" #define PARSER_BEGIN\ int old_argc = argc;\ char **old_argv = argv;\ - { + /* { */ #define PARSER_END\ - ;}\ + /* } */\ assert(argv0 == old_argv[0]);\ assert(argv == &old_argv[old_argc - argc]);\ return argc #define PARSER_END_NO_ARGV0\ - }\ + /* } */\ assert(argv0 == NULL);\ assert(argv == &old_argv[old_argc - argc]);\ return argc @@ -260,252 +260,253 @@ usage(void) static int parser1(int argc, char *argv[]) { - PARSER_BEGIN; - ARGBEGIN { - case 'a': SHORT_WITHOUT_ARG("-a"); break; - case 'b': SHORT_WITHOUT_ARG("-b"); break; - case 'c': SHORT_WITHOUT_ARG("-c"); break; - case 'd': SHORT_WITHOUT_ARG("-d"); break; - case 'e': SHORT_WITHOUT_ARG("-e"); break; - case 'A': SHORT_WITHOUT_ARG("-A"); break; - case 'B': SHORT_WITHOUT_ARG("-B"); break; - case 'C': SHORT_WITHOUT_ARG("-C"); break; - case 'D': SHORT_WITHOUT_ARG("-D"); break; - case 'E': SHORT_WITHOUT_ARG("-E"); break; - case 'x': SHORT_WITH_ARG("-x"); break; - case 'y': SHORT_WITH_ARG("-y"); break; - case 'z': SHORT_WITH_ARG("-z"); break; - case 'X': SHORT_WITH_ARG("-X"); break; - case 'Y': SHORT_WITH_ARG("-Y"); break; - case 'Z': SHORT_WITH_ARG("-Z"); break; - case '-': SHORT_WITHOUT_ARG("--"); break; - case ARGNUM: SHORT_WITH_ARGHERE("-#"); break; - case '@': SHORT_WITH_MISSING_ARG("-@"); break; - default: + PARSER_BEGIN { + ARGBEGIN { + case 'a': SHORT_WITHOUT_ARG("-a"); break; + case 'b': SHORT_WITHOUT_ARG("-b"); break; + case 'c': SHORT_WITHOUT_ARG("-c"); break; + case 'd': SHORT_WITHOUT_ARG("-d"); break; + case 'e': SHORT_WITHOUT_ARG("-e"); break; + case 'A': SHORT_WITHOUT_ARG("-A"); break; + case 'B': SHORT_WITHOUT_ARG("-B"); break; + case 'C': SHORT_WITHOUT_ARG("-C"); break; + case 'D': SHORT_WITHOUT_ARG("-D"); break; + case 'E': SHORT_WITHOUT_ARG("-E"); break; + case 'x': SHORT_WITH_ARG("-x"); break; + case 'y': SHORT_WITH_ARG("-y"); break; + case 'z': SHORT_WITH_ARG("-z"); break; + case 'X': SHORT_WITH_ARG("-X"); break; + case 'Y': SHORT_WITH_ARG("-Y"); break; + case 'Z': SHORT_WITH_ARG("-Z"); break; + case '-': SHORT_WITHOUT_ARG("--"); break; + case ARGNUM: SHORT_WITH_ARGHERE("-#"); break; + case '@': SHORT_WITH_MISSING_ARG("-@"); break; + default: usage(); - } ARGEND; - PARSER_END; + } ARGEND; + } PARSER_END; } static int parser2(int argc, char *argv[]) { - PARSER_BEGIN; - SUBARGBEGIN { - case 'a': SHORT_WITHOUT_ARG("-a"); break; - case 'b': SHORT_WITHOUT_ARG("-b"); break; - case 'c': SHORT_WITHOUT_ARG("-c"); break; - case 'd': SHORT_WITHOUT_ARG("-d"); break; - case 'e': SHORT_WITHOUT_ARG("-e"); break; - case 'A': SHORT_WITHOUT_ARG("-A"); break; - case 'B': SHORT_WITHOUT_ARG("-B"); break; - case 'C': SHORT_WITHOUT_ARG("-C"); break; - case 'D': SHORT_WITHOUT_ARG("-D"); break; - case 'E': SHORT_WITHOUT_ARG("-E"); break; - case 'x': SHORT_WITH_ARG("-x"); break; - case 'y': SHORT_WITH_ARG("-y"); break; - case 'z': SHORT_WITH_ARG("-z"); break; - case 'X': SHORT_WITH_ARG("-X"); break; - case 'Y': SHORT_WITH_ARG("-Y"); break; - case 'Z': SHORT_WITH_ARG("-Z"); break; - case '-': SHORT_WITHOUT_ARG("--"); break; - case ARGNUM: SHORT_WITH_ARGHERE("-#"); break; - case '@': SHORT_WITH_MISSING_ARG("-@"); break; - default: - usage(); - } ARGEND; - PARSER_END_NO_ARGV0; + PARSER_BEGIN { + SUBARGBEGIN { + case 'a': SHORT_WITHOUT_ARG("-a"); break; + case 'b': SHORT_WITHOUT_ARG("-b"); break; + case 'c': SHORT_WITHOUT_ARG("-c"); break; + case 'd': SHORT_WITHOUT_ARG("-d"); break; + case 'e': SHORT_WITHOUT_ARG("-e"); break; + case 'A': SHORT_WITHOUT_ARG("-A"); break; + case 'B': SHORT_WITHOUT_ARG("-B"); break; + case 'C': SHORT_WITHOUT_ARG("-C"); break; + case 'D': SHORT_WITHOUT_ARG("-D"); break; + case 'E': SHORT_WITHOUT_ARG("-E"); break; + case 'x': SHORT_WITH_ARG("-x"); break; + case 'y': SHORT_WITH_ARG("-y"); break; + case 'z': SHORT_WITH_ARG("-z"); break; + case 'X': SHORT_WITH_ARG("-X"); break; + case 'Y': SHORT_WITH_ARG("-Y"); break; + case 'Z': SHORT_WITH_ARG("-Z"); break; + case '-': SHORT_WITHOUT_ARG("--"); break; + case ARGNUM: SHORT_WITH_ARGHERE("-#"); break; + case '@': SHORT_WITH_MISSING_ARG("-@"); break; + default: + usage(); + } ARGEND; + } PARSER_END_NO_ARGV0; } static int parser3(int argc, char *argv[]) { - PARSER_BEGIN; - NOFLAGS(0); - PARSER_END; + PARSER_BEGIN { + NOFLAGS(0); + } PARSER_END; } static int parser4(int argc, char *argv[]) { - PARSER_BEGIN; - NOFLAGS(argc); - PARSER_END; + PARSER_BEGIN { + NOFLAGS(argc); + } PARSER_END; } static int parser5(int argc, char *argv[]) { - PARSER_BEGIN; - ARGBEGIN { - case 'a': SHORT_WITHOUT_ARG("-a"); break; - case 'x': SHORT_WITHOUT_ARG("-x"); break; - case '-': SHORT_WITHOUT_ARG("--"); break; - default: - usage(); - } ARGALT('+') { - case 'a': SHORT_WITHOUT_ARG("+a"); break; - case 'y': SHORT_WITHOUT_ARG("+y"); break; - case '+': SHORT_WITHOUT_ARG("++"); break; - default: - usage(); - } ARGALT('/') { - case 'a': SHORT_WITHOUT_ARG("/a"); break; - case 'z': SHORT_WITHOUT_ARG("/z"); break; - case '/': SHORT_WITHOUT_ARG("//"); break; - default: - usage(); - } ARGALT('x') { - case 'a': SHORT_WITHOUT_ARG("xa"); break; - case 'b': SHORT_WITHOUT_ARG("xb"); break; - case 'x': SHORT_WITHOUT_ARG("xx"); break; - default: - usage(); - } ARGEND; - PARSER_END; + PARSER_BEGIN { + ARGBEGIN { + case 'a': SHORT_WITHOUT_ARG("-a"); break; + case 'x': SHORT_WITHOUT_ARG("-x"); break; + case '-': SHORT_WITHOUT_ARG("--"); break; + default: + usage(); + } ARGALT('+') { + case 'a': SHORT_WITHOUT_ARG("+a"); break; + case 'y': SHORT_WITHOUT_ARG("+y"); break; + case '+': SHORT_WITHOUT_ARG("++"); break; + default: + usage(); + } ARGALT('/') { + case 'a': SHORT_WITHOUT_ARG("/a"); break; + case 'z': SHORT_WITHOUT_ARG("/z"); break; + case '/': SHORT_WITHOUT_ARG("//"); break; + default: + usage(); + } ARGALT('x') { + case 'a': SHORT_WITHOUT_ARG("xa"); break; + case 'b': SHORT_WITHOUT_ARG("xb"); break; + case 'x': SHORT_WITHOUT_ARG("xx"); break; + default: + usage(); + } ARGEND; + } PARSER_END; } static int parser6(int argc, char *argv[]) { - PARSER_BEGIN; - ARGBEGIN2(1, 1) { - default: - assert(ARGHERE() == &LFLAG()[1]); - argv[0] = LFLAG(); - goto stop; - } ARGALT('+') { - case 'a': SHORT_WITHOUT_ARG("+a"); break; - case 'b': SHORT_WITHOUT_ARG("+b"); break; - case 'c': SHORT_WITHOUT_ARG("+c"); break; - case 'd': SHORT_WITHOUT_ARG("+d"); break; - case 'e': SHORT_WITHOUT_ARG("+e"); break; - case 'A': SHORT_WITHOUT_ARG("+A"); break; - case 'B': SHORT_WITHOUT_ARG("+B"); break; - case 'C': SHORT_WITHOUT_ARG("+C"); break; - case 'D': SHORT_WITHOUT_ARG("+D"); break; - case 'E': SHORT_WITHOUT_ARG("+E"); break; - case 'x': SHORT_WITH_ARG("+x"); break; - case 'y': SHORT_WITH_ARG("+y"); break; - case 'z': SHORT_WITH_ARG("+z"); break; - case 'X': SHORT_WITH_ARG("+X"); break; - case 'Y': SHORT_WITH_ARG("+Y"); break; - case 'Z': SHORT_WITH_ARG("+Z"); break; - case '+': SHORT_WITHOUT_ARG("++"); break; - case ARGNUM: SHORT_WITH_ARGHERE("+#"); break; - case '@': SHORT_WITH_MISSING_ARG("+@"); break; - default: - usage(); - } ARGEND; -stop: - PARSER_END; + PARSER_BEGIN { + ARGBEGIN2(1, 1) { + default: + assert(ARGHERE() == &LFLAG()[1]); + argv[0] = LFLAG(); + goto stop; + } ARGALT('+') { + case 'a': SHORT_WITHOUT_ARG("+a"); break; + case 'b': SHORT_WITHOUT_ARG("+b"); break; + case 'c': SHORT_WITHOUT_ARG("+c"); break; + case 'd': SHORT_WITHOUT_ARG("+d"); break; + case 'e': SHORT_WITHOUT_ARG("+e"); break; + case 'A': SHORT_WITHOUT_ARG("+A"); break; + case 'B': SHORT_WITHOUT_ARG("+B"); break; + case 'C': SHORT_WITHOUT_ARG("+C"); break; + case 'D': SHORT_WITHOUT_ARG("+D"); break; + case 'E': SHORT_WITHOUT_ARG("+E"); break; + case 'x': SHORT_WITH_ARG("+x"); break; + case 'y': SHORT_WITH_ARG("+y"); break; + case 'z': SHORT_WITH_ARG("+z"); break; + case 'X': SHORT_WITH_ARG("+X"); break; + case 'Y': SHORT_WITH_ARG("+Y"); break; + case 'Z': SHORT_WITH_ARG("+Z"); break; + case '+': SHORT_WITHOUT_ARG("++"); break; + case ARGNUM: SHORT_WITH_ARGHERE("+#"); break; + case '@': SHORT_WITH_MISSING_ARG("+@"); break; + default: + usage(); + } ARGEND; + stop:; + } PARSER_END; } static int parser7(int argc, char *argv[]) { - PARSER_BEGIN; - ARGBEGIN { - case '-': - if (TESTLONG("--alpha", 0)) - LONG_WITHOUT_ARG("--alpha"); - else if (TESTLONG("--alpha=", 0)) - LONG_WITHOUT_ARG("--alpha="); - else if (TESTLONG("--beta", 1)) - LONG_WITH_ARG("--beta"); - else if (TESTLONG("--gamma=", 1)) - LONG_WITH_ARG("--gamma"); - else if (TESTLONG("--gamma", 0)) - LONG_WITHOUT_ARG("--gamma"); - else if (TESTLONG("--missing", 1)) - LONG_WITH_MISSING_ARG("--missing"); - else + PARSER_BEGIN { + ARGBEGIN { + case '-': + if (TESTLONG("--alpha", 0)) + LONG_WITHOUT_ARG("--alpha"); + else if (TESTLONG("--alpha=", 0)) + LONG_WITHOUT_ARG("--alpha="); + else if (TESTLONG("--beta", 1)) + LONG_WITH_ARG("--beta"); + else if (TESTLONG("--gamma=", 1)) + LONG_WITH_ARG("--gamma"); + else if (TESTLONG("--gamma", 0)) + LONG_WITHOUT_ARG("--gamma"); + else if (TESTLONG("--missing", 1)) + LONG_WITH_MISSING_ARG("--missing"); + else + usage(); + break; + default: usage(); - break; - default: - usage(); - } ARGALT('+') { - case '+': - if (TESTLONG("++alpha", 0)) - LONG_WITHOUT_ARG("++alpha"); - else if (TESTLONG("++alpha=", 0)) - LONG_WITHOUT_ARG("++alpha="); - else if (TESTLONG("++beta", 1)) - LONG_WITH_ARG("++beta"); - else if (TESTLONG("++gamma=", 1)) - LONG_WITH_ARG("++gamma"); - else if (TESTLONG("++gamma", 0)) - LONG_WITHOUT_ARG("++gamma"); - else if (TESTLONG("++missing", 1)) - LONG_WITH_MISSING_ARG("++missing"); - else + } ARGALT('+') { + case '+': + if (TESTLONG("++alpha", 0)) + LONG_WITHOUT_ARG("++alpha"); + else if (TESTLONG("++alpha=", 0)) + LONG_WITHOUT_ARG("++alpha="); + else if (TESTLONG("++beta", 1)) + LONG_WITH_ARG("++beta"); + else if (TESTLONG("++gamma=", 1)) + LONG_WITH_ARG("++gamma"); + else if (TESTLONG("++gamma", 0)) + LONG_WITHOUT_ARG("++gamma"); + else if (TESTLONG("++missing", 1)) + LONG_WITH_MISSING_ARG("++missing"); + else + usage(); + break; + default: usage(); - break; - default: - usage(); - } ARGEND; - PARSER_END; + } ARGEND; + } PARSER_END; } static int parser8(int argc, char *argv[]) { - PARSER_BEGIN; - ARGBEGIN { - case 'a': SHORT_WITHOUT_ARG("-a"); break; - case 'A': SHORT_WITHOUT_ARG("-A"); break; - case 'b': SHORT_WITH_ARG("-b"); break; - case 'g': SHORT_WITH_ARG("-g"); break; - case 'G': SHORT_WITHOUT_ARG("-G"); break; - case 'm': SHORT_WITH_MISSING_ARG("-m"); break; - case '-': - ARGMAPLONG(((struct longopt []){ - {"--alpha", 'a', 0}, - {"--alpha=", 'A', 0}, - {"--beta", 'b', 1}, - {"--gamma=", 'g', 1}, - {"--gamma", 'G', 0}, - {"--missing", 'm', 1}, - {NULL, '\0', 0}, - })); - /* fall through */ - default: - usage(); - } ARGALT('+') { - case 'a': SHORT_WITHOUT_ARG("+a"); break; - case 'A': SHORT_WITHOUT_ARG("+A"); break; - case 'b': SHORT_WITH_ARG("+b"); break; - case 'g': SHORT_WITH_ARG("+g"); break; - case 'G': SHORT_WITHOUT_ARG("+G"); break; - case 'm': SHORT_WITH_MISSING_ARG("+m"); break; - case '+': - ARGMAPLONG(((struct longopt []){ - {"++alpha", 'a', 0}, - {"++alpha=", 'A', 0}, - {"++beta", 'b', 1}, - {"++gamma=", 'g', 1}, - {"++gamma", 'G', 0}, - {"++missing", 'm', 1}, - {NULL, '\0', 0}, - })); - /* fall through */ - default: - usage(); - } ARGEND; - PARSER_END; + PARSER_BEGIN { + ARGBEGIN { + case 'a': SHORT_WITHOUT_ARG("-a"); break; + case 'A': SHORT_WITHOUT_ARG("-A"); break; + case 'b': SHORT_WITH_ARG("-b"); break; + case 'g': SHORT_WITH_ARG("-g"); break; + case 'G': SHORT_WITHOUT_ARG("-G"); break; + case 'm': SHORT_WITH_MISSING_ARG("-m"); break; + case '-': + ARGMAPLONG(((struct longopt []){ + {"--alpha", 'a', 0}, + {"--alpha=", 'A', 0}, + {"--beta", 'b', 1}, + {"--gamma=", 'g', 1}, + {"--gamma", 'G', 0}, + {"--missing", 'm', 1}, + {NULL, '\0', 0}, + })); + /* fall through */ + default: + usage(); + } ARGALT('+') { + case 'a': SHORT_WITHOUT_ARG("+a"); break; + case 'A': SHORT_WITHOUT_ARG("+A"); break; + case 'b': SHORT_WITH_ARG("+b"); break; + case 'g': SHORT_WITH_ARG("+g"); break; + case 'G': SHORT_WITHOUT_ARG("+G"); break; + case 'm': SHORT_WITH_MISSING_ARG("+m"); break; + case '+': + ARGMAPLONG(((struct longopt []){ + {"++alpha", 'a', 0}, + {"++alpha=", 'A', 0}, + {"++beta", 'b', 1}, + {"++gamma=", 'g', 1}, + {"++gamma", 'G', 0}, + {"++missing", 'm', 1}, + {NULL, '\0', 0}, + })); + /* fall through */ + default: + usage(); + } ARGEND; + } PARSER_END; } int main(void) { + char buf[10]; const char *a1; size_t i; @@ -696,22 +697,22 @@ main(void) ASSERT_ENTRY("+G", NULL, NULL); ASSERT_END(); - argv0_1 = "[1]"; + argv0_1 = strcpy(buf, "[1]"); assert_exit(usage1()); assert(exit_status == 1); assert_stderr("usage: [1] -1\n"); - argv0_2 = "[2]"; + argv0_2 = strcpy(buf, "[2]"); assert_exit(usage2()); assert_stderr("usage: [2] -2\n"); assert(exit_status == 2); - argv0_3 = "[3]"; + argv0_3 = strcpy(buf, "[3]"); assert_exit(usage3()); assert_stderr("usage: [3]\n"); assert(exit_status == 3); - argv0_0 = "[0]"; + argv0_0 = strcpy(buf, "[0]"); assert_exit(usage0()); assert_stderr("usage: [0]\n"); assert(exit_status == 0); diff --git a/libsimple-arg.h b/libsimple-arg.h index 67be5e9..1d52b33 100644 --- a/libsimple-arg.h +++ b/libsimple-arg.h @@ -436,7 +436,7 @@ struct longopt { static _LIBSIMPLE_NORETURN void\ usage(void)\ {\ - const char *syn = SYNOPSIS ? SYNOPSIS : "";\ + const char *syn = (const char *)SYNOPSIS ? SYNOPSIS : "";\ fprintf(stderr, "usage: %s%s%s\n", argv0, *syn ? " " : "", syn);\ exit(STATUS);\ }\ diff --git a/libsimple.c b/libsimple.c index 1230b60..0140b84 100644 --- a/libsimple.c +++ b/libsimple.c @@ -89,8 +89,6 @@ main(void) { struct allocinfo *volatile info; void *ptr, *old; - struct timespec ts, ts1, ts2; - struct timeval tv1, tv2; const char *cs; const wchar_t *cws; char buf[1024], *s; @@ -225,14 +223,20 @@ main(void) assert(MAX3(-3, -1, -2) == -1); assert(MAX3(-3, -2, -1) == -1); - assert(ELEMSOF((char [1]){}) == 1); - assert(ELEMSOF((char [2]){}) == 2); - assert(ELEMSOF((char [3]){}) == 3); - assert(ELEMSOF((short int [3]){}) == 3); - assert(ELEMSOF((int [3]){}) == 3); - assert(ELEMSOF((long int [3]){}) == 3); - assert(ELEMSOF((float [3]){}) == 3); - assert(ELEMSOF((double [3]){}) == 3); +#define _1 0 +#define _2 0, 0 +#define _3 0, 0, 0 + assert(ELEMSOF((char []){_1}) == 1); + assert(ELEMSOF((char []){_2}) == 2); + assert(ELEMSOF((char []){_3}) == 3); + assert(ELEMSOF((short int []){_3}) == 3); + assert(ELEMSOF((int []){_3}) == 3); + assert(ELEMSOF((long int []){_3}) == 3); + assert(ELEMSOF((float []){_3}) == 3); + assert(ELEMSOF((double []){_3}) == 3); +#undef _1 +#undef _2 +#undef _3 assert(STRLEN("") == 0); assert(STRLEN("a") == 1); @@ -285,10 +289,6 @@ main(void) assert(libsimple_inchrset('z', "xyz") == 1); assert(libsimple_inchrset('\0', "xyz") == 0); - stpcpy(buf, "abcxyz"); - assert(libsimple_mempcpy(buf, "123", 3) == &buf[3]); - assert(!strcmpnul(buf, "123xyz")); - assert(libsimple_streq("abc", "abc") == 1); assert(libsimple_streq("abc", "ab") == 0); assert(libsimple_streq("ab", "abc") == 0); @@ -962,258 +962,6 @@ main(void) assert(test_timeval(0, 0, 0, 0, "+0.000000", "0")); assert(test_timeval(-10, -10, 0, -10, "-10.000000", "-10")); - libsimple_timeval2timespec(&ts, &(struct timeval){0, 0L}); - assert(ts.tv_sec == 0); - assert(ts.tv_nsec == 0L); - libsimple_timeval2timespec(&ts, &(struct timeval){0, 1L}); - assert(ts.tv_sec == 0); - assert(ts.tv_nsec == 1000L); - libsimple_timeval2timespec(&ts, &(struct timeval){0, 999999L}); - assert(ts.tv_sec == 0); - assert(ts.tv_nsec == 999999000L); - libsimple_timeval2timespec(&ts, &(struct timeval){10, 0L}); - assert(ts.tv_sec == 10); - assert(ts.tv_nsec == 0L); - libsimple_timeval2timespec(&ts, &(struct timeval){10, 1L}); - assert(ts.tv_sec == 10); - assert(ts.tv_nsec == 1000L); - libsimple_timeval2timespec(&ts, &(struct timeval){-10, 0L}); - assert(ts.tv_sec == -10); - assert(ts.tv_nsec == 0L); - libsimple_timeval2timespec(&ts, &(struct timeval){-10, 1L}); - assert(ts.tv_sec == -10); - assert(ts.tv_nsec == 1000L); - - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; - ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = TIME_MAX, ts1.tv_nsec = 0L; - ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 999999L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = 0, tv1.tv_usec = 999999L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 999999L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 999999L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 999999L; - tv2.tv_sec = 0, tv2.tv_usec = 999999L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = 1, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 1, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 1, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 1, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = 1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = 1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = 1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = 1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 1, tv1.tv_usec = 0L; - tv2.tv_sec = 1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = 1, tv1.tv_usec = 1L; - tv2.tv_sec = 1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 1, tv1.tv_usec = 0L; - tv2.tv_sec = 1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 1, tv1.tv_usec = 1L; - tv2.tv_sec = 1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = -1, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = -1, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = -1, tv1.tv_usec = 0L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = -1, tv1.tv_usec = 1L; - tv2.tv_sec = 0, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = -1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = -1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = -1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = 0, tv1.tv_usec = 1L; - tv2.tv_sec = -1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = -1, tv1.tv_usec = 0L; - tv2.tv_sec = -1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = -1, tv1.tv_usec = 1L; - tv2.tv_sec = -1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = -1, tv1.tv_usec = 0L; - tv2.tv_sec = -1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = -1, tv1.tv_usec = 1L; - tv2.tv_sec = -1, tv2.tv_usec = 1L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = 0, tv1.tv_usec = 0L; - tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = 1, tv1.tv_usec = 0L; - tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - tv1.tv_sec = TIME_MAX, tv1.tv_usec = 0L; - tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 0); - tv1.tv_sec = 1, tv1.tv_usec = 0L; - tv2.tv_sec = -1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == 1); - tv1.tv_sec = -1, tv1.tv_usec = 0L; - tv2.tv_sec = 1, tv2.tv_usec = 0L; - assert(libsimple_cmptimeval(&tv1, &tv2) == -1); - assert((ptr = libsimple_mallocz(0, 11))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1289,30 +1037,6 @@ main(void) free(ptr); ptr = NULL; - assert(!libsimple_posix_memalignz(&ptr, 0, 8 * sizeof(void *), 8)); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 8); - ASSERT_ALIGNMENT(info, 8 * sizeof(void *)); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert(!libsimple_posix_memalignz(&ptr, 1, 4 * sizeof(void *), 16)); - assert(ptr); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 16); - ASSERT_ALIGNMENT(info, 4 * sizeof(void *)); - assert(info->zeroed == 16); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - assert((ptr = libsimple_memalignz(0, 4, 9))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1484,28 +1208,6 @@ main(void) free(ptr); ptr = NULL; - assert((ptr = libsimple_vallocz(0, 9))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 9 || info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_vallocz(1, 7))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 7 || info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == 7 || info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - assert((ptr = libsimple_valloc(5))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1517,28 +1219,6 @@ main(void) free(ptr); ptr = NULL; - assert((ptr = libsimple_vallocz(1, 3 * pagesize))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 3 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == 3 * pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_vallocz(0, 4 * pagesize))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 4 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - assert((ptr = libsimple_valloc(5 * pagesize))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1550,28 +1230,6 @@ main(void) free(ptr); ptr = NULL; - assert((ptr = libsimple_valloczn(1, 3 * pagesize, 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 6 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == 6 * pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_valloczn(0, 4 * pagesize, 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 8 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - assert((ptr = libsimple_vallocn(5 * pagesize, 2, 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1583,186 +1241,12 @@ main(void) free(ptr); ptr = NULL; - assert(!libsimple_valloczn(0, 0) && errno == EINVAL); - errno = 0; - assert(!libsimple_valloczn(1, 0) && errno == EINVAL); - errno = 0; assert(!libsimple_vallocn(0) && errno == EINVAL); errno = 0; - assert(!libsimple_valloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM); - errno = 0; - assert(!libsimple_valloczn(1, SIZE_MAX, 2, 0) && errno == ENOMEM); - errno = 0; assert(!libsimple_vallocn(SIZE_MAX, 2, 0) && errno == ENOMEM); errno = 0; - assert((ptr = libsimple_pvallocz(0, 9))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocz(1, 7))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvalloc(5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5 || info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocz(1, pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocz(1, pagesize))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocz(1, pagesize + 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 2 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == 2 * pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocz(1, 3 * pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 3 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == 3 * pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocz(0, 4 * pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 4 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvalloc(5 * pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvalloczn(1, 3 * pagesize - 1, 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 6 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == 6 * pagesize); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvalloczn(0, 4 * pagesize - 1, 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 8 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_pvallocn(5 * pagesize - 1, 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 10 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); - } - free(ptr); - ptr = NULL; - - assert(!libsimple_pvalloczn(0, 0) && errno == EINVAL); - errno = 0; - assert(!libsimple_pvalloczn(1, 0) && errno == EINVAL); - errno = 0; - assert(!libsimple_pvallocn(0) && errno == EINVAL); - errno = 0; - - assert(!libsimple_pvalloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM); - errno = 0; - assert(!libsimple_pvalloczn(1, SIZE_MAX, 2, 0) && errno == ENOMEM); - errno = 0; - assert(!libsimple_pvallocn(SIZE_MAX, 2, 0) && errno == ENOMEM); - errno = 0; - - assert((ptr = libsimple_valloczn(0, 9, 9, pagesize - 1, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 81 * (pagesize - 1)); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - - assert((ptr = libsimple_valloczn(1, 9, 8, pagesize - 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 72 * (pagesize - 2)); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - assert((ptr = libsimple_vallocn(9, (pagesize - 1), 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1773,50 +1257,6 @@ main(void) } free(ptr); - assert((ptr = libsimple_envallocz(1, 1, 5 * pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5 * pagesize - 1); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_evallocz(1, 3 * pagesize + 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 3 * pagesize + 1); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_envallocz(1, 0, pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize - 1); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_evallocz(0, pagesize + 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize + 1); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - assert((ptr = libsimple_envalloc(1, 127))); if (have_custom_malloc()) { assert((info = get_allocinfo(ptr))); @@ -1839,102 +1279,6 @@ main(void) free(ptr); ptr = NULL; - assert((ptr = libsimple_pvalloczn(0, 9, 9, pagesize - 1, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 81 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - - assert((ptr = libsimple_pvalloczn(1, 9, 8, pagesize - 2, 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 72 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - - assert((ptr = libsimple_pvallocn(9, (pagesize - 1), 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 9 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - - assert((ptr = libsimple_enpvallocz(1, 1, 5 * pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 5 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_epvallocz(1, 3 * pagesize + 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 4 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(info->zeroed == info->size); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_enpvallocz(1, 0, pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_epvallocz(0, pagesize + 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 2 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_enpvalloc(1, 127))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - - assert((ptr = libsimple_epvalloc(3 * pagesize - 1))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(ptr))); - assert(info->size == 3 * pagesize); - ASSERT_ALIGNMENT(info, pagesize); - assert(!info->zeroed); - assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); - } - free(ptr); - ptr = NULL; - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enmallocz(5, 0, 20)); @@ -1980,14 +1324,6 @@ main(void) errno = 0; - alloc_fail_in = 1; - assert(libsimple_posix_memalignz(&ptr, 0, 4 * sizeof(void *), 8) == ENOMEM && !errno); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert(libsimple_posix_memalignz(&ptr, 1, 16 * sizeof(void *), 16) == ENOMEM && !errno); - assert(!alloc_fail_in); - alloc_fail_in = 1; assert(!libsimple_memalignz(0, 4 * sizeof(void *), 8) && errno == ENOMEM); assert(!alloc_fail_in); @@ -2038,42 +1374,6 @@ main(void) assert(!alloc_fail_in); libsimple_default_failure_exit = 1; - alloc_fail_in = 1; - assert(!libsimple_vallocz(0, 8) && errno == ENOMEM); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert(!libsimple_vallocz(1, 16) && errno == ENOMEM); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert_exit_ptr(libsimple_envallocz(3, 1, 4)); - assert(exit_status == 3); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 102; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_evallocz(1, 4)); - assert(exit_status == 102); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert_exit_ptr(libsimple_envallocz(5, 0, 4)); - assert(exit_status == 5); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 103; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_evallocz(0, 4)); - assert(exit_status == 103); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_envalloc(7, 4)); assert(exit_status == 7); @@ -2087,56 +1387,6 @@ main(void) assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert(!libsimple_pvallocz(0, 8) && errno == ENOMEM); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert(!libsimple_pvallocz(1, 16) && errno == ENOMEM); - assert(!alloc_fail_in); - - alloc_fail_in = 1; - assert_exit_ptr(libsimple_enpvallocz(3, 1, 4)); - assert(exit_status == 3); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 102; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_epvallocz(1, 4)); - assert(exit_status == 102); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert_exit_ptr(libsimple_enpvallocz(5, 0, 4)); - assert(exit_status == 5); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 103; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_epvallocz(0, 4)); - assert(exit_status == 103); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert_exit_ptr(libsimple_enpvalloc(7, 4)); - assert(exit_status == 7); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 104; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_epvalloc(4)); - assert(exit_status == 104); - assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } assert_exit_ptr(libsimple_enmemalignz(3, 1, 0, 4)); @@ -2259,28 +1509,6 @@ main(void) assert(libsimple_aligned_reallocarray(NULL, 8, 1, 1) && errno == ENOSYS); #endif - assert(libsimple_memeq("abcxyz", "abc123", 3)); - assert(!libsimple_memeq("abcxyz", "abc123", 4)); - assert(libsimple_memeq("abcxyz", "abcx23", 4)); - assert(libsimple_memeq("1", "2", 0)); - assert(!libsimple_memeq("1", "2", 1)); - assert(!libsimple_memeq("abc", "ABC", 3)); - assert(!libsimple_memeq("ABC", "abc", 3)); - assert(libsimple_memeq("ABC", "ABC", 3)); - - assert(libsimple_memcaseeq("abcxyz", "abc123", 3)); - assert(!libsimple_memcaseeq("abcxyz", "abc123", 4)); - assert(libsimple_memcaseeq("abcxyz", "abcx23", 4)); - assert(libsimple_memcaseeq("1", "2", 0)); - assert(!libsimple_memcaseeq("1", "2", 1)); - assert(libsimple_memcaseeq("abc", "ABC", 3)); - assert(libsimple_memcaseeq("ABC", "abc", 3)); - assert(libsimple_memcaseeq("ABC", "ABC", 3)); - - stpcpy(buf, "abc123"); - assert(!strcmpnul(libsimple_mempset(buf, '.', 3), "123")); - assert(!strcmp(buf, "...123")); - #ifdef libsimple_asprintfa s = libsimple_asprintfa("%sxyz%s", "abc", "123"); assert(s); @@ -2442,15 +1670,6 @@ main(void) assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_memreplace(buf, 'o', 'x', 46) == &buf[46]); - assert(!memcmp(buf, "hellx wxrld\0gxxdbye wxrld", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_memreplace(buf, 'o', 'x', 12) == &buf[12]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]); assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); @@ -2708,64 +1927,6 @@ main(void) assert(!strncmp(buf, "helx", 4)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'o') == &buf[5 + 5]); - assert(!strncmp(buf, "-----hello-", 11)); - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; - assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'l') == &buf[5 + 3]); - assert(!strncmp(buf, "-----hello-", 11)); - - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'o') == &buf[3 + 5]); - assert(!strncmp(buf, "---hellolo-", 11)); - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'l') == &buf[3 + 3]); - assert(!strncmp(buf, "---helello-", 11)); - - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'o') == &buf[8 + 5]); - assert(!strncmp(buf, "-----helhello-", 14)); - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'l') == &buf[8 + 3]); - assert(!strncmp(buf, "-----helhel-", 12)); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_rawmemccpy(buf, "hello", 'o') == &buf[5]); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_rawmemccpy(buf, "hello", 'l') == &buf[3]); - assert(!strncmp(buf, "helx", 4)); - - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_mempmove(&buf[5], &buf[5], 5) == &buf[5 + 5]); - assert(!strncmp(buf, "-----hello-", 11)); - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_mempmove(&buf[3], &buf[5], 5) == &buf[3 + 5]); - assert(!strncmp(buf, "---hellolo-", 11)); - - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-'; - assert(libsimple_mempmove(&buf[8], &buf[5], 5) == &buf[8 + 5]); - assert(!strncmp(buf, "-----helhello-", 14)); - - if (!have_custom_malloc()) { stderr_real = 1; fprintf(stderr, "\nSome tests have not been ran because malloc(3) was not " diff --git a/libsimple.h b/libsimple.h index 2dda0c2..8af98e8 100644 --- a/libsimple.h +++ b/libsimple.h @@ -43,51 +43,56 @@ #include +#if defined(__GLIBC__) && (__GLIBC_PREREQ(2, 29) ? defined(_DEFAULT_SOURCE) : (__GLIBC_PREREQ(2, 26) && defined(_GNU_SOURCE))) +# define reallocarray reallocarray +#endif + + #if defined(__GNUC__) && !defined(__clang__) -# define _LIBSIMPLE_GCC_ONLY(x) x -# define _LIBSIMPLE_NON_GCC_ONLY(x) +# define LIBSIMPLE_GCC_ONLY__(x) x +# define LIBSIMPLE_NON_GCC_ONLY__(x) #else -# define _LIBSIMPLE_GCC_ONLY(x) -# define _LIBSIMPLE_NON_GCC_ONLY(x) x +# define LIBSIMPLE_GCC_ONLY__(x) +# define LIBSIMPLE_NON_GCC_ONLY__(x) x #endif #if __STDC_VERSION__ >= 199409L -# define _LIBSIMPLE_C95_ONLY(x) x -# define _LIBSIMPLE_PRE_C95_ONLY(x) +# define LIBSIMPLE_C95_ONLY__(x) x +# define LIBSIMPLE_PRE_C95_ONLY__(x) #else -# define _LIBSIMPLE_C95_ONLY(x) -# define _LIBSIMPLE_PRE_C95_ONLY(x) x +# define LIBSIMPLE_C95_ONLY__(x) +# define LIBSIMPLE_PRE_C95_ONLY__(x) x #endif #if __STDC_VERSION__ >= 199901L -# define _LIBSIMPLE_C99_ONLY(x) x -# define _LIBSIMPLE_PRE_C99_ONLY(x) +# define LIBSIMPLE_C99_ONLY__(x) x +# define LIBSIMPLE_PRE_C99_ONLY__(x) #else -# define _LIBSIMPLE_C99_ONLY(x) -# define _LIBSIMPLE_PRE_C99_ONLY(x) x +# define LIBSIMPLE_C99_ONLY__(x) +# define LIBSIMPLE_PRE_C99_ONLY__(x) x #endif #if __STDC_VERSION__ >= 201112L -# define _LIBSIMPLE_C11_ONLY(x) x -# define _LIBSIMPLE_PRE_C11_ONLY(x) +# define LIBSIMPLE_C11_ONLY__(x) x +# define LIBSIMPLE_PRE_C11_ONLY__(x) #else -# define _LIBSIMPLE_C11_ONLY(x) -# define _LIBSIMPLE_PRE_C11_ONLY(x) x +# define LIBSIMPLE_C11_ONLY__(x) +# define LIBSIMPLE_PRE_C11_ONLY__(x) x #endif #if __STDC_VERSION__ >= 201710L -# define _LIBSIMPLE_C17_ONLY(x) x -# define _LIBSIMPLE_PRE_C17_ONLY(x) +# define LIBSIMPLE_C17_ONLY__(x) x +# define LIBSIMPLE_PRE_C17_ONLY__(x) #else -# define _LIBSIMPLE_C17_ONLY(x) -# define _LIBSIMPLE_PRE_C17_ONLY(x) x +# define LIBSIMPLE_C17_ONLY__(x) +# define LIBSIMPLE_PRE_C17_ONLY__(x) x #endif -#define _libsimple_assume_aligned_as(TYPE)\ - _LIBSIMPLE_C11_ONLY(__assume_aligned__(_Alignof(TYPE)))\ - _LIBSIMPLE_PRE_C11_ONLY(_LIBSIMPLE_GCC_ONLY__assume_aligned__(__alignof(TYPE))) +#define libsimple_assume_aligned_as__(TYPE)\ + LIBSIMPLE_C11_ONLY__(__assume_aligned__(_Alignof(TYPE)))\ + LIBSIMPLE_PRE_C11_ONLY__(LIBSIMPLE_GCC_ONLY__(__assume_aligned__(__alignof(TYPE)))) #include "libsimple/overflow.h" @@ -141,16 +146,16 @@ * @return Return value of close(3) (0 on success, * -1 on error), 0 if `*fdp < 0` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) inline int -libsimple_close(int *__fdp) +libsimple_close(int *fdp__) { - int __ret; - if (*__fdp < 0) + int ret__; + if (*fdp__ < 0) return 0; - __ret = close(*__fdp); - *__fdp = -1; - return __ret; + ret__ = close(*fdp__); + *fdp__ = -1; + return ret__; } @@ -179,45 +184,45 @@ libsimple_close(int *__fdp) * @param n Pointer to the number of items in the list, will be updated * @param width The width, in bytes, of each item in the list */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) inline void -libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width) +libsimple_unlist(void *list__, size_t i__, size_t *np__, size_t width__) { - char *__lst = __list; - memmove(&__lst[__i * __width], &__lst[(__i + 1) * __width], (--*__np - __i) * __width); + char *lst__ = list__; + memmove(&lst__[i__ * width__], &lst__[(i__ + 1) * width__], (--*np__ - i__) * width__); } #ifndef unlist # define unlist libsimple_unlist #endif -#define _LIBSIMPLE_REMOVE_CONST(X, TYPE, ...) (*(TYPE *)(void *)&(X)) -#define LIBSIMPLE_REMOVE_CONST(...) _LIBSIMPLE_REMOVE_CONST(__VA_ARGS__, void *) /* TODO test, doc, man */ +#define LIBSIMPLE_REMOVE_CONST__(X, TYPE, ...) (*(TYPE *)(void *)&(X)) +#define LIBSIMPLE_REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST__(__VA_ARGS__, void *) /* TODO test, doc, man */ #ifndef REMOVE_CONST # define REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST(__VA_ARGS__) #endif #define LIBSIMPLE_PREFETCH_RDONLY(ADDRESS, LOCALITY) /* void */ /* TODO test, doc, man */\ - _LIBSIMPLE_GCC_ONLY(__builtin_prefetch(ADDRESS, 0, LOCALITY)) + LIBSIMPLE_GCC_ONLY__(__builtin_prefetch(ADDRESS, 0, LOCALITY)) #ifndef PREFETCH_RDONLY # define PREFETCH_RDONLY(...) LIBSIMPLE_PREFETCH_RDONLY(__VA_ARGS__) #endif #define LIBSIMPLE_PREFETCH_RDWR(ADDRESS, LOCALITY) /* void */ /* TODO test, doc, man */\ - _LIBSIMPLE_GCC_ONLY(__builtin_prefetch(ADDRESS, 1, LOCALITY)) + LIBSIMPLE_GCC_ONLY__(__builtin_prefetch(ADDRESS, 1, LOCALITY)) #ifndef PREFETCH_RDWR # define PREFETCH_RDWR(...) LIBSIMPLE_PREFETCH_RDWR(__VA_ARGS__) #endif -#define _LIBSIMPLE_ASSUME_ALIGNED(PTR, ALIGNMENT, ...)\ - _LIBSIMPLE_GCC_ONLY(__builtin_assume_aligned(PTR, ALIGNMENT)) +#define LIBSIMPLE_ASSUME_ALIGNED__(PTR, ALIGNMENT, ...)\ + LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ALIGNMENT)) #if defined(__GNUC__) && !defined(__clang__) # define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man */\ - _LIBSIMPLE_GCC_ONLY(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\ - _LIBSIMPLE_C11_ONLY(_Alignof(PTR))\ + LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\ + LIBSIMPLE_C11_ONLY__(_Alignof(PTR))\ _LIBSIMPLE_PREC11_ONLY(__alignof(PTR)))) #endif #ifndef ASSUME_ALIGNED @@ -232,13 +237,13 @@ libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width) #endif -#define LIBSIMPLE_UNROLLED(N) _LIBSIMPLE_GCC_ONLY(_LIBSIMPLE_C11_ONLY(_Pragma("GCC unroll "#N))) /* TODO test, doc, man */ +#define LIBSIMPLE_UNROLLED(N) LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC unroll "#N))) /* TODO test, doc, man */ #ifndef UNROLLED # define UNROLLED(N) LIBSIMPLE_UNROLLED(N) #endif -#define LIBSIMPLE_SIMDLOOP _LIBSIMPLE_GCC_ONLY(_LIBSIMPLE_C11_ONLY(_Pragma("GCC ivdep"))) /* TODO test, doc, man */ +#define LIBSIMPLE_SIMDLOOP LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC ivdep"))) /* TODO test, doc, man */ #ifndef SIMDLOOP # define SIMDLOOP LIBSIMPLE_SIMDLOOP #endif diff --git a/libsimple/aligned_alloc.h b/libsimple/aligned_alloc.h index b2a60f1..a4fe0fc 100644 --- a/libsimple/aligned_alloc.h +++ b/libsimple/aligned_alloc.h @@ -19,9 +19,12 @@ * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) -static inline void *libsimple_valigned_allocn(size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_valigned_alloczn(0, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) +static inline void * +libsimple_valigned_allocn(size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_valigned_alloczn(0, alignment__, n__, ap__); +} #ifndef valigned_allocn # define valigned_allocn libsimple_valigned_allocn #endif @@ -38,14 +41,14 @@ static inline void *libsimple_valigned_allocn(size_t __alignment, size_t __n, va * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) static inline void * -libsimple_aligned_allocn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_aligned_allocn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_valigned_allocn(__alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_valigned_allocn(alignment__, n__, ap__); + va_end(ap__); } #ifndef aligned_allocn # define aligned_allocn libsimple_aligned_allocn @@ -67,9 +70,12 @@ libsimple_aligned_allocn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_enaligned_alloc(int __status, size_t __alignment, size_t __n) -{ return libsimple_enaligned_allocz(__status, 0, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_enaligned_alloc(int status__, size_t alignment__, size_t n__) +{ + return libsimple_enaligned_allocz(status__, 0, alignment__, n__); +} #ifndef enaligned_alloc # define enaligned_alloc libsimple_enaligned_alloc #endif @@ -96,9 +102,12 @@ static inline void *libsimple_enaligned_alloc(int __status, size_t __alignment, * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envaligned_allocn(int __status, size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envaligned_alloczn(__status, 0, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_envaligned_allocn(int status__, size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envaligned_alloczn(status__, 0, alignment__, n__, ap__); +} #ifndef envaligned_allocn # define envaligned_allocn libsimple_envaligned_allocn #endif @@ -125,14 +134,14 @@ static inline void *libsimple_envaligned_allocn(int __status, size_t __alignment * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enaligned_allocn(int __status, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_enaligned_allocn(int status__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envaligned_alloczn(__status, 0, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envaligned_alloczn(status__, 0, alignment__, n__, ap__); + va_end(ap__); } #ifndef enaligned_allocn # define enaligned_allocn libsimple_enaligned_allocn @@ -153,9 +162,12 @@ libsimple_enaligned_allocn(int __status, size_t __alignment, size_t __n, ... /*, * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ealigned_alloc(size_t __alignment, size_t __n) -{ return libsimple_enaligned_alloc(libsimple_default_failure_exit, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ealigned_alloc(size_t alignment__, size_t n__) +{ + return libsimple_enaligned_alloc(libsimple_default_failure_exit, alignment__, n__); +} #ifndef ealigned_alloc # define ealigned_alloc libsimple_ealigned_alloc #endif @@ -181,9 +193,12 @@ static inline void *libsimple_ealigned_alloc(size_t __alignment, size_t __n) * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evaligned_allocn(size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envaligned_allocn(libsimple_default_failure_exit, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evaligned_allocn(size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envaligned_allocn(libsimple_default_failure_exit, alignment__, n__, ap__); +} #ifndef evaligned_allocn # define evaligned_allocn libsimple_evaligned_allocn #endif @@ -209,14 +224,14 @@ static inline void *libsimple_evaligned_allocn(size_t __alignment, size_t __n, v * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_ealigned_allocn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_ealigned_allocn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evaligned_allocn(__alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evaligned_allocn(alignment__, n__, ap__); + va_end(ap__); } #ifndef ealigned_allocn # define ealigned_allocn libsimple_ealigned_allocn diff --git a/libsimple/aligned_allocz.h b/libsimple/aligned_allocz.h index 9380a50..7213c9b 100644 --- a/libsimple/aligned_allocz.h +++ b/libsimple/aligned_allocz.h @@ -20,7 +20,7 @@ * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) void *libsimple_valigned_alloczn(int, size_t, size_t, va_list); #ifndef valigned_alloczn # define valigned_alloczn libsimple_valigned_alloczn @@ -40,14 +40,14 @@ void *libsimple_valigned_alloczn(int, size_t, size_t, va_list); * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) static inline void * -libsimple_aligned_allocz(int __clear, size_t __alignment, size_t __n) +libsimple_aligned_allocz(int clear__, size_t alignment__, size_t n__) { - void *__ret = aligned_alloc(__alignment, __n); - if (__ret && __clear) - memset(__ret, 0, __n); - return __ret; + void *ret__ = aligned_alloc(alignment__, n__); + if (ret__ && clear__) + memset(ret__, 0, n__); + return ret__; } #ifndef aligned_allocz # define aligned_allocz libsimple_aligned_allocz @@ -73,14 +73,14 @@ libsimple_aligned_allocz(int __clear, size_t __alignment, size_t __n) * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) static inline void * -libsimple_aligned_alloczn(int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_aligned_alloczn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_valigned_alloczn(__clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_valigned_alloczn(clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef aligned_alloczn # define aligned_alloczn libsimple_aligned_alloczn @@ -103,7 +103,7 @@ libsimple_aligned_alloczn(int __clear, size_t __alignment, size_t __n, ... /*, ( * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enaligned_allocz(int, int, size_t, size_t); #ifndef enaligned_allocz # define enaligned_allocz libsimple_enaligned_allocz @@ -132,7 +132,7 @@ void *libsimple_enaligned_allocz(int, int, size_t, size_t); * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) void *libsimple_envaligned_alloczn(int, int, size_t, size_t, va_list); #ifndef envaligned_alloczn # define envaligned_alloczn libsimple_envaligned_alloczn @@ -161,14 +161,14 @@ void *libsimple_envaligned_alloczn(int, int, size_t, size_t, va_list); * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enaligned_alloczn(int __status, int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_enaligned_alloczn(int status__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envaligned_alloczn(__status, __clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envaligned_alloczn(status__, clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef enaligned_alloczn # define enaligned_alloczn libsimple_enaligned_alloczn @@ -189,9 +189,12 @@ libsimple_enaligned_alloczn(int __status, int __clear, size_t __alignment, size_ * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ealigned_allocz(int __clear, size_t __alignment, size_t __n) -{ return libsimple_enaligned_allocz(libsimple_default_failure_exit, __clear, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ealigned_allocz(int clear__, size_t alignment__, size_t n__) +{ + return libsimple_enaligned_allocz(libsimple_default_failure_exit, clear__, alignment__, n__); +} #ifndef ealigned_allocz # define ealigned_allocz libsimple_ealigned_allocz #endif @@ -218,9 +221,12 @@ static inline void *libsimple_ealigned_allocz(int __clear, size_t __alignment, s * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evaligned_alloczn(int __clear, size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envaligned_alloczn(libsimple_default_failure_exit, __clear, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evaligned_alloczn(int clear__, size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envaligned_alloczn(libsimple_default_failure_exit, clear__, alignment__, n__, ap__); +} #ifndef evaligned_alloczn # define evaligned_alloczn libsimple_evaligned_alloczn #endif @@ -247,14 +253,14 @@ static inline void *libsimple_evaligned_alloczn(int __clear, size_t __alignment, * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_ealigned_alloczn(int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_ealigned_alloczn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evaligned_alloczn(__clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evaligned_alloczn(clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef ealigned_alloczn # define ealigned_alloczn libsimple_ealigned_alloczn diff --git a/libsimple/aligned_memdup.h b/libsimple/aligned_memdup.h index 7c17375..d612be0 100644 --- a/libsimple/aligned_memdup.h +++ b/libsimple/aligned_memdup.h @@ -11,6 +11,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_memdupa(s, alignment, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ const char *__s = (s);\ size_t __n = (n);\ @@ -40,7 +41,7 @@ * @param n The number of bytes to copy * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __nonnull__, __warn_unused_result__))) void *libsimple_aligned_memdup(const void *, size_t, size_t); #ifndef aligned_memdup # define aligned_memdup libsimple_aligned_memdup @@ -56,7 +57,7 @@ void *libsimple_aligned_memdup(const void *, size_t, size_t); * @param n The number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enaligned_memdup(int, const void *, size_t, size_t); #ifndef enaligned_memdup # define enaligned_memdup libsimple_enaligned_memdup @@ -71,11 +72,11 @@ void *libsimple_enaligned_memdup(int, const void *, size_t, size_t); * @param n The number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) inline void * -libsimple_ealigned_memdup(const void *__s, size_t __alignment, size_t __n) +libsimple_ealigned_memdup(const void *s__, size_t alignment__, size_t n__) { - return libsimple_enaligned_memdup(libsimple_default_failure_exit, __s, __alignment, __n); + return libsimple_enaligned_memdup(libsimple_default_failure_exit, s__, alignment__, n__); } #ifndef ealigned_memdup # define ealigned_memdup libsimple_ealigned_memdup diff --git a/libsimple/aligned_realloc.h b/libsimple/aligned_realloc.h index 1da7ba7..bc66d84 100644 --- a/libsimple/aligned_realloc.h +++ b/libsimple/aligned_realloc.h @@ -27,33 +27,33 @@ * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) #if defined(__GLIBC__) # define LIBSIMPLE_HAVE_ALIGNED_REALLOC # include static inline void * -libsimple_aligned_realloc(void *__ptr, size_t __alignment, size_t __n) /* TODO musl */ +libsimple_aligned_realloc(void *ptr__, size_t alignment__, size_t n__) /* TODO musl */ { - size_t __old = malloc_usable_size(__ptr); + size_t old__ = malloc_usable_size(ptr__); #if __STDC_VERSION__ >= 201112L || defined(_ISOC11_SOURCE) - size_t __extra = (__alignment - __n % __alignment) % __alignment; - void *__new = aligned_alloc(__alignment, __n + __extra); + size_t extra__ = (alignment__ - n__ % alignment__) % alignment__; + void *new__ = aligned_alloc(alignment__, n__ + extra__); #else - void *__new = memalign(__alignment, __n); + void *new__ = memalign(alignment__, n__); #endif - if (__new) { - memcpy(__new, __ptr, __old < __n ? __old : __n); - free(__ptr); + if (new__) { + memcpy(new__, ptr__, old__ < n__ ? old__ : n__); + free(ptr__); } - return __new; + return new__; } #else static inline void * -libsimple_aligned_realloc(void *__ptr, size_t __alignment, size_t __n) +libsimple_aligned_realloc(void *ptr__, size_t alignment__, size_t n__) { - (void) __ptr; - (void) __alignment; - (void) __n; + (void) ptr__; + (void) alignment__; + (void) n__; errno = ENOSYS; return NULL; } @@ -89,7 +89,7 @@ libsimple_aligned_realloc(void *__ptr, size_t __alignment, size_t __n) * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enaligned_realloc(int, void *, size_t, size_t); #ifndef enaligned_realloc # define enaligned_realloc libsimple_enaligned_realloc @@ -121,9 +121,12 @@ void *libsimple_enaligned_realloc(int, void *, size_t, size_t); * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ealigned_realloc(void *__ptr, size_t __alignment, size_t __n) -{ return libsimple_enaligned_realloc(libsimple_default_failure_exit, __ptr, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ealigned_realloc(void *ptr__, size_t alignment__, size_t n__) +{ + return libsimple_enaligned_realloc(libsimple_default_failure_exit, ptr__, alignment__, n__); +} #ifndef ealigned_realloc # define ealigned_realloc libsimple_ealigned_realloc #endif @@ -155,13 +158,13 @@ static inline void *libsimple_ealigned_realloc(void *__ptr, size_t __alignment, * @throws EINVAL `alignment` is not a valid alignment * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) static inline void * -libsimple_aligned_reallocf(void *__ptr, size_t __alignment, size_t __n) /* TODO test */ +libsimple_aligned_reallocf(void *ptr__, size_t alignment__, size_t n__) /* TODO test */ { - void *__new = __n ? libsimple_aligned_realloc(__ptr, __alignment, __n) : NULL; - if (!__new) - free(__ptr); + void *new__ = n__ ? libsimple_aligned_realloc(ptr__, alignment__, n__) : NULL; + if (!new__) + free(ptr__); return NULL; } #ifndef aligned_reallocf @@ -198,15 +201,15 @@ libsimple_aligned_reallocf(void *__ptr, size_t __alignment, size_t __n) /* TODO * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) static inline void * -libsimple_aligned_reallocarray(void *__ptr, size_t __alignment, size_t __n, size_t __m) +libsimple_aligned_reallocarray(void *ptr__, size_t alignment__, size_t n__, size_t m__) { - if (LIBSIMPLE_UMUL_OVERFLOW(__n, __m, &__n, SIZE_MAX)) { + if (LIBSIMPLE_UMUL_OVERFLOW(n__, m__, &n__, SIZE_MAX)) { errno = ENOMEM; return NULL; } - return libsimple_aligned_realloc(__ptr, __alignment, __n); + return libsimple_aligned_realloc(ptr__, alignment__, n__); } #ifndef aligned_reallocarray # define aligned_reallocarray libsimple_aligned_reallocarray @@ -242,7 +245,7 @@ libsimple_aligned_reallocarray(void *__ptr, size_t __alignment, size_t __n, size * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(3), __alloc_size__(4, 5), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(3), __alloc_size__(4, 5), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enaligned_reallocarray(int, void *, size_t, size_t, size_t); #ifndef enaligned_reallocarray # define enaligned_reallocarray libsimple_enaligned_reallocarray @@ -278,9 +281,12 @@ void *libsimple_enaligned_reallocarray(int, void *, size_t, size_t, size_t); * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ealigned_reallocarray(void *__ptr, size_t __alignment, size_t __n, size_t __m) -{ return libsimple_enaligned_reallocarray(libsimple_default_failure_exit, __ptr, __alignment, __n, __m); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ealigned_reallocarray(void *ptr__, size_t alignment__, size_t n__, size_t m__) +{ + return libsimple_enaligned_reallocarray(libsimple_default_failure_exit, ptr__, alignment__, n__, m__); +} #ifndef ealigned_reallocarray # define ealigned_reallocarray libsimple_ealigned_reallocarray #endif @@ -311,13 +317,13 @@ static inline void *libsimple_ealigned_reallocarray(void *__ptr, size_t __alignm * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) static inline void * -libsimple_aligned_reallocarrayf(void *__ptr, size_t __alignment, size_t __n, size_t __m) /* TODO test */ +libsimple_aligned_reallocarrayf(void *ptr__, size_t alignment__, size_t n__, size_t m__) /* TODO test */ { - void *__new = (__n && __m) ? libsimple_aligned_reallocarray(__ptr, __alignment, __n, __m) : NULL; - if (!__new) - free(__ptr); + void *new__ = (n__ && m__) ? libsimple_aligned_reallocarray(ptr__, alignment__, n__, m__) : NULL; + if (!new__) + free(ptr__); return NULL; } #ifndef aligned_reallocarrayf @@ -355,7 +361,7 @@ libsimple_aligned_reallocarrayf(void *__ptr, size_t __alignment, size_t __n, siz * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) void *libsimple_valigned_reallocn(void *, size_t, size_t, va_list); #ifndef valigned_reallocn # define valigned_reallocn libsimple_valigned_reallocn @@ -393,7 +399,7 @@ void *libsimple_valigned_reallocn(void *, size_t, size_t, va_list); * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) void *libsimple_envaligned_reallocn(int, void *, size_t, size_t, va_list); #ifndef envaligned_reallocn # define envaligned_reallocn libsimple_envaligned_reallocn @@ -430,9 +436,12 @@ void *libsimple_envaligned_reallocn(int, void *, size_t, size_t, va_list); * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evaligned_reallocn(void *__ptr, size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envaligned_reallocn(libsimple_default_failure_exit, __ptr, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evaligned_reallocn(void *ptr__, size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envaligned_reallocn(libsimple_default_failure_exit, ptr__, alignment__, n__, ap__); +} #ifndef evaligned_reallocn # define evaligned_reallocn libsimple_evaligned_reallocn #endif @@ -464,14 +473,14 @@ static inline void *libsimple_evaligned_reallocn(void *__ptr, size_t __alignment * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) static inline void * -libsimple_valigned_reallocfn(void *__ptr, size_t __alignment, size_t __n, va_list __ap) /* TODO test (aligned_reallocfn) */ +libsimple_valigned_reallocfn(void *ptr__, size_t alignment__, size_t n__, va_list ap__) /* TODO test (aligned_reallocfn) */ { - void *__new = libsimple_valigned_reallocn(__ptr, __alignment, __n, __ap); - if (!__new) - free(__ptr); - return __new; + void *new__ = libsimple_valigned_reallocn(ptr__, alignment__, n__, ap__); + if (!new__) + free(ptr__); + return new__; } #ifndef valigned_reallocfn # define valigned_reallocfn libsimple_aligned_reallocnf @@ -508,14 +517,14 @@ libsimple_valigned_reallocfn(void *__ptr, size_t __alignment, size_t __n, va_lis * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) static inline void * -libsimple_aligned_reallocn(void *__ptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_aligned_reallocn(void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_valigned_reallocn(__ptr, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_valigned_reallocn(ptr__, alignment__, n__, ap__); + va_end(ap__); } #ifndef aligned_reallocn # define aligned_reallocn libsimple_aligned_reallocn @@ -553,14 +562,14 @@ libsimple_aligned_reallocn(void *__ptr, size_t __alignment, size_t __n, ... /*, * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enaligned_reallocn(int __status, void *__ptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_enaligned_reallocn(int status__, void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envaligned_reallocn(__status, __ptr, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envaligned_reallocn(status__, ptr__, alignment__, n__, ap__); + va_end(ap__); } #ifndef enaligned_reallocn # define enaligned_reallocn libsimple_enaligned_reallocn @@ -597,14 +606,14 @@ libsimple_enaligned_reallocn(int __status, void *__ptr, size_t __alignment, size * @return Either `ptr` or a unique pointer with at least * the specified size */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_ealigned_reallocn(void *__ptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_ealigned_reallocn(void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evaligned_reallocn(__ptr, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evaligned_reallocn(ptr__, alignment__, n__, ap__); + va_end(ap__); } #ifndef ealigned_reallocn # define ealigned_reallocn libsimple_ealigned_reallocn @@ -641,14 +650,14 @@ libsimple_ealigned_reallocn(void *__ptr, size_t __alignment, size_t __n, ... /*, * @throws ENOMEM Could not allocated enough memory * @throws ENOSYS Not implemented (requires non-standard libc functions) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) static inline void * -libsimple_aligned_reallocfn(void *__ptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_aligned_reallocfn(void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_valigned_reallocfn(__ptr, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_valigned_reallocfn(ptr__, alignment__, n__, ap__); + va_end(ap__); } #ifndef aligned_reallocfn # define aligned_reallocfn libsimple_aligned_reallocfn diff --git a/libsimple/aligned_strdup.h b/libsimple/aligned_strdup.h index 07b7edf..c7b713e 100644 --- a/libsimple/aligned_strdup.h +++ b/libsimple/aligned_strdup.h @@ -10,18 +10,19 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_strdupa(s, alignment)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__s = (s);\ - size_t __n = strlen(__s) + 1;\ - size_t __a = (alignment);\ - uintptr_t __misalignment;\ - char *__r;\ - __a += !__a;\ - __r = alloca(__n + (__a - 1));\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - memcpy(__r, __s, __n);\ + const char *s__ = (s);\ + size_t n__ = strlen(s__) + 1;\ + size_t a__ = (alignment);\ + uintptr_t misalignment__;\ + char *r__;\ + a__ += !a__;\ + r__ = alloca(n__ + (a__ - 1));\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + memcpy(r__, s__, n__);\ }) # ifndef aligned_strdupa # define aligned_strdupa(s, alignment) libsimple_aligned_strdupa(s, alignment) @@ -36,9 +37,12 @@ * @param alignment The alignment of the returned pointer * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) -static inline char *libsimple_aligned_strdup(const char * __s, size_t __alignment) -{ return libsimple_aligned_memdup(__s, __alignment, strlen(__s) + 1); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) +inline char * +libsimple_aligned_strdup(const char *s__, size_t alignment__) +{ + return libsimple_aligned_memdup(s__, alignment__, strlen(s__) + 1); +} #ifndef aligned_strdup # define aligned_strdup libsimple_aligned_strdup #endif @@ -52,7 +56,7 @@ static inline char *libsimple_aligned_strdup(const char * __s, size_t __alignmen * @param alignment The alignment of the returned pointer * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) char *libsimple_enaligned_strdup(int, const char *, size_t); #ifndef enaligned_strdup # define enaligned_strdup libsimple_enaligned_strdup @@ -66,9 +70,12 @@ char *libsimple_enaligned_strdup(int, const char *, size_t); * @param alignment The alignment of the returned pointer * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_ealigned_strdup(const char *__s, size_t __alignment) -{ return libsimple_enaligned_strdup(libsimple_default_failure_exit, __s, __alignment); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +inline char * +libsimple_ealigned_strdup(const char *s__, size_t alignment__) +{ + return libsimple_enaligned_strdup(libsimple_default_failure_exit, s__, alignment__); +} #ifndef ealigned_strdup # define ealigned_strdup libsimple_ealigned_strdup #endif diff --git a/libsimple/aligned_strndup.h b/libsimple/aligned_strndup.h index 68b9d00..201afef 100644 --- a/libsimple/aligned_strndup.h +++ b/libsimple/aligned_strndup.h @@ -11,20 +11,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_strndupa(s, alignment, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__s = (s);\ - size_t __n = strnlen(__s, n);\ - size_t __a = (alignment);\ - uintptr_t __misalignment;\ - char *__r;\ - __a += !__a;\ - __r = alloca(__n + 1 + (__a - 1));\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - memcpy(__r, __s, __n);\ - __r[__n] = '\0';\ - __r;\ + const char *s__ = (s);\ + size_t n__ = strnlen(s__, n);\ + size_t a__ = (alignment);\ + uintptr_t misalignment__;\ + char *r__;\ + a__ += !a__;\ + r__ = alloca(n__ + 1 + (a__ - 1));\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + memcpy(r__, s__, n__);\ + r__[n__] = '\0';\ + r__;\ }) # ifndef aligned_strndupa # define aligned_strndupa(s, alignment, n) libsimple_aligned_strndupa(s, alignment, n) @@ -40,8 +41,8 @@ * @param n The maximum number of bytes to copy * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) -char *libsimple_aligned_strndup(const char * __s, size_t __alignment, size_t __n); +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) +char *libsimple_aligned_strndup(const char * s__, size_t alignment__, size_t n__); #ifndef aligned_strndup # define aligned_strndup libsimple_aligned_strndup #endif @@ -56,7 +57,7 @@ char *libsimple_aligned_strndup(const char * __s, size_t __alignment, size_t __n * @param n The maximum number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) char *libsimple_enaligned_strndup(int, const char *, size_t, size_t); #ifndef enaligned_strndup # define enaligned_strndup libsimple_enaligned_strndup @@ -71,11 +72,11 @@ char *libsimple_enaligned_strndup(int, const char *, size_t, size_t); * @param n The maximum number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) inline char * -libsimple_ealigned_strndup(const char *__s, size_t __alignment, size_t __n) +libsimple_ealigned_strndup(const char *s__, size_t alignment__, size_t n__) { - return libsimple_enaligned_strndup(libsimple_default_failure_exit, __s, __alignment, __n); + return libsimple_enaligned_strndup(libsimple_default_failure_exit, s__, alignment__, n__); } #ifndef ealigned_strndup # define ealigned_strndup libsimple_ealigned_strndup diff --git a/libsimple/aligned_wcsdup.h b/libsimple/aligned_wcsdup.h index 527d210..c9fc0cf 100644 --- a/libsimple/aligned_wcsdup.h +++ b/libsimple/aligned_wcsdup.h @@ -10,18 +10,19 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wcsdupa(s, alignment)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const wchar_t *__s = (s);\ - size_t __n = wcslen(__s) + 1;\ - size_t __a = (alignment);\ - uintptr_t __misalignment;\ - wchar_t *__r;\ - __a += !__a;\ - __r = alloca(__n * sizeof(wchar_t) + (__a - 1));\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - wmemcpy(__r, __s, __n);\ + const wchar_t *s__ = (s);\ + size_t n__ = wcslen(s__) + 1;\ + size_t a__ = (alignment);\ + uintptr_t misalignment__;\ + wchar_t *r__;\ + a__ += !a__;\ + r__ = alloca(n__ * sizeof(wchar_t) + (a__ - 1));\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + wmemcpy(r__, s__, n__);\ }) # ifndef aligned_wcsdupa # define aligned_wcsdupa(s, alignment) libsimple_aligned_wcsdupa(s, alignment) @@ -36,9 +37,12 @@ * @param alignment The alignment of the returned pointer * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) -static inline wchar_t *libsimple_aligned_wcsdup(const wchar_t * __s, size_t __alignment) -{ return libsimple_aligned_wmemdup(__s, __alignment, wcslen(__s) + 1); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) +inline wchar_t * +libsimple_aligned_wcsdup(const wchar_t *s__, size_t alignment__) +{ + return libsimple_aligned_wmemdup(s__, alignment__, wcslen(s__) + 1); +} #ifndef aligned_wcsdup # define aligned_wcsdup libsimple_aligned_wcsdup #endif @@ -52,7 +56,7 @@ static inline wchar_t *libsimple_aligned_wcsdup(const wchar_t * __s, size_t __al * @param alignment The alignment of the returned pointer * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) wchar_t *libsimple_enaligned_wcsdup(int, const wchar_t *, size_t); #ifndef enaligned_wcsdup # define enaligned_wcsdup libsimple_enaligned_wcsdup @@ -66,9 +70,12 @@ wchar_t *libsimple_enaligned_wcsdup(int, const wchar_t *, size_t); * @param alignment The alignment of the returned pointer * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ealigned_wcsdup(const wchar_t *__s, size_t __alignment) -{ return libsimple_enaligned_wcsdup(libsimple_default_failure_exit, __s, __alignment); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +inline wchar_t * +libsimple_ealigned_wcsdup(const wchar_t *s__, size_t alignment__) +{ + return libsimple_enaligned_wcsdup(libsimple_default_failure_exit, s__, alignment__); +} #ifndef ealigned_wcsdup # define ealigned_wcsdup libsimple_ealigned_wcsdup #endif diff --git a/libsimple/aligned_wcsndup.h b/libsimple/aligned_wcsndup.h index 4e081ee..cd06ff8 100644 --- a/libsimple/aligned_wcsndup.h +++ b/libsimple/aligned_wcsndup.h @@ -11,20 +11,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wcsndupa(s, alignment, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const wchar_t *__s = (s);\ - size_t __n = wcsnlen(__s, n);\ - size_t __a = (alignment);\ - uintptr_t __misalignment;\ - wchar_t *__r;\ - __a += !__a;\ - __r = alloca((__n + 1) * sizeof(wchar_t) + (__a - 1));\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - wmemcpy(__r, __s, __n);\ - __r[__n] = 0;\ - __r;\ + const wchar_t *s__ = (s);\ + size_t n__ = wcsnlen(s__, n);\ + size_t a__ = (alignment);\ + uintptr_t misalignment__;\ + wchar_t *r__;\ + a__ += !a__;\ + r__ = alloca((n__ + 1) * sizeof(wchar_t) + (a__ - 1));\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + wmemcpy(r__, s__, n__);\ + r__[n__] = 0;\ + r__;\ }) # ifndef aligned_wcsndupa # define aligned_wcsndupa(s, alignment, n) libsimple_aligned_wcsndupa(s, alignment, n) @@ -40,8 +41,8 @@ * @param n The maximum number of wide characters to copy * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) -wchar_t *libsimple_aligned_wcsndup(const wchar_t * __s, size_t __alignment, size_t __n); +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__))) +wchar_t *libsimple_aligned_wcsndup(const wchar_t * s__, size_t alignment__, size_t n__); #ifndef aligned_wcsndup # define aligned_wcsndup libsimple_aligned_wcsndup #endif @@ -56,7 +57,7 @@ wchar_t *libsimple_aligned_wcsndup(const wchar_t * __s, size_t __alignment, size * @param n The maximum number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __nonnull__, __warn_unused_result__, __returns_nonnull__))) wchar_t *libsimple_enaligned_wcsndup(int, const wchar_t *, size_t, size_t); #ifndef enaligned_wcsndup # define enaligned_wcsndup libsimple_enaligned_wcsndup @@ -71,11 +72,11 @@ wchar_t *libsimple_enaligned_wcsndup(int, const wchar_t *, size_t, size_t); * @param n The maximum number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) inline wchar_t * -libsimple_ealigned_wcsndup(const wchar_t *__s, size_t __alignment, size_t __n) +libsimple_ealigned_wcsndup(const wchar_t *s__, size_t alignment__, size_t n__) { - return libsimple_enaligned_wcsndup(libsimple_default_failure_exit, __s, __alignment, __n); + return libsimple_enaligned_wcsndup(libsimple_default_failure_exit, s__, alignment__, n__); } #ifndef ealigned_wcsndup # define ealigned_wcsndup libsimple_ealigned_wcsndup diff --git a/libsimple/aligned_wmemdup.h b/libsimple/aligned_wmemdup.h index 79b59dd..56148d8 100644 --- a/libsimple/aligned_wmemdup.h +++ b/libsimple/aligned_wmemdup.h @@ -11,20 +11,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wmemdupa(s, alignment, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const wchar_t *__s = (s);\ - size_t __n = (n);\ - size_t __a = (alignment);\ - size_t __size;\ - uintptr_t __misalignment;\ - wchar_t *__r;\ - __a += !__a;\ - __size = __n * sizeof(wchar_t) + (__a - 1);\ - __r = alloca(__size + !__size);\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - wmemcpy(__r, __s, __n);\ + const wchar_t *s__ = (s);\ + size_t n__ = (n);\ + size_t a__ = (alignment);\ + size_t size__;\ + uintptr_t misalignment__;\ + wchar_t *r__;\ + a__ += !a__;\ + size__ = n__ * sizeof(wchar_t) + (a__ - 1);\ + r__ = alloca(size__ + !size__);\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + wmemcpy(r__, s__, n__);\ }) # ifndef aligned_wmemdupa # define aligned_wmemdupa(s, alignment, n) libsimple_aligned_wmemdupa(s, alignment, n) @@ -40,7 +41,7 @@ * @param n The number of wide characters to copy * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __nonnull__, __warn_unused_result__))) wchar_t *libsimple_aligned_wmemdup(const wchar_t *, size_t, size_t); #ifndef aligned_wmemdup # define aligned_wmemdup libsimple_aligned_wmemdup @@ -56,7 +57,7 @@ wchar_t *libsimple_aligned_wmemdup(const wchar_t *, size_t, size_t); * @param n The number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) wchar_t *libsimple_enaligned_wmemdup(int, const wchar_t *, size_t, size_t); #ifndef enaligned_wmemdup # define enaligned_wmemdup libsimple_enaligned_wmemdup @@ -71,11 +72,11 @@ wchar_t *libsimple_enaligned_wmemdup(int, const wchar_t *, size_t, size_t); * @param n The number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) inline wchar_t * -libsimple_ealigned_wmemdup(const wchar_t *__s, size_t __alignment, size_t __n) +libsimple_ealigned_wmemdup(const wchar_t *s__, size_t alignment__, size_t n__) { - return libsimple_enaligned_wmemdup(libsimple_default_failure_exit, __s, __alignment, __n); + return libsimple_enaligned_wmemdup(libsimple_default_failure_exit, s__, alignment__, n__); } #ifndef ealigned_wmemdup # define ealigned_wmemdup libsimple_ealigned_wmemdup diff --git a/libsimple/calloc.h b/libsimple/calloc.h index 7b373e9..28f284d 100644 --- a/libsimple/calloc.h +++ b/libsimple/calloc.h @@ -18,9 +18,12 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void *libsimple_vcallocn(size_t __n, va_list __ap) -{ return libsimple_vmalloczn(1, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +static inline void * +libsimple_vcallocn(size_t n__, va_list ap__) +{ + return libsimple_vmalloczn(1, n__, ap__); +} #ifndef vcallocn # define vcallocn libsimple_vcallocn #endif @@ -43,14 +46,14 @@ static inline void *libsimple_vcallocn(size_t __n, va_list __ap) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) static inline void * -libsimple_callocn(size_t __n, ... /*, (size_t)0 */) +libsimple_callocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vmalloczn(1, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vmalloczn(1, n__, ap__); + va_end(ap__); } #ifndef callocn # define callocn libsimple_callocn @@ -73,8 +76,11 @@ libsimple_callocn(size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the size `n * m` * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2, 3), __warn_unused_result__, __returns_nonnull__))) +#ifndef LIBSIMPLE_DEFINED_LIBSIMPLE_ENCALLOC__ +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2, 3), __warn_unused_result__, __returns_nonnull__))) void *libsimple_encalloc(int, size_t, size_t); +# define LIBSIMPLE_DEFINED_LIBSIMPLE_ENCALLOC__ +#endif #ifndef encalloc # define encalloc libsimple_encalloc #endif @@ -99,9 +105,12 @@ void *libsimple_encalloc(int, size_t, size_t); * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envcallocn(int __status, size_t __n, va_list __ap) -{ return libsimple_envmalloczn(__status, 1, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_envcallocn(int status__, size_t n__, va_list ap__) +{ + return libsimple_envmalloczn(status__, 1, n__, ap__); +} #ifndef envcallocn # define envcallocn libsimple_envcallocn #endif @@ -126,14 +135,14 @@ static inline void *libsimple_envcallocn(int __status, size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_encallocn(int __status, size_t __n, ... /*, (size_t)0 */) +libsimple_encallocn(int status__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envcallocn(__status, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envcallocn(status__, n__, ap__); + va_end(ap__); } #ifndef encallocn # define encallocn libsimple_encallocn @@ -155,9 +164,12 @@ libsimple_encallocn(int __status, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the size `n * m` * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(1, 2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ecalloc(size_t __n, size_t __m) -{ return encalloc(libsimple_default_failure_exit, __n, __m); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1, 2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ecalloc(size_t n__, size_t m__) +{ + return encalloc(libsimple_default_failure_exit, n__, m__); +} #ifndef ecalloc # define ecalloc libsimple_ecalloc #endif @@ -181,9 +193,12 @@ static inline void *libsimple_ecalloc(size_t __n, size_t __m) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evcallocn(size_t __n, va_list __ap) -{ return libsimple_envcallocn(libsimple_default_failure_exit, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evcallocn(size_t n__, va_list ap__) +{ + return libsimple_envcallocn(libsimple_default_failure_exit, n__, ap__); +} #ifndef evcallocn # define evcallocn libsimple_evcallocn #endif @@ -207,14 +222,14 @@ static inline void *libsimple_evcallocn(size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_ecallocn(size_t __n, ... /*, (size_t)0 */) +libsimple_ecallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evcallocn(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evcallocn(n__, ap__); + va_end(ap__); } #ifndef ecallocn # define ecallocn libsimple_ecallocn diff --git a/libsimple/env.h b/libsimple/env.h index f9139c7..530b21e 100644 --- a/libsimple/env.h +++ b/libsimple/env.h @@ -7,12 +7,12 @@ * @param var The environment variable's name * @return The environment variable's value, `NULL` if empty or not defined */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__))) inline char * -libsimple_getenv_ne(const char *__name) +libsimple_getenv_ne(const char *name__) { - char *__env = getenv(__name); - return (__env && *__env) ? __env : NULL; + char *env__ = getenv(name__); + return (env__ && *env__) ? env__ : NULL; } #ifndef getenv_ne # define getenv_ne libsimple_getenv_ne @@ -25,12 +25,12 @@ libsimple_getenv_ne(const char *__name) * @param var The environment variable's name * @return The environment variable's value, "" if empty or not defined */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __returns_nonnull__))) inline const char * -libsimple_getenv_e(const char *__name) +libsimple_getenv_e(const char *name__) { - const char *__env = getenv(__name); - return (__env && *__env) ? __env : ""; + const char *env__ = getenv(name__); + return (env__ && *env__) ? env__ : ""; } #ifndef getenv_e # define getenv_e libsimple_getenv_e @@ -50,7 +50,7 @@ libsimple_getenv_e(const char *__name) * @param ap Format arguments, see vsprintf(3) * @return 0 on success, -1 on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_vputenvf(const char *, va_list); #ifndef vputenvf # define vputenvf libsimple_vputenvf @@ -70,14 +70,14 @@ int libsimple_vputenvf(const char *, va_list); * @param ... Format arguments, see vsprintf(3) * @return 0 on success, -1 on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) inline int -libsimple_putenvf(const char *__fmt, ...) +libsimple_putenvf(const char *fmt__, ...) { - va_list __ap; - va_start(__ap, __fmt); - return libsimple_vputenvf(__fmt, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, fmt__); + return libsimple_vputenvf(fmt__, ap__); + va_end(ap__); } #ifndef putenvf # define putenvf libsimple_putenvf @@ -101,7 +101,7 @@ libsimple_putenvf(const char *__fmt, ...) * @param fmt Format string, see vsprintf(3) * @param ap Format arguments, see vsprintf(3) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) void libsimple_envputenvf(int, const char *, va_list); #ifndef envputenvf # define envputenvf libsimple_envputenvf @@ -125,14 +125,14 @@ void libsimple_envputenvf(int, const char *, va_list); * @param fmt Format string, see vsprintf(3) * @param ap Format arguments, see vsprintf(3) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 2, 3)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 2, 3)))) inline void -libsimple_enputenvf(int __status, const char *__fmt, ...) +libsimple_enputenvf(int status__, const char *fmt__, ...) { - va_list __ap; - va_start(__ap, __fmt); - libsimple_envputenvf(__status, __fmt, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, fmt__); + libsimple_envputenvf(status__, fmt__, ap__); + va_end(ap__); } #ifndef enputenvf # define enputenvf libsimple_enputenvf @@ -155,11 +155,11 @@ libsimple_enputenvf(int __status, const char *__fmt, ...) * @param fmt Format string, see vsprintf(3) * @param ap Format arguments, see vsprintf(3) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) inline void -libsimple_evputenvf(const char *__fmt, va_list __ap) +libsimple_evputenvf(const char *fmt__, va_list ap__) { - libsimple_envputenvf(libsimple_default_failure_exit, __fmt, __ap); + libsimple_envputenvf(libsimple_default_failure_exit, fmt__, ap__); } #ifndef evputenvf # define evputenvf libsimple_evputenvf @@ -182,14 +182,14 @@ libsimple_evputenvf(const char *__fmt, va_list __ap) * @param fmt Format string, see vsprintf(3) * @param ap Format arguments, see vsprintf(3) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) inline void -libsimple_eputenvf(const char *__fmt, ...) +libsimple_eputenvf(const char *fmt__, ...) { - va_list __ap; - va_start(__ap, __fmt); - libsimple_evputenvf(__fmt, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, fmt__); + libsimple_evputenvf(fmt__, ap__); + va_end(ap__); } #ifndef eputenvf # define eputenvf libsimple_eputenvf diff --git a/libsimple/malloc.h b/libsimple/malloc.h index b57f81f..ca057da 100644 --- a/libsimple/malloc.h +++ b/libsimple/malloc.h @@ -18,9 +18,12 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void *libsimple_vmallocn(size_t __n, va_list __ap) -{ return libsimple_vmalloczn(0, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +static inline void * +libsimple_vmallocn(size_t n__, va_list ap__) +{ + return libsimple_vmalloczn(0, n__, ap__); +} #ifndef vmallocn # define vmallocn libsimple_vmallocn #endif @@ -43,14 +46,14 @@ static inline void *libsimple_vmallocn(size_t __n, va_list __ap) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) static inline void * -libsimple_mallocn(size_t __n, ... /*, (size_t)0 */) +libsimple_mallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vmalloczn(0, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vmalloczn(0, n__, ap__); + va_end(ap__); } #ifndef mallocn # define mallocn libsimple_mallocn @@ -71,8 +74,11 @@ libsimple_mallocn(size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +#ifndef LIBSIMPLE_DEFINED_LIBSIMPLE_ENMALLOC__ +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enmalloc(int, size_t); +# define LIBSIMPLE_DEFINED_LIBSIMPLE_ENMALLOC__ +#endif #ifndef enmalloc # define enmalloc libsimple_enmalloc #endif @@ -97,9 +103,12 @@ void *libsimple_enmalloc(int, size_t); * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envmallocn(int __status, size_t __n, va_list __ap) -{ return libsimple_envmalloczn(__status, 0, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_envmallocn(int status__, size_t n__, va_list ap__) +{ + return libsimple_envmalloczn(status__, 0, n__, ap__); +} #ifndef envmallocn # define envmallocn libsimple_envmallocn #endif @@ -124,14 +133,14 @@ static inline void *libsimple_envmallocn(int __status, size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enmallocn(int __status, size_t __n, ... /*, (size_t)0 */) +libsimple_enmallocn(int status__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envmallocn(__status, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envmallocn(status__, n__, ap__); + va_end(ap__); } #ifndef enmallocn # define enmallocn libsimple_enmallocn @@ -151,9 +160,12 @@ libsimple_enmallocn(int __status, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_emalloc(size_t __n) -{ return libsimple_enmalloc(libsimple_default_failure_exit, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_emalloc(size_t n__) +{ + return libsimple_enmalloc(libsimple_default_failure_exit, n__); +} #ifndef emalloc # define emalloc libsimple_emalloc #endif @@ -177,9 +189,12 @@ static inline void *libsimple_emalloc(size_t __n) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evmallocn(size_t __n, va_list __ap) -{ return libsimple_envmallocn(libsimple_default_failure_exit, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evmallocn(size_t n__, va_list ap__) +{ + return libsimple_envmallocn(libsimple_default_failure_exit, n__, ap__); +} #ifndef evmallocn # define evmallocn libsimple_evmallocn #endif @@ -203,14 +218,14 @@ static inline void *libsimple_evmallocn(size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_emallocn(size_t __n, ... /*, (size_t)0 */) +libsimple_emallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evmallocn(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evmallocn(n__, ap__); + va_end(ap__); } #ifndef emallocn # define emallocn libsimple_emallocn diff --git a/libsimple/mallocz.h b/libsimple/mallocz.h index 2bbd607..7bd9999 100644 --- a/libsimple/mallocz.h +++ b/libsimple/mallocz.h @@ -3,11 +3,17 @@ /* Properly declared elsewhere { */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2, 3), __warn_unused_result__, __returns_nonnull__))) +#ifndef LIBSIMPLE_DEFINED_LIBSIMPLE_ENCALLOC__ +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2, 3), __warn_unused_result__, __returns_nonnull__))) void *libsimple_encalloc(int, size_t, size_t); +# define LIBSIMPLE_DEFINED_LIBSIMPLE_ENCALLOC__ +#endif -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +#ifndef LIBSIMPLE_DEFINED_LIBSIMPLE_ENMALLOC__ +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enmalloc(int, size_t); +# define LIBSIMPLE_DEFINED_LIBSIMPLE_ENMALLOC__ +#endif /* } */ @@ -30,7 +36,7 @@ void *libsimple_enmalloc(int, size_t); * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) void *libsimple_vmalloczn(int, size_t, va_list); #ifndef vmalloczn # define vmalloczn libsimple_vmalloczn @@ -49,9 +55,12 @@ void *libsimple_vmalloczn(int, size_t, va_list); * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) -static inline void *libsimple_mallocz(int __clear, size_t __n) -{ return __clear ? calloc(1, __n) : malloc(__n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) +static inline void * +libsimple_mallocz(int clear__, size_t n__) +{ + return clear__ ? calloc(1, n__) : malloc(n__); +} #ifndef mallocz # define mallocz libsimple_mallocz #endif @@ -75,14 +84,14 @@ static inline void *libsimple_mallocz(int __clear, size_t __n) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) static inline void * -libsimple_malloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +libsimple_malloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vmalloczn(__clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vmalloczn(clear__, n__, ap__); + va_end(ap__); } #ifndef malloczn # define malloczn libsimple_malloczn @@ -103,9 +112,12 @@ libsimple_malloczn(int __clear, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_enmallocz(int __status, int __clear, size_t __n) -{ return __clear ? libsimple_encalloc(__status, 1, __n) : libsimple_enmalloc(__status, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_enmallocz(int status__, int clear__, size_t n__) +{ + return clear__ ? libsimple_encalloc(status__, 1, n__) : libsimple_enmalloc(status__, n__); +} #ifndef enmallocz # define enmallocz libsimple_enmallocz #endif @@ -132,7 +144,7 @@ static inline void *libsimple_enmallocz(int __status, int __clear, size_t __n) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) void *libsimple_envmalloczn(int, int, size_t, va_list); #ifndef envmalloczn # define envmalloczn libsimple_envmalloczn @@ -160,14 +172,14 @@ void *libsimple_envmalloczn(int, int, size_t, va_list); * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enmalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */) +libsimple_enmalloczn(int status__, int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envmalloczn(__status, __clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envmalloczn(status__, clear__, n__, ap__); + va_end(ap__); } #ifndef enmalloczn # define enmalloczn libsimple_enmalloczn @@ -187,9 +199,12 @@ libsimple_enmalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */ * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_emallocz(int __clear, size_t __n) -{ return libsimple_enmallocz(libsimple_default_failure_exit, __clear, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_emallocz(int clear__, size_t n__) +{ + return libsimple_enmallocz(libsimple_default_failure_exit, clear__, n__); +} #ifndef emallocz # define emallocz libsimple_emallocz #endif @@ -214,9 +229,12 @@ static inline void *libsimple_emallocz(int __clear, size_t __n) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evmalloczn(int __clear, size_t __n, va_list __ap) -{ return libsimple_envmalloczn(libsimple_default_failure_exit, __clear, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evmalloczn(int clear__, size_t n__, va_list ap__) +{ + return libsimple_envmalloczn(libsimple_default_failure_exit, clear__, n__, ap__); +} #ifndef evmalloczn # define evmalloczn libsimple_evmalloczn #endif @@ -241,14 +259,14 @@ static inline void *libsimple_evmalloczn(int __clear, size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with the alignment `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_emalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +libsimple_emalloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evmalloczn(__clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evmalloczn(clear__, n__, ap__); + va_end(ap__); } #ifndef emalloczn # define emalloczn libsimple_emalloczn diff --git a/libsimple/mem.h b/libsimple/mem.h index f4c01dc..a7cf038 100644 --- a/libsimple/mem.h +++ b/libsimple/mem.h @@ -12,7 +12,7 @@ * where `r` is the returned pointer, `&s[n]` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_memscan(const void *, int, size_t); #ifndef memscan # define memscan libsimple_memscan @@ -30,7 +30,7 @@ void *libsimple_memscan(const void *, int, size_t); * where `r` is the returned pointer, `NULL` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memcasechr(const void *, int, size_t); #ifndef memcasechr # define memcasechr libsimple_memcasechr @@ -48,7 +48,7 @@ void *libsimple_memcasechr(const void *, int, size_t); * where `r` is the returned pointer, `&s[n]` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_memcasescan(const void *, int, size_t); #ifndef memcasescan # define memcasescan libsimple_memcasescan @@ -69,7 +69,7 @@ void *libsimple_memcasescan(const void *, int, size_t); * @return `s` with a miminal offset such that `*r == c`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemchr(const void *, int); #ifndef rawmemchr # define rawmemchr libsimple_rawmemchr @@ -90,7 +90,7 @@ void *libsimple_rawmemchr(const void *, int); * @return `s` with a miminal offset such that `tolower(*r) == tolower(c)`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemcasechr(const void *, int); #ifndef rawmemcasechr # define rawmemcasechr libsimple_rawmemcasechr @@ -108,7 +108,7 @@ void *libsimple_rawmemcasechr(const void *, int); * where `r` is the returned pointer `NULL` if no * such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrchr(const void *, int, size_t); #ifndef memrchr # define memrchr libsimple_memrchr @@ -126,7 +126,7 @@ void *libsimple_memrchr(const void *, int, size_t); * where `r` is the returned pointer `NULL` if no * such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrcasechr(const void *, int, size_t); #ifndef memrcasechr # define memrcasechr libsimple_memrcasechr @@ -148,7 +148,7 @@ void *libsimple_memrcasechr(const void *, int, size_t); * @return `s` with a maximal offset such that `*r == c`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemrchr(const void *, int, size_t); #ifndef rawmemrchr # define rawmemrchr libsimple_rawmemrchr @@ -170,7 +170,7 @@ void *libsimple_rawmemrchr(const void *, int, size_t); * @return `s` with a maximal offset such that `tolower(*r) == tolower(c)`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemrcasechr(const void *, int, size_t); #ifndef rawmemrcasechr # define rawmemrcasechr libsimple_rawmemrcasechr @@ -188,7 +188,7 @@ void *libsimple_rawmemrcasechr(const void *, int, size_t); * where `r` is the returned pointer, `NULL` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memchr_inv(const void *, int, size_t); #ifndef memchr_inv # define memchr_inv libsimple_memchr_inv @@ -206,7 +206,7 @@ void *libsimple_memchr_inv(const void *, int, size_t); * where `r` is the returned pointer, `&s[n]` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_memscan_inv(const void *, int, size_t); #ifndef memscan_inv # define memscan_inv libsimple_memscan_inv @@ -224,7 +224,7 @@ void *libsimple_memscan_inv(const void *, int, size_t); * where `r` is the returned pointer, `NULL` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memcasechr_inv(const void *, int, size_t); #ifndef memcasechr_inv # define memcasechr_inv libsimple_memcasechr_inv @@ -242,7 +242,7 @@ void *libsimple_memcasechr_inv(const void *, int, size_t); * where `r` is the returned pointer, `&s[n]` if * no such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_memcasescan_inv(const void *, int, size_t); #ifndef memcasescan_inv # define memcasescan_inv libsimple_memcasescan_inv @@ -263,7 +263,7 @@ void *libsimple_memcasescan_inv(const void *, int, size_t); * @return `s` with a miminal offset such that `*r != c`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemchr_inv(const void *, int); #ifndef rawmemchr_inv # define rawmemchr_inv libsimple_rawmemchr_inv @@ -284,7 +284,7 @@ void *libsimple_rawmemchr_inv(const void *, int); * @return `s` with a miminal offset such that `tolower(*r) != tolower(c)`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemcasechr_inv(const void *, int); #ifndef rawmemcasechr_inv # define rawmemcasechr_inv libsimple_rawmemcasechr_inv @@ -302,7 +302,7 @@ void *libsimple_rawmemcasechr_inv(const void *, int); * where `r` is the returned pointer `NULL` if no * such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrchr_inv(const void *, int, size_t); #ifndef memrchr_inv # define memrchr_inv libsimple_memrchr_inv @@ -320,7 +320,7 @@ void *libsimple_memrchr_inv(const void *, int, size_t); * where `r` is the returned pointer `NULL` if no * such offset exists within [s, &s[n]) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrcasechr_inv(const void *, int, size_t); #ifndef memrcasechr_inv # define memrcasechr_inv libsimple_memrcasechr_inv @@ -342,7 +342,7 @@ void *libsimple_memrcasechr_inv(const void *, int, size_t); * @return `s` with a maximal offset such that `*r != c`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemrchr_inv(const void *, int, size_t); #ifndef rawmemrchr_inv # define rawmemrchr_inv libsimple_rawmemrchr_inv @@ -364,7 +364,7 @@ void *libsimple_rawmemrchr_inv(const void *, int, size_t); * @return `s` with a maximal offset such that `tolower(*r) != tolower(c)`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemrcasechr_inv(const void *, int, size_t); #ifndef rawmemrcasechr_inv # define rawmemrcasechr_inv libsimple_rawmemrcasechr_inv @@ -382,7 +382,7 @@ void *libsimple_rawmemrcasechr_inv(const void *, int, size_t); * `!memcmp(r, needle, nneedle)` where `r` is the * returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memmem(const void *, size_t, const void *, size_t); #ifndef memmem # define memmem libsimple_memmem @@ -400,7 +400,7 @@ void *libsimple_memmem(const void *, size_t, const void *, size_t); * `!memcasecmp(r, needle, nneedle)` where `r` is the * returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memcasemem(const void *, size_t, const void *, size_t); #ifndef memcasemem # define memcasemem libsimple_memcasemem @@ -418,7 +418,7 @@ void *libsimple_memcasemem(const void *, size_t, const void *, size_t); * `!memcmp(r, needle, nneedle)` where `r` is the * returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrmem(const void *, size_t, const void *, size_t); #ifndef memrmem # define memrmem libsimple_memrmem @@ -436,7 +436,7 @@ void *libsimple_memrmem(const void *, size_t, const void *, size_t); * `!memcasecmp(r, needle, nneedle)` where `r` is the * returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrcasemem(const void *, size_t, const void *, size_t); #ifndef memrcasemem # define memrcasemem libsimple_memrcasemem @@ -452,7 +452,7 @@ void *libsimple_memrcasemem(const void *, size_t, const void *, size_t); * @param m The length of `t` * @return 1 if `s` begins with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) int libsimple_memstarts(const void *, size_t, const void *, size_t); #ifndef memstarts # define memstarts libsimple_memstarts @@ -468,7 +468,7 @@ int libsimple_memstarts(const void *, size_t, const void *, size_t); * @param m The length of `t` * @return 1 if `s` begins with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) int libsimple_memcasestarts(const void *, size_t, const void *, size_t); #ifndef memcasestarts # define memcasestarts libsimple_memcasestarts @@ -484,7 +484,7 @@ int libsimple_memcasestarts(const void *, size_t, const void *, size_t); * @param m The length of `t` * @return 1 if `s` ends with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) int libsimple_memends(const void *, size_t, const void *, size_t); #ifndef memends # define memends libsimple_memends @@ -500,7 +500,7 @@ int libsimple_memends(const void *, size_t, const void *, size_t); * @param m The length of `t` * @return 1 if `s` ends with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) int libsimple_memcaseends(const void *, size_t, const void *, size_t); #ifndef memcaseends # define memcaseends libsimple_memcaseends @@ -515,7 +515,7 @@ int libsimple_memcaseends(const void *, size_t, const void *, size_t); * @param n The lengths of the arrays * @return 1 if the arrays are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) int libsimple_memcasecmp(const void *, const void *, size_t); #ifndef memcasecmp # define memcasecmp libsimple_memcasecmp @@ -530,9 +530,12 @@ int libsimple_memcasecmp(const void *, const void *, size_t); * @param n The lengths of the arrays * @return 1 if the arrays are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_memeq(const void *__a, const void *__b, size_t __n) -{ return !memcmp(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +inline int +libsimple_memeq(const void *a__, const void *b__, size_t n__) +{ + return !memcmp(a__, b__, n__); +} #ifndef memeq # define memeq libsimple_memeq #endif @@ -546,9 +549,12 @@ static inline int libsimple_memeq(const void *__a, const void *__b, size_t __n) * @param n The lengths of the arrays * @return 1 if the arrays are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_memcaseeq(const void *__a, const void *__b, size_t __n) -{ return !memcasecmp(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +inline int +libsimple_memcaseeq(const void *a__, const void *b__, size_t n__) +{ + return !memcasecmp(a__, b__, n__); +} #ifndef memcaseeq # define memcaseeq libsimple_memcaseeq #endif @@ -562,8 +568,11 @@ static inline int libsimple_memcaseeq(const void *__a, const void *__b, size_t _ * @param n The number of bytes to copy * @return `&d[n]` */ -static inline void *libsimple_mempcpy(void *restrict __d, const void *restrict __s, size_t __n) -{ return &((char *)memcpy(__d, __s, __n))[__n]; } +inline void * +libsimple_mempcpy(void *restrict d__, const void *restrict s__, size_t n__) +{ + return &((char *)memcpy(d__, s__, n__))[n__]; +} #ifndef mempcpy # define mempcpy libsimple_mempcpy #endif @@ -577,8 +586,11 @@ static inline void *libsimple_mempcpy(void *restrict __d, const void *restrict _ * @param n The number of bytes to move * @return `&d[n]` */ -static inline void *libsimple_mempmove(void *__d, const void *__s, size_t __n) -{ return &((char *)memmove(__d, __s, __n))[__n]; } +inline void * +libsimple_mempmove(void *d__, const void *s__, size_t n__) +{ + return &((char *)memmove(d__, s__, n__))[n__]; +} #ifndef mempmove # define mempmove libsimple_mempmove #endif @@ -592,8 +604,11 @@ static inline void *libsimple_mempmove(void *__d, const void *__s, size_t __n) * @param n The number of bytes to write to `s` * @return `&s[n]` */ -static inline void *libsimple_mempset(void *__s, int __c, size_t __n) -{ return &((char *)memset(__s, __c, __n))[__n]; } +inline void * +libsimple_mempset(void *s__, int c__, size_t n__) +{ + return &((char *)memset(s__, c__, n__))[n__]; +} #ifndef mempset # define mempset libsimple_mempset #endif @@ -612,13 +627,13 @@ static inline void *libsimple_mempset(void *__s, int __c, size_t __n) * @param c The byte that stops the copying * @return `&rawmemchr(d, c)[1]` (after copying) */ -static inline void * -libsimple_rawmemccpy(void *restrict __d_, const void *restrict __s_, int __c_) +inline void * +libsimple_rawmemccpy(void *restrict d___, const void *restrict s___, int c___) { - char __c = (char)__c_, *restrict __d = __d_; - const char *restrict __s = __s_; - for (; (*__d++ = *__s) != __c; __s++); - return __d; + char c__ = (char)c___, *restrict d__ = d___; + const char *restrict s__ = s___; + for (; (*d__++ = *s__) != c__; s__++); + return d__; } #ifndef rawmemccpy # define rawmemccpy libsimple_rawmemccpy @@ -655,24 +670,24 @@ void *libsimple_memcmove(void *, const void *, int, size_t); * @param c The byte that stops the copying * @return `&rawmemchr(d, c)[1]` (after copying) */ -static inline void * -libsimple_rawmemcmove(void *__d_, const void *__s_, int __c_) +inline void * +libsimple_rawmemcmove(void *d___, const void *s___, int c___) { - char *__d = __d_, *__p, __c = (char)__c_; - const char *__s = __s_; - size_t __n; - if (__d <= __s) { - for (; (*__d++ = *__s) != __c; __s++); - return __d; + char *d__ = d___, *p__, c__ = (char)c___; + const char *s__ = s___; + size_t n__; + if (d__ <= s__) { + for (; (*d__++ = *s__) != c__; s__++); + return d__; } else { - for (__p = *(char **)(void *)&__s; *__p++ != __c;); - __n = (size_t)(__p - __s); - __p = &__d[__n]; - while (__n) { - __n--; - __d[__n] = __s[__n]; + for (p__ = *(char **)(void *)&s__; *p__++ != c__;); + n__ = (size_t)(p__ - s__); + p__ = &d__[n__]; + while (n__) { + n__--; + d__[n__] = s__[n__]; } - return __p; + return p__; } } #ifndef rawmemcmove @@ -689,15 +704,15 @@ libsimple_rawmemcmove(void *__d_, const void *__s_, int __c_) * @param n The length of `s` * @return `(void *)&((char *)s)[n]` */ -static inline void * -libsimple_memreplace(void *__s_, int __old_, int __new_, size_t __n) +inline void * +libsimple_memreplace(void *s___, int old___, int new___, size_t n__) { - char __old = (char)__old_, __new = (char)__new_, *__s = __s_; - char *__ret = &__s[__n]; - while (__n) - if (__s[--__n] == __old) - __s[__n] = __new; - return __ret; + char old__ = (char)old___, new__ = (char)new___, *s__ = s___; + char *ret__ = &s__[n__]; + while (n__) + if (s__[--n__] == old__) + s__[n__] = new__; + return ret__; } #ifndef memreplace # define memreplace libsimple_memreplace @@ -755,8 +770,12 @@ void *libsimple_memptoupper(void *, const void *, size_t); * @param n The number of bytes to copy or covert * @return `d` */ -static inline void *libsimple_memtolower(void *__d, const void *__s, size_t __n) -{ libsimple_memptolower(__d, __s, __n); return __d; } +inline void * +libsimple_memtolower(void *d__, const void *s__, size_t n__) +{ + libsimple_memptolower(d__, s__, n__); + return d__; +} #ifndef memtolower # define memtolower libsimple_memtolower #endif @@ -775,8 +794,12 @@ static inline void *libsimple_memtolower(void *__d, const void *__s, size_t __n) * @param n The number of bytes to copy or covert * @return `d` */ -static inline void *libsimple_memtoupper(void *__d, const void *__s, size_t __n) -{ libsimple_memptoupper(__d, __s, __n); return __d; } +inline void * +libsimple_memtoupper(void *d__, const void *s__, size_t n__) +{ + libsimple_memptoupper(d__, s__, n__); + return d__; +} #ifndef memtoupper # define memtoupper libsimple_memtoupper #endif @@ -792,7 +815,7 @@ static inline void *libsimple_memtoupper(void *__d, const void *__s, size_t __n) * @return The number of bytes `a` and `b` have * in common in their beginnings */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) size_t libsimple_memeqlen(const void *, size_t, const void *, size_t); #ifndef memeqlen # define memeqlen libsimple_memeqlen @@ -809,7 +832,7 @@ size_t libsimple_memeqlen(const void *, size_t, const void *, size_t); * @return The number of bytes `a` and `b` have * in common in their beginnings */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) size_t libsimple_memcaseeqlen(const void *, size_t, const void *, size_t); #ifndef memcaseeqlen # define memcaseeqlen libsimple_memcaseeqlen @@ -826,7 +849,7 @@ size_t libsimple_memcaseeqlen(const void *, size_t, const void *, size_t); * @return The number of bytes `a` and `b` have * in common in their ends */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) size_t libsimple_memreqlen(const void *, size_t, const void *, size_t); #ifndef memreqlen # define memreqlen libsimple_memreqlen @@ -843,7 +866,7 @@ size_t libsimple_memreqlen(const void *, size_t, const void *, size_t); * @return The number of bytes `a` and `b` have * in common in their ends */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) size_t libsimple_memrcaseeqlen(const void *, size_t, const void *, size_t); #ifndef memrcaseeqlen # define memrcaseeqlen libsimple_memrcaseeqlen @@ -859,7 +882,7 @@ size_t libsimple_memrcaseeqlen(const void *, size_t, const void *, size_t); * allows a two-byte encoding for NUL * @return 1 if good, 0 on encoding error */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) int libsimple_memisutf8(const char *, size_t, int); #ifndef memisutf8 # define memisutf8 libsimple_memisutf8 diff --git a/libsimple/memalign.h b/libsimple/memalign.h index d533751..e36c6f9 100644 --- a/libsimple/memalign.h +++ b/libsimple/memalign.h @@ -19,9 +19,12 @@ * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) -static inline void *libsimple_vmemalignn(size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_vmemalignzn(0, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) +static inline void * +libsimple_vmemalignn(size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_vmemalignzn(0, alignment__, n__, ap__); +} #ifndef vmemalignn # define vmemalignn libsimple_vmemalignn #endif @@ -38,9 +41,12 @@ static inline void *libsimple_vmemalignn(size_t __alignment, size_t __n, va_list * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__))) -static inline void *libsimple_memalign(size_t __alignment, size_t __n) -{ return libsimple_memalignz(0, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__))) +static inline void * +libsimple_memalign(size_t alignment__, size_t n__) +{ + return libsimple_memalignz(0, alignment__, n__); +} #ifndef memalign # define memalign libsimple_memalign #endif @@ -64,14 +70,14 @@ static inline void *libsimple_memalign(size_t __alignment, size_t __n) * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) static inline void * -libsimple_memalignn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_memalignn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vmemalignn(__alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vmemalignn(alignment__, n__, ap__); + va_end(ap__); } #ifndef memalignn # define memalignn libsimple_memalignn @@ -93,9 +99,12 @@ libsimple_memalignn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_enmemalign(int __status, size_t __alignment, size_t __n) -{ return libsimple_enmemalignz(__status, 0, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_enmemalign(int status__, size_t alignment__, size_t n__) +{ + return libsimple_enmemalignz(status__, 0, alignment__, n__); +} #ifndef enmemalign # define enmemalign libsimple_enmemalign #endif @@ -122,9 +131,12 @@ static inline void *libsimple_enmemalign(int __status, size_t __alignment, size_ * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envmemalignn(int __status, size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envmemalignzn(__status, 0, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_envmemalignn(int status__, size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envmemalignzn(status__, 0, alignment__, n__, ap__); +} #ifndef envmemalignn # define envmemalignn libsimple_envmemalignn #endif @@ -151,14 +163,14 @@ static inline void *libsimple_envmemalignn(int __status, size_t __alignment, siz * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enmemalignn(int __status, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_enmemalignn(int status__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envmemalignzn(__status, 0, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envmemalignzn(status__, 0, alignment__, n__, ap__); + va_end(ap__); } #ifndef enmemalignn # define enmemalignn libsimple_enmemalignn @@ -179,9 +191,12 @@ libsimple_enmemalignn(int __status, size_t __alignment, size_t __n, ... /*, (siz * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ememalign(size_t __alignment, size_t __n) -{ return libsimple_enmemalign(libsimple_default_failure_exit, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ememalign(size_t alignment__, size_t n__) +{ + return libsimple_enmemalign(libsimple_default_failure_exit, alignment__, n__); +} #ifndef ememalign # define ememalign libsimple_ememalign #endif @@ -208,9 +223,12 @@ static inline void *libsimple_ememalign(size_t __alignment, size_t __n) * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evmemalignn(size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envmemalignn(libsimple_default_failure_exit, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evmemalignn(size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envmemalignn(libsimple_default_failure_exit, alignment__, n__, ap__); +} #ifndef evmemalignn # define evmemalignn libsimple_evmemalignn #endif @@ -236,14 +254,14 @@ static inline void *libsimple_evmemalignn(size_t __alignment, size_t __n, va_lis * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_ememalignn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_ememalignn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evmemalignn(__alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evmemalignn(alignment__, n__, ap__); + va_end(ap__); } #ifndef ememalignn # define ememalignn libsimple_ememalignn diff --git a/libsimple/memalignz.h b/libsimple/memalignz.h index 7eab805..62ab444 100644 --- a/libsimple/memalignz.h +++ b/libsimple/memalignz.h @@ -20,17 +20,17 @@ * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) static inline void * -libsimple_vmemalignzn(int __clear, size_t __alignment, size_t __n, va_list __ap) +libsimple_vmemalignzn(int clear__, size_t alignment__, size_t n__, va_list ap__) { - if (!__alignment || (__alignment & (__alignment - 1UL))) { + if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { errno = EINVAL; return NULL; } - return libsimple_memalloc(0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, __n, __ap, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, - LIBSIMPLE_MEMALLOC_ALIGNMENT, __alignment, + return libsimple_memalloc(0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, n__, ap__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, + LIBSIMPLE_MEMALLOC_ALIGNMENT, alignment__, LIBSIMPLE_MEMALLOC_END); } #ifndef vmemalignzn @@ -50,17 +50,17 @@ libsimple_vmemalignzn(int __clear, size_t __alignment, size_t __n, va_list __ap) * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) static inline void * -libsimple_memalignz(int __clear, size_t __alignment, size_t __n) +libsimple_memalignz(int clear__, size_t alignment__, size_t n__) { - if (!__alignment || (__alignment & (__alignment - 1UL))) { + if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { errno = EINVAL; return NULL; } - return libsimple_memalloc(__n, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, - LIBSIMPLE_MEMALLOC_ALIGNMENT, __alignment, + return libsimple_memalloc(n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, + LIBSIMPLE_MEMALLOC_ALIGNMENT, alignment__, LIBSIMPLE_MEMALLOC_END); } #ifndef memalignz @@ -87,14 +87,14 @@ libsimple_memalignz(int __clear, size_t __alignment, size_t __n) * @throws EINVAL `n` is 0 or `alignment` is not a power of 2 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) static inline void * -libsimple_memalignzn(int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_memalignzn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vmemalignzn(__clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vmemalignzn(clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef memalignzn # define memalignzn libsimple_memalignzn @@ -117,17 +117,17 @@ libsimple_memalignzn(int __clear, size_t __alignment, size_t __n, ... /*, (size_ * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enmemalignz(int __status, int __clear, size_t __alignment, size_t __n) +libsimple_enmemalignz(int status__, int clear__, size_t alignment__, size_t n__) { - if (!__alignment || (__alignment & (__alignment - 1UL))) { + if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { errno = EINVAL; - libsimple_enprintf(__status, "libsimple_vmemalignz:"); + libsimple_enprintf(status__, "libsimple_vmemalignz:"); } - return libsimple_enmemalloc(__status, __n, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, - LIBSIMPLE_MEMALLOC_ALIGNMENT, __alignment, + return libsimple_enmemalloc(status__, n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, + LIBSIMPLE_MEMALLOC_ALIGNMENT, alignment__, LIBSIMPLE_MEMALLOC_END); } #ifndef enmemalignz @@ -157,18 +157,18 @@ libsimple_enmemalignz(int __status, int __clear, size_t __alignment, size_t __n) * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_envmemalignzn(int __status, int __clear, size_t __alignment, size_t __n, va_list __ap) +libsimple_envmemalignzn(int status__, int clear__, size_t alignment__, size_t n__, va_list ap__) { - if (!__alignment || (__alignment & (__alignment - 1UL))) { + if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { errno = EINVAL; return NULL; } - return libsimple_enmemalloc(__status, - 0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, __n, __ap, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, - LIBSIMPLE_MEMALLOC_ALIGNMENT, __alignment, + return libsimple_enmemalloc(status__, + 0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, n__, ap__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, + LIBSIMPLE_MEMALLOC_ALIGNMENT, alignment__, LIBSIMPLE_MEMALLOC_END); } #ifndef envmemalignzn @@ -198,14 +198,14 @@ libsimple_envmemalignzn(int __status, int __clear, size_t __alignment, size_t __ * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_enmemalignzn(int __status, int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_enmemalignzn(int status__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envmemalignzn(__status, __clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envmemalignzn(status__, clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef enmemalignzn # define enmemalignzn libsimple_enmemalignzn @@ -227,9 +227,12 @@ libsimple_enmemalignzn(int __status, int __clear, size_t __alignment, size_t __n * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ememalignz(int __clear, size_t __alignment, size_t __n) -{ return libsimple_enmemalignz(libsimple_default_failure_exit, __clear, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_ememalignz(int clear__, size_t alignment__, size_t n__) +{ + return libsimple_enmemalignz(libsimple_default_failure_exit, clear__, alignment__, n__); +} #ifndef ememalignz # define ememalignz libsimple_ememalignz #endif @@ -256,9 +259,12 @@ static inline void *libsimple_ememalignz(int __clear, size_t __alignment, size_t * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evmemalignzn(int __clear, size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_envmemalignzn(libsimple_default_failure_exit, __clear, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evmemalignzn(int clear__, size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_envmemalignzn(libsimple_default_failure_exit, clear__, alignment__, n__, ap__); +} #ifndef evmemalignzn # define evmemalignzn libsimple_evmemalignzn #endif @@ -285,14 +291,14 @@ static inline void *libsimple_evmemalignzn(int __clear, size_t __alignment, size * @return A unique pointer with at least the specified size * and alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_ememalignzn(int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +libsimple_ememalignzn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evmemalignzn(__clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evmemalignzn(clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef ememalignzn # define ememalignzn libsimple_ememalignzn diff --git a/libsimple/memalloc.h b/libsimple/memalloc.h index 5b91a64..9f894e8 100644 --- a/libsimple/memalloc.h +++ b/libsimple/memalloc.h @@ -78,42 +78,45 @@ enum libsimple_memalloc_option { LIBSIMPLE_MEMALLOC_ALIGNMENT, _Alignof(TYPE),\ __VA_ARGS__) -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) void *libsimple_vmemalloc(size_t, va_list); -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) void *libsimple_envmemalloc(int, size_t, va_list); -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void *libsimple_evmemalloc(size_t __n, va_list __ap) -{ return libsimple_envmemalloc(libsimple_default_failure_exit, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_evmemalloc(size_t n__, va_list ap__) +{ + return libsimple_envmemalloc(libsimple_default_failure_exit, n__, ap__); +} -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_memalloc(size_t __n, ... /*, LIBSIMPLE_MEMALLOC_END */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_memalloc(size_t n__, ... /*, LIBSIMPLE_MEMALLOC_END */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vmemalloc(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vmemalloc(n__, ap__); + va_end(ap__); } -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_enmemalloc(int __status, size_t __n, ... /*, LIBSIMPLE_MEMALLOC_END */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_enmemalloc(int status__, size_t n__, ... /*, LIBSIMPLE_MEMALLOC_END */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envmemalloc(__status, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envmemalloc(status__, n__, ap__); + va_end(ap__); } -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_ememalloc(size_t __n, ... /*, LIBSIMPLE_MEMALLOC_END */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_ememalloc(size_t n__, ... /*, LIBSIMPLE_MEMALLOC_END */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evmemalloc(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evmemalloc(n__, ap__); + va_end(ap__); } diff --git a/libsimple/memdup.h b/libsimple/memdup.h index 383b338..f799eee 100644 --- a/libsimple/memdup.h +++ b/libsimple/memdup.h @@ -10,11 +10,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_memdupa(s, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__s = (s);\ - size_t __n = (n);\ - char *__r = alloca(__n + !__n);\ - memcpy(__r, __s, __n);\ + const char *s__ = (s);\ + size_t n__ = (n);\ + char *r__ = alloca(n__ + !n__);\ + memcpy(r__, s__, n__);\ }) # ifndef memdupa # define memdupa(s, n) libsimple_memdupa(s, n) @@ -29,7 +30,7 @@ * @param n The number of bytes to copy * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2), __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2), __nonnull__, __warn_unused_result__))) void *libsimple_memdup(const void *, size_t); #ifndef memdup # define memdup libsimple_memdup @@ -44,7 +45,7 @@ void *libsimple_memdup(const void *, size_t); * @param n The number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enmemdup(int, const void *, size_t); #ifndef enmemdup # define enmemdup libsimple_enmemdup @@ -58,11 +59,11 @@ void *libsimple_enmemdup(int, const void *, size_t); * @param n The number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) inline void * -libsimple_ememdup(const void *__s, size_t __n) +libsimple_ememdup(const void *s__, size_t n__) { - return libsimple_enmemdup(libsimple_default_failure_exit, __s, __n); + return libsimple_enmemdup(libsimple_default_failure_exit, s__, n__); } #ifndef ememdup # define ememdup libsimple_ememdup diff --git a/libsimple/memelem.h b/libsimple/memelem.h index ab4ffca..e78251a 100644 --- a/libsimple/memelem.h +++ b/libsimple/memelem.h @@ -13,7 +13,7 @@ * pointer and such that `(r - haystack) % width == 0`, * `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memelem(const void *, const void *, size_t, size_t); #ifndef memelem # define memelem libsimple_memelem @@ -35,7 +35,7 @@ void *libsimple_memelem(const void *, const void *, size_t, size_t); * `!memcmp(r, needle, width)` where `r` is the returned * pointer and such that `(r - haystack) % width == 0` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemelem(const void *, const void *, size_t); #ifndef rawmemelem # define rawmemelem libsimple_rawmemelem @@ -55,7 +55,7 @@ void *libsimple_rawmemelem(const void *, const void *, size_t); * `(void *)&((char *)haystack)[n * width]` if no such * offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memelemscan(const void *, const void *, size_t, size_t); #ifndef memelemscan # define memelemscan libsimple_memelemscan @@ -74,7 +74,7 @@ void *libsimple_memelemscan(const void *, const void *, size_t, size_t); * pointer and such that `(r - haystack) % width == 0`, * `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrelem(const void *, const void *, size_t, size_t); #ifndef memrelem # define memrelem libsimple_memrelem @@ -97,7 +97,7 @@ void *libsimple_memrelem(const void *, const void *, size_t, size_t); * `!memcmp(r, needle, width)` where `r` is the returned * pointer and such that `(r - haystack) % width == 0` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemrelem(const void *, const void *, size_t, size_t); #ifndef rawmemrelem # define rawmemrelem libsimple_rawmemrelem @@ -117,7 +117,7 @@ void *libsimple_rawmemrelem(const void *, const void *, size_t, size_t); * pointer and such that `(r - haystack) % width == 0`, * `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memelem_inv(const void *, const void *, size_t, size_t); #ifndef memelem_inv # define memelem_inv libsimple_memelem_inv @@ -140,7 +140,7 @@ void *libsimple_memelem_inv(const void *, const void *, size_t, size_t); * `memcmp(r, needle, width)` where `r` is the returned * pointer and such that `(r - haystack) % width == 0` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemelem_inv(const void *, const void *, size_t); #ifndef rawmemelem_inv # define rawmemelem_inv libsimple_rawmemelem_inv @@ -161,7 +161,7 @@ void *libsimple_rawmemelem_inv(const void *, const void *, size_t); * `(void *)&((char *)haystack)[n * width]` if no such * offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memelemscan_inv(const void *, const void *, size_t, size_t); #ifndef memelemscan_inv # define memelemscan_inv libsimple_memelemscan_inv @@ -181,7 +181,7 @@ void *libsimple_memelemscan_inv(const void *, const void *, size_t, size_t); * pointer and such that `(r - haystack) % width == 0`, * `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) void *libsimple_memrelem_inv(const void *, const void *, size_t, size_t); #ifndef memrelem_inv # define memrelem_inv libsimple_memrelem_inv @@ -205,7 +205,7 @@ void *libsimple_memrelem_inv(const void *, const void *, size_t, size_t); * `memcmp(r, needle, width)` where `r` is the returned * pointer and such that `(r - haystack) % width == 0` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__))) void *libsimple_rawmemrelem_inv(const void *, const void *, size_t, size_t); #ifndef rawmemrelem_inv # define rawmemrelem_inv libsimple_rawmemrelem_inv @@ -221,7 +221,7 @@ void *libsimple_rawmemrelem_inv(const void *, const void *, size_t, size_t); * @param n The number of copies to fill `buf` with * @return `&buf[n * width]` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) void *libsimple_mempsetelem(void *, const void *, size_t, size_t); #ifndef mempsetelem # define mempsetelem libsimple_mempsetelem @@ -237,12 +237,12 @@ void *libsimple_mempsetelem(void *, const void *, size_t, size_t); * @param n The number of copies to fill `buf` with * @return `buf` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) inline void * -libsimple_memsetelem(void *__buf, const void *__item, size_t __width, size_t __n) +libsimple_memsetelem(void *buf__, const void *item__, size_t width__, size_t n__) { - __item = libsimple_mempsetelem(__buf, __item, __width, __n); - return __buf; + item__ = libsimple_mempsetelem(buf__, item__, width__, n__); + return buf__; } #ifndef memsetelem # define memsetelem libsimple_memsetelem diff --git a/libsimple/posix_memalign.h b/libsimple/posix_memalign.h index f656ea8..78924de 100644 --- a/libsimple/posix_memalign.h +++ b/libsimple/posix_memalign.h @@ -25,9 +25,12 @@ * `alignment` is not a multiple of `sizeof(void *)` * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline int libsimple_vposix_memalignn(void **__memptr, size_t __alignment, size_t __n, va_list __ap) -{ return libsimple_vposix_memalignzn(__memptr, 0, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline int +libsimple_vposix_memalignn(void **memptr__, size_t alignment__, size_t n__, va_list ap__) +{ + return libsimple_vposix_memalignzn(memptr__, 0, alignment__, n__, ap__); +} #ifndef vposix_memalignn # define vposix_memalignn libsimple_vposix_memalignn #endif @@ -57,14 +60,14 @@ static inline int libsimple_vposix_memalignn(void **__memptr, size_t __alignment * `alignment` is not a multiple of `sizeof(void *)` * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline int -libsimple_posix_memalignn(void **__memptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline int +libsimple_posix_memalignn(void **memptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vposix_memalignn(__memptr, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vposix_memalignn(memptr__, alignment__, n__, ap__); + va_end(ap__); } #ifndef posix_memalignn # define posix_memalignn libsimple_posix_memalignn @@ -88,9 +91,12 @@ libsimple_posix_memalignn(void **__memptr, size_t __alignment, size_t __n, ... / * @param n The number of bytes to allocate, the behaviour of * this function is unspecified for the value 0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) -static inline void libsimple_enposix_memalign(int __status, void **__memptr, size_t __alignment, size_t __n) -{ libsimple_enposix_memalignz(__status, __memptr, 0, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) +inline void +libsimple_enposix_memalign(int status__, void **memptr__, size_t alignment__, size_t n__) +{ + libsimple_enposix_memalignz(status__, memptr__, 0, alignment__, n__); +} #ifndef enposix_memalign # define enposix_memalign libsimple_enposix_memalign #endif @@ -119,9 +125,12 @@ static inline void libsimple_enposix_memalign(int __status, void **__memptr, siz * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) -static inline void libsimple_envposix_memalignn(int __status, void **__memptr, size_t __alignment, size_t __n, va_list __ap) -{ libsimple_envposix_memalignzn(__status, __memptr, 0, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) +inline void +libsimple_envposix_memalignn(int status__, void **memptr__, size_t alignment__, size_t n__, va_list ap__) +{ + libsimple_envposix_memalignzn(status__, memptr__, 0, alignment__, n__, ap__); +} #ifndef envposix_memalignn # define envposix_memalignn libsimple_envposix_memalignn #endif @@ -150,14 +159,14 @@ static inline void libsimple_envposix_memalignn(int __status, void **__memptr, s * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) -static inline void -libsimple_enposix_memalignn(int __status, void **__memptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) +inline void +libsimple_enposix_memalignn(int status__, void **memptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - libsimple_envposix_memalignzn(__status, __memptr, 0, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + libsimple_envposix_memalignzn(status__, memptr__, 0, alignment__, n__, ap__); + va_end(ap__); } #ifndef enposix_memalignn # define enposix_memalignn libsimple_enposix_memalignn @@ -180,9 +189,12 @@ libsimple_enposix_memalignn(int __status, void **__memptr, size_t __alignment, s * @param n The number of bytes to allocate, the behaviour of * this function is unspecified for the value 0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void libsimple_eposix_memalign(void **__memptr, size_t __alignment, size_t __n) -{ libsimple_enposix_memalign(libsimple_default_failure_exit, __memptr, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_eposix_memalign(void **memptr__, size_t alignment__, size_t n__) +{ + libsimple_enposix_memalign(libsimple_default_failure_exit, memptr__, alignment__, n__); +} #ifndef eposix_memalign # define eposix_memalign libsimple_eposix_memalign #endif @@ -210,9 +222,12 @@ static inline void libsimple_eposix_memalign(void **__memptr, size_t __alignment * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void libsimple_evposix_memalignn(void **__memptr, size_t __alignment, size_t __n, va_list __ap) -{ libsimple_envposix_memalignn(libsimple_default_failure_exit, __memptr, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_evposix_memalignn(void **memptr__, size_t alignment__, size_t n__, va_list ap__) +{ + libsimple_envposix_memalignn(libsimple_default_failure_exit, memptr__, alignment__, n__, ap__); +} #ifndef evposix_memalignn # define evposix_memalignn libsimple_evposix_memalignn #endif @@ -240,14 +255,14 @@ static inline void libsimple_evposix_memalignn(void **__memptr, size_t __alignme * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void -libsimple_eposix_memalignn(void **__memptr, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_eposix_memalignn(void **memptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - libsimple_evposix_memalignn(__memptr, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + libsimple_evposix_memalignn(memptr__, alignment__, n__, ap__); + va_end(ap__); } #ifndef eposix_memalignn # define eposix_memalignn libsimple_eposix_memalignn diff --git a/libsimple/posix_memalignz.h b/libsimple/posix_memalignz.h index 323863d..eb3e138 100644 --- a/libsimple/posix_memalignz.h +++ b/libsimple/posix_memalignz.h @@ -26,7 +26,7 @@ * `alignment` is not a multiple of `sizeof(void *)` * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) int libsimple_vposix_memalignzn(void **, int, size_t, size_t, va_list); #ifndef vposix_memalignzn # define vposix_memalignzn libsimple_vposix_memalignzn @@ -52,14 +52,14 @@ int libsimple_vposix_memalignzn(void **, int, size_t, size_t, va_list); * `alignment` is not a multiple of `sizeof(void *)` * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline int -libsimple_posix_memalignz(void **__memptr, int __clear, size_t __alignment, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline int +libsimple_posix_memalignz(void **memptr__, int clear__, size_t alignment__, size_t n__) { - int __ret = posix_memalign(__memptr, __alignment, __n); - if (!__ret && __clear) - memset(*__memptr, 0, __n); - return __ret; + int ret__ = posix_memalign(memptr__, alignment__, n__); + if (!ret__ && clear__) + memset(*memptr__, 0, n__); + return ret__; } #ifndef posix_memalignz # define posix_memalignz libsimple_posix_memalignz @@ -91,14 +91,14 @@ libsimple_posix_memalignz(void **__memptr, int __clear, size_t __alignment, size * `alignment` is not a multiple of `sizeof(void *)` * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline int -libsimple_posix_memalignzn(void **__memptr, int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline int +libsimple_posix_memalignzn(void **memptr__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vposix_memalignzn(__memptr, __clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vposix_memalignzn(memptr__, clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef posix_memalignzn # define posix_memalignzn libsimple_posix_memalignzn @@ -123,7 +123,7 @@ libsimple_posix_memalignzn(void **__memptr, int __clear, size_t __alignment, siz * @param n The number of bytes to allocate, the behaviour of * this function is unspecified for the value 0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) void libsimple_enposix_memalignz(int, void **, int, size_t, size_t); #ifndef enposix_memalignz # define enposix_memalignz libsimple_enposix_memalignz @@ -154,7 +154,7 @@ void libsimple_enposix_memalignz(int, void **, int, size_t, size_t); * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) void libsimple_envposix_memalignzn(int, void **, int, size_t, size_t, va_list); #ifndef envposix_memalignzn # define envposix_memalignzn libsimple_envposix_memalignzn @@ -185,14 +185,14 @@ void libsimple_envposix_memalignzn(int, void **, int, size_t, size_t, va_list); * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) -static inline void -libsimple_enposix_memalignzn(int __status, void **__memptr, int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) +inline void +libsimple_enposix_memalignzn(int status__, void **memptr__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - libsimple_envposix_memalignzn(__status, __memptr, __clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + libsimple_envposix_memalignzn(status__, memptr__, clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef enposix_memalignzn # define enposix_memalignzn libsimple_enposix_memalignzn @@ -216,9 +216,12 @@ libsimple_enposix_memalignzn(int __status, void **__memptr, int __clear, size_t * @param n The number of bytes to allocate, the behaviour of * this function is unspecified for the value 0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void libsimple_eposix_memalignz(void **__memptr, int __clear, size_t __alignment, size_t __n) -{ libsimple_enposix_memalignz(libsimple_default_failure_exit, __memptr, __clear, __alignment, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_eposix_memalignz(void **memptr__, int clear__, size_t alignment__, size_t n__) +{ + libsimple_enposix_memalignz(libsimple_default_failure_exit, memptr__, clear__, alignment__, n__); +} #ifndef eposix_memalignz # define eposix_memalignz libsimple_eposix_memalignz #endif @@ -247,9 +250,12 @@ static inline void libsimple_eposix_memalignz(void **__memptr, int __clear, size * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void libsimple_evposix_memalignzn(void **__memptr, int __clear, size_t __alignment, size_t __n, va_list __ap) -{ libsimple_envposix_memalignzn(libsimple_default_failure_exit, __memptr, __clear, __alignment, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_evposix_memalignzn(void **memptr__, int clear__, size_t alignment__, size_t n__, va_list ap__) +{ + libsimple_envposix_memalignzn(libsimple_default_failure_exit, memptr__, clear__, alignment__, n__, ap__); +} #ifndef evposix_memalignzn # define evposix_memalignzn libsimple_evposix_memalignzn #endif @@ -278,14 +284,14 @@ static inline void libsimple_evposix_memalignzn(void **__memptr, int __clear, si * all arguments should have the type `size_t`, and * list must end with 0 (which is not factor) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void -libsimple_eposix_memalignzn(void **__memptr, int __clear, size_t __alignment, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_eposix_memalignzn(void **memptr__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - libsimple_evposix_memalignzn(__memptr, __clear, __alignment, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + libsimple_evposix_memalignzn(memptr__, clear__, alignment__, n__, ap__); + va_end(ap__); } #ifndef eposix_memalignzn # define eposix_memalignzn libsimple_eposix_memalignzn diff --git a/libsimple/printf.h b/libsimple/printf.h index cf7192e..95f6935 100644 --- a/libsimple/printf.h +++ b/libsimple/printf.h @@ -51,7 +51,7 @@ extern void (*libsimple_eprintf_postprint)(void); * @throws ENOMEM Could not allocate enough memory * @throws Any error specified for `fprintf` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1, 2), __format__(__printf__, 2, 3)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1, 2), __format__(__printf__, 2, 3)))) int libsimple_asprintf(char **, const char *, ...); #ifndef asprintf # define asprintf libsimple_asprintf @@ -74,7 +74,7 @@ int libsimple_asprintf(char **, const char *, ...); * @throws ENOMEM Could not allocate enough memory * @throws Any error specified for `fprintf` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1, 2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1, 2)))) int libsimple_vasprintf(char **, const char *, va_list); #ifndef vasprintf # define vasprintf libsimple_vasprintf @@ -95,16 +95,17 @@ int libsimple_vasprintf(char **, const char *, va_list); * @throws Any error specified for `snprintf` */ #if defined(__GNUC__) || defined(__clang__) -# define libsimple_asprintfa(__fmt, ...)\ +# define libsimple_asprintfa(fmt__, ...)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__f = (__fmt);\ - char *__ret = NULL;\ - int __r = snprintf(NULL, 0, __f, __VA_ARGS__);\ - if (__r >= 0) {\ - __ret = alloca((size_t)__r + 1);\ - sprintf(__ret, __f, __VA_ARGS__);\ + const char *f__ = (fmt__);\ + char *ret__ = NULL;\ + int r__ = snprintf(NULL, 0, f__, __VA_ARGS__);\ + if (r__ >= 0) {\ + ret__ = alloca((size_t)r__ + 1);\ + sprintf(ret__, f__, __VA_ARGS__);\ }\ - __ret;\ + ret__;\ }) # ifndef asprintfa # define asprintfa(...) libsimple_asprintfa(__VA_ARGS__) @@ -126,23 +127,24 @@ int libsimple_vasprintf(char **, const char *, va_list); * @throws Any error specified for `snprintf` */ #if defined(__GNUC__) || defined(__clang__) -# define libsimple_vasprintfa(__fmt, __ap)\ +# define libsimple_vasprintfa(fmt__, ap__)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__f = (__fmt);\ - va_list __a1;\ - va_list __a2;\ - char *__ret = NULL;\ - int __r;\ - va_copy(__a1, __ap);\ - va_copy(__a2, __a1);\ - __r = vsnprintf(NULL, 0, __f, __a1);\ - if (__r >= 0) {\ - __ret = alloca((size_t)__r + 1);\ - vsprintf(__ret, __f, __a2);\ + const char *f__ = (fmt__);\ + va_list a1__;\ + va_list a2__;\ + char *ret__ = NULL;\ + int r__;\ + va_copy(a1__, ap__);\ + va_copy(a2__, a1__);\ + r__ = vsnprintf(NULL, 0, f__, a1__);\ + if (r__ >= 0) {\ + ret__ = alloca((size_t)r__ + 1);\ + vsprintf(ret__, f__, a2__);\ }\ - va_end(__a2);\ - va_end(__a1);\ - __ret;\ + va_end(a2__);\ + va_end(a1__);\ + ret__;\ }) # ifndef vasprintfa # define vasprintfa(fmt, ap) libsimple_vasprintfa(fmt, ap) @@ -167,7 +169,7 @@ int libsimple_vasprintf(char **, const char *, va_list); * @param fmt The format string * @param ap The format argument */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) void libsimple_vweprintf(const char *, va_list); #ifndef vweprintf # define vweprintf libsimple_vweprintf @@ -191,14 +193,14 @@ void libsimple_vweprintf(const char *, va_list); * @param fmt The format string * @param ... The format argument */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1), __format__(__printf__, 1, 2)))) -static inline void -libsimple_weprintf(const char *__fmt, ...) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __format__(__printf__, 1, 2)))) +inline void +libsimple_weprintf(const char *fmt__, ...) { - va_list __ap; - va_start(__ap, __fmt); - libsimple_vweprintf(__fmt, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, fmt__); + libsimple_vweprintf(fmt__, ap__); + va_end(ap__); } #ifndef weprintf # define weprintf libsimple_weprintf @@ -225,12 +227,12 @@ libsimple_weprintf(const char *__fmt, ...) * @param fmt The format string * @param ap The format argument */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __noreturn__))) -static inline void -libsimple_venprintf(int __status, const char *__fmt, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __noreturn__))) +inline void +libsimple_venprintf(int status__, const char *fmt__, va_list ap__) { - libsimple_vweprintf(__fmt, __ap); - exit(__status); + libsimple_vweprintf(fmt__, ap__); + exit(status__); } #ifndef venprintf # define venprintf libsimple_venprintf @@ -257,14 +259,14 @@ libsimple_venprintf(int __status, const char *__fmt, va_list __ap) * @param fmt The format string * @param ... The format argument */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __format__(__printf__, 2, 3), __noreturn__))) -static inline void -libsimple_enprintf(int __status, const char *__fmt, ...) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __format__(__printf__, 2, 3), __noreturn__))) +inline void +libsimple_enprintf(int status__, const char *fmt__, ...) { - va_list __ap; - va_start(__ap, __fmt); - libsimple_venprintf(__status, __fmt, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, fmt__); + libsimple_venprintf(status__, fmt__, ap__); + va_end(ap__); } #ifndef enprintf # define enprintf libsimple_enprintf @@ -291,11 +293,11 @@ libsimple_enprintf(int __status, const char *__fmt, ...) * @param fmt The format string * @param ap The format argument */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1), __noreturn__))) -static inline void -libsimple_veprintf(const char *__fmt, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __noreturn__))) +inline void +libsimple_veprintf(const char *fmt__, va_list ap__) { - libsimple_vweprintf(__fmt, __ap); + libsimple_vweprintf(fmt__, ap__); exit(libsimple_default_failure_exit); } #ifndef veprintf @@ -323,14 +325,14 @@ libsimple_veprintf(const char *__fmt, va_list __ap) * @param fmt The format string * @param ... The format argument */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1), __format__(__printf__, 1, 2), __noreturn__))) -static inline void -libsimple_eprintf(const char *__fmt, ...) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __format__(__printf__, 1, 2), __noreturn__))) +inline void +libsimple_eprintf(const char *fmt__, ...) { - va_list __ap; - va_start(__ap, __fmt); - libsimple_veprintf(__fmt, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, fmt__); + libsimple_veprintf(fmt__, ap__); + va_end(ap__); } #ifndef eprintf # define eprintf libsimple_eprintf diff --git a/libsimple/pvalloc.h b/libsimple/pvalloc.h index 78deb1a..bc23e85 100644 --- a/libsimple/pvalloc.h +++ b/libsimple/pvalloc.h @@ -21,9 +21,12 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void *libsimple_vpvallocn(size_t __n, va_list __ap) -{ return libsimple_vpvalloczn(0, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_vpvallocn(size_t n__, va_list ap__) +{ + return libsimple_vpvalloczn(0, n__, ap__); +} #ifndef vpvallocn # define vpvallocn libsimple_vpvallocn #endif @@ -43,9 +46,12 @@ static inline void *libsimple_vpvallocn(size_t __n, va_list __ap) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void *libsimple_pvalloc(size_t __n) -{ return libsimple_pvallocz(0, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_pvalloc(size_t n__) +{ + return libsimple_pvallocz(0, n__); +} #ifndef pvalloc # define pvalloc libsimple_pvalloc #endif @@ -71,14 +77,14 @@ static inline void *libsimple_pvalloc(size_t __n) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_pvallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_pvallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vpvallocn(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vpvallocn(n__, ap__); + va_end(ap__); } #ifndef pvallocn # define pvallocn libsimple_pvallocn @@ -103,9 +109,12 @@ libsimple_pvallocn(size_t __n, ... /*, (size_t)0 */) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_enpvalloc(int __status, size_t __n) -{ return libsimple_enpvallocz(__status, 0, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_enpvalloc(int status__, size_t n__) +{ + return libsimple_enpvallocz(status__, 0, n__); +} #ifndef enpvalloc # define enpvalloc libsimple_enpvalloc #endif @@ -134,9 +143,12 @@ static inline void *libsimple_enpvalloc(int __status, size_t __n) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envpvallocn(int __status, size_t __n, va_list __ap) -{ return libsimple_envpvalloczn(__status, 0, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_envpvallocn(int status__, size_t n__, va_list ap__) +{ + return libsimple_envpvalloczn(status__, 0, n__, ap__); +} #ifndef envpvallocn # define envpvallocn libsimple_envpvallocn #endif @@ -165,14 +177,14 @@ static inline void *libsimple_envpvallocn(int __status, size_t __n, va_list __ap * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_enpvallocn(int __status, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_enpvallocn(int status__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envpvalloczn(__status, 0, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envpvalloczn(status__, 0, n__, ap__); + va_end(ap__); } #ifndef enpvallocn # define enpvallocn libsimple_enpvallocn @@ -196,9 +208,12 @@ libsimple_enpvallocn(int __status, size_t __n, ... /*, (size_t)0 */) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_epvalloc(size_t __n) -{ return libsimple_enpvalloc(libsimple_default_failure_exit, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_epvalloc(size_t n__) +{ + return libsimple_enpvalloc(libsimple_default_failure_exit, n__); +} #ifndef epvalloc # define epvalloc libsimple_epvalloc #endif @@ -226,9 +241,12 @@ static inline void *libsimple_epvalloc(size_t __n) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evpvallocn(size_t __n, va_list __ap) -{ return libsimple_envpvallocn(libsimple_default_failure_exit, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_evpvallocn(size_t n__, va_list ap__) +{ + return libsimple_envpvallocn(libsimple_default_failure_exit, n__, ap__); +} #ifndef evpvallocn # define evpvallocn libsimple_evpvallocn #endif @@ -256,14 +274,14 @@ static inline void *libsimple_evpvallocn(size_t __n, va_list __ap) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_epvallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_epvallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evpvallocn(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evpvallocn(n__, ap__); + va_end(ap__); } #ifndef epvallocn # define epvallocn libsimple_epvallocn diff --git a/libsimple/pvallocz.h b/libsimple/pvallocz.h index a61f80b..6b4eaf6 100644 --- a/libsimple/pvallocz.h +++ b/libsimple/pvallocz.h @@ -22,12 +22,12 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_vpvalloczn(int __clear, size_t __n, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_vpvalloczn(int clear__, size_t n__, va_list ap__) { - return libsimple_memalloc(0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, __n, __ap, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_memalloc(0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, n__, ap__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_ROUND_UP_SIZE_TO_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); @@ -52,12 +52,12 @@ libsimple_vpvalloczn(int __clear, size_t __n, va_list __ap) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) -static inline void * -libsimple_pvallocz(int __clear, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) +inline void * +libsimple_pvallocz(int clear__, size_t n__) { - return libsimple_memalloc(__n, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_memalloc(n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_ROUND_UP_SIZE_TO_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); @@ -88,14 +88,14 @@ libsimple_pvallocz(int __clear, size_t __n) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_pvalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_pvalloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vpvalloczn(__clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vpvalloczn(clear__, n__, ap__); + va_end(ap__); } #ifndef pvalloczn # define pvalloczn libsimple_pvalloczn @@ -121,12 +121,12 @@ libsimple_pvalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_enpvallocz(int __status, int __clear, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_enpvallocz(int status__, int clear__, size_t n__) { - return libsimple_enmemalloc(__status, __n, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_enmemalloc(status__, n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_ROUND_UP_SIZE_TO_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); @@ -161,13 +161,13 @@ libsimple_enpvallocz(int __status, int __clear, size_t __n) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_envpvalloczn(int __status, int __clear, size_t __n, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_envpvalloczn(int status__, int clear__, size_t n__, va_list ap__) { - return libsimple_enmemalloc(__status, - 0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, __n, __ap, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_enmemalloc(status__, + 0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, n__, ap__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_ROUND_UP_SIZE_TO_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); @@ -202,14 +202,14 @@ libsimple_envpvalloczn(int __status, int __clear, size_t __n, va_list __ap) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_enpvalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_enpvalloczn(int status__, int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envpvalloczn(__status, __clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envpvalloczn(status__, clear__, n__, ap__); + va_end(ap__); } #ifndef enpvalloczn # define enpvalloczn libsimple_enpvalloczn @@ -234,9 +234,12 @@ libsimple_enpvalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 * * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_epvallocz(int __clear, size_t __n) -{ return libsimple_enpvallocz(libsimple_default_failure_exit, __clear, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_epvallocz(int clear__, size_t n__) +{ + return libsimple_enpvallocz(libsimple_default_failure_exit, clear__, n__); +} #ifndef epvallocz # define epvallocz libsimple_epvallocz #endif @@ -265,9 +268,12 @@ static inline void *libsimple_epvallocz(int __clear, size_t __n) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evpvalloczn(int __clear, size_t __n, va_list __ap) -{ return libsimple_envpvalloczn(libsimple_default_failure_exit, __clear, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_evpvalloczn(int clear__, size_t n__, va_list ap__) +{ + return libsimple_envpvalloczn(libsimple_default_failure_exit, clear__, n__, ap__); +} #ifndef evpvalloczn # define evpvalloczn libsimple_evpvalloczn #endif @@ -296,14 +302,14 @@ static inline void *libsimple_evpvalloczn(int __clear, size_t __n, va_list __ap) * rounded up to the next multiple of the page size, * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_epvalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_epvalloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evpvalloczn(__clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evpvalloczn(clear__, n__, ap__); + va_end(ap__); } #ifndef epvalloczn # define epvalloczn libsimple_epvalloczn diff --git a/libsimple/realloc.h b/libsimple/realloc.h index b02c08a..4f780d5 100644 --- a/libsimple/realloc.h +++ b/libsimple/realloc.h @@ -26,7 +26,7 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) void *libsimple_vreallocn(void *, size_t, va_list); #ifndef vreallocn # define vreallocn libsimple_vreallocn @@ -58,14 +58,14 @@ void *libsimple_vreallocn(void *, size_t, va_list); * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) -static inline void * -libsimple_reallocn(void *__ptr, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) +inline void * +libsimple_reallocn(void *ptr__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vreallocn(__ptr, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vreallocn(ptr__, n__, ap__); + va_end(ap__); } #ifndef reallocn # define reallocn libsimple_reallocn @@ -95,7 +95,7 @@ libsimple_reallocn(void *__ptr, size_t __n, ... /*, (size_t)0 */) * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enrealloc(int, void *, size_t); #ifndef enrealloc # define enrealloc libsimple_enrealloc @@ -130,7 +130,7 @@ void *libsimple_enrealloc(int, void *, size_t); * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__, __returns_nonnull__))) void *libsimple_envreallocn(int, void *, size_t, va_list); #ifndef envreallocn # define envreallocn libsimple_envreallocn @@ -165,14 +165,14 @@ void *libsimple_envreallocn(int, void *, size_t, va_list); * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_enreallocn(int __status, void *__ptr, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_enreallocn(int status__, void *ptr__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envreallocn(__status, __ptr, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envreallocn(status__, ptr__, n__, ap__); + va_end(ap__); } #ifndef enreallocn # define enreallocn libsimple_enreallocn @@ -201,9 +201,12 @@ libsimple_enreallocn(int __status, void *__ptr, size_t __n, ... /*, (size_t)0 */ * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_erealloc(void *__ptr, size_t __n) -{ return libsimple_enrealloc(libsimple_default_failure_exit, __ptr, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_erealloc(void *ptr__, size_t n__) +{ + return libsimple_enrealloc(libsimple_default_failure_exit, ptr__, n__); +} #ifndef erealloc # define erealloc libsimple_erealloc #endif @@ -236,9 +239,12 @@ static inline void *libsimple_erealloc(void *__ptr, size_t __n) * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evreallocn(void *__ptr, size_t __n, va_list __ap) -{ return libsimple_envreallocn(libsimple_default_failure_exit, __ptr, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_evreallocn(void *ptr__, size_t n__, va_list ap__) +{ + return libsimple_envreallocn(libsimple_default_failure_exit, ptr__, n__, ap__); +} #ifndef evreallocn # define evreallocn libsimple_evreallocn #endif @@ -271,14 +277,14 @@ static inline void *libsimple_evreallocn(void *__ptr, size_t __n, va_list __ap) * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_ereallocn(void *__ptr, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_ereallocn(void *ptr__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evreallocn(__ptr, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evreallocn(ptr__, n__, ap__); + va_end(ap__); } #ifndef ereallocn # define ereallocn libsimple_ereallocn @@ -307,14 +313,14 @@ libsimple_ereallocn(void *__ptr, size_t __n, ... /*, (size_t)0 */) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2), __warn_unused_result__))) -static inline void * -libsimple_reallocf(void *__ptr, size_t __n) /* TODO test */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2), __warn_unused_result__))) +inline void * +libsimple_reallocf(void *ptr__, size_t n__) { - void *__new = __n ? realloc(__ptr, __n) : NULL; - if (!__new) - free(__ptr); - return __new; + void *new__ = n__ ? realloc(ptr__, n__) : NULL; + if (!new__) + free(ptr__); + return new__; } #ifndef reallocf # define reallocf libsimple_reallocf @@ -345,15 +351,15 @@ libsimple_reallocf(void *__ptr, size_t __n) /* TODO test */ * @throws EINVAL `n` or `m` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2, 3), __warn_unused_result__))) -static inline void * -libsimple_reallocarray(void *__ptr, size_t __n, size_t __m) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2, 3), __warn_unused_result__))) +inline void * +libsimple_reallocarray(void *ptr__, size_t n__, size_t m__) { - if (LIBSIMPLE_UMUL_OVERFLOW(__n, __m, &__n, SIZE_MAX)) { + if (LIBSIMPLE_UMUL_OVERFLOW(n__, m__, &n__, SIZE_MAX)) { errno = ENOMEM; return NULL; } - return realloc(__ptr, __n); + return realloc(ptr__, n__); } #ifndef reallocarray # define reallocarray libsimple_reallocarray @@ -386,7 +392,7 @@ libsimple_reallocarray(void *__ptr, size_t __n, size_t __m) * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(3, 4), __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(3, 4), __warn_unused_result__, __returns_nonnull__))) void *libsimple_enreallocarray(int, void *, size_t, size_t); #ifndef enreallocarray # define enreallocarray libsimple_enreallocarray @@ -419,9 +425,12 @@ void *libsimple_enreallocarray(int, void *, size_t, size_t); * the specified size and with the alignment * `alignof(max_align_t)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2, 3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ereallocarray(void *__ptr, size_t __n, size_t __m) -{ return libsimple_enreallocarray(libsimple_default_failure_exit, __ptr, __n, __m); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2, 3), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_ereallocarray(void *ptr__, size_t n__, size_t m__) +{ + return libsimple_enreallocarray(libsimple_default_failure_exit, ptr__, n__, m__); +} #ifndef ereallocarray # define ereallocarray libsimple_ereallocarray #endif @@ -451,14 +460,14 @@ static inline void *libsimple_ereallocarray(void *__ptr, size_t __n, size_t __m) * @throws EINVAL `n` or `m` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2, 3), __warn_unused_result__))) -static inline void * -libsimple_reallocarrayf(void *__ptr, size_t __n, size_t __m) /* TODO test */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2, 3), __warn_unused_result__))) +inline void * +libsimple_reallocarrayf(void *ptr__, size_t n__, size_t m__) { - void *__new = __n ? libsimple_reallocarray(__ptr, __n, __m) : NULL; - if (!__new) - free(__ptr); - return __new; + void *new__ = n__ ? libsimple_reallocarray(ptr__, n__, m__) : NULL; + if (!new__) + free(ptr__); + return new__; } #ifndef reallocarrayf # define reallocarrayf libsimple_reallocarrayf @@ -490,14 +499,14 @@ libsimple_reallocarrayf(void *__ptr, size_t __n, size_t __m) /* TODO test */ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) -static inline void * -libsimple_vreallocfn(void *__ptr, size_t __n, va_list __ap) /* TODO test (reallocfn) */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) +inline void * +libsimple_vreallocfn(void *ptr__, size_t n__, va_list ap__) { - void *__new = libsimple_vreallocn(__ptr, __n, __ap); - if (!__new) - free(__ptr); - return __new; + void *new__ = libsimple_vreallocn(ptr__, n__, ap__); + if (!new__) + free(ptr__); + return new__; } #ifndef vreallocfn # define vreallocfn libsimple_vreallocfn @@ -529,14 +538,14 @@ libsimple_vreallocfn(void *__ptr, size_t __n, va_list __ap) /* TODO test (reallo * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) -static inline void * -libsimple_reallocfn(void *__ptr, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) +inline void * +libsimple_reallocfn(void *ptr__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vreallocfn(__ptr, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vreallocfn(ptr__, n__, ap__); + va_end(ap__); } #ifndef reallocfn # define reallocfn libsimple_reallocfn diff --git a/libsimple/str.h b/libsimple/str.h index 4bf5793..d01086e 100644 --- a/libsimple/str.h +++ b/libsimple/str.h @@ -9,7 +9,7 @@ * @return `s` with a minimal offset such that `*r == c || !*r`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strchrnul(const char *, int); #ifndef strchrnul # define strchrnul libsimple_strchrnul @@ -24,7 +24,7 @@ char *libsimple_strchrnul(const char *, int); * @return `s` with a minimal offset such that `tolower(*r) == tolower(c)`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strcasechr(const char *, int); #ifndef strcasechr # define strcasechr libsimple_strcasechr @@ -39,7 +39,7 @@ char *libsimple_strcasechr(const char *, int); * @return `s` with a minimal offset such that `tolower(*r) == tolower(c) || !*r`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strcasechrnul(const char *, int); #ifndef strcasechrnul # define strcasechrnul libsimple_strcasechrnul @@ -54,7 +54,7 @@ char *libsimple_strcasechrnul(const char *, int); * @return `s` with a maximal offset such that `tolower(*r) == tolower(c)`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrcasechr(const char *, int); #ifndef strrcasechr # define strrcasechr libsimple_strrcasechr @@ -70,7 +70,7 @@ char *libsimple_strrcasechr(const char *, int); * @return `s` with a minimal offset such that `*r != c`, where `r` * is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strchr_inv(const char *, int); #ifndef strchr_inv # define strchr_inv libsimple_strchr_inv @@ -86,7 +86,7 @@ char *libsimple_strchr_inv(const char *, int); * @return `s` with a minimal offset such that `*r != c || !*r`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strchrnul_inv(const char *, int); #ifndef strchrnul_inv # define strchrnul_inv libsimple_strchrnul_inv @@ -102,7 +102,7 @@ char *libsimple_strchrnul_inv(const char *, int); * @return `s` with a minimal offset such that `tolower(*r) != tolower(c)`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strcasechr_inv(const char *, int); #ifndef strcasechr_inv # define strcasechr_inv libsimple_strcasechr_inv @@ -118,7 +118,7 @@ char *libsimple_strcasechr_inv(const char *, int); * @return `s` with a minimal offset such that `tolower(*r) != tolower(c) || !*r`, * where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strcasechrnul_inv(const char *, int); #ifndef strcasechrnul_inv # define strcasechrnul_inv libsimple_strcasechrnul_inv @@ -134,7 +134,7 @@ char *libsimple_strcasechrnul_inv(const char *, int); * @return `s` with a maximal offset such that `*r != c`, where `r` * is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrchr_inv(const char *, int); #ifndef strrchr_inv # define strrchr_inv libsimple_strrchr_inv @@ -150,7 +150,7 @@ char *libsimple_strrchr_inv(const char *, int); * @return `s` with a maximal offset such that `tolower(*r) != tolower(c)`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrcasechr_inv(const char *, int); #ifndef strrcasechr_inv # define strrcasechr_inv libsimple_strrcasechr_inv @@ -163,9 +163,12 @@ char *libsimple_strrcasechr_inv(const char *, int); * @param s The string * @return `s` with an offset such `!*r`, where `r` is the returned pointer */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline char *libsimple_strend(const char *__s) -{ return strchr(__s, '\0'); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline char * +libsimple_strend(const char *s__) +{ + return strchr(s__, '\0'); +} #ifndef strend # define strend libsimple_strend #endif @@ -178,7 +181,7 @@ static inline char *libsimple_strend(const char *__s) * @param t The string `s` should begin with * @return 1 if `s` starts with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strstarts(const char *, const char *); #ifndef strstarts # define strstarts libsimple_strstarts @@ -192,9 +195,12 @@ int libsimple_strstarts(const char *, const char *); * @param t The string `s` should begin with * @return 1 if `s` starts with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_strcasestarts(const char *__s, const char *__t) -{ return !strncasecmp(__s, __t, strlen(__t)); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_strcasestarts(const char *s__, const char *t__) +{ + return !strncasecmp(s__, t__, strlen(t__)); +} #ifndef strcasestarts # define strcasestarts libsimple_strcasestarts #endif @@ -207,7 +213,7 @@ static inline int libsimple_strcasestarts(const char *__s, const char *__t) * @param t The string `s` should begin with * @return 1 if `s` ends with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strends(const char *, const char *); #ifndef strends # define strends libsimple_strends @@ -221,7 +227,7 @@ int libsimple_strends(const char *, const char *); * @param t The string `s` should begin with * @return 1 if `s` end with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strcaseends(const char *, const char *); #ifndef strcaseends # define strcaseends libsimple_strcaseends @@ -237,7 +243,7 @@ int libsimple_strcaseends(const char *, const char *); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrstr(const char *, const char *); #ifndef strrstr # define strrstr libsimple_strrstr @@ -253,7 +259,7 @@ char *libsimple_strrstr(const char *, const char *); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strcasestr(const char *, const char *); #ifndef strcasestr # define strcasestr libsimple_strcasestr @@ -269,7 +275,7 @@ char *libsimple_strcasestr(const char *, const char *); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrcasestr(const char *, const char *); #ifndef strrcasestr # define strrcasestr libsimple_strrcasestr @@ -286,9 +292,12 @@ char *libsimple_strrcasestr(const char *, const char *); * a positive value if `a` is greater than `b`, * 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strcmpnul(const char *__a, const char *__b) -{ return (!__a || !__b) ? !__b - !__a : strcmp(__a, __b); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strcmpnul(const char *a__, const char *b__) +{ + return (!a__ || !b__) ? !b__ - !a__ : strcmp(a__, b__); +} #ifndef strcmpnul # define strcmpnul libsimple_strcmpnul #endif @@ -304,9 +313,12 @@ static inline int libsimple_strcmpnul(const char *__a, const char *__b) * a positive value if `a` is greater than `b`, * 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strcasecmpnul(const char *__a, const char *__b) -{ return (!__a || !__b) ? !__b - !__a : strcasecmp(__a, __b); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strcasecmpnul(const char *a__, const char *b__) +{ + return (!a__ || !b__) ? !b__ - !a__ : strcasecmp(a__, b__); +} #ifndef strcasecmpnul # define strcasecmpnul libsimple_strcasecmpnul #endif @@ -320,9 +332,12 @@ static inline int libsimple_strcasecmpnul(const char *__a, const char *__b) * @param b The other string, may not be `NULL` * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_streq(const char *__a, const char *__b) -{ return !strcmp(__a, __b); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_streq(const char *a__, const char *b__) +{ + return !strcmp(a__, b__); +} #ifndef streq # define streq libsimple_streq #endif @@ -336,9 +351,12 @@ static inline int libsimple_streq(const char *__a, const char *__b) * @param b The other string, may be `NULL` * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_streqnul(const char *__a, const char *__b) -{ return !libsimple_strcmpnul(__a, __b); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_streqnul(const char *a__, const char *b__) +{ + return !libsimple_strcmpnul(a__, b__); +} #ifndef streqnul # define streqnul libsimple_streqnul #endif @@ -352,9 +370,12 @@ static inline int libsimple_streqnul(const char *__a, const char *__b) * @param b The other string, may not be `NULL` * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_strcaseeq(const char *__a, const char *__b) -{ return !strcasecmp(__a, __b); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_strcaseeq(const char *a__, const char *b__) +{ + return !strcasecmp(a__, b__); +} #ifndef strcaseeq # define strcaseeq libsimple_strcaseeq #endif @@ -368,9 +389,12 @@ static inline int libsimple_strcaseeq(const char *__a, const char *__b) * @param b The other string, may be `NULL` * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strcaseeqnul(const char *__a, const char *__b) -{ return !libsimple_strcasecmpnul(__a, __b); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strcaseeqnul(const char *a__, const char *b__) +{ + return !libsimple_strcasecmpnul(a__, b__); +} #ifndef strcaseeqnul # define strcaseeqnul libsimple_strcaseeqnul #endif @@ -384,7 +408,7 @@ static inline int libsimple_strcaseeqnul(const char *__a, const char *__b) * @return The number of bytes `a` and `b` have * in common in their beginnings */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) size_t libsimple_streqlen(const char *, const char *); #ifndef streqlen # define streqlen libsimple_streqlen @@ -399,7 +423,7 @@ size_t libsimple_streqlen(const char *, const char *); * @return The number of bytes `a` and `b` have * in common in their beginnings */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) size_t libsimple_strcaseeqlen(const char *, const char *); #ifndef strcaseeqlen # define strcaseeqlen libsimple_strcaseeqlen @@ -414,9 +438,12 @@ size_t libsimple_strcaseeqlen(const char *, const char *); * @return The number of bytes `a` and `b` have * in common in their ends */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t libsimple_strreqlen(const char *__a, const char *__b) -{ return libsimple_memreqlen(__a, strlen(__a), __b, strlen(__b)); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline size_t +libsimple_strreqlen(const char *a__, const char *b__) +{ + return libsimple_memreqlen(a__, strlen(a__), b__, strlen(b__)); +} #ifndef strreqlen # define strreqlen libsimple_strreqlen #endif @@ -430,9 +457,12 @@ static inline size_t libsimple_strreqlen(const char *__a, const char *__b) * @return The number of bytes `a` and `b` have * in common in their ends */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t libsimple_strrcaseeqlen(const char *__a, const char *__b) -{ return libsimple_memrcaseeqlen(__a, strlen(__a), __b, strlen(__b)); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline size_t +libsimple_strrcaseeqlen(const char *a__, const char *b__) +{ + return libsimple_memrcaseeqlen(a__, strlen(a__), b__, strlen(b__)); +} #ifndef strrcaseeqlen # define strrcaseeqlen libsimple_strrcaseeqlen #endif @@ -446,9 +476,12 @@ static inline size_t libsimple_strrcaseeqlen(const char *__a, const char *__b) * @return 1 if the byte `c` is not the NUL byte and can be found in `s`, * 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_inchrset(int __c, const char *__s) -{ return __c && strchr(__s, __c); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_inchrset(int c__, const char *s__) +{ + return c__ && strchr(s__, c__); +} #ifndef inchrset # define inchrset libsimple_inchrset #endif @@ -462,9 +495,12 @@ static inline int libsimple_inchrset(int __c, const char *__s) * @return 1 if the byte `c` is not the NUL byte and can be found in `s`, * 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_inchrcaseset(int __c, const char *__s) -{ return __c && strcasechr(__s, __c); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_inchrcaseset(int c__, const char *s__) +{ + return c__ && strcasechr(s__, c__); +} #ifndef inchrcaseset # define inchrcaseset libsimple_inchrcaseset #endif @@ -478,9 +514,12 @@ static inline int libsimple_inchrcaseset(int __c, const char *__s) * @param s The string to move * @return `d` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char *libsimple_strmove(char *__d, const char *__s) -{ return memmove(__d, __s, strlen(__s) + 1); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +static inline char * +libsimple_strmove(char *d__, const char *s__) +{ + return memmove(d__, s__, strlen(s__) + 1); +} #ifndef strmove # define strmove libsimple_strmove #endif @@ -494,9 +533,14 @@ static inline char *libsimple_strmove(char *__d, const char *__s) * @param s The string to move * @return `&d[strlen(s)]` (this byte will be a NUL byte) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char *libsimple_stpmove(char *__d, const char *__s) -{ size_t __n = strlen(__s); memmove(__d, __s, __n + 1); return &__d[__n]; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +static inline char * +libsimple_stpmove(char *d__, const char *s__) +{ + size_t n__ = strlen(s__); + memmove(d__, s__, n__ + 1); + return &d__[n__]; +} #ifndef stpmove # define stpmove libsimple_stpmove #endif @@ -509,13 +553,13 @@ static inline char *libsimple_stpmove(char *__d, const char *__s) * @param c The byte to replace all bytes in `s` with * @return `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_strset(char *__s, int __c_) +libsimple_strset(char *s__, int c___) { - char __c = (char)__c_, *__r = __s; - while (*__s) *__s++ = __c; - return __r; + char c__ = (char)c___, *r__ = s__; + while (*s__) *s__++ = c__; + return r__; } #ifndef strset # define strset libsimple_strset @@ -529,13 +573,13 @@ libsimple_strset(char *__s, int __c_) * @param c The byte to replace all bytes in `s` with * @return `&s[strlen(s)]` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_stpset(char *__s, int __c_) +libsimple_stpset(char *s__, int c___) { - char __c = (char)__c_; - while (*__s) *__s++ = __c; - return __s; + char c__ = (char)c___; + while (*s__) *s__++ = c__; + return s__; } #ifndef stpset # define stpset libsimple_stpset @@ -552,15 +596,17 @@ libsimple_stpset(char *__s, int __c_) * @return `&strchr(d, c)[1]` (after copying) if `c` can be * found in `s`, `NULL` otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_strccpy(char *restrict __d, const char *restrict __s, int __c_) +libsimple_strccpy(char *restrict d__, const char *restrict s__, int c___) { - char __c = (char)__c_; + char c__ = (char)c___; do { - if ((*__d++ = *__s) == __c) - return *__d = '\0', __d; - } while (*__s++); + if ((*d__++ = *s__) == c__) { + *d__ = '\0'; + return d__; + } + } while (*s__++); return NULL; } #ifndef strccpy @@ -577,7 +623,7 @@ libsimple_strccpy(char *restrict __d, const char *restrict __s, int __c_) * @return `&strchr(d, c)[1]` (after copying) if `c` can be * found in `s` (before copying), `NULL` otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) char *libsimple_strcmove(char *, const char *, int); #ifndef strcmove # define strcmove libsimple_strcmove @@ -593,15 +639,15 @@ char *libsimple_strcmove(char *, const char *, int); * @param new The value to replace the characters with * @return `strchr(s, '\0')` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) static inline char * -libsimple_strreplace(char *__s, int __old_, int __new_) +libsimple_strreplace(char *s__, int old___, int new___) { - char __old = (char)__old_, __new = (char)__new_; - for (; *__s; __s++) - if (*__s == __old) - *__s = __new; - return __s; + char old__ = (char)old___, new__ = (char)new___; + for (; *s__; s__++) + if (*s__ == old__) + *s__ = new__; + return s__; } #ifndef strreplace # define strreplace libsimple_strreplace @@ -620,7 +666,7 @@ libsimple_strreplace(char *__s, int __old_, int __new_) * @param s The string to copy * @return `strchr(d, '\0')` (after copying) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) char *libsimple_stptolower(char *, const char *); #ifndef stptolower # define stptolower libsimple_stptolower @@ -639,7 +685,7 @@ char *libsimple_stptolower(char *, const char *); * @param s The string to copy * @return `strchr(d, '\0')` (after copying) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) char *libsimple_stptoupper(char *, const char *); #ifndef stptoupper # define stptoupper libsimple_stptoupper @@ -658,9 +704,13 @@ char *libsimple_stptoupper(char *, const char *); * @param s The string to copy * @return `d` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char *libsimple_strtolower(char *__d, const char *__s) -{ libsimple_stptolower(__d, __s); return __d; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) +static inline char * +libsimple_strtolower(char *d__, const char *s__) +{ + libsimple_stptolower(d__, s__); + return d__; +} #ifndef strtolower # define strtolower libsimple_strtolower #endif @@ -678,9 +728,13 @@ static inline char *libsimple_strtolower(char *__d, const char *__s) * @param s The string to copy * @return `d` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char *libsimple_strtoupper(char *__d, const char *__s) -{ libsimple_stptoupper(__d, __s); return __d; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) +static inline char * +libsimple_strtoupper(char *d__, const char *s__) +{ + libsimple_stptoupper(d__, s__); + return d__; +} #ifndef strtoupper # define strtoupper libsimple_strtoupper #endif @@ -694,9 +748,12 @@ static inline char *libsimple_strtoupper(char *__d, const char *__s) * allows a two-byte encoding for NUL * @return 1 if good, 0 on encoding error */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_strisutf8(const char *__string, int __allow_modified_nul) -{ return libsimple_memisutf8(__string, strlen(__string) ,__allow_modified_nul); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_strisutf8(const char *string__, int allow_modified_nul__) +{ + return libsimple_memisutf8(string__, strlen(string__), allow_modified_nul__); +} #ifndef strisutf8 # define strisutf8 libsimple_strisutf8 #endif diff --git a/libsimple/strdup.h b/libsimple/strdup.h index a826414..cc3b67a 100644 --- a/libsimple/strdup.h +++ b/libsimple/strdup.h @@ -9,11 +9,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_strdupa(s)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__s = (s);\ - size_t __n = strlen(__s) + 1;\ - char *__r = alloca(__n);\ - memcpy(__r, __s, __n);\ + const char *s__ = (s);\ + size_t n__ = strlen(s__) + 1;\ + char *r__ = alloca(n__);\ + memcpy(r__, s__, n__);\ }) # ifndef strdupa # define strdupa(s) libsimple_strdupa(s) @@ -28,7 +29,7 @@ * @param s The string to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) char *libsimple_enstrdup(int, const char *); #ifndef enstrdup # define enstrdup libsimple_enstrdup @@ -41,11 +42,11 @@ char *libsimple_enstrdup(int, const char *); * @param s The string to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) inline char * -libsimple_estrdup(const char *__s) +libsimple_estrdup(const char *s__) { - return libsimple_enstrdup(libsimple_default_failure_exit, __s); + return libsimple_enstrdup(libsimple_default_failure_exit, s__); } #ifndef estrdup # define estrdup libsimple_estrdup diff --git a/libsimple/strn.h b/libsimple/strn.h index aa8a889..8d10fff 100644 --- a/libsimple/strn.h +++ b/libsimple/strn.h @@ -11,7 +11,7 @@ * where `r` is the returned pointer, `NULL` if no such offset exists * within the first `n` bytes */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strnchr(const char *, int, size_t); #ifndef strnchr # define strnchr libsimple_strnchr @@ -28,7 +28,7 @@ char *libsimple_strnchr(const char *, int, size_t); * where `r` is the returned pointer, `NULL` if no such offset exists * within the first `n` bytes */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strncasechr(const char *, int, size_t); #ifndef strncasechr # define strncasechr libsimple_strncasechr @@ -45,7 +45,7 @@ char *libsimple_strncasechr(const char *, int, size_t); * where `r` is the returned pointer, however if no such * offset exists within the first `n` bytes, `&s[n]` is returned */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strnchrnul(const char *, int, size_t); #ifndef strnchrnul # define strnchrnul libsimple_strnchrnul @@ -62,7 +62,7 @@ char *libsimple_strnchrnul(const char *, int, size_t); * where `r` is the returned pointer, however if no such offset * exists within the first `n` bytes, `&s[n]` is returned */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strncasechrnul(const char *, int, size_t); #ifndef strncasechrnul # define strncasechrnul libsimple_strncasechrnul @@ -78,7 +78,7 @@ char *libsimple_strncasechrnul(const char *, int, size_t); * @return `s` with a maximal offset such that `*r == c`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrnchr(const char *, int, size_t); #ifndef strrnchr # define strrnchr libsimple_strrnchr @@ -95,7 +95,7 @@ char *libsimple_strrnchr(const char *, int, size_t); * @return `s` with a maximal offset such that `tolower(*r) == tolower(c)`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrncasechr(const char *, int, size_t); #ifndef strrncasechr # define strrncasechr libsimple_strrncasechr @@ -113,7 +113,7 @@ char *libsimple_strrncasechr(const char *, int, size_t); * where `r` is the returned pointer, `NULL` if no such offset exists * within the first `n` bytes */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strnchr_inv(const char *, int, size_t); #ifndef strnchr_inv # define strnchr_inv libsimple_strnchr_inv @@ -131,7 +131,7 @@ char *libsimple_strnchr_inv(const char *, int, size_t); * where `r` is the returned pointer, `NULL` if no such offset exists * within the first `n` bytes */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strncasechr_inv(const char *, int, size_t); #ifndef strncasechr_inv # define strncasechr_inv libsimple_strncasechr_inv @@ -149,7 +149,7 @@ char *libsimple_strncasechr_inv(const char *, int, size_t); * where `r` is the returned pointer, however if no such * offset exists within the first `n` bytes, `&s[n]` is returned */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strnchrnul_inv(const char *, int, size_t); #ifndef strnchrnul_inv # define strnchrnul_inv libsimple_strnchrnul_inv @@ -167,7 +167,7 @@ char *libsimple_strnchrnul_inv(const char *, int, size_t); * where `r` is the returned pointer, however if no such offset * exists within the first `n` bytes, `&s[n]` is returned */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strncasechrnul_inv(const char *, int, size_t); #ifndef strncasechrnul_inv # define strncasechrnul_inv libsimple_strncasechrnul_inv @@ -184,7 +184,7 @@ char *libsimple_strncasechrnul_inv(const char *, int, size_t); * @return `s` with a maximal offset such that `*r != c`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrnchr_inv(const char *, int, size_t); #ifndef strrnchr_inv # define strrnchr_inv libsimple_strrnchr_inv @@ -201,7 +201,7 @@ char *libsimple_strrnchr_inv(const char *, int, size_t); * @return `s` with a maximal offset such that `tolower(*r) != tolower(c)`, * where `r` is the returned pointer, `NULL` if no such offset exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrncasechr_inv(const char *, int, size_t); #ifndef strrncasechr_inv # define strrncasechr_inv libsimple_strrncasechr_inv @@ -218,7 +218,7 @@ char *libsimple_strrncasechr_inv(const char *, int, size_t); * is not NUL byte within the first `n` bytes * if `s`, `&s[n]` is returned */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __returns_nonnull__, __warn_unused_result__))) char *libsimple_strnend(const char *, size_t); #ifndef strnend # define strnend libsimple_strnend @@ -233,7 +233,7 @@ char *libsimple_strnend(const char *, size_t); * @param n Truncate `s` to this length if it is longer * @return 1 if `s` starts with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strnstarts(const char *, const char *, size_t); #ifndef strnstarts # define strnstarts libsimple_strnstarts @@ -248,7 +248,7 @@ int libsimple_strnstarts(const char *, const char *, size_t); * @param n Truncate `s` to this length if it is longer * @return 1 if `s` starts with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strncasestarts(const char *, const char *, size_t); #ifndef strncasestarts # define strncasestarts libsimple_strncasestarts @@ -263,7 +263,7 @@ int libsimple_strncasestarts(const char *, const char *, size_t); * @param n Truncate `s` to this length if it is longer * @return 1 if `s` ends with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strnends(const char *, const char *, size_t); #ifndef strnends # define strnends libsimple_strnends @@ -278,7 +278,7 @@ int libsimple_strnends(const char *, const char *, size_t); * @param n Truncate `s` to this length if it is longer * @return 1 if `s` end with `t`, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) int libsimple_strncaseends(const char *, const char *, size_t); #ifndef strncaseends # define strncaseends libsimple_strncaseends @@ -295,7 +295,7 @@ int libsimple_strncaseends(const char *, const char *, size_t); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strnstr(const char *, const char *, size_t); #ifndef strnstr # define strnstr libsimple_strnstr @@ -312,7 +312,7 @@ char *libsimple_strnstr(const char *, const char *, size_t); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strncasestr(const char *, const char *, size_t); #ifndef strncasestr # define strncasestr libsimple_strncasestr @@ -329,7 +329,7 @@ char *libsimple_strncasestr(const char *, const char *, size_t); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrnstr(const char *, const char *, size_t); #ifndef strrnstr # define strrnstr libsimple_strrnstr @@ -346,7 +346,7 @@ char *libsimple_strrnstr(const char *, const char *, size_t); * pointer begins with `needle`, `NULL` if no such offset * exists */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) char *libsimple_strrncasestr(const char *, const char *, size_t); #ifndef strrncasestr # define strrncasestr libsimple_strrncasestr @@ -365,9 +365,12 @@ char *libsimple_strrncasestr(const char *, const char *, size_t); * a positive value if `a` is greater than `b`, * 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strncmpnul(const char *__a, const char *__b, size_t __n) -{ return (!__a || !__b) ? !__b - !__a : strncmp(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strncmpnul(const char *a__, const char *b__, size_t n__) +{ + return (!a__ || !b__) ? !b__ - !a__ : strncmp(a__, b__, n__); +} #ifndef strncmpnul # define strncmpnul libsimple_strncmpnul #endif @@ -385,9 +388,12 @@ static inline int libsimple_strncmpnul(const char *__a, const char *__b, size_t * a positive value if `a` is greater than `b`, * 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strncasecmpnul(const char *__a, const char *__b, size_t __n) -{ return (!__a || !__b) ? !__b - !__a : strncasecmp(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strncasecmpnul(const char *a__, const char *b__, size_t n__) +{ + return (!a__ || !b__) ? !b__ - !a__ : strncasecmp(a__, b__, n__); +} #ifndef strncasecmpnul # define strncasecmpnul libsimple_strncasecmpnul #endif @@ -403,9 +409,12 @@ static inline int libsimple_strncasecmpnul(const char *__a, const char *__b, siz * longer than this to this length * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_strneq(const char *__a, const char *__b, size_t __n) -{ return !strncmp(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_strneq(const char *a__, const char *b__, size_t n__) +{ + return !strncmp(a__, b__, n__); +} #ifndef strneq # define strneq libsimple_strneq #endif @@ -421,9 +430,12 @@ static inline int libsimple_strneq(const char *__a, const char *__b, size_t __n) * longer than this to this length * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strneqnul(const char *__a, const char *__b, size_t __n) -{ return !strncmpnul(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strneqnul(const char *a__, const char *b__, size_t n__) +{ + return !strncmpnul(a__, b__, n__); +} #ifndef strneqnul # define strneqnul libsimple_strneqnul #endif @@ -439,9 +451,12 @@ static inline int libsimple_strneqnul(const char *__a, const char *__b, size_t _ * longer than this to this length * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_strncaseeq(const char *__a, const char *__b, size_t __n) -{ return !strncasecmp(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_strncaseeq(const char *a__, const char *b__, size_t n__) +{ + return !strncasecmp(a__, b__, n__); +} #ifndef strncaseeq # define strncaseeq libsimple_strncaseeq #endif @@ -457,9 +472,12 @@ static inline int libsimple_strncaseeq(const char *__a, const char *__b, size_t * longer than this to this length * @return 1 if the strings are equal, 0 otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__))) -static inline int libsimple_strncaseeqnul(const char *__a, const char *__b, size_t __n) -{ return !libsimple_strncasecmpnul(__a, __b, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) +static inline int +libsimple_strncaseeqnul(const char *a__, const char *b__, size_t n__) +{ + return !libsimple_strncasecmpnul(a__, b__, n__); +} #ifndef strncaseeqnul # define strncaseeqnul libsimple_strncaseeqnul #endif @@ -475,7 +493,7 @@ static inline int libsimple_strncaseeqnul(const char *__a, const char *__b, size * @return The number of bytes `a` and `b` have * in common in their beginnings */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) size_t libsimple_strneqlen(const char *, const char *, size_t); #ifndef strneqlen # define strneqlen libsimple_strneqlen @@ -492,7 +510,7 @@ size_t libsimple_strneqlen(const char *, const char *, size_t); * @return The number of bytes `a` and `b` have * in common in their beginnings */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) size_t libsimple_strncaseeqlen(const char *, const char *, size_t); #ifndef strncaseeqlen # define strncaseeqlen libsimple_strncaseeqlen @@ -509,9 +527,12 @@ size_t libsimple_strncaseeqlen(const char *, const char *, size_t); * @return The number of bytes `a` and `b` have * in common in their ends */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t libsimple_strrneqlen(const char *__a, const char *__b, size_t __n) -{ return libsimple_memreqlen(__a, strnlen(__a, __n), __b, strnlen(__b, __n)); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline size_t +libsimple_strrneqlen(const char *a__, const char *b__, size_t n__) +{ + return libsimple_memreqlen(a__, strnlen(a__, n__), b__, strnlen(b__, n__)); +} #ifndef strrneqlen # define strrneqlen libsimple_strrneqlen #endif @@ -527,9 +548,12 @@ static inline size_t libsimple_strrneqlen(const char *__a, const char *__b, size * @return The number of bytes `a` and `b` have * in common in their ends */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t libsimple_strrncaseeqlen(const char *__a, const char *__b, size_t __n) -{ return libsimple_memrcaseeqlen(__a, strnlen(__a, __n), __b, strnlen(__b, __n)); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline size_t +libsimple_strrncaseeqlen(const char *a__, const char *b__, size_t n__) +{ + return libsimple_memrcaseeqlen(a__, strnlen(a__, n__), b__, strnlen(b__, n__)); +} #ifndef strrncaseeqlen # define strrncaseeqlen libsimple_strrncaseeqlen #endif @@ -544,9 +568,13 @@ static inline size_t libsimple_strrncaseeqlen(const char *__a, const char *__b, * @param n The maximum number of bytes to move * @return `d` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char *libsimple_strnmove(char *__d, const char *__s, size_t __n) -{ size_t __len = strnlen(__s, __n); return memmove(__d, __s, __len + (__len < __n)); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +static inline char * +libsimple_strnmove(char *d__, const char *s__, size_t n__) +{ + size_t len__ = strnlen(s__, n__); + return memmove(d__, s__, len__ + (len__ < n__)); +} #ifndef strnmove # define strnmove libsimple_strnmove #endif @@ -561,13 +589,13 @@ static inline char *libsimple_strnmove(char *__d, const char *__s, size_t __n) * @param n The maximum number of bytes to move * @return `&d[strnlen(s, n)]` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_stpnmove(char *__d, const char *__s, size_t __n) +libsimple_stpnmove(char *d__, const char *s__, size_t n__) { - size_t __len = strnlen(__s, __n); - memmove(__d, __s, __len + (__len < __n)); - return &__d[__len]; + size_t len__ = strnlen(s__, n__); + memmove(d__, s__, len__ + (len__ < n__)); + return &d__[len__]; } #ifndef stpnmove # define stpnmove libsimple_stpnmove @@ -582,13 +610,13 @@ libsimple_stpnmove(char *__d, const char *__s, size_t __n) * @param n The maximum number of bytes to write * @return `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_strnset(char *__s, int __c_, size_t __n) +libsimple_strnset(char *s__, int c___, size_t n__) { - char __c = (char)__c_, *__r = __s; - for (; __n && *__s; __n--) *__s++ = __c; - return __r; + char c__ = (char)c___, *r__ = s__; + for (; n__ && *s__; n__--) *s__++ = c__; + return r__; } #ifndef strnset # define strnset libsimple_strnset @@ -603,13 +631,13 @@ libsimple_strnset(char *__s, int __c_, size_t __n) * @param n The maximum number of bytes to write * @return `&s[strnlen(s, n)]` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_stpnset(char *__s, int __c_, size_t __n) +libsimple_stpnset(char *s__, int c___, size_t n__) { - char __c = (char)__c_; - for (; __n && *__s; __n--) *__s++ = __c; - return __s; + char c__ = (char)c___; + for (; n__ && *s__; n__--) *s__++ = c__; + return s__; } #ifndef stpnset # define stpnset libsimple_stpnset @@ -628,21 +656,21 @@ libsimple_stpnset(char *__s, int __c_, size_t __n) * @return `&strchr(d, c)[1]` (after copying) if `c` can be * found in `s`, `NULL` otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) static inline char * -libsimple_strnccpy(char *restrict __d, const char *restrict __s, int __c_, size_t __n) +libsimple_strnccpy(char *restrict d__, const char *restrict s__, int c___, size_t n__) { - char __c = (char)__c_, *__end = &__d[__n]; + char c__ = (char)c___, *end__ = &d__[n__]; do { - if (!__n) + if (!n__) break; - if ((*__d++ = *__s) == __c) { - if (__d != __end) - *__d = '\0'; - return __d; + if ((*d__++ = *s__) == c__) { + if (d__ != end__) + *d__ = '\0'; + return d__; } - __n--; - } while (*__s++); + n__--; + } while (*s__++); return NULL; } #ifndef strnccpy @@ -661,7 +689,7 @@ libsimple_strnccpy(char *restrict __d, const char *restrict __s, int __c_, size_ * found within the first `n` bytes of `s` (before * copying), `NULL` otherwise */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) char *libsimple_strncmove(char *, const char *, int, size_t); #ifndef strncmove # define strncmove libsimple_strncmove @@ -678,15 +706,15 @@ char *libsimple_strncmove(char *, const char *, int, size_t); * @param n The maximum length of `s` * @return `strnchr(s, '\0', n)` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) static inline char * -libsimple_strnreplace(char *__s, int __old_, int __new_, size_t __n) +libsimple_strnreplace(char *s__, int old___, int new___, size_t n__) { - char __old = (char)__old_, __new = (char)__new_; - for (; __n && *__s; __s++, __n--) - if (*__s == __old) - *__s = __new; - return __s; + char old__ = (char)old___, new__ = (char)new___; + for (; n__ && *s__; s__++, n__--) + if (*s__ == old__) + *s__ = new__; + return s__; } #ifndef strnreplace # define strnreplace libsimple_strnreplace @@ -706,7 +734,7 @@ libsimple_strnreplace(char *__s, int __old_, int __new_, size_t __n) * @param n The maximum number of bytes to copy or convert * @return `strnchrnul(d, '\0', n)` (after copying) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) char *libsimple_stpntolower(char *, const char *, size_t); #ifndef stpntolower # define stpntolower libsimple_stpntolower @@ -726,7 +754,7 @@ char *libsimple_stpntolower(char *, const char *, size_t); * @param n The maximum number of bytes to copy or convert * @return `strnchrnul(d, '\0', n)` (after copying) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) char *libsimple_stpntoupper(char *, const char *, size_t); #ifndef stpntoupper # define stpntoupper libsimple_stpntoupper @@ -746,9 +774,13 @@ char *libsimple_stpntoupper(char *, const char *, size_t); * @param n The maximum number of bytes to copy or convert * @return `d` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char *libsimple_strntolower(char *__d, const char *__s, size_t __n) -{ libsimple_stpntolower(__d, __s, __n); return __d; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) +static inline char * +libsimple_strntolower(char *d__, const char *s__, size_t n__) +{ + libsimple_stpntolower(d__, s__, n__); + return d__; +} #ifndef strntolower # define strntolower libsimple_strntolower #endif @@ -767,9 +799,13 @@ static inline char *libsimple_strntolower(char *__d, const char *__s, size_t __n * @param n The maximum number of bytes to copy or convert * @return `d` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char *libsimple_strntoupper(char *__d, const char *__s, size_t __n) -{ libsimple_stpntoupper(__d, __s, __n); return __d; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) +static inline char * +libsimple_strntoupper(char *d__, const char *s__, size_t n__) +{ + libsimple_stpntoupper(d__, s__, n__); + return d__; +} #ifndef strntoupper # define strntoupper libsimple_strntoupper #endif @@ -787,9 +823,12 @@ static inline char *libsimple_strntoupper(char *__d, const char *__s, size_t __n * allows a two-byte encoding for NUL * @return 1 if good, 0 on encoding error */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int libsimple_strnisutf8(const char *__string, size_t __n, int __allow_modified_nul) -{ return libsimple_memisutf8(__string, strnlen(__string, __n) ,__allow_modified_nul); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) +static inline int +libsimple_strnisutf8(const char *string__, size_t n__, int allow_modified_nul__) +{ + return libsimple_memisutf8(string__, strnlen(string__, n__), allow_modified_nul__); +} #ifndef strnisutf8 # define strnisutf8 libsimple_strnisutf8 #endif diff --git a/libsimple/strndup.h b/libsimple/strndup.h index 6259a1e..ccf3842 100644 --- a/libsimple/strndup.h +++ b/libsimple/strndup.h @@ -10,14 +10,15 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_strndupa(s, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const char *__s = (s);\ - size_t __n = strnlen(__s, n);\ - char *__r;\ - __r = alloca(__n + 1);\ - memcpy(__r, __s, __n);\ - __r[__n] = '\0';\ - __r;\ + const char *s__ = (s);\ + size_t n__ = strnlen(s__, n);\ + char *r__;\ + r__ = alloca(n__ + 1);\ + memcpy(r__, s__, n__);\ + r__[n__] = '\0';\ + r__;\ }) # ifndef strndupa # define strndupa(s, n) libsimple_strndupa(s, n) @@ -33,7 +34,7 @@ * @param n The maximum number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) char *libsimple_enstrndup(int, const char *, size_t); #ifndef enstrndup # define enstrndup libsimple_enstrndup @@ -47,11 +48,11 @@ char *libsimple_enstrndup(int, const char *, size_t); * @param n The maximum number of bytes to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) inline char * -libsimple_estrndup(const char *__s, size_t __n) +libsimple_estrndup(const char *s__, size_t n__) { - return libsimple_enstrndup(libsimple_default_failure_exit, __s, __n); + return libsimple_enstrndup(libsimple_default_failure_exit, s__, n__); } #ifndef estrndup # define estrndup libsimple_estrndup diff --git a/libsimple/strtoint.h b/libsimple/strtoint.h index ba2c92e..a342045 100644 --- a/libsimple/strtoint.h +++ b/libsimple/strtoint.h @@ -17,7 +17,7 @@ * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) signed char libsimple_strtohh(const char *restrict, char **restrict, int); #ifndef strtohh # define strtohh libsimple_strtohh @@ -40,7 +40,7 @@ signed char libsimple_strtohh(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) unsigned char libsimple_strtouhh(const char *restrict, char **restrict, int); #ifndef strtouhh # define strtouhh libsimple_strtouhh @@ -63,7 +63,7 @@ unsigned char libsimple_strtouhh(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) signed short int libsimple_strtoh(const char *restrict, char **restrict, int); #ifndef strtoh # define strtoh libsimple_strtoh @@ -86,7 +86,7 @@ signed short int libsimple_strtoh(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) unsigned short int libsimple_strtouh(const char *restrict, char **restrict, int); #ifndef strtouh # define strtouh libsimple_strtouh @@ -109,7 +109,7 @@ unsigned short int libsimple_strtouh(const char *restrict, char **restrict, int) * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) signed int libsimple_strtoi(const char *restrict, char **restrict, int); #ifndef strtoi # define strtoi libsimple_strtoi @@ -132,7 +132,7 @@ signed int libsimple_strtoi(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) unsigned int libsimple_strtou(const char *restrict, char **restrict, int); #ifndef strtou # define strtou libsimple_strtou @@ -155,11 +155,11 @@ unsigned int libsimple_strtou(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) inline ssize_t -libsimple_strtoz(const char *restrict __nptr, char **restrict __endptr, int __base) +libsimple_strtoz(const char *restrict nptr__, char **restrict endptr__, int base__) { - return (ssize_t)strtol(__nptr, __endptr, __base); + return (ssize_t)strtol(nptr__, endptr__, base__); } #ifndef strtoz # define strtoz libsimple_strtoz @@ -182,11 +182,11 @@ libsimple_strtoz(const char *restrict __nptr, char **restrict __endptr, int __ba * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) inline size_t -libsimple_strtouz(const char *restrict __nptr, char **restrict __endptr, int __base) +libsimple_strtouz(const char *restrict nptr__, char **restrict endptr__, int base__) { - return (size_t)strtoul(__nptr, __endptr, __base); + return (size_t)strtoul(nptr__, endptr__, base__); } #ifndef strtouz # define strtouz libsimple_strtouz @@ -209,7 +209,7 @@ libsimple_strtouz(const char *restrict __nptr, char **restrict __endptr, int __b * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) int_least8_t libsimple_strtoi8(const char *restrict, char **restrict, int); #ifndef strtoi8 # define strtoi8 libsimple_strtoi8 @@ -232,7 +232,7 @@ int_least8_t libsimple_strtoi8(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) uint_least8_t libsimple_strtou8(const char *restrict, char **restrict, int); #ifndef strtou8 # define strtou8 libsimple_strtou8 @@ -255,7 +255,7 @@ uint_least8_t libsimple_strtou8(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) int_least16_t libsimple_strtoi16(const char *restrict, char **restrict, int); #ifndef strtoi16 # define strtoi16 libsimple_strtoi16 @@ -278,7 +278,7 @@ int_least16_t libsimple_strtoi16(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) uint_least16_t libsimple_strtou16(const char *restrict, char **restrict, int); #ifndef strtou16 # define strtou16 libsimple_strtou16 @@ -301,7 +301,7 @@ uint_least16_t libsimple_strtou16(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) int_least32_t libsimple_strtoi32(const char *restrict, char **restrict, int); #ifndef strtoi32 # define strtoi32 libsimple_strtoi32 @@ -324,7 +324,7 @@ int_least32_t libsimple_strtoi32(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) uint_least32_t libsimple_strtou32(const char *restrict, char **restrict, int); #ifndef strtou32 # define strtou32 libsimple_strtou32 @@ -347,7 +347,7 @@ uint_least32_t libsimple_strtou32(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) int_least64_t libsimple_strtoi64(const char *restrict, char **restrict, int); #ifndef strtoi64 # define strtoi64 libsimple_strtoi64 @@ -370,7 +370,7 @@ int_least64_t libsimple_strtoi64(const char *restrict, char **restrict, int); * closed value that can be represented; 0 on * failure (unless `errno` not set to `ERANGE`) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __warn_unused_result__))) uint_least64_t libsimple_strtou64(const char *restrict, char **restrict, int); #ifndef strtou64 # define strtou64 libsimple_strtou64 diff --git a/libsimple/time.h b/libsimple/time.h index 71c19fe..6618d9d 100644 --- a/libsimple/time.h +++ b/libsimple/time.h @@ -13,7 +13,7 @@ * result too large and `{.tv_sec = TIME_MIN, .tv_nsec = 0L}` * if the result too small */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_sumtimespec(struct timespec *, const struct timespec *, const struct timespec *); #ifndef sumtimespec # define sumtimespec libsimple_sumtimespec @@ -32,7 +32,7 @@ int libsimple_sumtimespec(struct timespec *, const struct timespec *, const stru * result too large and `{.tv_sec = TIME_MIN, .tv_nsec = 0L}` * if the result too small */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_difftimespec(struct timespec *, const struct timespec *, const struct timespec *); #ifndef difftimespec # define difftimespec libsimple_difftimespec @@ -51,7 +51,7 @@ int libsimple_difftimespec(struct timespec *, const struct timespec *, const str * result too large and `{.tv_sec = TIME_MIN, .tv_nsec = 0L}` * if the result too small */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_multimespec(struct timespec *, const struct timespec *, int); #ifndef multimespec # define multimespec libsimple_multimespec @@ -65,13 +65,13 @@ int libsimple_multimespec(struct timespec *, const struct timespec *, int); * @param b The other `struct timespec` * @return -1 if `a` < `b`, 0 if `a` = `b`, and +1 if `a` > `b` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__))) -static inline int -libsimple_cmptimespec(const struct timespec *__a, const struct timespec *__b) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__))) +inline int +libsimple_cmptimespec(const struct timespec *a__, const struct timespec *b__) { - if (__a->tv_sec != __b->tv_sec) - return __a->tv_sec < __b->tv_sec ? -1 : +1; - return __a->tv_nsec < __b->tv_nsec ? -1 : __a->tv_nsec > __b->tv_nsec; + if (a__->tv_sec != b__->tv_sec) + return a__->tv_sec < b__->tv_sec ? -1 : +1; + return a__->tv_nsec < b__->tv_nsec ? -1 : a__->tv_nsec > b__->tv_nsec; } #ifndef cmptimespec # define cmptimespec libsimple_cmptimespec @@ -90,7 +90,7 @@ libsimple_cmptimespec(const struct timespec *__a, const struct timespec *__b) * result too large and `{.tv_sec = TIME_MIN, .tv_usec = 0L}` * if the result too small */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_sumtimeval(struct timeval *, const struct timeval *, const struct timeval *); #ifndef sumtimeval # define sumtimeval libsimple_sumtimeval @@ -109,7 +109,7 @@ int libsimple_sumtimeval(struct timeval *, const struct timeval *, const struct * result too large and `{.tv_sec = TIME_MIN, .tv_usec = 0L}` * if the result too small */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_difftimeval(struct timeval *, const struct timeval *, const struct timeval *); #ifndef difftimeval # define difftimeval libsimple_difftimeval @@ -128,7 +128,7 @@ int libsimple_difftimeval(struct timeval *, const struct timeval *, const struct * result too large and `{.tv_sec = TIME_MIN, .tv_usec = 0L}` * if the result too small */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_multimeval(struct timeval *, const struct timeval *, int); #ifndef multimeval # define multimeval libsimple_multimeval @@ -142,13 +142,13 @@ int libsimple_multimeval(struct timeval *, const struct timeval *, int); * @param b The other `struct timeval` * @return -1 if `a` < `b`, 0 if `a` = `b`, and +1 if `a` > `b` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__))) -static inline int -libsimple_cmptimeval(const struct timeval *__a, const struct timeval *__b) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__))) +inline int +libsimple_cmptimeval(const struct timeval *a__, const struct timeval *b__) { - if (__a->tv_sec != __b->tv_sec) - return __a->tv_sec < __b->tv_sec ? -1 : +1; - return __a->tv_usec < __b->tv_usec ? -1 : __a->tv_usec > __b->tv_usec; + if (a__->tv_sec != b__->tv_sec) + return a__->tv_sec < b__->tv_sec ? -1 : +1; + return a__->tv_usec < b__->tv_usec ? -1 : a__->tv_usec > b__->tv_usec; } #ifndef cmptimeval # define cmptimeval libsimple_cmptimeval @@ -161,13 +161,13 @@ libsimple_cmptimeval(const struct timeval *__a, const struct timeval *__b) * @param ts Output parameter for the result * @param tv The value to convert */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline void -libsimple_timeval2timespec(struct timespec *restrict __ts, const struct timeval *restrict __tv) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline void +libsimple_timeval2timespec(struct timespec *restrict ts__, const struct timeval *restrict tv__) { - __ts->tv_sec = __tv->tv_sec; - __ts->tv_nsec = __tv->tv_usec; - __ts->tv_nsec *= 1000L; + ts__->tv_sec = tv__->tv_sec; + ts__->tv_nsec = tv__->tv_usec; + ts__->tv_nsec *= 1000L; } #ifndef timeval2timespec # define timeval2timespec libsimple_timeval2timespec @@ -183,7 +183,7 @@ libsimple_timeval2timespec(struct timespec *restrict __ts, const struct timeval * @throws EOVERFLOW The value is too large to be convert, the value will be * truncated to `{.tv_sec = TIME_MAX, .tv_usec = 999999L}` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) int libsimple_timespec2timeval(struct timeval *restrict, const struct timespec *restrict); #ifndef timespec2timeval # define timespec2timeval libsimple_timespec2timeval @@ -208,7 +208,7 @@ int libsimple_timespec2timeval(struct timeval *restrict, const struct timespec * * result too large and `{.tv_sec = TIME_MIN, .tv_nsec = 0L}` * if the result too small (`*end` is set) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1, 2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1, 2)))) int libsimple_strtotimespec(struct timespec *restrict, const char *restrict, char **restrict); #ifndef strtotimespec # define strtotimespec libsimple_strtotimespec @@ -233,7 +233,7 @@ int libsimple_strtotimespec(struct timespec *restrict, const char *restrict, cha * result too large and `{.tv_sec = TIME_MIN, .tv_usec = 0L}` * if the result too small (`*end` is set) */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1, 2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1, 2)))) int libsimple_strtotimeval(struct timeval *restrict, const char *restrict, char **restrict); #ifndef strtotimeval # define strtotimeval libsimple_strtotimeval @@ -252,7 +252,7 @@ int libsimple_strtotimeval(struct timeval *restrict, const char *restrict, char * @throws ENOMEM Output buffer could not be allocated (only if `buf == NULL`) * @throws EINVAL `ts->tv_nsec` is negative or greater than 999999999 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) char *libsimple_timespectostr(char *restrict, const struct timespec *restrict); #ifndef timespectostr # define timespectostr libsimple_timespectostr @@ -271,7 +271,7 @@ char *libsimple_timespectostr(char *restrict, const struct timespec *restrict); * @throws ENOMEM Output buffer could not be allocated (only if `buf == NULL`) * @throws EINVAL `ts->tv_usec` is negative or greater than 999999 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) char *libsimple_timevaltostr(char *restrict, const struct timeval *restrict); #ifndef timevaltostr # define timevaltostr libsimple_timevaltostr @@ -284,14 +284,14 @@ char *libsimple_timevaltostr(char *restrict, const struct timeval *restrict); * @param ts The value to convert * @return The result */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline double -libsimple_timespectodouble(const struct timespec *__ts) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline double +libsimple_timespectodouble(const struct timespec *ts__) { - double __ret = (double)(__ts->tv_nsec); - __ret /= (double)1000000000L; - __ret += (double)(__ts->tv_sec); - return __ret; + double ret__ = (double)(ts__->tv_nsec); + ret__ /= (double)1000000000L; + ret__ += (double)(ts__->tv_sec); + return ret__; } #ifndef timespectodouble # define timespectodouble libsimple_timespectodouble @@ -304,14 +304,14 @@ libsimple_timespectodouble(const struct timespec *__ts) * @param tv The value to convert * @return The result */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline double -libsimple_timevaltodouble(const struct timeval *__tv) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline double +libsimple_timevaltodouble(const struct timeval *tv__) { - double __ret = (double)(__tv->tv_usec); - __ret /= (double)1000000L; - __ret += (double)(__tv->tv_sec); - return __ret; + double ret__ = (double)(tv__->tv_usec); + ret__ /= (double)1000000L; + ret__ += (double)(tv__->tv_sec); + return ret__; } #ifndef timevaltodouble # define timevaltodouble libsimple_timevaltodouble @@ -326,7 +326,7 @@ libsimple_timevaltodouble(const struct timeval *__tv) * @param ts Output parameter for the result * @param d The value to convert */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) void libsimple_doubletotimespec(struct timespec *, double); #ifndef doubletotimespec # define doubletotimespec libsimple_doubletotimespec @@ -341,7 +341,7 @@ void libsimple_doubletotimespec(struct timespec *, double); * @param tv Output parameter for the result * @param d The value to convert */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) void libsimple_doubletotimeval(struct timeval *, double); #ifndef doubletotimeval # define doubletotimeval libsimple_doubletotimeval @@ -356,7 +356,7 @@ void libsimple_doubletotimeval(struct timeval *, double); * @param s The string to minimise * @return `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__returns_nonnull__, __nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__returns_nonnull__, __nonnull__))) char *libsimple_minimise_number_string(char *); #ifndef minimise_number_string # define minimise_number_string libsimple_minimise_number_string @@ -374,7 +374,7 @@ char *libsimple_minimise_number_string(char *); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) int libsimple_localtime(struct tm *, struct timespec *); /** @@ -392,7 +392,7 @@ int libsimple_localtime(struct tm *, struct timespec *); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) void libsimple_enlocaltime(int, struct tm *, struct timespec *); /** @@ -409,9 +409,12 @@ void libsimple_enlocaltime(int, struct tm *, struct timespec *); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void libsimple_elocaltime(struct tm *__tm, struct timespec *__ts) -{ libsimple_enlocaltime(libsimple_default_failure_exit, __tm, __ts); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_elocaltime(struct tm *tm__, struct timespec *ts__) +{ + libsimple_enlocaltime(libsimple_default_failure_exit, tm__, ts__); +} /** @@ -425,7 +428,7 @@ static inline void libsimple_elocaltime(struct tm *__tm, struct timespec *__ts) * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) int libsimple_gmtime(struct tm *, struct timespec *); /** @@ -443,7 +446,7 @@ int libsimple_gmtime(struct tm *, struct timespec *); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2)))) void libsimple_engmtime(int, struct tm *, struct timespec *); /** @@ -460,6 +463,9 @@ void libsimple_engmtime(int, struct tm *, struct timespec *); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) -static inline void libsimple_egmtime(struct tm *__tm, struct timespec *__ts) -{ libsimple_engmtime(libsimple_default_failure_exit, __tm, __ts); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1)))) +inline void +libsimple_egmtime(struct tm *tm__, struct timespec *ts__) +{ + libsimple_engmtime(libsimple_default_failure_exit, tm__, ts__); +} diff --git a/libsimple/valloc.h b/libsimple/valloc.h index c0fcd03..55e8fd5 100644 --- a/libsimple/valloc.h +++ b/libsimple/valloc.h @@ -17,9 +17,12 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void *libsimple_vvallocn(size_t __n, va_list __ap) -{ return libsimple_vvalloczn(0, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +static inline void * +libsimple_vvallocn(size_t n__, va_list ap__) +{ + return libsimple_vvalloczn(0, n__, ap__); +} #ifndef vvallocn # define vvallocn libsimple_vvallocn #endif @@ -35,9 +38,12 @@ static inline void *libsimple_vvallocn(size_t __n, va_list __ap) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__))) -static inline void *libsimple_valloc(size_t __n) -{ return libsimple_vallocz(0, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__))) +static inline void * +libsimple_valloc(size_t n__) +{ + return libsimple_vallocz(0, n__); +} #ifndef valloc # define valloc libsimple_valloc #endif @@ -59,14 +65,14 @@ static inline void *libsimple_valloc(size_t __n) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) static inline void * -libsimple_vallocn(size_t __n, ... /*, (size_t)0 */) +libsimple_vallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vvallocn(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vvallocn(n__, ap__); + va_end(ap__); } #ifndef vallocn # define vallocn libsimple_vallocn @@ -87,9 +93,12 @@ libsimple_vallocn(size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envalloc(int __status, size_t __n) -{ return libsimple_envallocz(__status, 0, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_envalloc(int status__, size_t n__) +{ + return libsimple_envallocz(status__, 0, n__); +} #ifndef envalloc # define envalloc libsimple_envalloc #endif @@ -114,9 +123,12 @@ static inline void *libsimple_envalloc(int __status, size_t __n) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_envvallocn(int __status, size_t __n, va_list __ap) -{ return libsimple_envvalloczn(__status, 0, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_envvallocn(int status__, size_t n__, va_list ap__) +{ + return libsimple_envvalloczn(status__, 0, n__, ap__); +} #ifndef envvallocn # define envvallocn libsimple_envvallocn #endif @@ -141,14 +153,14 @@ static inline void *libsimple_envvallocn(int __status, size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_envallocn(int __status, size_t __n, ... /*, (size_t)0 */) +libsimple_envallocn(int status__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envvalloczn(__status, 0, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envvalloczn(status__, 0, n__, ap__); + va_end(ap__); } #ifndef envallocn # define envallocn libsimple_envallocn @@ -168,9 +180,12 @@ libsimple_envallocn(int __status, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evalloc(size_t __n) -{ return libsimple_envalloc(libsimple_default_failure_exit, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evalloc(size_t n__) +{ + return libsimple_envalloc(libsimple_default_failure_exit, n__); +} #ifndef evalloc # define evalloc libsimple_evalloc #endif @@ -194,9 +209,12 @@ static inline void *libsimple_evalloc(size_t __n) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evvallocn(size_t __n, va_list __ap) -{ return libsimple_envvallocn(libsimple_default_failure_exit, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +static inline void * +libsimple_evvallocn(size_t n__, va_list ap__) +{ + return libsimple_envvallocn(libsimple_default_failure_exit, n__, ap__); +} #ifndef evvallocn # define evvallocn libsimple_evvallocn #endif @@ -220,14 +238,14 @@ static inline void *libsimple_evvallocn(size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) static inline void * -libsimple_evallocn(size_t __n, ... /*, (size_t)0 */) +libsimple_evallocn(size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evvallocn(__n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evvallocn(n__, ap__); + va_end(ap__); } #ifndef evallocn # define evallocn libsimple_evallocn diff --git a/libsimple/vallocz.h b/libsimple/vallocz.h index 3d8b4ec..5c8258e 100644 --- a/libsimple/vallocz.h +++ b/libsimple/vallocz.h @@ -18,12 +18,12 @@ * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_vvalloczn(int __clear, size_t __n, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_vvalloczn(int clear__, size_t n__, va_list ap__) { - return libsimple_memalloc(0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, __n, __ap, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_memalloc(0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, n__, ap__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); } @@ -43,12 +43,12 @@ libsimple_vvalloczn(int __clear, size_t __n, va_list __ap) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) -static inline void * -libsimple_vallocz(int __clear, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) +inline void * +libsimple_vallocz(int clear__, size_t n__) { - return libsimple_memalloc(__n, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_memalloc(n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); } @@ -74,14 +74,14 @@ libsimple_vallocz(int __clear, size_t __n) * @throws EINVAL `n` is 0 * @throws ENOMEM Could not allocated enough memory */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_valloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +libsimple_valloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_vvalloczn(__clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_vvalloczn(clear__, n__, ap__); + va_end(ap__); } #ifndef valloczn # define valloczn libsimple_valloczn @@ -103,12 +103,12 @@ libsimple_valloczn(int __clear, size_t __n, ... /*, (size_t)0 */) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_envallocz(int __status, int __clear, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_envallocz(int status__, int clear__, size_t n__) { - return libsimple_enmemalloc(__status, __n, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_enmemalloc(status__, n__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); } @@ -138,13 +138,13 @@ libsimple_envallocz(int __status, int __clear, size_t __n) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_envvalloczn(int __status, int __clear, size_t __n, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_envvalloczn(int status__, int clear__, size_t n__, va_list ap__) { - return libsimple_enmemalloc(__status, - 0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, __n, __ap, - LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, __clear, + return libsimple_enmemalloc(status__, + 0, LIBSIMPLE_MEMALLOC_1_VA_PRODUCT_SIZE, n__, ap__, + LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT, clear__, LIBSIMPLE_MEMALLOC_PAGE_ALIGNMENT, LIBSIMPLE_MEMALLOC_END); } @@ -174,14 +174,14 @@ libsimple_envvalloczn(int __status, int __clear, size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_envalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_envalloczn(int status__, int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_envvalloczn(__status, __clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_envvalloczn(status__, clear__, n__, ap__); + va_end(ap__); } #ifndef envalloczn # define envalloczn libsimple_envalloczn @@ -202,9 +202,12 @@ libsimple_envalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */ * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evallocz(int __clear, size_t __n) -{ return libsimple_envallocz(libsimple_default_failure_exit, __clear, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_evallocz(int clear__, size_t n__) +{ + return libsimple_envallocz(libsimple_default_failure_exit, clear__, n__); +} #ifndef evallocz # define evallocz libsimple_evallocz #endif @@ -229,9 +232,12 @@ static inline void *libsimple_evallocz(int __clear, size_t __n) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_evvalloczn(int __clear, size_t __n, va_list __ap) -{ return libsimple_envvalloczn(libsimple_default_failure_exit, __clear, __n, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_evvalloczn(int clear__, size_t n__, va_list ap__) +{ + return libsimple_envvalloczn(libsimple_default_failure_exit, clear__, n__, ap__); +} #ifndef evvalloczn # define evvalloczn libsimple_evvalloczn #endif @@ -256,14 +262,14 @@ static inline void *libsimple_evvalloczn(int __clear, size_t __n, va_list __ap) * @return A unique pointer with at least the specified size * and with page size alignment */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_evalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_evalloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { - va_list __ap; - va_start(__ap, __n); - return libsimple_evvalloczn(__clear, __n, __ap); - va_end(__ap); + va_list ap__; + va_start(ap__, n__); + return libsimple_evvalloczn(clear__, n__, ap__); + va_end(ap__); } #ifndef evalloczn # define evalloczn libsimple_evalloczn diff --git a/libsimple/wcsdup.h b/libsimple/wcsdup.h index 8a2e8d2..9b15103 100644 --- a/libsimple/wcsdup.h +++ b/libsimple/wcsdup.h @@ -9,11 +9,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wcsdupa(s)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const wchar_t *__s = (s);\ - size_t __n = wcslen(__s) + 1;\ - wchar_t *__r = alloca(__n * sizeof(wchar_t));\ - wmemcpy(__r, __s, __n);\ + const wchar_t *s__ = (s);\ + size_t n__ = wcslen(s__) + 1;\ + wchar_t *r__ = alloca(n__ * sizeof(wchar_t));\ + wmemcpy(r__, s__, n__);\ }) # ifndef wcsdupa # define wcsdupa(s) libsimple_wcsdupa(s) @@ -28,7 +29,7 @@ * @param s The string to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __nonnull__, +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __nonnull__, __warn_unused_result__, __returns_nonnull__))) wchar_t *libsimple_enwcsdup(int, const wchar_t *); #ifndef enwcsdup @@ -42,12 +43,12 @@ wchar_t *libsimple_enwcsdup(int, const wchar_t *); * @param s The string to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __nonnull__, __warn_unused_result__, __returns_nonnull__))) inline wchar_t * -libsimple_ewcsdup(const wchar_t *__s) +libsimple_ewcsdup(const wchar_t *s__) { - return enwcsdup(libsimple_default_failure_exit, __s); + return enwcsdup(libsimple_default_failure_exit, s__); } #ifndef ewcsdup # define ewcsdup libsimple_ewcsdup diff --git a/libsimple/wcsndup.h b/libsimple/wcsndup.h index 583ce65..0d36a25 100644 --- a/libsimple/wcsndup.h +++ b/libsimple/wcsndup.h @@ -10,14 +10,15 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wcsndupa(s, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const wchar_t *__s = (s);\ - size_t __n = wcsnlen(__s, n);\ - wchar_t *__r;\ - __r = alloca((__n + 1) * sizeof(wchar_t));\ - wmemcpy(__r, __s, __n);\ - __r[__n] = 0;\ - __r;\ + const wchar_t *s__ = (s);\ + size_t n__ = wcsnlen(s__, n);\ + wchar_t *r__;\ + r__ = alloca((n__ + 1) * sizeof(wchar_t));\ + wmemcpy(r__, s__, n__);\ + r__[n__] = 0;\ + r__;\ }) # ifndef wcsndupa # define wcsndupa(s, n) libsimple_wcsndupa(s, n) @@ -32,7 +33,7 @@ * @param n The maximum number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __nonnull__, +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __nonnull__, __warn_unused_result__))) wchar_t *libsimple_wcsndup(const wchar_t *, size_t); #ifndef wcsndup @@ -48,7 +49,7 @@ wchar_t *libsimple_wcsndup(const wchar_t *, size_t); * @param n The maximum number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __nonnull__, +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __nonnull__, __warn_unused_result__, __returns_nonnull__))) wchar_t *libsimple_enwcsndup(int, const wchar_t *, size_t); #ifndef enwcsndup @@ -63,12 +64,12 @@ wchar_t *libsimple_enwcsndup(int, const wchar_t *, size_t); * @param n The maximum number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __nonnull__, __warn_unused_result__, __returns_nonnull__))) inline wchar_t * -libsimple_ewcsndup(const wchar_t *__s, size_t __n) +libsimple_ewcsndup(const wchar_t *s__, size_t n__) { - return libsimple_enwcsndup(libsimple_default_failure_exit, __s, __n); + return libsimple_enwcsndup(libsimple_default_failure_exit, s__, n__); } #ifndef ewcsndup # define ewcsndup libsimple_ewcsndup diff --git a/libsimple/wmemdup.h b/libsimple/wmemdup.h index 9c63cbc..467aa61 100644 --- a/libsimple/wmemdup.h +++ b/libsimple/wmemdup.h @@ -10,11 +10,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wmemdupa(s, n)\ + LIBSIMPLE_GCC_ONLY__(__extension__)\ ({\ - const wchar_t *__s = (s);\ - size_t __n = (n);\ - wchar_t *__r = alloca(__n * sizeof(wchar_t) + !__n);\ - wmemcpy(__r, __s, __n);\ + const wchar_t *s__ = (s);\ + size_t n__ = (n);\ + wchar_t *r__ = alloca(n__ * sizeof(wchar_t) + !n__);\ + wmemcpy(r__, s__, n__);\ }) # ifndef wmemdupa # define wmemdupa(s, n) libsimple_wmemdupa(s, n) @@ -29,7 +30,7 @@ * @param n The number of wide characters to copy * @return Duplicate of `s`, `NULL` on failure */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __alloc_size__(2), __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __alloc_size__(2), __warn_unused_result__))) wchar_t *libsimple_wmemdup(const wchar_t *, size_t); #ifndef wmemdup # define wmemdup libsimple_wmemdup @@ -44,7 +45,7 @@ wchar_t *libsimple_wmemdup(const wchar_t *, size_t); * @param n The number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __alloc_size__(3), +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) wchar_t *libsimple_enwmemdup(int, const wchar_t *, size_t); #ifndef enwmemdup @@ -59,12 +60,12 @@ wchar_t *libsimple_enwmemdup(int, const wchar_t *, size_t); * @param n The number of wide characters to copy * @return Duplicate of `s` */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, _libsimple_assume_aligned_as(wchar_t), __alloc_size__(2), +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, libsimple_assume_aligned_as__(wchar_t), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) inline wchar_t * -libsimple_ewmemdup(const wchar_t *__s, size_t __n) +libsimple_ewmemdup(const wchar_t *s__, size_t n__) { - return libsimple_enwmemdup(libsimple_default_failure_exit, __s, __n); + return libsimple_enwmemdup(libsimple_default_failure_exit, s__, n__); } #ifndef ewmemdup # define ewmemdup libsimple_ewmemdup diff --git a/man3/libsimple_aligned_allocz.3 b/man3/libsimple_aligned_allocz.3 index 0bee4d9..b61232b 100644 --- a/man3/libsimple_aligned_allocz.3 +++ b/man3/libsimple_aligned_allocz.3 @@ -6,9 +6,9 @@ libsimple_aligned_allocz \- allocate optionally initialised memory with custom a .nf #include -static inline void *libsimple_aligned_allocz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_aligned_allocz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); void *libsimple_enaligned_allocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_ealigned_allocz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_ealigned_allocz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_allocz # define aligned_allocz libsimple_aligned_allocz diff --git a/man3/libsimple_aligned_memdup.3 b/man3/libsimple_aligned_memdup.3 index cff094d..14d6c7a 100644 --- a/man3/libsimple_aligned_memdup.3 +++ b/man3/libsimple_aligned_memdup.3 @@ -9,7 +9,7 @@ libsimple_aligned_memdup, libsimple_aligned_memdupa \- duplicate bytes in memory void *libsimple_aligned_memdupa(const void *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); void *libsimple_aligned_memdup(const void *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); void *libsimple_enaligned_memdup(int \fIstatus\fP, const void *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_ealigned_memdup(const void *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_ealigned_memdup(const void *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_memdupa # define aligned_memdupa libsimple_aligned_memdupa diff --git a/man3/libsimple_aligned_realloc.3 b/man3/libsimple_aligned_realloc.3 index 1845408..0e176b9 100644 --- a/man3/libsimple_aligned_realloc.3 +++ b/man3/libsimple_aligned_realloc.3 @@ -6,9 +6,9 @@ libsimple_aligned_realloc \- reallocate memory and customise alignment .nf #include -static inline void *libsimple_aligned_realloc(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_aligned_realloc(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); void *libsimple_enaligned_realloc(int \fIstatus\fP, void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_ealigned_realloc(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_ealigned_realloc(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_realloc # define aligned_realloc libsimple_aligned_realloc diff --git a/man3/libsimple_aligned_reallocarray.3 b/man3/libsimple_aligned_reallocarray.3 index e056c72..c4cc765 100644 --- a/man3/libsimple_aligned_reallocarray.3 +++ b/man3/libsimple_aligned_reallocarray.3 @@ -6,9 +6,9 @@ libsimple_aligned_reallocarray \- reallocate memory and customise alignment .nf #include -static inline void *libsimple_aligned_reallocarray(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_aligned_reallocarray(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); void *libsimple_enaligned_reallocarray(int \fIstatus\fP, void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); -static inline void *libsimple_ealigned_reallocarray(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_ealigned_reallocarray(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); #ifndef aligned_reallocarray # define aligned_reallocarray libsimple_aligned_reallocarray diff --git a/man3/libsimple_aligned_reallocarrayf.3 b/man3/libsimple_aligned_reallocarrayf.3 index 998d49a..46a4057 100644 --- a/man3/libsimple_aligned_reallocarrayf.3 +++ b/man3/libsimple_aligned_reallocarrayf.3 @@ -6,7 +6,7 @@ libsimple_aligned_reallocarrayf \- reallocate memory and customise alignment .nf #include -static inline void *libsimple_aligned_reallocarrayf(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_aligned_reallocarrayf(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, size_t \fIm\fP); #ifndef aligned_reallocarrayf # define aligned_reallocarrayf libsimple_aligned_reallocarrayf diff --git a/man3/libsimple_aligned_reallocf.3 b/man3/libsimple_aligned_reallocf.3 index 97d6dff..4ad9fcc 100644 --- a/man3/libsimple_aligned_reallocf.3 +++ b/man3/libsimple_aligned_reallocf.3 @@ -6,7 +6,7 @@ libsimple_aligned_reallocf \- reallocate memory and customise alignment .nf #include -static inline void *libsimple_aligned_reallocf(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_aligned_reallocf(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_reallocf # define aligned_reallocf libsimple_aligned_reallocf diff --git a/man3/libsimple_aligned_strdup.3 b/man3/libsimple_aligned_strdup.3 index 1570e68..c365a18 100644 --- a/man3/libsimple_aligned_strdup.3 +++ b/man3/libsimple_aligned_strdup.3 @@ -9,7 +9,7 @@ libsimple_aligned_strdup, libsimple_aligned_strdupa \- duplicate a string char *libsimple_aligned_strdupa(const char *\fIs\fP, size_t \fIn\fP); char *libsimple_aligned_strdup(const char *\fIs\fP, size_t \fIn\fP); char *libsimple_enaligned_strdup(int \fIstatus\fP, const char *\fIs\fP, size_t \fIn\fP); -static inline char *libsimple_ealigned_strdup(const char *\fIs\fP, size_t \fIn\fP); +inline char *libsimple_ealigned_strdup(const char *\fIs\fP, size_t \fIn\fP); #ifndef aligned_strdupa # define aligned_strdupa libsimple_aligned_strdupa diff --git a/man3/libsimple_aligned_strndup.3 b/man3/libsimple_aligned_strndup.3 index 05c6d3a..773f0ee 100644 --- a/man3/libsimple_aligned_strndup.3 +++ b/man3/libsimple_aligned_strndup.3 @@ -9,7 +9,7 @@ libsimple_aligned_strndup, libsimple_aligned_strndupa \- duplicate a string char *libsimple_aligned_strndupa(const char *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); char *libsimple_aligned_strndup(const char *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); char *libsimple_enaligned_strndup(int \fIstatus\fP, const char *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline char *libsimple_ealigned_strndup(const char *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline char *libsimple_ealigned_strndup(const char *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_strndupa # define aligned_strndupa libsimple_aligned_strndupa diff --git a/man3/libsimple_aligned_wcsdup.3 b/man3/libsimple_aligned_wcsdup.3 index 42f9cd9..6332064 100644 --- a/man3/libsimple_aligned_wcsdup.3 +++ b/man3/libsimple_aligned_wcsdup.3 @@ -9,7 +9,7 @@ libsimple_aligned_wcsdup, libsimple_aligned_wcsdupa \- duplicate a wide-characte wchar_t *libsimple_aligned_wcsdupa(const wchar_t *\fIs\fP, size_t \fIalignment\fP); wchar_t *libsimple_aligned_wcsdup(const wchar_t *\fIs\fP, size_t \fIalignment\fP); wchar_t *libsimple_enaligned_wcsdup(int \fIstatus\fP, const wchar_t *\fIs\fP, size_t \fIalignment\fP); -static inline wchar_t *libsimple_ealigned_wcsdup(const wchar_t *\fIs\fP, size_t \fIalignment\fP); +inline wchar_t *libsimple_ealigned_wcsdup(const wchar_t *\fIs\fP, size_t \fIalignment\fP); #ifndef aligned_wcsdupa # define aligned_wcsdupa libsimple_aligned_wcsdupa diff --git a/man3/libsimple_aligned_wcsndup.3 b/man3/libsimple_aligned_wcsndup.3 index 669b790..f70a099 100644 --- a/man3/libsimple_aligned_wcsndup.3 +++ b/man3/libsimple_aligned_wcsndup.3 @@ -9,7 +9,7 @@ libsimple_aligned_wcsndup, libsimple_aligned_wcsndupa \- duplicate a wide-charac wchar_t *libsimple_aligned_wcsndupa(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); wchar_t *libsimple_aligned_wcsndup(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); wchar_t *libsimple_enaligned_wcsndup(int \fIstatus\fP, const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline wchar_t *libsimple_ealigned_wcsndup(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline wchar_t *libsimple_ealigned_wcsndup(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_wcsndupa # define aligned_wcsndupa libsimple_aligned_wcsndupa diff --git a/man3/libsimple_aligned_wmemdup.3 b/man3/libsimple_aligned_wmemdup.3 index a269082..353d716 100644 --- a/man3/libsimple_aligned_wmemdup.3 +++ b/man3/libsimple_aligned_wmemdup.3 @@ -9,7 +9,7 @@ libsimple_aligned_wmemdup, libsimple_aligned_wmemdupa \- duplicate a wide-charac wchar_t *libsimple_aligned_wmemdupa(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); wchar_t *libsimple_aligned_wmemdup(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); wchar_t *libsimple_enaligned_wmemdup(int \fIstatus\fP, const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline wchar_t *libsimple_ealigned_wmemdup(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline wchar_t *libsimple_ealigned_wmemdup(const wchar_t *\fIs\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef aligned_wmemdupa # define aligned_wmemdupa libsimple_aligned_wmemdupa diff --git a/man3/libsimple_close.3 b/man3/libsimple_close.3 index d9fb852..7050899 100644 --- a/man3/libsimple_close.3 +++ b/man3/libsimple_close.3 @@ -6,7 +6,7 @@ libsimple_close \- close file descriptor and mark it as closed .nf #include -static inline int libsimple_close(int *\fIfdp\fP); +inline int libsimple_close(int *\fIfdp\fP); .fi .PP Link with diff --git a/man3/libsimple_cmptimespec.3 b/man3/libsimple_cmptimespec.3 index 9d6869a..34de111 100644 --- a/man3/libsimple_cmptimespec.3 +++ b/man3/libsimple_cmptimespec.3 @@ -6,8 +6,8 @@ libsimple_cmptimespec, libsimple_cmptimeval \- calculate the sum of two duration .nf #include -static inline int libsimple_cmptimespec(const struct timespec *\fIa\fP, const struct timespec *\fIb\fP); -static inline int libsimple_cmptimeval(const struct timeval *\fIa\fP, const struct timeval *\fIb\fP); +inline int libsimple_cmptimespec(const struct timespec *\fIa\fP, const struct timespec *\fIb\fP); +inline int libsimple_cmptimeval(const struct timeval *\fIa\fP, const struct timeval *\fIb\fP); #ifndef cmptimespec # define cmptimespec libsimple_cmptimespec diff --git a/man3/libsimple_enaligned_alloc.3 b/man3/libsimple_enaligned_alloc.3 index 27abe3d..0e6c4c7 100644 --- a/man3/libsimple_enaligned_alloc.3 +++ b/man3/libsimple_enaligned_alloc.3 @@ -6,8 +6,8 @@ libsimple_enaligned_alloc \- allocate memory with custom alignment or die .nf #include -static inline void *libsimple_enaligned_alloc(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_ealigned_alloc(size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_enaligned_alloc(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_ealigned_alloc(size_t \fIalignment\fP, size_t \fIn\fP); #ifndef enaligned_alloc # define enaligned_alloc libsimple_enaligned_alloc diff --git a/man3/libsimple_encalloc.3 b/man3/libsimple_encalloc.3 index 905bdd2..c373fa5 100644 --- a/man3/libsimple_encalloc.3 +++ b/man3/libsimple_encalloc.3 @@ -7,7 +7,7 @@ libsimple_encalloc \- allocate initialised memory or die #include void *libsimple_encalloc(int \fIstatus\fP, size_t \fIn\fP, size_t \fIm\fP); -static inline void *libsimple_ecalloc(size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_ecalloc(size_t \fIn\fP, size_t \fIm\fP); #ifndef encalloc # define encalloc libsimple_encalloc diff --git a/man3/libsimple_enmalloc.3 b/man3/libsimple_enmalloc.3 index 975f44c..c1d166a 100644 --- a/man3/libsimple_enmalloc.3 +++ b/man3/libsimple_enmalloc.3 @@ -7,7 +7,7 @@ libsimple_enmalloc \- allocate memory or die #include void *libsimple_enmalloc(int \fIstatus\fP, size_t \fIn\fP); -static inline void *libsimple_emalloc(size_t \fIn\fP); +inline void *libsimple_emalloc(size_t \fIn\fP); #ifndef enmalloc # define enmalloc libsimple_enmalloc diff --git a/man3/libsimple_enposix_memalign.3 b/man3/libsimple_enposix_memalign.3 index 1d8ec20..33df98e 100644 --- a/man3/libsimple_enposix_memalign.3 +++ b/man3/libsimple_enposix_memalign.3 @@ -6,8 +6,8 @@ libsimple_enposix_memalign \- allocate memory with custom alignment or die .nf #include -static inline void libsimple_enposix_memalign(int \fIstatus\fP, void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void libsimple_eposix_memalign(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void libsimple_enposix_memalign(int \fIstatus\fP, void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void libsimple_eposix_memalign(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef enposix_memalign # define enposix_memalign libsimple_enposix_memalign diff --git a/man3/libsimple_enrealloc.3 b/man3/libsimple_enrealloc.3 index 829a0f5..430fecd 100644 --- a/man3/libsimple_enrealloc.3 +++ b/man3/libsimple_enrealloc.3 @@ -7,7 +7,7 @@ libsimple_enrealloc \- reallocate memory or die #include void *libsimple_enrealloc(int \fIstatus\fP, void *\fIptr\fP, size_t \fIn\fP); -static inline void *libsimple_erealloc(void *\fIptr\fP, size_t \fIn\fP); +inline void *libsimple_erealloc(void *\fIptr\fP, size_t \fIn\fP); #ifndef enrealloc # define enrealloc libsimple_enrealloc diff --git a/man3/libsimple_enstrdup.3 b/man3/libsimple_enstrdup.3 index 33cc6c7..b6224f4 100644 --- a/man3/libsimple_enstrdup.3 +++ b/man3/libsimple_enstrdup.3 @@ -8,7 +8,7 @@ libsimple_enstrdup, libsimple_strdupa \- duplicate a string char *libsimple_strdupa(const char *\fIs\fP); char *libsimple_enstrdup(int \fIstatus\fP, const char *\fIs\fP); -static inline char *libsimple_estrdup(const char *\fIs\fP); +inline char *libsimple_estrdup(const char *\fIs\fP); #ifndef strdupa # define strdupa libsimple_strdupa diff --git a/man3/libsimple_enstrndup.3 b/man3/libsimple_enstrndup.3 index 2c62600..455f895 100644 --- a/man3/libsimple_enstrndup.3 +++ b/man3/libsimple_enstrndup.3 @@ -8,7 +8,7 @@ libsimple_enstrndup, libsimple_strndupa \- duplicate the beginning of a string char *libsimple_strndupa(const char *\fIs\fP, size_t \fIn\fP); char *libsimple_enstrndup(int \fIstatus\fP, const char *\fIs\fP, size_t \fIn\fP); -static inline char *libsimple_estrndup(const char *\fIs\fP, size_t \fIn\fP); +inline char *libsimple_estrndup(const char *\fIs\fP, size_t \fIn\fP); #ifndef strndupa # define strndupa libsimple_strndupa diff --git a/man3/libsimple_enwcsdup.3 b/man3/libsimple_enwcsdup.3 index df013a8..10560b4 100644 --- a/man3/libsimple_enwcsdup.3 +++ b/man3/libsimple_enwcsdup.3 @@ -8,7 +8,7 @@ libsimple_enwcsdup, libsimple_wcsdupa \- duplicate a wide-character string wchar_t *libsimple_wcsdupa(const wchar_t *\fIs\fP); wchar_t *libsimple_enwcsdup(int \fIstatus\fP, const wchar_t *\fIs\fP); -static inline char *libsimple_ewcsdup(const wchar_t *\fIs\fP); +inline char *libsimple_ewcsdup(const wchar_t *\fIs\fP); #ifndef wcsdupa # define wcsdupa libsimple_wcsdupa diff --git a/man3/libsimple_getenv_e.3 b/man3/libsimple_getenv_e.3 index 0ed445b..c9d12e3 100644 --- a/man3/libsimple_getenv_e.3 +++ b/man3/libsimple_getenv_e.3 @@ -6,7 +6,7 @@ libsimple_getenv_e \- get value of an environment variable or the empty string .nf #include -static inline const char *libsimple_getenv_e(const char *\fIname\fP); +inline const char *libsimple_getenv_e(const char *\fIname\fP); #ifndef getenv_e # define getenv_e libsimple_getenv_e diff --git a/man3/libsimple_getenv_ne.3 b/man3/libsimple_getenv_ne.3 index 69c7de8..574b78e 100644 --- a/man3/libsimple_getenv_ne.3 +++ b/man3/libsimple_getenv_ne.3 @@ -6,7 +6,7 @@ libsimple_getenv_ne \- get non-empty value of an environment variable .nf #include -static inline char *libsimple_getenv_ne(const char *\fIname\fP); +inline char *libsimple_getenv_ne(const char *\fIname\fP); #ifndef getenv_ne # define getenv_ne libsimple_getenv_ne diff --git a/man3/libsimple_gmtime.3 b/man3/libsimple_gmtime.3 index be050f2..ac5ab17 100644 --- a/man3/libsimple_gmtime.3 +++ b/man3/libsimple_gmtime.3 @@ -7,8 +7,8 @@ libsimple_gmtime \- get the current UTC time with leap second adjustment #include int libsimple_gmtime(struct tm *\fItm\fP, struct timespec *\fIts\fP); -static inline void libsimple_engmtime(int \fIstatus\fPstruct tm *\fItm\fP, struct timespec *\fIts\fP); -static inline void libsimple_egmtime(struct tm *\fItm\fP, struct timespec *\fIts\fP); +inline void libsimple_engmtime(int \fIstatus\fPstruct tm *\fItm\fP, struct timespec *\fIts\fP); +inline void libsimple_egmtime(struct tm *\fItm\fP, struct timespec *\fIts\fP); .fi .PP Link with diff --git a/man3/libsimple_inchrset.3 b/man3/libsimple_inchrset.3 index 44a3eb1..07d1fe4 100644 --- a/man3/libsimple_inchrset.3 +++ b/man3/libsimple_inchrset.3 @@ -6,8 +6,8 @@ libsimple_inchrset, libsimple_inchrcaseset \- the whether a character belongs to .nf #include -static inline int libsimple_inchrset(int \fIc\fP, const char *\fIs\fP); -static inline int libsimple_inchrcaseset(int \fIc\fP, const char *\fIs\fP); +inline int libsimple_inchrset(int \fIc\fP, const char *\fIs\fP); +inline int libsimple_inchrcaseset(int \fIc\fP, const char *\fIs\fP); #ifndef inchrset # define inchrset libsimple_inchrset diff --git a/man3/libsimple_localtime.3 b/man3/libsimple_localtime.3 index 0f6aa19..18e0375 100644 --- a/man3/libsimple_localtime.3 +++ b/man3/libsimple_localtime.3 @@ -7,8 +7,8 @@ libsimple_localtime \- get the current local time with leap second adjustment #include int libsimple_localtime(struct tm *\fItm\fP, struct timespec *\fIts\fP); -static inline void libsimple_enlocaltime(int \fIstatus\fPstruct tm *\fItm\fP, struct timespec *\fIts\fP); -static inline void libsimple_elocaltime(struct tm *\fItm\fP, struct timespec *\fIts\fP); +inline void libsimple_enlocaltime(int \fIstatus\fPstruct tm *\fItm\fP, struct timespec *\fIts\fP); +inline void libsimple_elocaltime(struct tm *\fItm\fP, struct timespec *\fIts\fP); .fi .PP Link with diff --git a/man3/libsimple_mallocz.3 b/man3/libsimple_mallocz.3 index 54ca3e7..e04c0c7 100644 --- a/man3/libsimple_mallocz.3 +++ b/man3/libsimple_mallocz.3 @@ -6,9 +6,9 @@ libsimple_mallocz \- allocate optionally initialised memory .nf #include -static inline void *libsimple_mallocz(int \fIclear\fP, size_t \fIn\fP); -static inline void *libsimple_enmallocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP); -static inline void *libsimple_emallocz(int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_mallocz(int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_enmallocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_emallocz(int \fIclear\fP, size_t \fIn\fP); #ifndef mallocz # define mallocz libsimple_mallocz diff --git a/man3/libsimple_memalign.3 b/man3/libsimple_memalign.3 index 8bbf57e..d8b0c89 100644 --- a/man3/libsimple_memalign.3 +++ b/man3/libsimple_memalign.3 @@ -6,9 +6,9 @@ libsimple_memalign \- allocate memory with custom alignment .nf #include -static inline void *libsimple_memalign(size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_enmemalign(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_ememalign(size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_memalign(size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_enmemalign(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_ememalign(size_t \fIalignment\fP, size_t \fIn\fP); #ifndef memalign # define memalign libsimple_memalign diff --git a/man3/libsimple_memalignz.3 b/man3/libsimple_memalignz.3 index f756539..c7e0af2 100644 --- a/man3/libsimple_memalignz.3 +++ b/man3/libsimple_memalignz.3 @@ -6,9 +6,9 @@ libsimple_memalignz \- allocate optionally initialised memory with custom alignm .nf #include -static inline void *libsimple_memalignz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_enmemalignz(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void *libsimple_ememalignz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_memalignz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_enmemalignz(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void *libsimple_ememalignz(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef memalignz # define memalignz libsimple_memalignz diff --git a/man3/libsimple_memcasecmp.3 b/man3/libsimple_memcasecmp.3 index a7ccf79..e8852ae 100644 --- a/man3/libsimple_memcasecmp.3 +++ b/man3/libsimple_memcasecmp.3 @@ -6,7 +6,7 @@ libsimple_memcasecmp \- compare two memory segments .nf #include -static inline int libsimple_memcasecmp(const void *\fIa\fP, const void *\fIb\fP, size_t \fIn\fP); +inline int libsimple_memcasecmp(const void *\fIa\fP, const void *\fIb\fP, size_t \fIn\fP); #ifndef memcasecmp # define memcasecmp libsimple_memcasecmp diff --git a/man3/libsimple_memcaseeq.3 b/man3/libsimple_memcaseeq.3 index c48b7c5..3728cd7 100644 --- a/man3/libsimple_memcaseeq.3 +++ b/man3/libsimple_memcaseeq.3 @@ -6,7 +6,7 @@ libsimple_memcaseeq \- check two memory segments for equality .nf #include -static inline int libsimple_memcaseeq(const void *\fIa\fP, const void *\fIb\fP, size_t \fIn\fP); +inline int libsimple_memcaseeq(const void *\fIa\fP, const void *\fIb\fP, size_t \fIn\fP); #ifndef memcaseeq # define memcaseeq libsimple_memcaseeq diff --git a/man3/libsimple_memdup.3 b/man3/libsimple_memdup.3 index 8a6903d..756297c 100644 --- a/man3/libsimple_memdup.3 +++ b/man3/libsimple_memdup.3 @@ -9,7 +9,7 @@ libsimple_memdup \- duplicate bytes in memory void *libsimple_memdupa(const void *\fIs\fP, size_t \fIn\fP); void *libsimple_memdup(const void *\fIs\fP, size_t \fIn\fP); void *libsimple_enmemdup(int \fIstatus\fP, const void *\fIs\fP, size_t \fIn\fP); -static inline void *libsimple_ememdup(const void *\fIs\fP, size_t \fIn\fP); +inline void *libsimple_ememdup(const void *\fIs\fP, size_t \fIn\fP); #ifndef memdupa # define memdupa libsimple_memdupa diff --git a/man3/libsimple_memelemmove.3 b/man3/libsimple_memelemmove.3 index 194ff79..5422d12 100644 --- a/man3/libsimple_memelemmove.3 +++ b/man3/libsimple_memelemmove.3 @@ -6,8 +6,8 @@ libsimple_memelemmove, libsimple_memelemcpy \- copy or move elements within an a .nf #include -static inline void *libsimple_memelemmove(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP, size_t \fIn\fP); -static inline void *libsimple_memelemcpy(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP, size_t \fIn\fP); +inline void *libsimple_memelemmove(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP, size_t \fIn\fP); +inline void *libsimple_memelemcpy(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP, size_t \fIn\fP); #ifndef memelemmove # define memelemmove libsimple_memelemmove diff --git a/man3/libsimple_memeq.3 b/man3/libsimple_memeq.3 index a5683e5..a04e975 100644 --- a/man3/libsimple_memeq.3 +++ b/man3/libsimple_memeq.3 @@ -6,7 +6,7 @@ libsimple_memeq \- check two memory segments for equality .nf #include -static inline int libsimple_memeq(const void *\fIa\fP, const void *\fIb\fP, size_t \fIn\fP); +inline int libsimple_memeq(const void *\fIa\fP, const void *\fIb\fP, size_t \fIn\fP); #ifndef memeq # define memeq libsimple_memeq diff --git a/man3/libsimple_mempcpy.3 b/man3/libsimple_mempcpy.3 index a10bba0..3fe7865 100644 --- a/man3/libsimple_mempcpy.3 +++ b/man3/libsimple_mempcpy.3 @@ -6,7 +6,7 @@ libsimple_mempcpy \- copy an array of bytes into another .nf #include -static inline void *libsimple_mempcpy(void *restrict \fIdest\fP, const void *restrict \fIsrc\fP, size_t \fIn\fP); +inline void *libsimple_mempcpy(void *restrict \fIdest\fP, const void *restrict \fIsrc\fP, size_t \fIn\fP); #ifndef mempcpy # define mempcpy libsimple_mempcpy diff --git a/man3/libsimple_mempmove.3 b/man3/libsimple_mempmove.3 index 29b7e4e..8a89ea1 100644 --- a/man3/libsimple_mempmove.3 +++ b/man3/libsimple_mempmove.3 @@ -6,7 +6,7 @@ libsimple_mempmove \- move bytes within an array of bytes .nf #include -static inline void *libsimple_mempmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); +inline void *libsimple_mempmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); #ifndef mempmove # define mempmove libsimple_mempmove diff --git a/man3/libsimple_mempset.3 b/man3/libsimple_mempset.3 index 31ebd06..69e8951 100644 --- a/man3/libsimple_mempset.3 +++ b/man3/libsimple_mempset.3 @@ -6,7 +6,7 @@ libsimple_mempset \- fill an array of bytes .nf #include -static inline void *libsimple_mempset(void *\fIs\fP, int \fIc\fP, size_t \fIn\fP); +inline void *libsimple_mempset(void *\fIs\fP, int \fIc\fP, size_t \fIn\fP); #ifndef mempset # define mempset libsimple_mempset diff --git a/man3/libsimple_memreplace.3 b/man3/libsimple_memreplace.3 index 45800bb..c77e9ed 100644 --- a/man3/libsimple_memreplace.3 +++ b/man3/libsimple_memreplace.3 @@ -6,7 +6,7 @@ libsimple_memreplace \- replace bytes in an array of bytes .nf #include -static inline void *libsimple_memreplace(void *\fIs\fP, int \fIold\fP, int \fInew\fP, size_t \fIn\fP); +inline void *libsimple_memreplace(void *\fIs\fP, int \fIold\fP, int \fInew\fP, size_t \fIn\fP); #ifndef memreplace # define memreplace libsimple_memreplace diff --git a/man3/libsimple_memsetelem.3 b/man3/libsimple_memsetelem.3 index 37e7022..2bbf488 100644 --- a/man3/libsimple_memsetelem.3 +++ b/man3/libsimple_memsetelem.3 @@ -6,7 +6,7 @@ libsimple_memsetelem \- fill an array with a value .nf #include -static inline void *libsimple_memsetelem(void *\fIbuf\fP, const void *\fIitem\fP, size_t \fIwidth\fP, size_t \fIn\fP); +inline void *libsimple_memsetelem(void *\fIbuf\fP, const void *\fIitem\fP, size_t \fIwidth\fP, size_t \fIn\fP); #ifndef memsetelem # define memsetelem libsimple_memsetelem diff --git a/man3/libsimple_memtolower.3 b/man3/libsimple_memtolower.3 index facb09d..8e36915 100644 --- a/man3/libsimple_memtolower.3 +++ b/man3/libsimple_memtolower.3 @@ -6,7 +6,7 @@ libsimple_memtolower, libsimple_memptolower \- convert a character array to lowe .nf #include -static inline void *libsimple_memtolower(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); +inline void *libsimple_memtolower(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); void *libsimple_memptolower(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); #ifndef memtolower diff --git a/man3/libsimple_memtoupper.3 b/man3/libsimple_memtoupper.3 index 17a747c..cbac534 100644 --- a/man3/libsimple_memtoupper.3 +++ b/man3/libsimple_memtoupper.3 @@ -6,7 +6,7 @@ libsimple_memtoupper, libsimple_memptoupper \- convert a character array to uppe .nf #include -static inline void *libsimple_memtoupper(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); +inline void *libsimple_memtoupper(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); void *libsimple_memptoupper(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); #ifndef memtoupper diff --git a/man3/libsimple_posix_memalignz.3 b/man3/libsimple_posix_memalignz.3 index a82605f..e79e85b 100644 --- a/man3/libsimple_posix_memalignz.3 +++ b/man3/libsimple_posix_memalignz.3 @@ -6,9 +6,9 @@ libsimple_posix_memalignz \- allocate optionally initialised memory with custom .nf #include -static inline int libsimple_posix_memalignz(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline int libsimple_posix_memalignz(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); void libsimple_enposix_memalignz(int \fIstatus\fP, void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); -static inline void libsimple_eposix_memalignz(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); +inline void libsimple_eposix_memalignz(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP); #ifndef posix_memalignz # define posix_memalignz libsimple_posix_memalignz diff --git a/man3/libsimple_pvalloc.3 b/man3/libsimple_pvalloc.3 index 9440712..e552a51 100644 --- a/man3/libsimple_pvalloc.3 +++ b/man3/libsimple_pvalloc.3 @@ -6,9 +6,9 @@ libsimple_pvalloc \- allocate memory with page size alignment .nf #include -static inline void *libsimple_pvalloc(size_t \fIn\fP); -static inline void *libsimple_enpvalloc(int \fIstatus\fP, size_t \fIn\fP); -static inline void *libsimple_epvalloc(size_t \fIn\fP); +inline void *libsimple_pvalloc(size_t \fIn\fP); +inline void *libsimple_enpvalloc(int \fIstatus\fP, size_t \fIn\fP); +inline void *libsimple_epvalloc(size_t \fIn\fP); #ifndef pvalloc # define pvalloc libsimple_pvalloc diff --git a/man3/libsimple_pvallocz.3 b/man3/libsimple_pvallocz.3 index 1fcc898..d18253a 100644 --- a/man3/libsimple_pvallocz.3 +++ b/man3/libsimple_pvallocz.3 @@ -6,9 +6,9 @@ libsimple_pvallocz \- allocate optionally initialised memory with page size alig .nf #include -static inline void *libsimple_pvallocz(int \fIclear\fP, size_t \fIn\fP); -static inline void *libsimple_enpvallocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP); -static inline void *libsimple_epvallocz(int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_pvallocz(int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_enpvallocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_epvallocz(int \fIclear\fP, size_t \fIn\fP); #ifndef pvallocz # define pvallocz libsimple_pvallocz diff --git a/man3/libsimple_rawmemcmove.3 b/man3/libsimple_rawmemcmove.3 index d4df247..246ccfa 100644 --- a/man3/libsimple_rawmemcmove.3 +++ b/man3/libsimple_rawmemcmove.3 @@ -6,8 +6,8 @@ libsimple_rawmemcmove, libsimple_rawmemccpy \- copy or move bytes within an arra .nf #include -static inline void *libsimple_rawmemcmove(void *\fIdest\fP, const void *\fIsrc\fP, int \fIc\fP); -static inline void *libsimple_rawmemccpy(void *\fIdest\fP, const void *\fIsrc\fP, int \fIc\fP); +inline void *libsimple_rawmemcmove(void *\fIdest\fP, const void *\fIsrc\fP, int \fIc\fP); +inline void *libsimple_rawmemccpy(void *\fIdest\fP, const void *\fIsrc\fP, int \fIc\fP); #ifndef rawmemcmove # define rawmemcmove libsimple_rawmemcmove diff --git a/man3/libsimple_rawmemelemmove.3 b/man3/libsimple_rawmemelemmove.3 index da7b242..6b0f7a3 100644 --- a/man3/libsimple_rawmemelemmove.3 +++ b/man3/libsimple_rawmemelemmove.3 @@ -6,8 +6,8 @@ libsimple_rawmemelemmove, libsimple_rawmemelemcpy \- copy or move elements withi .nf #include -static inline void *libsimple_rawmemelemmove(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP); -static inline void *libsimple_rawmemelemcpy(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP); +inline void *libsimple_rawmemelemmove(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP); +inline void *libsimple_rawmemelemcpy(void *\fIdest\fP, const void *\fIsrc\fP, int \fIelem\fP, size_t \fIwidth\fP); #ifndef rawmemelemmove # define rawmemelemmove libsimple_rawmemelemmove diff --git a/man3/libsimple_reallocarray.3 b/man3/libsimple_reallocarray.3 index c6c6635..5626e63 100644 --- a/man3/libsimple_reallocarray.3 +++ b/man3/libsimple_reallocarray.3 @@ -6,9 +6,9 @@ libsimple_reallocarray \- reallocate memory .nf #include -static inline void *libsimple_reallocarray(void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); -static inline void *libsimple_enreallocarray(int \fIstatus\fP, void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); -static inline void *libsimple_ereallocarray(void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_reallocarray(void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_enreallocarray(int \fIstatus\fP, void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_ereallocarray(void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); #ifndef reallocarray # define reallocarray libsimple_reallocarray diff --git a/man3/libsimple_reallocarrayf.3 b/man3/libsimple_reallocarrayf.3 index b3c2504..f0d3104 100644 --- a/man3/libsimple_reallocarrayf.3 +++ b/man3/libsimple_reallocarrayf.3 @@ -6,7 +6,7 @@ libsimple_reallocarrayf \- reallocate memory .nf #include -static inline void *libsimple_reallocarrayf(void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); +inline void *libsimple_reallocarrayf(void *\fIptr\fP, size_t \fIn\fP, size_t \fIm\fP); #ifndef reallocarrayf # define reallocarrayf libsimple_reallocarrayf diff --git a/man3/libsimple_reallocf.3 b/man3/libsimple_reallocf.3 index b0c2d1b..d3b7523 100644 --- a/man3/libsimple_reallocf.3 +++ b/man3/libsimple_reallocf.3 @@ -6,7 +6,7 @@ libsimple_reallocf \- reallocate memory .nf #include -static inline void *libsimple_reallocf(void *\fIptr\fP, size_t \fIn\fP); +inline void *libsimple_reallocf(void *\fIptr\fP, size_t \fIn\fP); #ifndef reallocf # define reallocf libsimple_reallocf diff --git a/man3/libsimple_stpmove.3 b/man3/libsimple_stpmove.3 index d9e8db1..09eb764 100644 --- a/man3/libsimple_stpmove.3 +++ b/man3/libsimple_stpmove.3 @@ -6,7 +6,7 @@ libsimple_stpmove \- move a string within an array of bytes .nf #include -static inline void *libsimple_stpmove(void *\fIdest\fP, const void *\fIsrc\fP); +inline void *libsimple_stpmove(void *\fIdest\fP, const void *\fIsrc\fP); #ifndef stpmove # define stpmove libsimple_stpmove diff --git a/man3/libsimple_stpnmove.3 b/man3/libsimple_stpnmove.3 index f2fd267..7d3b4a9 100644 --- a/man3/libsimple_stpnmove.3 +++ b/man3/libsimple_stpnmove.3 @@ -6,7 +6,7 @@ libsimple_stpnmove \- move a string within an array of bytes .nf #include -static inline void *libsimple_stpnmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); +inline void *libsimple_stpnmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); #ifndef stpnmove # define stpnmove libsimple_stpnmove diff --git a/man3/libsimple_strcasecmpnul.3 b/man3/libsimple_strcasecmpnul.3 index 1f4561e..48b9dce 100644 --- a/man3/libsimple_strcasecmpnul.3 +++ b/man3/libsimple_strcasecmpnul.3 @@ -6,7 +6,7 @@ libsimple_strcasecmpnul \- compare two strings .nf #include -static inline int libsimple_strcasecmpnul(const char *\fIa\fP, const char *\fIb\fP); +inline int libsimple_strcasecmpnul(const char *\fIa\fP, const char *\fIb\fP); #ifndef strcasecmpnul # define strcasecmpnul libsimple_strcasecmpnul diff --git a/man3/libsimple_strcaseeq.3 b/man3/libsimple_strcaseeq.3 index e0dbf7f..737565a 100644 --- a/man3/libsimple_strcaseeq.3 +++ b/man3/libsimple_strcaseeq.3 @@ -6,7 +6,7 @@ libsimple_strcaseeq \- compare two strings .nf #include -static inline int libsimple_strcaseeq(const char *\fIa\fP, const char *\fIb\fP); +inline int libsimple_strcaseeq(const char *\fIa\fP, const char *\fIb\fP); #ifndef strcaseeq # define strcaseeq libsimple_strcaseeq diff --git a/man3/libsimple_strcaseeqnul.3 b/man3/libsimple_strcaseeqnul.3 index 27595b0..4e4ac0c 100644 --- a/man3/libsimple_strcaseeqnul.3 +++ b/man3/libsimple_strcaseeqnul.3 @@ -6,7 +6,7 @@ libsimple_strcaseeqnul \- compare two strings .nf #include -static inline int libsimple_strcaseeqnul(const char *\fIa\fP, const char *\fIb\fP); +inline int libsimple_strcaseeqnul(const char *\fIa\fP, const char *\fIb\fP); #ifndef strcaseeqnul # define strcaseeqnul libsimple_strcaseeqnul diff --git a/man3/libsimple_strcasestarts.3 b/man3/libsimple_strcasestarts.3 index bf6786c..2f30942 100644 --- a/man3/libsimple_strcasestarts.3 +++ b/man3/libsimple_strcasestarts.3 @@ -6,7 +6,7 @@ libsimple_strcasestarts \- check the beginning of a string .nf #include -static inline int libsimple_strcasestarts(const char *\fIs\fP, const char *\fIt\fP); +inline int libsimple_strcasestarts(const char *\fIs\fP, const char *\fIt\fP); #ifndef strcasestarts # define strcasestarts libsimple_strcasestarts diff --git a/man3/libsimple_strcmove.3 b/man3/libsimple_strcmove.3 index 4888832..44b3579 100644 --- a/man3/libsimple_strcmove.3 +++ b/man3/libsimple_strcmove.3 @@ -7,7 +7,7 @@ libsimple_strcmove, libsimple_strccpy \- copy or move a string within an array o #include char *libsimple_strcmove(char *\fIdest\fP, const char *\fIsrc\fP, int \fIc\fP); -static inline char *libsimple_strccpy(char *restrict \fIdest\fP, const char *restrict \fIsrc\fP, int \fIc\fP); +inline char *libsimple_strccpy(char *restrict \fIdest\fP, const char *restrict \fIsrc\fP, int \fIc\fP); #ifndef strcmove # define strcmove libsimple_strcmove diff --git a/man3/libsimple_strcmpnul.3 b/man3/libsimple_strcmpnul.3 index 01a512c..f196ded 100644 --- a/man3/libsimple_strcmpnul.3 +++ b/man3/libsimple_strcmpnul.3 @@ -6,7 +6,7 @@ libsimple_strcmpnul \- compare two strings .nf #include -static inline int libsimple_strcmpnul(const char *\fIa\fP, const char *\fIb\fP); +inline int libsimple_strcmpnul(const char *\fIa\fP, const char *\fIb\fP); #ifndef strcmpnul # define strcmpnul libsimple_strcmpnul diff --git a/man3/libsimple_strend.3 b/man3/libsimple_strend.3 index a3a1bfe..e046742 100644 --- a/man3/libsimple_strend.3 +++ b/man3/libsimple_strend.3 @@ -6,7 +6,7 @@ libsimple_strend \- find a character in a string .nf #include -static inline char *libsimple_strend(const char *\fIs\fP); +inline char *libsimple_strend(const char *\fIs\fP); #ifndef strend # define strend libsimple_strend diff --git a/man3/libsimple_streq.3 b/man3/libsimple_streq.3 index 2a1fada..372a85b 100644 --- a/man3/libsimple_streq.3 +++ b/man3/libsimple_streq.3 @@ -6,7 +6,7 @@ libsimple_streq \- compare two strings .nf #include -static inline int libsimple_streq(const char *\fIa\fP, const char *\fIb\fP); +inline int libsimple_streq(const char *\fIa\fP, const char *\fIb\fP); #ifndef streq # define streq libsimple_streq diff --git a/man3/libsimple_streqnul.3 b/man3/libsimple_streqnul.3 index f2d7d07..f2474ad 100644 --- a/man3/libsimple_streqnul.3 +++ b/man3/libsimple_streqnul.3 @@ -6,7 +6,7 @@ libsimple_streqnul \- compare two strings .nf #include -static inline int libsimple_streqnul(const char *\fIa\fP, const char *\fIb\fP); +inline int libsimple_streqnul(const char *\fIa\fP, const char *\fIb\fP); #ifndef streqnul # define streqnul libsimple_streqnul diff --git a/man3/libsimple_strisutf8.3 b/man3/libsimple_strisutf8.3 index 0a525f1..3eecce6 100644 --- a/man3/libsimple_strisutf8.3 +++ b/man3/libsimple_strisutf8.3 @@ -6,8 +6,8 @@ libsimple_strisutf8, libsimple_strnisutf8, libsimple_memisutf8 \- check if a str .nf #include -static inline int libsimple_strisutf8(const char *\fIstring\fP, int \fIallow_modified_nul\fP); -static inline int libsimple_strnisutf8(const char *\fIstring\fP, size_t \fIn\fP, int \fIallow_modified_nul\fP); +inline int libsimple_strisutf8(const char *\fIstring\fP, int \fIallow_modified_nul\fP); +inline int libsimple_strnisutf8(const char *\fIstring\fP, size_t \fIn\fP, int \fIallow_modified_nul\fP); int libsimple_memisutf8(const char *\fIstring\fP, size_t \fIn\fP, int \fIallow_modified_nul\fP); #ifndef strisutf8 diff --git a/man3/libsimple_strmove.3 b/man3/libsimple_strmove.3 index 1b03800..a0b492c 100644 --- a/man3/libsimple_strmove.3 +++ b/man3/libsimple_strmove.3 @@ -6,7 +6,7 @@ libsimple_strmove \- move a string within an array of bytes .nf #include -static inline char *libsimple_strmove(char *\fIdest\fP, const char *\fIsrc\fP); +inline char *libsimple_strmove(char *\fIdest\fP, const char *\fIsrc\fP); #ifndef strmove # define strmove libsimple_strmove diff --git a/man3/libsimple_strncasecmpnul.3 b/man3/libsimple_strncasecmpnul.3 index 25b7239..aa7272d 100644 --- a/man3/libsimple_strncasecmpnul.3 +++ b/man3/libsimple_strncasecmpnul.3 @@ -6,7 +6,7 @@ libsimple_strncasecmpnul \- compare two strings .nf #include -static inline int libsimple_strncasecmpnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline int libsimple_strncasecmpnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strncasecmpnul # define strncasecmpnul libsimple_strncasecmpnul diff --git a/man3/libsimple_strncaseeq.3 b/man3/libsimple_strncaseeq.3 index 5b7a6a9..ff880ac 100644 --- a/man3/libsimple_strncaseeq.3 +++ b/man3/libsimple_strncaseeq.3 @@ -6,7 +6,7 @@ libsimple_strncaseeq \- compare two strings .nf #include -static inline int libsimple_strncaseeq(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline int libsimple_strncaseeq(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strncaseeq # define strncaseeq libsimple_strncaseeq diff --git a/man3/libsimple_strncaseeqnul.3 b/man3/libsimple_strncaseeqnul.3 index b713996..0805f5a 100644 --- a/man3/libsimple_strncaseeqnul.3 +++ b/man3/libsimple_strncaseeqnul.3 @@ -6,7 +6,7 @@ libsimple_strncaseeqnul \- compare two strings .nf #include -static inline int libsimple_strncaseeqnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline int libsimple_strncaseeqnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strncaseeqnul # define strncaseeqnul libsimple_strncaseeqnul diff --git a/man3/libsimple_strncmove.3 b/man3/libsimple_strncmove.3 index 0f33ad9..4cdc0d3 100644 --- a/man3/libsimple_strncmove.3 +++ b/man3/libsimple_strncmove.3 @@ -7,7 +7,7 @@ libsimple_strncmove, libsimple_strnccpy \- copy or move a string within an array #include char *libsimple_strncmove(char *\fIdest\fP, const char *\fIsrc\fP, int \fIc\fP, size_t \fIn\fP); -static inline char *libsimple_strnccpy(char *restrict \fIdest\fP, const char *restrict \fIsrc\fP, int \fIc\fP, size_t \fIn\fP); +inline char *libsimple_strnccpy(char *restrict \fIdest\fP, const char *restrict \fIsrc\fP, int \fIc\fP, size_t \fIn\fP); #ifndef strncmove # define strncmove libsimple_strncmove diff --git a/man3/libsimple_strncmpnul.3 b/man3/libsimple_strncmpnul.3 index d6a6cbe..fbb1e53 100644 --- a/man3/libsimple_strncmpnul.3 +++ b/man3/libsimple_strncmpnul.3 @@ -6,7 +6,7 @@ libsimple_strncmpnul \- compare two strings .nf #include -static inline int libsimple_strncmpnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline int libsimple_strncmpnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strncmpnul # define strncmpnul libsimple_strncmpnul diff --git a/man3/libsimple_strnend.3 b/man3/libsimple_strnend.3 index c3d918d..f5c2f53 100644 --- a/man3/libsimple_strnend.3 +++ b/man3/libsimple_strnend.3 @@ -6,7 +6,7 @@ libsimple_strnend \- find a character in a string .nf #include -static inline char *libsimple_strnend(const char *\fIs\fP, size_t \fIn\fP); +inline char *libsimple_strnend(const char *\fIs\fP, size_t \fIn\fP); #ifndef strnend # define strnend libsimple_strnend diff --git a/man3/libsimple_strneq.3 b/man3/libsimple_strneq.3 index 43f2442..f447bc6 100644 --- a/man3/libsimple_strneq.3 +++ b/man3/libsimple_strneq.3 @@ -6,7 +6,7 @@ libsimple_strneq \- compare two strings .nf #include -static inline int libsimple_strneq(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline int libsimple_strneq(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strneq # define strneq libsimple_strneq diff --git a/man3/libsimple_strneqnul.3 b/man3/libsimple_strneqnul.3 index b3de167..96dcae6 100644 --- a/man3/libsimple_strneqnul.3 +++ b/man3/libsimple_strneqnul.3 @@ -6,7 +6,7 @@ libsimple_strneqnul \- compare two strings .nf #include -static inline int libsimple_strneqnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline int libsimple_strneqnul(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strneqnul # define strneqnul libsimple_strneqnul diff --git a/man3/libsimple_strnmove.3 b/man3/libsimple_strnmove.3 index 38c58f6..e817bb4 100644 --- a/man3/libsimple_strnmove.3 +++ b/man3/libsimple_strnmove.3 @@ -6,7 +6,7 @@ libsimple_strnmove \- move a string within an array of bytes .nf #include -static inline void *libsimple_strnmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); +inline void *libsimple_strnmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP); #ifndef strnmove # define strnmove libsimple_strnmove diff --git a/man3/libsimple_strnreplace.3 b/man3/libsimple_strnreplace.3 index fc8718c..0c73a2f 100644 --- a/man3/libsimple_strnreplace.3 +++ b/man3/libsimple_strnreplace.3 @@ -6,7 +6,7 @@ libsimple_strnreplace \- replace characters in a string .nf #include -static inline char *libsimple_strnreplace(char *\fIs\fP, int \fIold\fP, int \fInew\fP, size_t \fIn\fP); +inline char *libsimple_strnreplace(char *\fIs\fP, int \fIold\fP, int \fInew\fP, size_t \fIn\fP); #ifndef strnreplace # define strnreplace libsimple_strnreplace diff --git a/man3/libsimple_strnset.3 b/man3/libsimple_strnset.3 index 1a9ce21..1991b5d 100644 --- a/man3/libsimple_strnset.3 +++ b/man3/libsimple_strnset.3 @@ -6,8 +6,8 @@ libsimple_strnset, libsimple_stpnset \- fill a string with a character .nf #include -static inline char *libsimple_strnset(char *\fIs\fP, int \fIc\fP, size_t \fIn\fP); -static inline char *libsimple_stpnset(char *\fIs\fP, int \fIc\fP, size_t \fIn\fP); +inline char *libsimple_strnset(char *\fIs\fP, int \fIc\fP, size_t \fIn\fP); +inline char *libsimple_stpnset(char *\fIs\fP, int \fIc\fP, size_t \fIn\fP); #ifndef strnset # define strnset libsimple_strnset diff --git a/man3/libsimple_strntolower.3 b/man3/libsimple_strntolower.3 index 8c0f41c..061666e 100644 --- a/man3/libsimple_strntolower.3 +++ b/man3/libsimple_strntolower.3 @@ -6,7 +6,7 @@ libsimple_strntolower, libsimple_stpntolower \- convert a string to lower case .nf #include -static inline char *libsimple_strntolower(char *\fIdest\fP, const char *\fIsrc\fP, size_t \fIn\fP); +inline char *libsimple_strntolower(char *\fIdest\fP, const char *\fIsrc\fP, size_t \fIn\fP); char *libsimple_stpntolower(char *\fIdest\fP, const char *\fIsrc\fP, size_t \fIn\fP); #ifndef strntolower diff --git a/man3/libsimple_strntoupper.3 b/man3/libsimple_strntoupper.3 index abb3408..995f6bf 100644 --- a/man3/libsimple_strntoupper.3 +++ b/man3/libsimple_strntoupper.3 @@ -6,7 +6,7 @@ libsimple_strntoupper, libsimple_stpntoupper \- convert a string to upper case .nf #include -static inline char *libsimple_strntoupper(char *\fIdest\fP, const char *\fIsrc\fP, size_t \fIn\fP); +inline char *libsimple_strntoupper(char *\fIdest\fP, const char *\fIsrc\fP, size_t \fIn\fP); char *libsimple_stpntoupper(char *\fIdest\fP, const char *\fIsrc\fP, size_t \fIn\fP); #ifndef strntoupper diff --git a/man3/libsimple_strrcaseeqlen.3 b/man3/libsimple_strrcaseeqlen.3 index 714c65a..ac525b2 100644 --- a/man3/libsimple_strrcaseeqlen.3 +++ b/man3/libsimple_strrcaseeqlen.3 @@ -6,7 +6,7 @@ libsimple_strrcaseeqlen \- check terminal commonality .nf #include -static inline size_t libsimple_strrcaseeqlen(const char *\fIa\fP, const char *\fIb\fP); +inline size_t libsimple_strrcaseeqlen(const char *\fIa\fP, const char *\fIb\fP); #ifndef strrcaseeqlen # define strrcaseeqlen libsimple_strrcaseeqlen diff --git a/man3/libsimple_strreplace.3 b/man3/libsimple_strreplace.3 index 0cdedd8..aabff9a 100644 --- a/man3/libsimple_strreplace.3 +++ b/man3/libsimple_strreplace.3 @@ -6,7 +6,7 @@ libsimple_strreplace \- replace characters in a string .nf #include -static inline char *libsimple_strreplace(char *\fIs\fP, int \fIold\fP, int \fInew\fP); +inline char *libsimple_strreplace(char *\fIs\fP, int \fIold\fP, int \fInew\fP); #ifndef strreplace # define strreplace libsimple_strreplace diff --git a/man3/libsimple_strreqlen.3 b/man3/libsimple_strreqlen.3 index 16c785e..0933a83 100644 --- a/man3/libsimple_strreqlen.3 +++ b/man3/libsimple_strreqlen.3 @@ -6,7 +6,7 @@ libsimple_strreqlen \- check terminal commonality .nf #include -static inline size_t libsimple_strreqlen(const char *\fIa\fP, const char *\fIb\fP); +inline size_t libsimple_strreqlen(const char *\fIa\fP, const char *\fIb\fP); #ifndef strreqlen # define strreqlen libsimple_strreqlen diff --git a/man3/libsimple_strrncaseeqlen.3 b/man3/libsimple_strrncaseeqlen.3 index 0d245f0..8a001c1 100644 --- a/man3/libsimple_strrncaseeqlen.3 +++ b/man3/libsimple_strrncaseeqlen.3 @@ -6,7 +6,7 @@ libsimple_strrncaseeqlen \- check terminal commonality .nf #include -static inline size_t libsimple_strrncaseeqlen(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline size_t libsimple_strrncaseeqlen(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strrncaseeqlen # define strrncaseeqlen libsimple_strrncaseeqlen diff --git a/man3/libsimple_strrneqlen.3 b/man3/libsimple_strrneqlen.3 index eced333..8744c6d 100644 --- a/man3/libsimple_strrneqlen.3 +++ b/man3/libsimple_strrneqlen.3 @@ -6,7 +6,7 @@ libsimple_strrneqlen \- check terminal commonality .nf #include -static inline size_t libsimple_strrneqlen(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); +inline size_t libsimple_strrneqlen(const char *\fIa\fP, const char *\fIb\fP, size_t \fIn\fP); #ifndef strrneqlen # define strrneqlen libsimple_strrneqlen diff --git a/man3/libsimple_strset.3 b/man3/libsimple_strset.3 index 6ed9ff4..a635c74 100644 --- a/man3/libsimple_strset.3 +++ b/man3/libsimple_strset.3 @@ -6,8 +6,8 @@ libsimple_strset, libsimple_stpset \- fill a string with a character .nf #include -static inline char *libsimple_strset(char *\fIs\fP, int \fIc\fP); -static inline char *libsimple_stpset(char *\fIs\fP, int \fIc\fP); +inline char *libsimple_strset(char *\fIs\fP, int \fIc\fP); +inline char *libsimple_stpset(char *\fIs\fP, int \fIc\fP); #ifndef strset # define strset libsimple_strset diff --git a/man3/libsimple_strtolower.3 b/man3/libsimple_strtolower.3 index 8075dde..695f5eb 100644 --- a/man3/libsimple_strtolower.3 +++ b/man3/libsimple_strtolower.3 @@ -6,7 +6,7 @@ libsimple_strtolower, libsimple_stptolower \- convert a string to lower case .nf #include -static inline char *libsimple_strtolower(char *\fIdest\fP, const char *\fIsrc\fP); +inline char *libsimple_strtolower(char *\fIdest\fP, const char *\fIsrc\fP); char *libsimple_stptolower(char *\fIdest\fP, const char *\fIsrc\fP); #ifndef strtolower diff --git a/man3/libsimple_strtoupper.3 b/man3/libsimple_strtoupper.3 index 10333e5..75f3959 100644 --- a/man3/libsimple_strtoupper.3 +++ b/man3/libsimple_strtoupper.3 @@ -6,7 +6,7 @@ libsimple_strtoupper, libsimple_stptoupper \- convert a string to upper case .nf #include -static inline char *libsimple_strtoupper(char *\fIdest\fP, const char *\fIsrc\fP); +inline char *libsimple_strtoupper(char *\fIdest\fP, const char *\fIsrc\fP); char *libsimple_stptoupper(char *\fIdest\fP, const char *\fIsrc\fP); #ifndef strtoupper diff --git a/man3/libsimple_timespectodouble.3 b/man3/libsimple_timespectodouble.3 index 4413f8f..83cdcbc 100644 --- a/man3/libsimple_timespectodouble.3 +++ b/man3/libsimple_timespectodouble.3 @@ -6,8 +6,8 @@ libsimple_timespectodouble, libsimple_timevaltodouble \- convert a duration data .nf #include -static inline double libsimple_timespectodouble(const struct timespec *\fIts\fP); -static inline double libsimple_timevaltodouble(const struct timeval *\fItv\fP); +inline double libsimple_timespectodouble(const struct timespec *\fIts\fP); +inline double libsimple_timevaltodouble(const struct timeval *\fItv\fP); #ifndef timespectodouble # define timespectodouble libsimple_timespectodouble diff --git a/man3/libsimple_timeval2timespec.3 b/man3/libsimple_timeval2timespec.3 index f6dcf90..f827463 100644 --- a/man3/libsimple_timeval2timespec.3 +++ b/man3/libsimple_timeval2timespec.3 @@ -6,7 +6,7 @@ libsimple_timeval2timespec, libsimple_timespec2timeval \- convert between timesp .nf #include -static inline void libsimple_timeval2timespec(struct timespec *restrict \fIts\fP, const struct timeval *restrict \fItv\fP); +inline void libsimple_timeval2timespec(struct timespec *restrict \fIts\fP, const struct timeval *restrict \fItv\fP); int libsimple_timespec2timeval(struct timeval *restrict \fItv\fP, const struct timespec *restrict \fIts\fP); #ifndef timeval2timespec diff --git a/man3/libsimple_valigned_allocn.3 b/man3/libsimple_valigned_allocn.3 index ab93f30..59edbb5 100644 --- a/man3/libsimple_valigned_allocn.3 +++ b/man3/libsimple_valigned_allocn.3 @@ -6,12 +6,12 @@ libsimple_valigned_allocn \- allocate memory with custom alignment .nf #include -static inline void *libsimple_valigned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envaligned_allocn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evaligned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_aligned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enaligned_allocn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ealigned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_valigned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envaligned_allocn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evaligned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_aligned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enaligned_allocn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ealigned_allocn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef valigned_allocn # define valigned_allocn libsimple_valigned_allocn diff --git a/man3/libsimple_valigned_alloczn.3 b/man3/libsimple_valigned_alloczn.3 index c40979e..a272bb1 100644 --- a/man3/libsimple_valigned_alloczn.3 +++ b/man3/libsimple_valigned_alloczn.3 @@ -8,10 +8,10 @@ libsimple_valigned_alloczn \- allocate optionally initialised memory with custom void *libsimple_valigned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); void *libsimple_envaligned_alloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evaligned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_aligned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enaligned_alloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ealigned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_evaligned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_aligned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enaligned_alloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ealigned_alloczn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef valigned_alloczn # define valigned_alloczn libsimple_valigned_alloczn diff --git a/man3/libsimple_valigned_reallocfn.3 b/man3/libsimple_valigned_reallocfn.3 index 0acf175..2afa6c2 100644 --- a/man3/libsimple_valigned_reallocfn.3 +++ b/man3/libsimple_valigned_reallocfn.3 @@ -6,8 +6,8 @@ libsimple_valigned_reallocfn \- reallocate memory and customise alignment .nf #include -static inline void *libsimple_valigned_reallocfn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_aligned_reallocfn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_valigned_reallocfn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_aligned_reallocfn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef valigned_reallocfn # define valigned_reallocfn libsimple_valigned_reallocfn diff --git a/man3/libsimple_valigned_reallocn.3 b/man3/libsimple_valigned_reallocn.3 index 94baffb..607684b 100644 --- a/man3/libsimple_valigned_reallocn.3 +++ b/man3/libsimple_valigned_reallocn.3 @@ -8,10 +8,10 @@ libsimple_valigned_reallocn \- reallocate memory and customise alignment void *libsimple_valigned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); void *libsimple_envaligned_reallocn(int \fIstatus\fP, void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evaligned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_aligned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enaligned_reallocn(int \fIstatus\fP, void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ealigned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_evaligned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_aligned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enaligned_reallocn(int \fIstatus\fP, void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ealigned_reallocn(void *\fIptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef valigned_reallocn # define valigned_reallocn libsimple_valigned_reallocn diff --git a/man3/libsimple_valloc.3 b/man3/libsimple_valloc.3 index 97e7b97..d7b0114 100644 --- a/man3/libsimple_valloc.3 +++ b/man3/libsimple_valloc.3 @@ -6,9 +6,9 @@ libsimple_valloc \- allocate memory with page size alignment .nf #include -static inline void *libsimple_valloc(size_t \fIn\fP); -static inline void *libsimple_envalloc(int \fIstatus\fP, size_t \fIn\fP); -static inline void *libsimple_evalloc(size_t \fIn\fP); +inline void *libsimple_valloc(size_t \fIn\fP); +inline void *libsimple_envalloc(int \fIstatus\fP, size_t \fIn\fP); +inline void *libsimple_evalloc(size_t \fIn\fP); #ifndef valloc # define valloc libsimple_valloc diff --git a/man3/libsimple_vallocz.3 b/man3/libsimple_vallocz.3 index bc2f8b8..10138ed 100644 --- a/man3/libsimple_vallocz.3 +++ b/man3/libsimple_vallocz.3 @@ -6,9 +6,9 @@ libsimple_vallocz \- allocate optionally initialised memory with page size align .nf #include -static inline void *libsimple_vallocz(int \fIclear\fP, size_t \fIn\fP); -static inline void *libsimple_envallocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP); -static inline void *libsimple_evallocz(int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_vallocz(int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_envallocz(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP); +inline void *libsimple_evallocz(int \fIclear\fP, size_t \fIn\fP); #ifndef vallocz # define vallocz libsimple_vallocz diff --git a/man3/libsimple_vcallocn.3 b/man3/libsimple_vcallocn.3 index 449cfd6..8d32c6a 100644 --- a/man3/libsimple_vcallocn.3 +++ b/man3/libsimple_vcallocn.3 @@ -6,12 +6,12 @@ libsimple_vcallocn \- allocate memory .nf #include -static inline void *libsimple_vcallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envcallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evcallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_callocn(size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_encallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ecallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vcallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envcallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evcallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_callocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_encallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ecallocn(size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vcallocn # define vcallocn libsimple_vcallocn diff --git a/man3/libsimple_vmallocn.3 b/man3/libsimple_vmallocn.3 index 9383069..130743f 100644 --- a/man3/libsimple_vmallocn.3 +++ b/man3/libsimple_vmallocn.3 @@ -6,12 +6,12 @@ libsimple_vmallocn \- allocate memory .nf #include -static inline void *libsimple_vmallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envmallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evmallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_mallocn(size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enmallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_emallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vmallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envmallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evmallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_mallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enmallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_emallocn(size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vmallocn # define vmallocn libsimple_vmallocn diff --git a/man3/libsimple_vmalloczn.3 b/man3/libsimple_vmalloczn.3 index 67354e6..a16f0d8 100644 --- a/man3/libsimple_vmalloczn.3 +++ b/man3/libsimple_vmalloczn.3 @@ -8,10 +8,10 @@ libsimple_vmalloczn \- allocate optionally initialised memory void *libsimple_vmalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); void *libsimple_envmalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evmalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_malloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enmalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_emalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_evmalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_malloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enmalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_emalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vmalloczn # define vmalloczn libsimple_vmalloczn diff --git a/man3/libsimple_vmemalignn.3 b/man3/libsimple_vmemalignn.3 index 1f13cd7..96f7794 100644 --- a/man3/libsimple_vmemalignn.3 +++ b/man3/libsimple_vmemalignn.3 @@ -6,12 +6,12 @@ libsimple_vmemalignn \- allocate memory with custom alignment .nf #include -static inline void *libsimple_vmemalignn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envmemalignn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evmemalignn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_memalignn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enmemalignn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ememalignn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vmemalignn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envmemalignn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evmemalignn(size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_memalignn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enmemalignn(int \fIstatus\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ememalignn(size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vmemalignn # define vmemalignn libsimple_vmemalignn diff --git a/man3/libsimple_vmemalignzn.3 b/man3/libsimple_vmemalignzn.3 index d9b0434..d048701 100644 --- a/man3/libsimple_vmemalignzn.3 +++ b/man3/libsimple_vmemalignzn.3 @@ -6,12 +6,12 @@ libsimple_vmemalignzn \- allocate optionally initialised memory with custom alig .nf #include -static inline void *libsimple_vmemalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envmemalignzn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evmemalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_memalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enmemalignzn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ememalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vmemalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envmemalignzn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evmemalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_memalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enmemalignzn(int \fIstatus\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ememalignzn(int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vmemalignzn # define vmemalignzn libsimple_vmemalignzn diff --git a/man3/libsimple_vmemalloc.3 b/man3/libsimple_vmemalloc.3 index ab0b4c3..0be0b71 100644 --- a/man3/libsimple_vmemalloc.3 +++ b/man3/libsimple_vmemalloc.3 @@ -12,10 +12,10 @@ enum libsimple_memalloc_option { void *libsimple_vmemalloc(size_t \fIn\fP, va_list \fIap\fP); void *libsimple_envmemalloc(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evmemalloc(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_memalloc(size_t \fIn\fP, ..., /* LIBSIMPLE_MEMALLOC_END */); -static inline void *libsimple_enmemalloc(int \fIstatus\fP, size_t \fIn\fP, ..., /* LIBSIMPLE_MEMALLOC_END */); -static inline void *libsimple_ememalloc(size_t \fIn\fP, ..., /* LIBSIMPLE_MEMALLOC_END */); +inline void *libsimple_evmemalloc(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_memalloc(size_t \fIn\fP, ..., /* LIBSIMPLE_MEMALLOC_END */); +inline void *libsimple_enmemalloc(int \fIstatus\fP, size_t \fIn\fP, ..., /* LIBSIMPLE_MEMALLOC_END */); +inline void *libsimple_ememalloc(size_t \fIn\fP, ..., /* LIBSIMPLE_MEMALLOC_END */); .fi .PP Link with diff --git a/man3/libsimple_vposix_memalignn.3 b/man3/libsimple_vposix_memalignn.3 index b8da3e8..614165d 100644 --- a/man3/libsimple_vposix_memalignn.3 +++ b/man3/libsimple_vposix_memalignn.3 @@ -6,12 +6,12 @@ libsimple_vposix_memalignn \- allocate memory with custom alignment .nf #include -static inline int libsimple_vposix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void libsimple_envposix_memalignn(int \fIstatus\fP, void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void libsimple_evposix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline int libsimple_posix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void libsimple_enposix_memalignn(int \fIstatus\fP, void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void libsimple_eposix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline int libsimple_vposix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void libsimple_envposix_memalignn(int \fIstatus\fP, void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void libsimple_evposix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline int libsimple_posix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void libsimple_enposix_memalignn(int \fIstatus\fP, void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void libsimple_eposix_memalignn(void **\fImemptr\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vposix_memalignn # define vposix_memalignn libsimple_vposix_memalignn diff --git a/man3/libsimple_vposix_memalignzn.3 b/man3/libsimple_vposix_memalignzn.3 index fd4c682..62dc434 100644 --- a/man3/libsimple_vposix_memalignzn.3 +++ b/man3/libsimple_vposix_memalignzn.3 @@ -8,10 +8,10 @@ libsimple_vposix_memalignzn \- allocate optionally initialised memory with custo int libsimple_vposix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); void libsimple_envposix_memalignzn(int \fIstatus\fP, void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void libsimple_evposix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline int libsimple_posix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void libsimple_enposix_memalignzn(int \fIstatus\fP, void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline int libsimple_eposix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void libsimple_evposix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, va_list \fIap\fP); +inline int libsimple_posix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void libsimple_enposix_memalignzn(int \fIstatus\fP, void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline int libsimple_eposix_memalignzn(void **\fImemptr\fP, int \fIclear\fP, size_t \fIalignment\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vposix_memalignzn # define vposix_memalignzn libsimple_vposix_memalignzn diff --git a/man3/libsimple_vputenvf.3 b/man3/libsimple_vputenvf.3 index d772c81..88748e7 100644 --- a/man3/libsimple_vputenvf.3 +++ b/man3/libsimple_vputenvf.3 @@ -7,11 +7,11 @@ libsimple_vputenvf \- change or add a string formatted value to the environment #include int libsimple_vputenvf(const char *\fIfmt\fP, va_list \fIap\fP); -static inline int libsimple_putenvf(const char *\fIfmt\fP, ...); +inline int libsimple_putenvf(const char *\fIfmt\fP, ...); void libsimple_envputenvf(int \fIstatus\fP, const char *\fIfmt\fP, va_list \fIap\fP); -static inline void libsimple_enputenvf(int \fIstatus\fP, const char *\fIfmt\fP, ...); -static inline void libsimple_evputenvf(const char *\fIfmt\fP, va_list \fIap\fP); -static inline void libsimple_eputenvf(const char *\fIfmt\fP, ...); +inline void libsimple_enputenvf(int \fIstatus\fP, const char *\fIfmt\fP, ...); +inline void libsimple_evputenvf(const char *\fIfmt\fP, va_list \fIap\fP); +inline void libsimple_eputenvf(const char *\fIfmt\fP, ...); #ifndef vputenvf # define vputenvf libsimple_vputenvf diff --git a/man3/libsimple_vpvallocn.3 b/man3/libsimple_vpvallocn.3 index 1d4bbbb..2769478 100644 --- a/man3/libsimple_vpvallocn.3 +++ b/man3/libsimple_vpvallocn.3 @@ -6,12 +6,12 @@ libsimple_vpvallocn \- allocate memory with page size alignment .nf #include -static inline void *libsimple_vpvallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envpvallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evpvallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_pvallocn(size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enpvallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_epvallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vpvallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envpvallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evpvallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_pvallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enpvallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_epvallocn(size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vpvallocn # define vpvallocn libsimple_vpvallocn diff --git a/man3/libsimple_vpvalloczn.3 b/man3/libsimple_vpvalloczn.3 index e620758..9070b98 100644 --- a/man3/libsimple_vpvalloczn.3 +++ b/man3/libsimple_vpvalloczn.3 @@ -6,12 +6,12 @@ libsimple_vpvalloczn \- allocate optionally initialised memory with page size al .nf #include -static inline void *libsimple_vpvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envpvalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evpvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_pvalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enpvalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_epvalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vpvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envpvalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evpvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_pvalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enpvalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_epvalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vpvalloczn # define vpvalloczn libsimple_vpvalloczn diff --git a/man3/libsimple_vreallocfn.3 b/man3/libsimple_vreallocfn.3 index 5dd5390..e0e75e0 100644 --- a/man3/libsimple_vreallocfn.3 +++ b/man3/libsimple_vreallocfn.3 @@ -6,8 +6,8 @@ libsimple_vreallocfn \- reallocate memory .nf #include -static inline void *libsimple_vreallocfn(void *\fIptr\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_reallocfn(void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vreallocfn(void *\fIptr\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_reallocfn(void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vreallocfn # define vreallocfn libsimple_vreallocfn diff --git a/man3/libsimple_vreallocn.3 b/man3/libsimple_vreallocn.3 index bddce8b..f1a8fad 100644 --- a/man3/libsimple_vreallocn.3 +++ b/man3/libsimple_vreallocn.3 @@ -8,10 +8,10 @@ libsimple_vreallocn \- reallocate memory void *libsimple_vreallocn(void *\fIptr\fP, size_t \fIn\fP, va_list \fIap\fP); void *libsimple_envreallocn(int \fIstatus\fP, void *\fIptr\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evreallocn(void *\fIptr\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_reallocn(void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_enreallocn(int \fIstatus\fP, void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_ereallocn(void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_evreallocn(void *\fIptr\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_reallocn(void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_enreallocn(int \fIstatus\fP, void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_ereallocn(void *\fIptr\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vreallocn # define vreallocn libsimple_vreallocn diff --git a/man3/libsimple_vvallocn.3 b/man3/libsimple_vvallocn.3 index c378660..24d861b 100644 --- a/man3/libsimple_vvallocn.3 +++ b/man3/libsimple_vvallocn.3 @@ -6,12 +6,12 @@ libsimple_vvallocn \- allocate memory with page size alignment .nf #include -static inline void *libsimple_vvallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envvallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evvallocn(size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_vallocn(size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_envallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_evallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vvallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envvallocn(int \fIstatus\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evvallocn(size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_vallocn(size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_envallocn(int \fIstatus\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_evallocn(size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vvallocn # define vvallocn libsimple_vvallocn diff --git a/man3/libsimple_vvalloczn.3 b/man3/libsimple_vvalloczn.3 index 9a2f9e4..5cbd57a 100644 --- a/man3/libsimple_vvalloczn.3 +++ b/man3/libsimple_vvalloczn.3 @@ -6,12 +6,12 @@ libsimple_vvalloczn \- allocate optionally initialised memory with page size ali .nf #include -static inline void *libsimple_vvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_envvalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_evvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); -static inline void *libsimple_valloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_envalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); -static inline void *libsimple_evalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_vvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_envvalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_evvalloczn(int \fIclear\fP, size_t \fIn\fP, va_list \fIap\fP); +inline void *libsimple_valloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_envalloczn(int \fIstatus\fP, int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); +inline void *libsimple_evalloczn(int \fIclear\fP, size_t \fIn\fP, ..., /* (size_t)0 */); #ifndef vvalloczn # define vvalloczn libsimple_vvalloczn diff --git a/man3/libsimple_vweprintf.3 b/man3/libsimple_vweprintf.3 index 868b8df..b40799d 100644 --- a/man3/libsimple_vweprintf.3 +++ b/man3/libsimple_vweprintf.3 @@ -11,11 +11,11 @@ extern void (*libsimple_eprintf_preprint)(void); extern void (*libsimple_eprintf_postprint)(void); void libsimple_vweprintf(const char *\fIfmt\fP, va_list \fIap\fP); -static inline void libsimple_weprintf(const char *\fIfmt\fP, ...); -static inline void libsimple_venprintf(int \fIstatus\fP, const char *\fIfmt\fP, va_list \fIap\fP); -static inline void libsimple_enprintf(int \fIstatus\fP, const char *\fIfmt\fP, ...); -static inline void libsimple_veprintf(const char *\fIfmt\fP, va_list \fIap\fP); -static inline void libsimple_eprintf(const char *\fIfmt\fP, ...); +inline void libsimple_weprintf(const char *\fIfmt\fP, ...); +inline void libsimple_venprintf(int \fIstatus\fP, const char *\fIfmt\fP, va_list \fIap\fP); +inline void libsimple_enprintf(int \fIstatus\fP, const char *\fIfmt\fP, ...); +inline void libsimple_veprintf(const char *\fIfmt\fP, va_list \fIap\fP); +inline void libsimple_eprintf(const char *\fIfmt\fP, ...); #ifndef vweprintf # define vweprintf libsimple_vweprintf diff --git a/man3/libsimple_wcsndup.3 b/man3/libsimple_wcsndup.3 index 6821d25..803a309 100644 --- a/man3/libsimple_wcsndup.3 +++ b/man3/libsimple_wcsndup.3 @@ -9,7 +9,7 @@ libsimple_wcsndup \- duplicate a wide-character string wchar_t *libsimple_wcsndupa(const wchar_t *\fIs\fP, size_t \fIn\fP); wchar_t *libsimple_wcsndup(const wchar_t *\fIs\fP, size_t \fIn\fP); wchar_t *libsimple_enwcsndup(int \fIstatus\fP, const wchar_t *\fIs\fP, size_t \fIn\fP); -static inline wchar_t *libsimple_ewcsndup(const wchar_t *\fIs\fP, size_t \fIn\fP); +inline wchar_t *libsimple_ewcsndup(const wchar_t *\fIs\fP, size_t \fIn\fP); #ifndef wcsndupa # define wcsndupa libsimple_wcsndupa diff --git a/man3/libsimple_wmemdup.3 b/man3/libsimple_wmemdup.3 index 1f9e9cd..9c6305e 100644 --- a/man3/libsimple_wmemdup.3 +++ b/man3/libsimple_wmemdup.3 @@ -9,7 +9,7 @@ libsimple_wmemdup \- duplicate a wide-character array wchar_t *libsimple_wmemdupa(const wchar_t *\fIs\fP, size_t \fIn\fP); wchar_t *libsimple_wmemdup(const wchar_t *\fIs\fP, size_t \fIn\fP); wchar_t *libsimple_enwmemdup(int \fIstatus\fP, const wchar_t *\fIs\fP, size_t \fIn\fP); -static inline wchar_t *libsimple_ewmemdup(const wchar_t *\fIs\fP, size_t \fIn\fP); +inline wchar_t *libsimple_ewmemdup(const wchar_t *\fIs\fP, size_t \fIn\fP); #ifndef wmemdupa # define wmemdupa libsimple_wmemdupa diff --git a/memalloc.c b/memalloc.c new file mode 100644 index 0000000..e0b9dc9 --- /dev/null +++ b/memalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memalloc(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memcaseends.c b/memcaseends.c index 0a673f7..8c938c4 100644 --- a/memcaseends.c +++ b/memcaseends.c @@ -9,9 +9,12 @@ libsimple_memcaseends(const void *s_, size_t n, const void *t_, size_t m) const char *s = s_, *t = t_; if (n < m) return 0; - while (n--, m--) + while (m) { + n--; + m--; if (tolower(s[n]) != tolower(t[m])) return 0; + } return 1; } diff --git a/memcaseeq.c b/memcaseeq.c new file mode 100644 index 0000000..bbcf1b0 --- /dev/null +++ b/memcaseeq.c @@ -0,0 +1,26 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_memcaseeq(const void *, const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_memcaseeq("abcxyz", "abc123", 3)); + assert(!libsimple_memcaseeq("abcxyz", "abc123", 4)); + assert(libsimple_memcaseeq("abcxyz", "abcx23", 4)); + assert(libsimple_memcaseeq("1", "2", 0)); + assert(!libsimple_memcaseeq("1", "2", 1)); + assert(libsimple_memcaseeq("abc", "ABC", 3)); + assert(libsimple_memcaseeq("ABC", "abc", 3)); + assert(libsimple_memcaseeq("ABC", "ABC", 3)); + return 0; +} + +#endif diff --git a/memcasemem.c b/memcasemem.c index 244042b..e118da8 100644 --- a/memcasemem.c +++ b/memcasemem.c @@ -6,11 +6,12 @@ void * libsimple_memcasemem(const void *hay_, size_t hayn, const void *sub_, size_t subn) { - char *hay = (void *)hay_, *end; + const char *hay = hay_; const char *sub = sub_; + const char *end; if (!subn) - return hay; + return REMOVE_CONST(hay, char *); if (hayn < subn) return NULL; if (subn == 1) @@ -18,7 +19,7 @@ libsimple_memcasemem(const void *hay_, size_t hayn, const void *sub_, size_t sub for (end = &hay[hayn - subn + 1]; hay != end; hay++) if (tolower(*hay) == tolower(*sub) && !libsimple_memcasecmp(hay, sub, subn)) - return hay; + return REMOVE_CONST(hay, char *); return NULL; } diff --git a/memcmove.c b/memcmove.c index ab9e6d9..11fa9c4 100644 --- a/memcmove.c +++ b/memcmove.c @@ -44,7 +44,7 @@ main(void) assert(!strncmp(buf, "-----hello-", 11)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); diff --git a/memelem.c b/memelem.c index 7d9231d..3344cd8 100644 --- a/memelem.c +++ b/memelem.c @@ -8,46 +8,46 @@ libsimple_memelem(const void *hay_, const void *sub_, size_t width, size_t n) { switch (width) { case 0: - return (void *)hay_; + return REMOVE_CONST(hay_, void *); case 1: - return memchr(hay_, *(char *)sub_, n); + return memchr(hay_, *(const char *)sub_, n); case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (; n--; hay++) if (*hay == sub) - return hay; + return REMOVE_CONST(hay, uint16_t *); break; } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (; n--; hay++) if (*hay == sub) - return hay; + return REMOVE_CONST(hay, uint32_t *); break; } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (; n--; hay++) if (*hay == sub) - return hay; + return REMOVE_CONST(hay, uint64_t *); break; } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (; n--; hay += width) { for (i = 0; i < width; i++) if (hay[i] != sub[i]) goto next; - return hay; + return REMOVE_CONST(hay, char *); next:; } break; diff --git a/memelem_inv.c b/memelem_inv.c index dace2d4..7e87d4c 100644 --- a/memelem_inv.c +++ b/memelem_inv.c @@ -10,43 +10,43 @@ libsimple_memelem_inv(const void *hay_, const void *sub_, size_t width, size_t n case 0: return NULL; case 1: - return libsimple_memchr_inv(hay_, *(char *)sub_, n); + return libsimple_memchr_inv(hay_, *(const char *)sub_, n); case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (; n--; hay++) if (*hay != sub) - return hay; + return REMOVE_CONST(hay, uint16_t *); break; } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (; n--; hay++) if (*hay != sub) - return hay; + return REMOVE_CONST(hay, uint32_t *); break; } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (; n--; hay++) if (*hay != sub) - return hay; + return REMOVE_CONST(hay, uint64_t *); break; } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (; n--; hay += width) { for (i = 0; i < width; i++) if (hay[i] != sub[i]) - return hay; + return REMOVE_CONST(hay, char *); } break; } diff --git a/memelemmove.c b/memelemmove.c index 7becbc2..d790a87 100644 --- a/memelemmove.c +++ b/memelemmove.c @@ -5,18 +5,19 @@ #define MEMELEMMOVE(TYPE)\ do {\ - TYPE *p;\ + const TYPE *p;\ + TYPE *ret;\ if (d <= s) {\ for (; n; n--, s++)\ if ((*d++ = *s) == elem)\ return d;\ } else {\ - for (p = *(TYPE **)(void *)&s; n; n--, p++) {\ + for (p = s; n; n--, p++) {\ if (*p == elem) {\ n = (size_t)(p - s);\ - p = &d[n + 1];\ + ret = &d[n + 1];\ do { d[n] = s[n]; } while (n--);\ - return p;\ + return ret;\ }\ }\ for (n = (size_t)(p - s); n;) {\ @@ -52,7 +53,8 @@ memelemmove64(uint64_t *restrict d, const uint64_t *restrict s, uint64_t elem, s static char * memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t width, size_t n) { - char *p; + const char *p; + char *ret; size_t i; if (d <= s) { for (; n; s += width, n--) { @@ -68,26 +70,26 @@ memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem } return NULL; } else { - for (p = *(char **)(void *)&s; n; n--) { + for (p = s; n; n--) { for (i = 0; i < width; i++) if (p[i] != elem[i]) goto next_backwards; p += width; n = (size_t)(p - s); - p = &d[n]; + ret = &d[n]; goto out_backwards; next_backwards: p += width; } n = (size_t)(p - s); - p = NULL; + ret = NULL; out_backwards: while (n) { n--; d[n] = s[n]; } - return p; + return ret; } } @@ -143,7 +145,7 @@ main(void) assert(!strncmp(buf, "-----hello-", 11)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "l", 1, 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); @@ -189,7 +191,7 @@ main(void) assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-';; + stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".l", 2, 5) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); @@ -235,7 +237,7 @@ main(void) assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-';; + stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..l", 3, 5) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); @@ -281,7 +283,7 @@ main(void) assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-';; + stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...l", 4, 5) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); @@ -327,7 +329,7 @@ main(void) assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-';; + stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......l", 8, 5) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); diff --git a/memelemscan.c b/memelemscan.c index d17297a..b402570 100644 --- a/memelemscan.c +++ b/memelemscan.c @@ -8,43 +8,43 @@ libsimple_memelemscan(const void *hay_, const void *sub_, size_t width, size_t n { switch (width) { case 0: - return (void *)hay_; + return REMOVE_CONST(hay_, void *); case 1: - return libsimple_memscan(hay_, *(char *)sub_, n); + return libsimple_memscan(hay_, *(const char *)sub_, n); case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (; n-- && *hay != sub; hay++); - return hay; + return REMOVE_CONST(hay, uint16_t *); } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (; n-- && *hay != sub; hay++); - return hay; + return REMOVE_CONST(hay, uint32_t *); } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (; n-- && *hay != sub; hay++); - return hay; + return REMOVE_CONST(hay, uint64_t *); } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (; n--; hay += width) { for (i = 0; i < width; i++) if (hay[i] != sub[i]) goto next; - return hay; + return REMOVE_CONST(hay, char *); next:; } - return hay; + return REMOVE_CONST(hay, char *); } } } diff --git a/memelemscan_inv.c b/memelemscan_inv.c index 37b479a..48d35b2 100644 --- a/memelemscan_inv.c +++ b/memelemscan_inv.c @@ -8,41 +8,41 @@ libsimple_memelemscan_inv(const void *hay_, const void *sub_, size_t width, size { switch (width) { case 0: - return (void *)hay_; + return REMOVE_CONST(hay_, void *); case 1: - return libsimple_memscan_inv(hay_, *(char *)sub_, n); + return libsimple_memscan_inv(hay_, *(const char *)sub_, n); case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (; n-- && *hay == sub; hay++); - return hay; + return REMOVE_CONST(hay, uint16_t *); } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (; n-- && *hay == sub; hay++); - return hay; + return REMOVE_CONST(hay, uint32_t *); } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (; n-- && *hay == sub; hay++); - return hay; + return REMOVE_CONST(hay, uint64_t *); } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (; n--; hay += width) { for (i = 0; i < width; i++) if (hay[i] != sub[i]) - return hay; + return REMOVE_CONST(hay, char *); } - return hay; + return REMOVE_CONST(hay, char *); } } } diff --git a/memends.c b/memends.c index f579222..be4b1d4 100644 --- a/memends.c +++ b/memends.c @@ -9,9 +9,12 @@ libsimple_memends(const void *s_, size_t n, const void *t_, size_t m) const char *s = s_, *t = t_; if (n < m) return 0; - while (n--, m--) + while (m) { + n--; + m--; if (s[n] != t[m]) return 0; + } return 1; } diff --git a/memeq.c b/memeq.c new file mode 100644 index 0000000..f3eb30c --- /dev/null +++ b/memeq.c @@ -0,0 +1,26 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_memeq(const void *, const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_memeq("abcxyz", "abc123", 3)); + assert(!libsimple_memeq("abcxyz", "abc123", 4)); + assert(libsimple_memeq("abcxyz", "abcx23", 4)); + assert(libsimple_memeq("1", "2", 0)); + assert(!libsimple_memeq("1", "2", 1)); + assert(!libsimple_memeq("abc", "ABC", 3)); + assert(!libsimple_memeq("ABC", "abc", 3)); + assert(libsimple_memeq("ABC", "ABC", 3)); + return 0; +} + +#endif diff --git a/memisutf8.c b/memisutf8.c index 96a8b6b..b3d321e 100644 --- a/memisutf8.c +++ b/memisutf8.c @@ -11,6 +11,8 @@ libsimple_memisutf8(const char *string, size_t n, int allow_modified_nul) long int bytes = 0, read_bytes = 0, bits = 0, c, character; size_t i; + character = 0; /* silence false warning from compiler; `character` is set in `if (!read_bytes)` before `else` */ + /* min bits max bits 0....... 0 7 110..... 10...... 8 11 @@ -36,8 +38,10 @@ libsimple_memisutf8(const char *string, size_t n, int allow_modified_nul) return 0; /* Multibyte character. */ - while ((c & 0x80)) - bytes++, c <<= 1; + while ((c & 0x80)) { + bytes++; + c <<= 1; + } read_bytes = 1; character = (c & 0xFF) >> bytes; if (bytes > 6) @@ -59,8 +63,10 @@ libsimple_memisutf8(const char *string, size_t n, int allow_modified_nul) continue; /* Check that the character is not unnecessarily long. */ - while (character) - character >>= 1, bits++; + while (character) { + character >>= 1; + bits++; + } bits = (!bits && bytes == 2 && allow_modified_nul) ? 8 : bits; if (bits < BYTES_TO_MIN_BITS[bytes] || BYTES_TO_MAX_BITS[bytes] < bits) return 0; diff --git a/memmem.c b/memmem.c index 2cee286..f05be99 100644 --- a/memmem.c +++ b/memmem.c @@ -6,11 +6,11 @@ void * libsimple_memmem(const void *hay_, size_t hayn, const void *sub_, size_t subn) { - char *hay = (void *)hay_, *end; + const char *hay = hay_, *end; const char *sub = sub_; if (!subn) - return hay; + return REMOVE_CONST(hay, char *); if (hayn < subn) return NULL; if (subn == 1) @@ -18,7 +18,7 @@ libsimple_memmem(const void *hay_, size_t hayn, const void *sub_, size_t subn) for (end = &hay[hayn - subn + 1]; hay != end; hay++) if (*hay == *sub && !memcmp(hay, sub, subn)) - return hay; + return REMOVE_CONST(hay, char *); return NULL; } diff --git a/mempcpy.c b/mempcpy.c new file mode 100644 index 0000000..8bac405 --- /dev/null +++ b/mempcpy.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_mempcpy(void *restrict, const void *restrict, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "abcxyz"); + assert(libsimple_mempcpy(buf, "123", 3) == &buf[3]); + assert(!strcmpnul(buf, "123xyz")); + + return 0; +} + +#endif diff --git a/mempmove.c b/mempmove.c new file mode 100644 index 0000000..2d42b0e --- /dev/null +++ b/mempmove.c @@ -0,0 +1,35 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_mempmove(void *, const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_mempmove(&buf[5], &buf[5], 5) == &buf[5 + 5]); + assert(!strncmp(buf, "-----hello-", 11)); + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_mempmove(&buf[3], &buf[5], 5) == &buf[3 + 5]); + assert(!strncmp(buf, "---hellolo-", 11)); + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_mempmove(&buf[8], &buf[5], 5) == &buf[8 + 5]); + assert(!strncmp(buf, "-----helhello-", 14)); + + return 0; +} + +#endif diff --git a/mempset.c b/mempset.c new file mode 100644 index 0000000..e69dcd1 --- /dev/null +++ b/mempset.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_mempset(void *, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "abc123"); + assert(!strcmpnul(libsimple_mempset(buf, '.', 3), "123")); + assert(!strcmp(buf, "...123")); + + return 0; +} + +#endif diff --git a/mempsetelem.c b/mempsetelem.c index 6a3bd4f..cf84702 100644 --- a/mempsetelem.c +++ b/mempsetelem.c @@ -10,27 +10,30 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) case 0: return buf_; case 1: - return &((char *)memset(buf_, *(char *)item, n))[n]; + return &((char *)memset(buf_, *(const char *)item, n))[n]; case 2: { - uint16_t *buf = buf_, e = *(uint16_t *)item; + uint16_t *buf = buf_; uint16_t *end = &buf[n]; + uint16_t e = *(const uint16_t *)item; for (; buf != end; buf++) *buf = e; return buf; } case 4: { - uint32_t *buf = buf_, e = *(uint32_t *)item; + uint32_t *buf = buf_; uint32_t *end = &buf[n]; + uint32_t e = *(const uint32_t *)item; for (; buf != end; buf++) *buf = e; return buf; } case 8: { - uint64_t *buf = buf_, e = *(uint64_t *)item; + uint64_t *buf = buf_; uint64_t *end = &buf[n]; + uint64_t e = *(const uint64_t *)item; for (; buf != end; buf++) *buf = e; return buf; @@ -59,22 +62,22 @@ main(void) size_t i; memset(buf, 0, sizeof(buf_)); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 0, 0) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 0, 10) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 1, 0) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 2, 0) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 4, 0) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 8, 0) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 16, 0) == &buf[0]); - assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 3, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 10) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 1, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 2, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 4, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 8, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 16, 0) == &buf[0]); + assert(libsimple_mempsetelem(buf, &(uint64_t){~(uint64_t)0}, 3, 0) == &buf[0]); assert(libsimple_mempsetelem(buf, &(uint8_t){0x09}, 1, 3000) == &buf[3000]); assert(libsimple_mempsetelem(buf, &(uint16_t){0x0807}, 2, 1000) == &buf[2000]); assert(libsimple_mempsetelem(buf, &(uint32_t){0x10203040UL}, 4, 300) == &buf[1200]); assert(libsimple_mempsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == &buf[800]); - assert(libsimple_mempsetelem(buf, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == &buf[48]); + assert(libsimple_mempsetelem(buf, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == &buf[48]); for (i = 0; i < 48; i++) - assert(buf[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]); + assert(buf[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); for (; i < 800; i += 8) assert(*(uint64_t *)&buf[i] == 0x0102030450607080ULL); for (; i < 1200; i += 4) diff --git a/memptolower.c b/memptolower.c index 251a13a..f9b05e5 100644 --- a/memptolower.c +++ b/memptolower.c @@ -10,17 +10,17 @@ libsimple_memptolower(void *d_, const void *s_, size_t n) const char *s = s_; if (d == s) { for (; n; d++, n--) - *d = tolower(*d); + *d = (char)tolower(*d); return d; } else if (d < s) { for (; n; d++, s++, n--) - *d = tolower(*s); + *d = (char)tolower(*s); return d; } else { ret = &d[n]; while (n) { n--; - d[n] = tolower(s[n]); + d[n] = (char)tolower(s[n]); } return ret; } @@ -44,15 +44,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(libsimple_memptolower(&buf[0], &buf[0], 16) == &buf[16]); assert(!strcmp(buf, "abcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_memtolower(&buf[3], &buf[0], 16), "abcdeabcde12345")); - assert(!strcmp(buf, "ABCabcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_memtolower(&buf[0], &buf[3], 13), "deabcde12345")); - assert(!strcmp(buf, "deabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_memtolower(&buf[0], &buf[0], 16), "abcdeabcde12345")); - assert(!strcmp(buf, "abcdeabcde12345")); return 0; } diff --git a/memptoupper.c b/memptoupper.c index f9798f4..c02cb3c 100644 --- a/memptoupper.c +++ b/memptoupper.c @@ -10,17 +10,17 @@ libsimple_memptoupper(void *d_, const void *s_, size_t n) const char *s = s_; if (d == s) { for (; n; d++, n--) - *d = toupper(*d); + *d = (char)toupper(*d); return d; } else if (d < s) { for (; n; d++, s++, n--) - *d = toupper(*s); + *d = (char)toupper(*s); return d; } else { ret = &d[n]; while (n) { n--; - d[n] = toupper(s[n]); + d[n] = (char)toupper(s[n]); } return ret; } @@ -44,15 +44,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(libsimple_memptoupper(&buf[0], &buf[0], 16) == &buf[16]); assert(!strcmp(buf, "ABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_memtoupper(&buf[3], &buf[0], 16), "ABCDEABCDE12345")); - assert(!strcmp(buf, "abcABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_memtoupper(&buf[0], &buf[3], 13), "DEABCDE12345")); - assert(!strcmp(buf, "DEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_memtoupper(&buf[0], &buf[0], 16), "ABCDEABCDE12345")); - assert(!strcmp(buf, "ABCDEABCDE12345")); return 0; } diff --git a/memrcasechr.c b/memrcasechr.c index e4fe52a..1e6662e 100644 --- a/memrcasechr.c +++ b/memrcasechr.c @@ -7,7 +7,7 @@ void * libsimple_memrcasechr(const void *s_, int c, size_t n_) { char *s = *(char **)(void *)&s_; - ssize_t n = n_; + ssize_t n = (ssize_t)n_; c = tolower(c); while (n-- && tolower(s[n]) != c); return n < 0 ? NULL : &s[n]; diff --git a/memrcasechr_inv.c b/memrcasechr_inv.c index 85f1f58..1bcf221 100644 --- a/memrcasechr_inv.c +++ b/memrcasechr_inv.c @@ -7,7 +7,7 @@ void * libsimple_memrcasechr_inv(const void *s_, int c, size_t n_) { char *s = *(char **)(void *)&s_; - ssize_t n = n_; + ssize_t n = (ssize_t)n_; c = tolower(c); while (n-- && tolower(s[n]) == c); return n < 0 ? NULL : &s[n]; diff --git a/memrcaseeqlen.c b/memrcaseeqlen.c index 3f586b7..91b98d3 100644 --- a/memrcaseeqlen.c +++ b/memrcaseeqlen.c @@ -6,9 +6,15 @@ size_t libsimple_memrcaseeqlen(const void *a_, size_t n, const void *b_, size_t m) { - const char *a = &((char *)a_)[n], *b = &((char *)b_)[m]; + const char *a = &((const char *)a_)[n]; + const char *b = &((const char *)b_)[m]; size_t i = 0, len = n < m ? n : m; - for (; i < len && (--a, --b, tolower(*a) == tolower(*b)); i++); + for (; i < len; i++) { + a--; + b--; + if (tolower(*a) != tolower(*b)) + break; + } return i; } diff --git a/memrcasemem.c b/memrcasemem.c index e7672f9..a7e9462 100644 --- a/memrcasemem.c +++ b/memrcasemem.c @@ -6,11 +6,12 @@ void * libsimple_memrcasemem(const void *hay_, size_t hayn, const void *sub_, size_t subn) { - char *hay = (void *)hay_, *start; + const char *hay = hay_; const char *sub = sub_; + const char *start; if (!subn) - return &hay[hayn]; + return &REMOVE_CONST(hay, char *)[hayn]; if (hayn < subn) return NULL; if (subn == 1) @@ -20,7 +21,7 @@ libsimple_memrcasemem(const void *hay_, size_t hayn, const void *sub_, size_t su hay = &hay[hayn - subn]; do { if (tolower(*hay) == tolower(*sub) && !libsimple_memcasecmp(hay, sub, subn)) - return hay; + return REMOVE_CONST(hay, char *); } while (hay-- != start); return NULL; diff --git a/memrchr.c b/memrchr.c index 36385ec..40186c4 100644 --- a/memrchr.c +++ b/memrchr.c @@ -7,7 +7,7 @@ void * libsimple_memrchr(const void *s_, int c_, size_t n_) { char *s = *(char **)(void *)&s_, c = (char)c_; - ssize_t n = n_; + ssize_t n = (ssize_t)n_; while (n-- && s[n] != c); return n < 0 ? NULL : &s[n]; } diff --git a/memrchr_inv.c b/memrchr_inv.c index 03613e3..9ebba42 100644 --- a/memrchr_inv.c +++ b/memrchr_inv.c @@ -7,7 +7,7 @@ void * libsimple_memrchr_inv(const void *s_, int c_, size_t n_) { char *s = *(char **)(void *)&s_, c = (char)c_; - ssize_t n = n_; + ssize_t n = (ssize_t)n_; while (n-- && s[n] == c); return n < 0 ? NULL : &s[n]; } diff --git a/memrelem.c b/memrelem.c index 5b9cf8f..d23cb1b 100644 --- a/memrelem.c +++ b/memrelem.c @@ -8,46 +8,46 @@ libsimple_memrelem(const void *hay_, const void *sub_, size_t width, size_t n) { switch (width) { case 0: - return (void *)hay_; + return REMOVE_CONST(hay_, void *); case 1: { - uint8_t *hay = (void *)hay_; - uint8_t sub = *(uint8_t *)sub_; + const uint8_t *hay = hay_; + uint8_t sub = *(const uint8_t *)sub_; for (hay += n; n--;) if (*--hay == sub) - return hay; + return REMOVE_CONST(hay, uint8_t *); break; } case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (hay += n; n--;) if (*--hay == sub) - return hay; + return REMOVE_CONST(hay, uint16_t *); break; } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (hay += n; n--;) if (*--hay == sub) - return hay; + return REMOVE_CONST(hay, uint32_t *); break; } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (hay += n; n--;) if (*--hay == sub) - return hay; + return REMOVE_CONST(hay, uint64_t *); break; } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (hay += n * width; n--;) { @@ -55,7 +55,7 @@ libsimple_memrelem(const void *hay_, const void *sub_, size_t width, size_t n) for (i = 0; i < width; i++) if (hay[i] != sub[i]) goto next; - return hay; + return REMOVE_CONST(hay, void *); next:; } break; diff --git a/memrelem_inv.c b/memrelem_inv.c index d90f358..3bb0f89 100644 --- a/memrelem_inv.c +++ b/memrelem_inv.c @@ -11,50 +11,50 @@ libsimple_memrelem_inv(const void *hay_, const void *sub_, size_t width, size_t return NULL; case 1: { - uint8_t *hay = (void *)hay_; - uint8_t sub = *(uint8_t *)sub_; + const uint8_t *hay = hay_; + uint8_t sub = *(const uint8_t *)sub_; for (hay += n; n--;) if (*--hay != sub) - return hay; + return REMOVE_CONST(hay, uint8_t *); break; } case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (hay += n; n--;) if (*--hay != sub) - return hay; + return REMOVE_CONST(hay, uint16_t *); break; } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (hay += n; n--;) if (*--hay != sub) - return hay; + return REMOVE_CONST(hay, uint32_t *); break; } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (hay += n; n--;) if (*--hay != sub) - return hay; + return REMOVE_CONST(hay, uint64_t *); break; } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (hay += n * width; n--;) { hay -= width; for (i = 0; i < width; i++) if (hay[i] != sub[i]) - return hay; + return REMOVE_CONST(hay, char *); } break; } diff --git a/memreplace.c b/memreplace.c new file mode 100644 index 0000000..563e76c --- /dev/null +++ b/memreplace.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void * libsimple_memreplace(void *, int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_memreplace(buf, 'o', 'x', 46) == &buf[46]); + assert(!memcmp(buf, "hellx wxrld\0gxxdbye wxrld", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_memreplace(buf, 'o', 'x', 12) == &buf[12]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/memreqlen.c b/memreqlen.c index c276b8d..64a2e83 100644 --- a/memreqlen.c +++ b/memreqlen.c @@ -6,7 +6,8 @@ size_t libsimple_memreqlen(const void *a_, size_t n, const void *b_, size_t m) { - const char *a = &((char *)a_)[n], *b = &((char *)b_)[m]; + const char *a = &((const char *)a_)[n]; + const char *b = &((const char *)b_)[m]; size_t i = 0, len = n < m ? n : m; for (; i < len && *--a == *--b; i++); return i; diff --git a/memrmem.c b/memrmem.c index 3968e73..68352c2 100644 --- a/memrmem.c +++ b/memrmem.c @@ -6,11 +6,11 @@ void * libsimple_memrmem(const void *hay_, size_t hayn, const void *sub_, size_t subn) { - char *hay = (void *)hay_, *start; + const char *hay = hay_, *start; const char *sub = sub_; if (!subn) - return &hay[hayn]; + return &REMOVE_CONST(hay, char *)[hayn]; if (hayn < subn) return NULL; if (subn == 1) @@ -20,7 +20,7 @@ libsimple_memrmem(const void *hay_, size_t hayn, const void *sub_, size_t subn) hay = &hay[hayn - subn]; do { if (*hay == *sub && !memcmp(hay, sub, subn)) - return hay; + return REMOVE_CONST(hay, char *); } while (hay-- != start); return NULL; diff --git a/memsetelem.c b/memsetelem.c index 6bcf021..32c3f74 100644 --- a/memsetelem.c +++ b/memsetelem.c @@ -17,22 +17,22 @@ main(void) size_t i; memset(p, 0, sizeof(p_)); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 10) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 1, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 2, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 4, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 8, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 16, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 3, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 0, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 0, 10) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 1, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 2, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 4, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 8, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 16, 0) == p); + assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 3, 0) == p); assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p); assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p); assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p); assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p); - assert(libsimple_memsetelem(p, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == p); + assert(libsimple_memsetelem(p, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == p); for (i = 0; i < 48; i++) - assert(p[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]); + assert(p[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); for (; i < 800; i += 8) assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL); for (; i < 1200; i += 4) diff --git a/memtolower.c b/memtolower.c new file mode 100644 index 0000000..364776a --- /dev/null +++ b/memtolower.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memtolower(void *, const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_memtolower(&buf[3], &buf[0], 16), "abcdeabcde12345")); + assert(!strcmp(buf, "ABCabcdeabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_memtolower(&buf[0], &buf[3], 13), "deabcde12345")); + assert(!strcmp(buf, "deabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_memtolower(&buf[0], &buf[0], 16), "abcdeabcde12345")); + assert(!strcmp(buf, "abcdeabcde12345")); + + return 0; +} + +#endif diff --git a/memtoupper.c b/memtoupper.c new file mode 100644 index 0000000..376037a --- /dev/null +++ b/memtoupper.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memtoupper(void *, const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_memtoupper(&buf[3], &buf[0], 16), "ABCDEABCDE12345")); + assert(!strcmp(buf, "abcABCDEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_memtoupper(&buf[0], &buf[3], 13), "DEABCDE12345")); + assert(!strcmp(buf, "DEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_memtoupper(&buf[0], &buf[0], 16), "ABCDEABCDE12345")); + assert(!strcmp(buf, "ABCDEABCDE12345")); + + return 0; +} + +#endif diff --git a/posix_memalignn.c b/posix_memalignn.c new file mode 100644 index 0000000..9f2617b --- /dev/null +++ b/posix_memalignn.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_posix_memalignn(void **, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr; + + assert(libsimple_posix_memalignn(&ptr, 128, 0) == EINVAL && !errno); + + assert(libsimple_posix_memalignn(&ptr, 1024, SIZE_MAX, 2, 0) == ENOMEM && !errno); + + assert(!libsimple_posix_memalignn(&ptr, 2 * sizeof(void *), 12, 12, 3, 0)); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 432); + assert(info->alignment == 2 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + assert(!errno); + + return 0; +} + +#endif diff --git a/posix_memalignz.c b/posix_memalignz.c new file mode 100644 index 0000000..18530ca --- /dev/null +++ b/posix_memalignz.c @@ -0,0 +1,56 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_posix_memalignz(void **, int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_CACHELINE; + + assert(!libsimple_posix_memalignz(&ptr, 0, 8 * sizeof(void *), 8)); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 8); + ASSERT_ALIGNMENT(info, 8 * sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert(!libsimple_posix_memalignz(&ptr, 1, 4 * sizeof(void *), 16)); + assert(ptr); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 16); + ASSERT_ALIGNMENT(info, 4 * sizeof(void *)); + assert(info->zeroed == 16); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(libsimple_posix_memalignz(&ptr, 0, 4 * sizeof(void *), 8) == ENOMEM && !errno); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + assert(libsimple_posix_memalignz(&ptr, 1, 16 * sizeof(void *), 16) == ENOMEM && !errno); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/posix_memalignzn.c b/posix_memalignzn.c new file mode 100644 index 0000000..d91924e --- /dev/null +++ b/posix_memalignzn.c @@ -0,0 +1,49 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_posix_memalignzn(void **, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr; + + assert(libsimple_posix_memalignzn(&ptr, 0, 128, 0) == EINVAL && !errno); + assert(libsimple_posix_memalignzn(&ptr, 1, 128, 0) == EINVAL && !errno); + + assert(libsimple_posix_memalignzn(&ptr, 0, 1024, SIZE_MAX, 2, 0) == ENOMEM && !errno); + assert(libsimple_posix_memalignzn(&ptr, 1, 1024, SIZE_MAX, 2, 0) == ENOMEM && !errno); + + assert(!libsimple_posix_memalignzn(&ptr, 0, sizeof(void *), 12, 12, 0)); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 144); + assert(info->alignment == sizeof(void *)); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + assert(!libsimple_posix_memalignzn(&ptr, 1, 2 * sizeof(void *), 12, 12, 2, 0)); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 288); + assert(info->alignment == 2 * sizeof(void *)); + assert(info->zeroed == 288); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + assert(!errno); + + return 0; +} + +#endif diff --git a/pvalloc.c b/pvalloc.c new file mode 100644 index 0000000..e5a9c7b --- /dev/null +++ b/pvalloc.c @@ -0,0 +1,45 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_pvalloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_pvalloc(5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5 || info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvalloc(5 * pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + return 0; +} + +#endif diff --git a/pvallocn.c b/pvallocn.c new file mode 100644 index 0000000..5a51408 --- /dev/null +++ b/pvallocn.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_pvallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_pvallocn(5 * pagesize - 1, 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 10 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert(!libsimple_pvallocn(0) && errno == EINVAL); + errno = 0; + + assert(!libsimple_pvallocn(SIZE_MAX, 2, 0) && errno == ENOMEM); + errno = 0; + + assert((ptr = libsimple_pvallocn(9, (pagesize - 1), 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 9 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + return 0; +} + +#endif diff --git a/pvallocz.c b/pvallocz.c new file mode 100644 index 0000000..3e3f187 --- /dev/null +++ b/pvallocz.c @@ -0,0 +1,110 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_pvallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_pvallocz(0, 9))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvallocz(1, 7))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvallocz(1, pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvallocz(1, pagesize))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvallocz(1, pagesize + 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 2 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == 2 * pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvallocz(1, 3 * pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 3 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == 3 * pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvallocz(0, 4 * pagesize - 1))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 4 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_pvallocz(0, 8) && errno == ENOMEM); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + assert(!libsimple_pvallocz(1, 16) && errno == ENOMEM); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/pvalloczn.c b/pvalloczn.c new file mode 100644 index 0000000..9349f47 --- /dev/null +++ b/pvalloczn.c @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_pvalloczn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_pvalloczn(1, 3 * pagesize - 1, 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 6 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == 6 * pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_pvalloczn(0, 4 * pagesize - 1, 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 8 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert(!libsimple_pvalloczn(0, 0) && errno == EINVAL); + errno = 0; + assert(!libsimple_pvalloczn(1, 0) && errno == EINVAL); + errno = 0; + + assert(!libsimple_pvalloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM); + errno = 0; + assert(!libsimple_pvalloczn(1, SIZE_MAX, 2, 0) && errno == ENOMEM); + errno = 0; + + assert((ptr = libsimple_pvalloczn(0, 9, 9, pagesize - 1, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 81 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + assert((ptr = libsimple_pvalloczn(1, 9, 8, pagesize - 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 72 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + return 0; +} + +#endif diff --git a/rawmemccpy.c b/rawmemccpy.c new file mode 100644 index 0000000..cba8476 --- /dev/null +++ b/rawmemccpy.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_rawmemccpy(void *restrict, const void *restrict, int); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_rawmemccpy(buf, "hello", 'o') == &buf[5]); + assert(!strncmp(buf, "hellox", 6)); + + memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_rawmemccpy(buf, "hello", 'l') == &buf[3]); + assert(!strncmp(buf, "helx", 4)); + + return 0; +} + +#endif diff --git a/rawmemcmove.c b/rawmemcmove.c new file mode 100644 index 0000000..fd831af --- /dev/null +++ b/rawmemcmove.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void * libsimple_rawmemcmove(void *__d_, const void *__s_, int __c_); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'o') == &buf[5 + 5]); + assert(!strncmp(buf, "-----hello-", 11)); + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'l') == &buf[5 + 3]); + assert(!strncmp(buf, "-----hello-", 11)); + + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'o') == &buf[3 + 5]); + assert(!strncmp(buf, "---hellolo-", 11)); + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'l') == &buf[3 + 3]); + assert(!strncmp(buf, "---helello-", 11)); + + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'o') == &buf[8 + 5]); + assert(!strncmp(buf, "-----helhello-", 14)); + + memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; + assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'l') == &buf[8 + 3]); + assert(!strncmp(buf, "-----helhel-", 12)); + + return 0; +} + +#endif diff --git a/rawmemelem.c b/rawmemelem.c index fa67a51..798f275 100644 --- a/rawmemelem.c +++ b/rawmemelem.c @@ -8,40 +8,40 @@ libsimple_rawmemelem(const void *hay_, const void *sub_, size_t width) { switch (width) { case 0: - return (void *)hay_; + return REMOVE_CONST(hay_, void *); case 1: - return rawmemchr(hay_, *(char *)sub_); + return rawmemchr(hay_, *(const char *)sub_); case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (; *hay != sub; hay++); - return hay; + return REMOVE_CONST(hay, uint16_t *); } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (; *hay != sub; hay++); - return hay; + return REMOVE_CONST(hay, uint32_t *); } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (; *hay != sub; hay++); - return hay; + return REMOVE_CONST(hay, uint64_t *); } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (;; hay += width) { for (i = 0; i < width; i++) if (hay[i] != sub[i]) goto next; - return hay; + return REMOVE_CONST(hay, char *); next:; } } diff --git a/rawmemelem_inv.c b/rawmemelem_inv.c index 7046d3c..d9ed507 100644 --- a/rawmemelem_inv.c +++ b/rawmemelem_inv.c @@ -10,37 +10,37 @@ libsimple_rawmemelem_inv(const void *hay_, const void *sub_, size_t width) case 0: abort(); case 1: - return rawmemchr_inv(hay_, *(char *)sub_); + return rawmemchr_inv(hay_, *(const char *)sub_); case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (; *hay == sub; hay++); - return hay; + return REMOVE_CONST(hay, uint16_t *); } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (; *hay == sub; hay++); - return hay; + return REMOVE_CONST(hay, uint32_t *); } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (; *hay == sub; hay++); - return hay; + return REMOVE_CONST(hay, uint64_t *); } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (;; hay += width) for (i = 0; i < width; i++) if (hay[i] != sub[i]) - return hay; + return REMOVE_CONST(hay, void *); } } } diff --git a/rawmemelemmove.c b/rawmemelemmove.c index 8903ae8..717a590 100644 --- a/rawmemelemmove.c +++ b/rawmemelemmove.c @@ -5,20 +5,21 @@ #define RAWMEMELEMMOVE(TYPE)\ do {\ - TYPE *p;\ + const TYPE *p;\ + TYPE *ret;\ size_t n;\ if (d <= s) {\ for (; (*d++ = *s) != elem; s++);\ return d;\ } else {\ - for (p = *(TYPE **)(void *)&s; *p++ != elem;);\ + for (p = s; *p++ != elem;);\ n = (size_t)(p - s);\ - p = &d[n];\ + ret = &d[n];\ while (n) {\ n--;\ d[n] = s[n];\ }\ - return p;\ + return ret;\ }\ } while (0) @@ -47,7 +48,8 @@ rawmemelemmove64(uint64_t *restrict d, const uint64_t *restrict s, uint64_t elem static char * rawmemelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t width) { - char *p; + const char *p; + char *ret; size_t i, n; if (d <= s) { for (;; s += width) { @@ -62,7 +64,7 @@ rawmemelemmovex(char *restrict d, const char *restrict s, const char *restrict e d += width; } } else { - for (p = *(char **)(void *)&s;;) { + for (p = s;;) { for (i = 0; i < width; i++) if (p[i] != elem[i]) goto next_backwards; @@ -72,12 +74,12 @@ rawmemelemmovex(char *restrict d, const char *restrict s, const char *restrict e p += width; } n = (size_t)(p - s); - p = &d[n]; + ret = &d[n]; while (n) { n--; d[n] = s[n]; } - return p; + return ret; } } @@ -133,7 +135,7 @@ main(void) assert(!strncmp(buf, "-----hello-", 11)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "l", 1) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); @@ -164,7 +166,7 @@ main(void) assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-';; + stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".l", 2) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); @@ -195,7 +197,7 @@ main(void) assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-';; + stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "..l", 3) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); @@ -226,7 +228,7 @@ main(void) assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-';; + stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "...l", 4) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); @@ -257,7 +259,7 @@ main(void) assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-';; + stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".......l", 8) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); diff --git a/rawmemrcasechr.c b/rawmemrcasechr.c index 68c5645..de33b8f 100644 --- a/rawmemrcasechr.c +++ b/rawmemrcasechr.c @@ -8,7 +8,9 @@ libsimple_rawmemrcasechr(const void *s_, int c, size_t n) { char *s = *(char **)(void *)&s_; c = tolower(c); - while (--n, tolower(s[n]) != c); + do { + n--; + } while (tolower(s[n]) != c); return &s[n]; } diff --git a/rawmemrcasechr_inv.c b/rawmemrcasechr_inv.c index 483de3e..74ec992 100644 --- a/rawmemrcasechr_inv.c +++ b/rawmemrcasechr_inv.c @@ -8,7 +8,9 @@ libsimple_rawmemrcasechr_inv(const void *s_, int c, size_t n) { char *s = *(char **)(void *)&s_; c = tolower(c); - while (--n, tolower(s[n]) == c); + do { + n--; + } while (tolower(s[n]) == c); return &s[n]; } diff --git a/rawmemrelem.c b/rawmemrelem.c index d8507b3..08e3377 100644 --- a/rawmemrelem.c +++ b/rawmemrelem.c @@ -8,38 +8,38 @@ libsimple_rawmemrelem(const void *hay_, const void *sub_, size_t width, size_t n { switch (width) { case 0: - return (void *)hay_; + return REMOVE_CONST(hay_, void *); case 1: { - uint8_t *hay = (void *)hay_; - uint8_t sub = *(uint8_t *)sub_; + const uint8_t *hay = hay_; + uint8_t sub = *(const uint8_t *)sub_; for (hay += n; *--hay != sub;); - return hay; + return REMOVE_CONST(hay, uint8_t *); } case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (hay += n; *--hay != sub;); - return hay; + return REMOVE_CONST(hay, uint16_t *); } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (hay += n; *--hay != sub;); - return hay; + return REMOVE_CONST(hay, uint32_t *); } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (hay += n; *--hay != sub;); - return hay; + return REMOVE_CONST(hay, uint64_t *); } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (hay += n * width;;) { @@ -47,7 +47,7 @@ libsimple_rawmemrelem(const void *hay_, const void *sub_, size_t width, size_t n for (i = 0; i < width; i++) if (hay[i] != sub[i]) goto next; - return hay; + return REMOVE_CONST(hay, char *); next:; } } diff --git a/rawmemrelem_inv.c b/rawmemrelem_inv.c index 74a3cfc..e39a271 100644 --- a/rawmemrelem_inv.c +++ b/rawmemrelem_inv.c @@ -11,42 +11,42 @@ libsimple_rawmemrelem_inv(const void *hay_, const void *sub_, size_t width, size abort(); case 1: { - uint8_t *hay = (void *)hay_; - uint8_t sub = *(uint8_t *)sub_; + const uint8_t *hay = hay_; + uint8_t sub = *(const uint8_t *)sub_; for (hay += n; *--hay == sub;); - return hay; + return REMOVE_CONST(hay, uint8_t *); } case 2: { - uint16_t *hay = (void *)hay_; - uint16_t sub = *(uint16_t *)sub_; + const uint16_t *hay = hay_; + uint16_t sub = *(const uint16_t *)sub_; for (hay += n; *--hay == sub;); - return hay; + return REMOVE_CONST(hay, uint16_t *); } case 4: { - uint32_t *hay = (void *)hay_; - uint32_t sub = *(uint32_t *)sub_; + const uint32_t *hay = hay_; + uint32_t sub = *(const uint32_t *)sub_; for (hay += n; *--hay == sub;); - return hay; + return REMOVE_CONST(hay, uint32_t *); } case 8: { - uint64_t *hay = (void *)hay_; - uint64_t sub = *(uint64_t *)sub_; + const uint64_t *hay = hay_; + uint64_t sub = *(const uint64_t *)sub_; for (hay += n; *--hay == sub;); - return hay; + return REMOVE_CONST(hay, uint64_t *); } default: { - char *hay = (void *)hay_; + const char *hay = hay_; const char *sub = sub_; size_t i; for (hay += n * width;;) { hay -= width; for (i = 0; i < width; i++) if (hay[i] != sub[i]) - return hay; + return REMOVE_CONST(hay, char *); } } } diff --git a/reallocarray.c b/reallocarray.c new file mode 100644 index 0000000..640e84a --- /dev/null +++ b/reallocarray.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_reallocarray(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr, *old; + + assert((ptr = libsimple_reallocarray(NULL, 1, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_reallocarray(old = ptr, 10, 10))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 100); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + assert(ptr != old); + free(old); + } + free(ptr); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_reallocarray(NULL, 1, 1) && errno == ENOMEM); + assert(!alloc_fail_in); + } + +#if defined(__GNUC__) && !defined(__clang) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Walloc-size-larger-than=" +#endif + + assert(!libsimple_reallocarray(NULL, SIZE_MAX, SIZE_MAX) && errno == ENOMEM); + +#if defined(__GNUC__) && !defined(__clang) +# pragma GCC diagnostic pop +#endif + + return 0; +} + +#endif diff --git a/reallocarrayf.c b/reallocarrayf.c new file mode 100644 index 0000000..f95c5ff --- /dev/null +++ b/reallocarrayf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_reallocarrayf(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/reallocf.c b/reallocf.c new file mode 100644 index 0000000..ded2f17 --- /dev/null +++ b/reallocf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_reallocf(void *, size_t); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/reallocfn.c b/reallocfn.c new file mode 100644 index 0000000..b22b1c7 --- /dev/null +++ b/reallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_reallocfn(void *, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/reallocn.c b/reallocn.c new file mode 100644 index 0000000..75860bd --- /dev/null +++ b/reallocn.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_reallocn(void *, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *ptr, *old; + + assert(!libsimple_reallocn(NULL, 0) && errno == EINVAL); + errno = 0; + + assert(!libsimple_reallocn(NULL, SIZE_MAX, 2, 0) && errno == ENOMEM); + errno = 0; + + assert((ptr = libsimple_reallocn(NULL, 5, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5); + assert(!info->zeroed); + info->refcount += 1; + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_reallocn(old = ptr, 10, 0))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 10); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + assert(ptr != old); + free(old); + } + free(ptr); + + assert(!errno); + + return 0; +} + +#endif diff --git a/stpntolower.c b/stpntolower.c index 9aca9f9..86adb89 100644 --- a/stpntolower.c +++ b/stpntolower.c @@ -10,11 +10,11 @@ libsimple_stpntolower(char *d, const char *s, size_t n) char *ret; if (d == s) { for (; n && *d; d++, n--) - *d = tolower(*d); + *d = (char)tolower(*d); return d; } else if (d < s) { for (; n && *s; d++, s++, n--) - *d = tolower(*s); + *d = (char)tolower(*s); if (n) *d = '\0'; return d; @@ -22,9 +22,9 @@ libsimple_stpntolower(char *d, const char *s, size_t n) for (i = 0; i < n && s[i]; i++); ret = &d[i]; if (i != n) - d[i] = tolower(s[i]); + d[i] = (char)tolower(s[i]); while (i--) - d[i] = tolower(s[i]); + d[i] = (char)tolower(s[i]); return ret; } } diff --git a/stpntoupper.c b/stpntoupper.c index a6e3769..a434153 100644 --- a/stpntoupper.c +++ b/stpntoupper.c @@ -10,11 +10,11 @@ libsimple_stpntoupper(char *d, const char *s, size_t n) char *ret; if (d == s) { for (; n && *d; d++, n--) - *d = toupper(*d); + *d = (char)toupper(*d); return d; } else if (d < s) { for (; n && *s; d++, s++, n--) - *d = toupper(*s); + *d = (char)toupper(*s); if (n) *d = '\0'; return d; @@ -22,9 +22,9 @@ libsimple_stpntoupper(char *d, const char *s, size_t n) for (i = 0; i < n && s[i]; i++); ret = &d[i]; if (i != n) - d[i] = toupper(s[i]); + d[i] = (char)toupper(s[i]); while (i--) - d[i] = toupper(s[i]); + d[i] = (char)toupper(s[i]); return ret; } } diff --git a/stptolower.c b/stptolower.c index 61108ad..73259f9 100644 --- a/stptolower.c +++ b/stptolower.c @@ -10,18 +10,18 @@ libsimple_stptolower(char *d, const char *s) char *ret; if (d == s) { for (; *d; d++) - *d = tolower(*d); + *d = (char)tolower(*d); return d; } else if (d < s) { for (; *s; d++, s++) - *d = tolower(*s); + *d = (char)tolower(*s); *d = '\0'; return d; } else { for (n = 0; s[n]; n++); ret = &d[n]; do { - d[n] = tolower(s[n]); + d[n] = (char)tolower(s[n]); } while (n--); return ret; } diff --git a/stptoupper.c b/stptoupper.c index ad6c73e..ee56b75 100644 --- a/stptoupper.c +++ b/stptoupper.c @@ -10,18 +10,18 @@ libsimple_stptoupper(char *d, const char *s) char *ret; if (d == s) { for (; *d; d++) - *d = toupper(*d); + *d = (char)toupper(*d); return d; } else if (d < s) { for (; *s; d++, s++) - *d = toupper(*s); + *d = (char)toupper(*s); *d = '\0'; return d; } else { for (n = 0; s[n]; n++); ret = &d[n]; do { - d[n] = toupper(s[n]); + d[n] = (char)toupper(s[n]); } while (n--); return ret; } diff --git a/strtoi.c b/strtoi.c index 6b3fcb2..448e485 100644 --- a/strtoi.c +++ b/strtoi.c @@ -6,7 +6,7 @@ signed int libsimple_strtoi(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ { - signed int r = strtol(nptr, end, base); + signed long int r = strtol(nptr, end, base); if(r < INT_MIN) { r = INT_MIN; errno = ERANGE; diff --git a/strtotimespec.c b/strtotimespec.c index d6bd64c..7c1494e 100644 --- a/strtotimespec.c +++ b/strtotimespec.c @@ -11,9 +11,12 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch long int nsec = 0; long int mul = 100000000L; const char *p; + const char *end_s; - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } while (isspace(*s)) s++; @@ -58,8 +61,10 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch if (*s != '.') { ts->tv_sec = sec; ts->tv_nsec = 0; - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } return 0; } @@ -85,7 +90,7 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch } } if (end) - *end = (void *)p; + *end = REMOVE_CONST(p, char *); p = s; while (mul) { for (s = p; mul && isdigit(*s); s++) { @@ -118,8 +123,10 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch while (isdigit(*s)) s++; } - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } } if (neg && nsec) { @@ -164,8 +171,10 @@ overflow_periodic: } overflow: - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } if (neg) { ts->tv_sec = TIME_MIN; ts->tv_nsec = 0; diff --git a/strtou.c b/strtou.c index 4201c1f..1faee3c 100644 --- a/strtou.c +++ b/strtou.c @@ -6,7 +6,7 @@ unsigned int libsimple_strtou(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ { - signed long int r = strtoul(nptr, end, base); + unsigned long int r = strtoul(nptr, end, base); if(r > UINT_MAX) { r = UINT_MAX; errno = ERANGE; diff --git a/strtouh.c b/strtouh.c index 7e4505f..9033930 100644 --- a/strtouh.c +++ b/strtouh.c @@ -6,7 +6,7 @@ unsigned short int libsimple_strtouh(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ { - signed long int r = strtoul(nptr, end, base); + unsigned long int r = strtoul(nptr, end, base); if(r > USHRT_MAX) { r = USHRT_MAX; errno = ERANGE; diff --git a/strtouhh.c b/strtouhh.c index b13800d..72dbd7c 100644 --- a/strtouhh.c +++ b/strtouhh.c @@ -6,7 +6,7 @@ unsigned char libsimple_strtouhh(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ { - signed long int r = strtoul(nptr, end, base); + unsigned long int r = strtoul(nptr, end, base); if(r > UCHAR_MAX) { r = UCHAR_MAX; errno = ERANGE; diff --git a/sumtimeval.c b/sumtimeval.c index e52d58f..09cadb1 100644 --- a/sumtimeval.c +++ b/sumtimeval.c @@ -47,62 +47,82 @@ main(void) { struct timeval r, a, b; - a.tv_sec = 0, a.tv_usec = 0; - b.tv_sec = 0, b.tv_usec = 0; + a.tv_sec = 0; + a.tv_usec = 0; + b.tv_sec = 0; + b.tv_usec = 0; assert(!libsimple_sumtimeval(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_usec == 0); - a.tv_sec = 10, a.tv_usec = 10000L; - b.tv_sec = 0, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 10000L; + b.tv_sec = 0; + b.tv_usec = 0L; assert(!libsimple_sumtimeval(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_usec == 10000L); - a.tv_sec = 10, a.tv_usec = 10000L; - b.tv_sec = -10, b.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 10000L; + b.tv_sec = -10; + b.tv_usec = 0L; assert(!libsimple_sumtimeval(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_usec == 10000L); - a.tv_sec = 10, a.tv_usec = 10000L; - b.tv_sec = -20, b.tv_usec = 20000L; + a.tv_sec = 10; + a.tv_usec = 10000L; + b.tv_sec = -20; + b.tv_usec = 20000L; assert(!libsimple_sumtimeval(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_usec == 30000L); - a.tv_sec = 1, a.tv_usec = 999999L; - b.tv_sec = 1, b.tv_usec = 1L; + a.tv_sec = 1; + a.tv_usec = 999999L; + b.tv_sec = 1; + b.tv_usec = 1L; assert(!libsimple_sumtimeval(&r, &a, &b)); assert(r.tv_sec == 3); assert(r.tv_usec == 0L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; - b.tv_sec = TIME_MAX, b.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; + b.tv_sec = TIME_MAX; + b.tv_usec = 0L; assert(libsimple_sumtimeval(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; - b.tv_sec = 0, b.tv_usec = 1L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; + b.tv_sec = 0; + b.tv_usec = 1L; assert(libsimple_sumtimeval(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 1L; - b.tv_sec = 0, b.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 1L; + b.tv_sec = 0; + b.tv_usec = 999999L; assert(libsimple_sumtimeval(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MIN, a.tv_usec = 0L; - b.tv_sec = TIME_MIN, b.tv_usec = 0L; + a.tv_sec = TIME_MIN; + a.tv_usec = 0L; + b.tv_sec = TIME_MIN; + b.tv_usec = 0L; assert(libsimple_sumtimeval(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 0L); - a.tv_sec = TIME_MIN, a.tv_usec = 100L; - b.tv_sec = TIME_MIN, b.tv_usec = 100L; + a.tv_sec = TIME_MIN; + a.tv_usec = 100L; + b.tv_sec = TIME_MIN; + b.tv_usec = 100L; assert(libsimple_sumtimeval(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 0L); diff --git a/test.c b/test.c index e5ecf00..29a501b 100644 --- a/test.c +++ b/test.c @@ -159,7 +159,7 @@ realloc(void *ptr, size_t size) return malloc(size); ret = malloc(size); if (!ret) - return malloc; + return NULL; info = get_allocinfo(ret); n = MIN(size, info->size); info->zeroed = MIN(n, info->zeroed); @@ -347,7 +347,7 @@ test_vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) n = (size_t)r; alloc_fail_in = 0; assert((buf = malloc(n + 1))); - n = vsnprintf(buf, n + 1, format, ap); + n = (size_t)vsnprintf(buf, n + 1, format, ap); if (fileno(stream) != STDERR_FILENO || stderr_real) { fwrite(buf, 1, n, stream); } else { diff --git a/test.h b/test.h index d8ac2d4..a961e13 100644 --- a/test.h +++ b/test.h @@ -52,7 +52,7 @@ assert(len__ >= 0);\ assert((size_t)len__ == stderr_n);\ assert(!memcmp(buf__, (char **)(void *)(&stderr_buf), stderr_n)); \ - } while (0); + } while (0) struct allocinfo { @@ -66,7 +66,9 @@ struct allocinfo { }; +#ifndef LIBSIMPLE_ARG_H extern char *argv0; +#endif extern volatile size_t alloc_fail_in; extern volatile int exit_real; @@ -98,17 +100,32 @@ test_fprintf(FILE *restrict stream, const char *restrict format, ...) +#if defined(__GNUC__) +__attribute__((__const__)) +#endif static size_t gcd(size_t u, size_t v) { size_t t; int shift = 0; /* Not needed because u>0, v>0: if (!(u | v)) return u + v; */ - while (!((u | v) & 1)) u >>= 1, v >>= 1, shift++; - while (!(u & 1)) u >>= 1; + while (!((u | v) & 1)) { + u >>= 1; + v >>= 1; + shift++; + } + while (!(u & 1)) { + u >>= 1; + } do { - while (!(v & 1)) v >>= 1; - if (u > v) t = u, u = v, v = t; + while (!(v & 1)) { + v >>= 1; + } + if (u > v) { + t = u; + u = v; + v = t; + } } while (v -= u); return u << shift; } diff --git a/timespectodouble.c b/timespectodouble.c new file mode 100644 index 0000000..e2d1bcc --- /dev/null +++ b/timespectodouble.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline double libsimple_timespectodouble(const struct timespec *); /* TODO tested in libsimple.c */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/timeval2timespec.c b/timeval2timespec.c new file mode 100644 index 0000000..e7e529e --- /dev/null +++ b/timeval2timespec.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_timeval2timespec(struct timespec *restrict, const struct timeval *restrict); + + +#else +#include "test.h" + +int +main(void) +{ + struct timespec ts; + libsimple_timeval2timespec(&ts, &(struct timeval){0, 0L}); + assert(ts.tv_sec == 0); + assert(ts.tv_nsec == 0L); + libsimple_timeval2timespec(&ts, &(struct timeval){0, 1L}); + assert(ts.tv_sec == 0); + assert(ts.tv_nsec == 1000L); + libsimple_timeval2timespec(&ts, &(struct timeval){0, 999999L}); + assert(ts.tv_sec == 0); + assert(ts.tv_nsec == 999999000L); + libsimple_timeval2timespec(&ts, &(struct timeval){10, 0L}); + assert(ts.tv_sec == 10); + assert(ts.tv_nsec == 0L); + libsimple_timeval2timespec(&ts, &(struct timeval){10, 1L}); + assert(ts.tv_sec == 10); + assert(ts.tv_nsec == 1000L); + libsimple_timeval2timespec(&ts, &(struct timeval){-10, 0L}); + assert(ts.tv_sec == -10); + assert(ts.tv_nsec == 0L); + libsimple_timeval2timespec(&ts, &(struct timeval){-10, 1L}); + assert(ts.tv_sec == -10); + assert(ts.tv_nsec == 1000L); + return 0; +} + +#endif diff --git a/timevaltodouble.c b/timevaltodouble.c new file mode 100644 index 0000000..1d3dacb --- /dev/null +++ b/timevaltodouble.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline double libsimple_timevaltodouble(const struct timeval *); /* TODO tested in libsimple.c */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/unlist.c b/unlist.c index 192fad0..92b7f8f 100644 --- a/unlist.c +++ b/unlist.c @@ -17,7 +17,7 @@ main(void) size_t i, n; for (i = 0, n = 10; i < n; i++) - buf[i] = i; + buf[i] = (char)i; LIBSIMPLE_UNLIST(buf, 4, &n); LIBSIMPLE_UNLIST(buf, 9 - 1, &n); LIBSIMPLE_UNLIST(buf, 6 - 1, &n); @@ -31,7 +31,7 @@ main(void) assert(buf[6] == 8); for (i = 0, n = 10; i < n; i++) - intarray[i] = i; + intarray[i] = (int)i; LIBSIMPLE_UNLIST(intarray, 4, &n); LIBSIMPLE_UNLIST(intarray, 9 - 1, &n); LIBSIMPLE_UNLIST(intarray, 6 - 1, &n); diff --git a/vallocz.c b/vallocz.c new file mode 100644 index 0000000..06263ed --- /dev/null +++ b/vallocz.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_vallocz(0, 9))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 9 || info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_vallocz(1, 7))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 7 || info->size == pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == 7 || info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_vallocz(1, 3 * pagesize))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 3 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == 3 * pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_vallocz(0, 4 * pagesize))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 4 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_vallocz(0, 8) && errno == ENOMEM); + assert(!alloc_fail_in); + + alloc_fail_in = 1; + assert(!libsimple_vallocz(1, 16) && errno == ENOMEM); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/valloczn.c b/valloczn.c new file mode 100644 index 0000000..27d6d1b --- /dev/null +++ b/valloczn.c @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_valloczn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *volatile info; + void *ptr; + DEFINE_PAGESIZE; + DEFINE_CACHELINE; + + assert((ptr = libsimple_valloczn(1, 3 * pagesize, 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 6 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == 6 * pagesize); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert((ptr = libsimple_valloczn(0, 4 * pagesize, 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 8 * pagesize); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)info->alignment)); + } + free(ptr); + ptr = NULL; + + assert(!libsimple_valloczn(0, 0) && errno == EINVAL); + errno = 0; + assert(!libsimple_valloczn(1, 0) && errno == EINVAL); + errno = 0; + + assert(!libsimple_valloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM); + errno = 0; + assert(!libsimple_valloczn(1, SIZE_MAX, 2, 0) && errno == ENOMEM); + errno = 0; + + assert((ptr = libsimple_valloczn(0, 9, 9, pagesize - 1, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 81 * (pagesize - 1)); + ASSERT_ALIGNMENT(info, pagesize); + assert(!info->zeroed); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + assert((ptr = libsimple_valloczn(1, 9, 8, pagesize - 2, 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 72 * (pagesize - 2)); + ASSERT_ALIGNMENT(info, pagesize); + assert(info->zeroed == info->size); + assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment))); + } + free(ptr); + + return 0; +} + +#endif diff --git a/venprintf.c b/venprintf.c new file mode 100644 index 0000000..1657954 --- /dev/null +++ b/venprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_venprintf(int, const char *, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enprintf */ +} + +#endif diff --git a/veprintf.c b/veprintf.c new file mode 100644 index 0000000..36d6f14 --- /dev/null +++ b/veprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_veprintf(const char *, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_eprintf */ +} + +#endif diff --git a/vmemalloc.c b/vmemalloc.c index 8d92035..cbaecea 100644 --- a/vmemalloc.c +++ b/vmemalloc.c @@ -76,7 +76,7 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap) case LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT: if (state->zero_init >= 0) goto inval; - state->zero_init = va_arg(ap, int); + state->zero_init = (char)va_arg(ap, int); state->zero_init = !!state->zero_init; break; @@ -158,7 +158,6 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap) } } - return 0; inval: errno = EINVAL; return -1; @@ -170,11 +169,23 @@ gcd(size_t u, size_t v) size_t t; int shift = 0; /* Not needed because u>0, v>0: if (!(u | v)) return u + v; */ - while (!((u | v) & 1)) u >>= 1, v >>= 1, shift++; - while (!(u & 1)) u >>= 1; + while (!((u | v) & 1)) { + u >>= 1; + v >>= 1; + shift++; + } + while (!(u & 1)) { + u >>= 1; + } do { - while (!(v & 1)) v >>= 1; - if (u > v) t = u, u = v, v = t; + while (!(v & 1)) { + v >>= 1; + } + if (u > v) { + t = u; + u = v; + v = t; + } } while (v -= u); return u << shift; } diff --git a/vposix_memalignn.c b/vposix_memalignn.c new file mode 100644 index 0000000..6001cdc --- /dev/null +++ b/vposix_memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_vposix_memalignn(void **, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_posix_memalignn */ +} + +#endif diff --git a/vpvallocn.c b/vpvallocn.c new file mode 100644 index 0000000..2a17882 --- /dev/null +++ b/vpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vpvallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_pvallocn */ +} + +#endif diff --git a/vpvalloczn.c b/vpvalloczn.c new file mode 100644 index 0000000..0aad778 --- /dev/null +++ b/vpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vpvalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_pvalloczn */ +} + +#endif diff --git a/vreallocfn.c b/vreallocfn.c new file mode 100644 index 0000000..fcd9c84 --- /dev/null +++ b/vreallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vreallocfn(void *, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_reallocfn */ +} + +#endif diff --git a/vvalloczn.c b/vvalloczn.c new file mode 100644 index 0000000..c387583 --- /dev/null +++ b/vvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vvalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_valloczn */ +} + +#endif diff --git a/vweprintf.c b/vweprintf.c index 9263d52..9c93037 100644 --- a/vweprintf.c +++ b/vweprintf.c @@ -69,111 +69,10 @@ libsimple_vweprintf(const char *fmt, va_list ap) #else #include "test.h" -#if defined(__GNUC__) && !defined(__clang__) -# pragma GCC diagnostic ignored "-Wformat-zero-length" -#endif - -static void -preprint(void) -{ - test_fprintf(stderr, "pre\n"); -} - -static void -postprint(void) -{ - test_fprintf(stderr, "post\n"); -} - int main(void) { - char prefix[100]; - int i, j; - -#define T(...)\ - do {\ - stderr_n = 0;\ - if (j == 0) {\ - libsimple_weprintf(__VA_ARGS__);\ - } else if (j == 1) {\ - assert_exit(libsimple_enprintf(107, __VA_ARGS__));\ - assert(exit_status == 107);\ - } else {\ - libsimple_default_failure_exit = 108;\ - assert_exit(libsimple_eprintf(__VA_ARGS__));\ - assert(exit_status == 108);\ - }\ - } while (0) - - sprintf(prefix, "%s: ", argv0); - stderr_ok = 1; - - for (i = 0; i < 2; i++, argv0 = NULL, *prefix = '\0') { - for (j = 0; j < 3; j++) { - T("%s%s%s\n", "abc", "123", "xyz"); - assert_stderr("%s%s\n", prefix, "abc123xyz"); - libsimple_eprintf_preprint = preprint; - T("%s%s%s\n", "abc", "123", "\n"); - assert_stderr("pre\n%s%s\n", prefix, "abc123\n"); - libsimple_eprintf_preprint = NULL; - libsimple_eprintf_postprint = postprint; - T("%s%s%s", "abc", "123", "xyz"); - assert_stderr("%s%s\npost\n", prefix, "abc123xyz"); - libsimple_eprintf_postprint = NULL; - T("%s%s%s", "abc", "123", "\n"); - assert_stderr("%s%s\n", prefix, "abc123\n"); - errno = EDOM; - libsimple_eprintf_preprint = preprint; - libsimple_eprintf_postprint = postprint; - T("%s%s%s:", "abc", "123", "\n"); - assert_stderr("pre\n%s%s: %s\npost\n", prefix, "abc123\n", strerror(EDOM)); - libsimple_eprintf_preprint = NULL; - libsimple_eprintf_postprint = NULL; - errno = ERANGE; - T("%s%s%s:", "abc", "123", "\n"); - assert_stderr("%s%s: %s\n", prefix, "abc123\n", strerror(ERANGE)); - errno = EOVERFLOW; - T(""); - assert_stderr("%s%s\n", prefix, strerror(EOVERFLOW)); - - T("%s%s%s\n", "usage: ", "123", "xyz"); - assert_stderr("%s%s\n", prefix, "usage: 123xyz"); - T("%s%s%s\n", "usage: ", "123", "\n"); - assert_stderr("%s%s\n", prefix, "usage: 123\n"); - T("%s%s%s", "usage: ", "123", "xyz"); - assert_stderr("%s%s\n", prefix, "usage: 123xyz"); - T("%s%s%s", "usage: ", "123", "\n"); - assert_stderr("%s%s\n", prefix, "usage: 123\n"); - errno = EDOM; - T("%s%s%s:", "usage: ", "123", "\n"); - assert_stderr("%s%s: %s\n", prefix, "usage: 123\n", strerror(EDOM)); - errno = ERANGE; - T("%s%s%s:", "usage: ", "123", "\n"); - assert_stderr("%s%s: %s\n", prefix, "usage: 123\n", strerror(ERANGE)); - - T("usage: %s%s%s\n", "abc", "123", "xyz"); - assert_stderr("%s: %s\n", "usage", "abc123xyz"); - T("usage: %s%s%s\n", "abc", "123", "\n"); - assert_stderr("%s: %s\n", "usage", "abc123\n"); - T("usage: %s%s%s", "abc", "123", "xyz"); - assert_stderr("%s: %s\n", "usage", "abc123xyz"); - T("usage: %s%s%s", "abc", "123", "\n"); - assert_stderr("%s: %s\n", "usage", "abc123\n"); - errno = EDOM; - T("usage: %s%s%s:", "abc", "123", "\n"); - assert_stderr("%s: %s: %s\n", "usage", "abc123\n", strerror(EDOM)); - errno = ERANGE; - T("usage: %s%s%s:", "abc", "123", "\n"); - assert_stderr("%s: %s: %s\n", "usage", "abc123\n", strerror(ERANGE)); - T("usage: "); - assert_stderr("%s", "usage: \n"); - } - } - -#undef T - - return 0; + return 0; /* Tested via libsimple_weprintf */ } #endif diff --git a/weprintf.c b/weprintf.c new file mode 100644 index 0000000..14984c6 --- /dev/null +++ b/weprintf.c @@ -0,0 +1,119 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void libsimple_weprintf(const char *, ...); + + +#else +#include "test.h" + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic ignored "-Wformat-zero-length" +#endif + +static void +preprint(void) +{ + test_fprintf(stderr, "pre\n"); +} + +static void +postprint(void) +{ + test_fprintf(stderr, "post\n"); +} + +int +main(void) +{ + char prefix[100]; + int i, j; + +#define T(...)\ + do {\ + stderr_n = 0;\ + if (j == 0) {\ + libsimple_weprintf(__VA_ARGS__);\ + } else if (j == 1) {\ + assert_exit(libsimple_enprintf(107, __VA_ARGS__));\ + assert(exit_status == 107);\ + } else {\ + libsimple_default_failure_exit = 108;\ + assert_exit(libsimple_eprintf(__VA_ARGS__));\ + assert(exit_status == 108);\ + }\ + } while (0) + + sprintf(prefix, "%s: ", argv0); + stderr_ok = 1; + + for (i = 0; i < 2; i++, argv0 = NULL, *prefix = '\0') { + for (j = 0; j < 3; j++) { + T("%s%s%s\n", "abc", "123", "xyz"); + assert_stderr("%s%s\n", prefix, "abc123xyz"); + libsimple_eprintf_preprint = preprint; + T("%s%s%s\n", "abc", "123", "\n"); + assert_stderr("pre\n%s%s\n", prefix, "abc123\n"); + libsimple_eprintf_preprint = NULL; + libsimple_eprintf_postprint = postprint; + T("%s%s%s", "abc", "123", "xyz"); + assert_stderr("%s%s\npost\n", prefix, "abc123xyz"); + libsimple_eprintf_postprint = NULL; + T("%s%s%s", "abc", "123", "\n"); + assert_stderr("%s%s\n", prefix, "abc123\n"); + errno = EDOM; + libsimple_eprintf_preprint = preprint; + libsimple_eprintf_postprint = postprint; + T("%s%s%s:", "abc", "123", "\n"); + assert_stderr("pre\n%s%s: %s\npost\n", prefix, "abc123\n", strerror(EDOM)); + libsimple_eprintf_preprint = NULL; + libsimple_eprintf_postprint = NULL; + errno = ERANGE; + T("%s%s%s:", "abc", "123", "\n"); + assert_stderr("%s%s: %s\n", prefix, "abc123\n", strerror(ERANGE)); + errno = EOVERFLOW; + T(""); + assert_stderr("%s%s\n", prefix, strerror(EOVERFLOW)); + + T("%s%s%s\n", "usage: ", "123", "xyz"); + assert_stderr("%s%s\n", prefix, "usage: 123xyz"); + T("%s%s%s\n", "usage: ", "123", "\n"); + assert_stderr("%s%s\n", prefix, "usage: 123\n"); + T("%s%s%s", "usage: ", "123", "xyz"); + assert_stderr("%s%s\n", prefix, "usage: 123xyz"); + T("%s%s%s", "usage: ", "123", "\n"); + assert_stderr("%s%s\n", prefix, "usage: 123\n"); + errno = EDOM; + T("%s%s%s:", "usage: ", "123", "\n"); + assert_stderr("%s%s: %s\n", prefix, "usage: 123\n", strerror(EDOM)); + errno = ERANGE; + T("%s%s%s:", "usage: ", "123", "\n"); + assert_stderr("%s%s: %s\n", prefix, "usage: 123\n", strerror(ERANGE)); + + T("usage: %s%s%s\n", "abc", "123", "xyz"); + assert_stderr("%s: %s\n", "usage", "abc123xyz"); + T("usage: %s%s%s\n", "abc", "123", "\n"); + assert_stderr("%s: %s\n", "usage", "abc123\n"); + T("usage: %s%s%s", "abc", "123", "xyz"); + assert_stderr("%s: %s\n", "usage", "abc123xyz"); + T("usage: %s%s%s", "abc", "123", "\n"); + assert_stderr("%s: %s\n", "usage", "abc123\n"); + errno = EDOM; + T("usage: %s%s%s:", "abc", "123", "\n"); + assert_stderr("%s: %s: %s\n", "usage", "abc123\n", strerror(EDOM)); + errno = ERANGE; + T("usage: %s%s%s:", "abc", "123", "\n"); + assert_stderr("%s: %s: %s\n", "usage", "abc123\n", strerror(ERANGE)); + T("usage: "); + assert_stderr("%s", "usage: \n"); + } + } + +#undef T + + return 0; +} + +#endif -- cgit v1.2.3-70-g09d2 From c76c12f0d0ea8c2f5fa6853636e3e7c2021ac93c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 11 Jun 2022 17:04:35 +0200 Subject: Remove `static` from some `static inline` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 91 +++++++++++++++++++++++++++++++++++++++++++++ aligned_allocn.c | 18 +++++++++ aligned_allocz.c | 18 +++++++++ aligned_alloczn.c | 18 +++++++++ aligned_realloc.c | 18 +++++++++ aligned_reallocarray.c | 18 +++++++++ aligned_reallocarrayf.c | 18 +++++++++ aligned_reallocf.c | 18 +++++++++ aligned_reallocfn.c | 18 +++++++++ aligned_reallocn.c | 18 +++++++++ callocn.c | 18 +++++++++ ealigned_alloc.c | 18 +++++++++ ealigned_allocn.c | 18 +++++++++ ealigned_allocz.c | 18 +++++++++ ealigned_alloczn.c | 18 +++++++++ ealigned_realloc.c | 18 +++++++++ ealigned_reallocarray.c | 18 +++++++++ ealigned_reallocn.c | 18 +++++++++ ecalloc.c | 18 +++++++++ ecallocn.c | 18 +++++++++ emalloc.c | 18 +++++++++ emallocn.c | 18 +++++++++ emallocz.c | 18 +++++++++ emalloczn.c | 18 +++++++++ ememalign.c | 18 +++++++++ ememalignn.c | 18 +++++++++ ememalignz.c | 18 +++++++++ ememalignzn.c | 18 +++++++++ enaligned_alloc.c | 18 +++++++++ enaligned_allocn.c | 18 +++++++++ enaligned_alloczn.c | 18 +++++++++ enaligned_reallocn.c | 18 +++++++++ encallocn.c | 18 +++++++++ enmallocn.c | 18 +++++++++ enmallocz.c | 18 +++++++++ enmalloczn.c | 18 +++++++++ enmemalign.c | 18 +++++++++ enmemalignn.c | 18 +++++++++ enmemalignz.c | 18 +++++++++ enmemalignzn.c | 18 +++++++++ envaligned_allocn.c | 18 +++++++++ envalloc.c | 18 +++++++++ envallocn.c | 18 +++++++++ envcallocn.c | 18 +++++++++ envmallocn.c | 18 +++++++++ envmemalignn.c | 18 +++++++++ envmemalignzn.c | 18 +++++++++ envvallocn.c | 18 +++++++++ evaligned_allocn.c | 18 +++++++++ evaligned_alloczn.c | 18 +++++++++ evaligned_reallocn.c | 18 +++++++++ evalloc.c | 18 +++++++++ evallocn.c | 18 +++++++++ evcallocn.c | 18 +++++++++ evmallocn.c | 18 +++++++++ evmalloczn.c | 18 +++++++++ evmemalignn.c | 18 +++++++++ evmemalignzn.c | 18 +++++++++ evvallocn.c | 18 +++++++++ libsimple/aligned_alloc.h | 16 ++++---- libsimple/aligned_allocz.h | 12 +++--- libsimple/aligned_realloc.h | 32 ++++++++-------- libsimple/calloc.h | 14 +++---- libsimple/malloc.h | 14 +++---- libsimple/mallocz.h | 14 +++---- libsimple/memalign.h | 18 ++++----- libsimple/memalignz.h | 18 ++++----- libsimple/strn.h | 34 ++++++++--------- libsimple/valloc.h | 18 ++++----- mallocn.c | 18 +++++++++ mallocz.c | 18 +++++++++ malloczn.c | 18 +++++++++ memalign.c | 18 +++++++++ memalignn.c | 18 +++++++++ memalignz.c | 18 +++++++++ memalignzn.c | 18 +++++++++ stpnmove.c | 18 +++++++++ stpnset.c | 18 +++++++++ strncasecmpnul.c | 18 +++++++++ strncaseeq.c | 18 +++++++++ strncaseeqnul.c | 18 +++++++++ strnccpy.c | 18 +++++++++ strncmpnul.c | 18 +++++++++ strneq.c | 18 +++++++++ strneqnul.c | 18 +++++++++ strnisutf8.c | 18 +++++++++ strnmove.c | 18 +++++++++ strnreplace.c | 18 +++++++++ strnset.c | 18 +++++++++ strntolower.c | 18 +++++++++ strntoupper.c | 18 +++++++++ strrncaseeqlen.c | 18 +++++++++ strrneqlen.c | 18 +++++++++ valigned_allocn.c | 18 +++++++++ valigned_reallocfn.c | 18 +++++++++ valloc.c | 18 +++++++++ vallocn.c | 18 +++++++++ vcallocn.c | 18 +++++++++ vmallocn.c | 18 +++++++++ vmemalignn.c | 18 +++++++++ vmemalignzn.c | 18 +++++++++ vvallocn.c | 18 +++++++++ 102 files changed, 1824 insertions(+), 95 deletions(-) create mode 100644 aligned_allocn.c create mode 100644 aligned_allocz.c create mode 100644 aligned_alloczn.c create mode 100644 aligned_realloc.c create mode 100644 aligned_reallocarray.c create mode 100644 aligned_reallocarrayf.c create mode 100644 aligned_reallocf.c create mode 100644 aligned_reallocfn.c create mode 100644 aligned_reallocn.c create mode 100644 callocn.c create mode 100644 ealigned_alloc.c create mode 100644 ealigned_allocn.c create mode 100644 ealigned_allocz.c create mode 100644 ealigned_alloczn.c create mode 100644 ealigned_realloc.c create mode 100644 ealigned_reallocarray.c create mode 100644 ealigned_reallocn.c create mode 100644 ecalloc.c create mode 100644 ecallocn.c create mode 100644 emalloc.c create mode 100644 emallocn.c create mode 100644 emallocz.c create mode 100644 emalloczn.c create mode 100644 ememalign.c create mode 100644 ememalignn.c create mode 100644 ememalignz.c create mode 100644 ememalignzn.c create mode 100644 enaligned_alloc.c create mode 100644 enaligned_allocn.c create mode 100644 enaligned_alloczn.c create mode 100644 enaligned_reallocn.c create mode 100644 encallocn.c create mode 100644 enmallocn.c create mode 100644 enmallocz.c create mode 100644 enmalloczn.c create mode 100644 enmemalign.c create mode 100644 enmemalignn.c create mode 100644 enmemalignz.c create mode 100644 enmemalignzn.c create mode 100644 envaligned_allocn.c create mode 100644 envalloc.c create mode 100644 envallocn.c create mode 100644 envcallocn.c create mode 100644 envmallocn.c create mode 100644 envmemalignn.c create mode 100644 envmemalignzn.c create mode 100644 envvallocn.c create mode 100644 evaligned_allocn.c create mode 100644 evaligned_alloczn.c create mode 100644 evaligned_reallocn.c create mode 100644 evalloc.c create mode 100644 evallocn.c create mode 100644 evcallocn.c create mode 100644 evmallocn.c create mode 100644 evmalloczn.c create mode 100644 evmemalignn.c create mode 100644 evmemalignzn.c create mode 100644 evvallocn.c create mode 100644 mallocn.c create mode 100644 mallocz.c create mode 100644 malloczn.c create mode 100644 memalign.c create mode 100644 memalignn.c create mode 100644 memalignz.c create mode 100644 memalignzn.c create mode 100644 stpnmove.c create mode 100644 stpnset.c create mode 100644 strncasecmpnul.c create mode 100644 strncaseeq.c create mode 100644 strncaseeqnul.c create mode 100644 strnccpy.c create mode 100644 strncmpnul.c create mode 100644 strneq.c create mode 100644 strneqnul.c create mode 100644 strnisutf8.c create mode 100644 strnmove.c create mode 100644 strnreplace.c create mode 100644 strnset.c create mode 100644 strntolower.c create mode 100644 strntoupper.c create mode 100644 strrncaseeqlen.c create mode 100644 strrneqlen.c create mode 100644 valigned_allocn.c create mode 100644 valigned_reallocfn.c create mode 100644 valloc.c create mode 100644 vallocn.c create mode 100644 vcallocn.c create mode 100644 vmallocn.c create mode 100644 vmemalignn.c create mode 100644 vmemalignzn.c create mode 100644 vvallocn.c (limited to 'Makefile') diff --git a/Makefile b/Makefile index 3299480..57bc372 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,16 @@ HDR =\ libsimple.h OBJ =\ + aligned_allocn.o\ + aligned_allocz.o\ + aligned_alloczn.o\ aligned_memdup.o\ + aligned_realloc.o\ + aligned_reallocarray.o\ + aligned_reallocarrayf.o\ + aligned_reallocf.o\ + aligned_reallocfn.o\ + aligned_reallocn.o\ aligned_strdup.o\ aligned_strndup.o\ aligned_wcsdup.o\ @@ -57,6 +66,7 @@ OBJ =\ aligned_wmemdup.o\ allocn.o\ asprintf.o\ + callocn.o\ close.o\ cmptimespec.o\ cmptimeval.o\ @@ -64,29 +74,58 @@ OBJ =\ difftimeval.o\ doubletotimespec.o\ doubletotimeval.o\ + ealigned_alloc.o\ + ealigned_allocn.o\ + ealigned_allocz.o\ + ealigned_alloczn.o\ ealigned_memdup.o\ + ealigned_realloc.o\ + ealigned_reallocarray.o\ + ealigned_reallocn.o\ ealigned_strdup.o\ ealigned_strndup.o\ ealigned_wcsdup.o\ ealigned_wcsndup.o\ ealigned_wmemdup.o\ + ecalloc.o\ + ecallocn.o\ egmtime.o\ elocaltime.o\ + emalloc.o\ + emallocn.o\ + emallocz.o\ + emalloczn.o\ + ememalign.o\ + ememalignn.o\ + ememalignz.o\ + ememalignzn.o\ ememalloc.o\ ememdup.o\ + enaligned_alloc.o\ + enaligned_allocn.o\ enaligned_allocz.o\ + enaligned_alloczn.o\ enaligned_memdup.o\ enaligned_realloc.o\ enaligned_reallocarray.o\ + enaligned_reallocn.o\ enaligned_strdup.o\ enaligned_strndup.o\ enaligned_wcsdup.o\ enaligned_wcsndup.o\ enaligned_wmemdup.o\ encalloc.o\ + encallocn.o\ engmtime.o\ enlocaltime.o\ enmalloc.o\ + enmallocn.o\ + enmallocz.o\ + enmalloczn.o\ + enmemalign.o\ + enmemalignn.o\ + enmemalignz.o\ + enmemalignzn.o\ enmemalloc.o\ enmemdup.o\ enposix_memalign.o\ @@ -104,11 +143,18 @@ OBJ =\ enreallocn.o\ enstrdup.o\ enstrndup.o\ + envaligned_allocn.o\ envaligned_alloczn.o\ envaligned_reallocn.o\ + envalloc.o\ + envallocn.o\ envallocz.o\ envalloczn.o\ + envcallocn.o\ + envmallocn.o\ envmalloczn.o\ + envmemalignn.o\ + envmemalignzn.o\ envmemalloc.o\ envposix_memalignn.o\ envposix_memalignzn.o\ @@ -116,6 +162,7 @@ OBJ =\ envpvallocn.o\ envpvalloczn.o\ envreallocn.o\ + envvallocn.o\ envvalloczn.o\ enwcsdup.o\ enwcsndup.o\ @@ -135,8 +182,18 @@ OBJ =\ ereallocn.o\ estrdup.o\ estrndup.o\ + evaligned_allocn.o\ + evaligned_alloczn.o\ + evaligned_reallocn.o\ + evalloc.o\ + evallocn.o\ evallocz.o\ evalloczn.o\ + evcallocn.o\ + evmallocn.o\ + evmalloczn.o\ + evmemalignn.o\ + evmemalignzn.o\ evmemalloc.o\ evposix_memalignn.o\ evposix_memalignzn.o\ @@ -144,6 +201,7 @@ OBJ =\ evpvallocn.o\ evpvalloczn.o\ evreallocn.o\ + evvallocn.o\ evvalloczn.o\ ewcsdup.o\ ewcsndup.o\ @@ -152,6 +210,13 @@ OBJ =\ getenv_ne.o\ gmtime.o\ localtime.o\ + mallocn.o\ + mallocz.o\ + malloczn.o\ + memalign.o\ + memalignn.o\ + memalignz.o\ + memalignzn.o\ memalloc.o\ memcasechr.o\ memcasechr_inv.o\ @@ -233,6 +298,8 @@ OBJ =\ reallocf.o\ reallocfn.o\ reallocn.o\ + stpnmove.o\ + stpnset.o\ stpntolower.o\ stpntoupper.o\ stptolower.o\ @@ -254,29 +321,44 @@ OBJ =\ strncasechr_inv.o\ strncasechrnul.o\ strncasechrnul_inv.o\ + strncasecmpnul.o\ strncaseends.o\ + strncaseeq.o\ strncaseeqlen.o\ + strncaseeqnul.o\ strncasestarts.o\ strncasestr.o\ + strnccpy.o\ strnchr.o\ strnchr_inv.o\ strnchrnul.o\ strnchrnul_inv.o\ strncmove.o\ + strncmpnul.o\ strnend.o\ strnends.o\ + strneq.o\ strneqlen.o\ + strneqnul.o\ + strnisutf8.o\ + strnmove.o\ + strnreplace.o\ + strnset.o\ strnstarts.o\ strnstr.o\ + strntolower.o\ + strntoupper.o\ strrcasechr.o\ strrcasechr_inv.o\ strrcasestr.o\ strrchr_inv.o\ strrncasechr.o\ strrncasechr_inv.o\ + strrncaseeqlen.o\ strrncasestr.o\ strrnchr.o\ strrnchr_inv.o\ + strrneqlen.o\ strrnstr.o\ strrstr.o\ strstarts.o\ @@ -307,17 +389,26 @@ OBJ =\ timevaltodouble.o\ timevaltostr.o\ unlist.o\ + valigned_allocn.o\ + valigned_reallocfn.o\ + valloc.o\ + vallocn.o\ vallocz.o\ valloczn.o\ vasprintf.o\ + vcallocn.o\ venprintf.o\ veprintf.o\ + vmallocn.o\ + vmemalignn.o\ + vmemalignzn.o\ vmemalloc.o\ vposix_memalignn.o\ vputenvf.o\ vpvallocn.o\ vpvalloczn.o\ vreallocfn.o\ + vvallocn.o\ vvalloczn.o\ vweprintf.o\ wcsndup.o\ diff --git a/aligned_allocn.c b/aligned_allocn.c new file mode 100644 index 0000000..42e614c --- /dev/null +++ b/aligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_allocn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_allocz.c b/aligned_allocz.c new file mode 100644 index 0000000..ab18d1a --- /dev/null +++ b/aligned_allocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_allocz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_alloczn.c b/aligned_alloczn.c new file mode 100644 index 0000000..9b35a17 --- /dev/null +++ b/aligned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_alloczn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_realloc.c b/aligned_realloc.c new file mode 100644 index 0000000..1aaa0b9 --- /dev/null +++ b/aligned_realloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_realloc(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocarray.c b/aligned_reallocarray.c new file mode 100644 index 0000000..185f24a --- /dev/null +++ b/aligned_reallocarray.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocarray(void *, size_t, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocarrayf.c b/aligned_reallocarrayf.c new file mode 100644 index 0000000..561615f --- /dev/null +++ b/aligned_reallocarrayf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocarrayf(void *, size_t, size_t, size_t); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocf.c b/aligned_reallocf.c new file mode 100644 index 0000000..9493fb9 --- /dev/null +++ b/aligned_reallocf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocf(void *, size_t, size_t); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocfn.c b/aligned_reallocfn.c new file mode 100644 index 0000000..21e97ec --- /dev/null +++ b/aligned_reallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocfn(void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocn.c b/aligned_reallocn.c new file mode 100644 index 0000000..ffae2fd --- /dev/null +++ b/aligned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocn(void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/callocn.c b/callocn.c new file mode 100644 index 0000000..70b95a6 --- /dev/null +++ b/callocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_callocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_alloc.c b/ealigned_alloc.c new file mode 100644 index 0000000..8076b23 --- /dev/null +++ b/ealigned_alloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_alloc(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_allocn.c b/ealigned_allocn.c new file mode 100644 index 0000000..e10399b --- /dev/null +++ b/ealigned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_allocn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_allocz.c b/ealigned_allocz.c new file mode 100644 index 0000000..586df48 --- /dev/null +++ b/ealigned_allocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_allocz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_alloczn.c b/ealigned_alloczn.c new file mode 100644 index 0000000..2787549 --- /dev/null +++ b/ealigned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_alloczn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_realloc.c b/ealigned_realloc.c new file mode 100644 index 0000000..40b8372 --- /dev/null +++ b/ealigned_realloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_realloc(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_reallocarray.c b/ealigned_reallocarray.c new file mode 100644 index 0000000..8f44315 --- /dev/null +++ b/ealigned_reallocarray.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_reallocarray(void *, size_t, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_reallocn.c b/ealigned_reallocn.c new file mode 100644 index 0000000..3292a5a --- /dev/null +++ b/ealigned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_reallocn(void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ecalloc.c b/ecalloc.c new file mode 100644 index 0000000..edf3549 --- /dev/null +++ b/ecalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ecalloc(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ecallocn.c b/ecallocn.c new file mode 100644 index 0000000..d5cf8f4 --- /dev/null +++ b/ecallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ecallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emalloc.c b/emalloc.c new file mode 100644 index 0000000..54da30d --- /dev/null +++ b/emalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_emalloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emallocn.c b/emallocn.c new file mode 100644 index 0000000..e742427 --- /dev/null +++ b/emallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_emallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emallocz.c b/emallocz.c new file mode 100644 index 0000000..ab52b36 --- /dev/null +++ b/emallocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_emallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emalloczn.c b/emalloczn.c new file mode 100644 index 0000000..760ee59 --- /dev/null +++ b/emalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_emalloczn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalign.c b/ememalign.c new file mode 100644 index 0000000..422c08d --- /dev/null +++ b/ememalign.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ememalign(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalignn.c b/ememalignn.c new file mode 100644 index 0000000..cda6e99 --- /dev/null +++ b/ememalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ememalignn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalignz.c b/ememalignz.c new file mode 100644 index 0000000..2ca550d --- /dev/null +++ b/ememalignz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ememalignz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalignzn.c b/ememalignzn.c new file mode 100644 index 0000000..72ab6f2 --- /dev/null +++ b/ememalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_ememalignzn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_alloc.c b/enaligned_alloc.c new file mode 100644 index 0000000..b7f8754 --- /dev/null +++ b/enaligned_alloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_alloc(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_allocn.c b/enaligned_allocn.c new file mode 100644 index 0000000..2c10177 --- /dev/null +++ b/enaligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_allocn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_alloczn.c b/enaligned_alloczn.c new file mode 100644 index 0000000..55f00d7 --- /dev/null +++ b/enaligned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_alloczn(int, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_reallocn.c b/enaligned_reallocn.c new file mode 100644 index 0000000..3b561d8 --- /dev/null +++ b/enaligned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_reallocn(int, void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/encallocn.c b/encallocn.c new file mode 100644 index 0000000..49336da --- /dev/null +++ b/encallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_encallocn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmallocn.c b/enmallocn.c new file mode 100644 index 0000000..761f196 --- /dev/null +++ b/enmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmallocn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmallocz.c b/enmallocz.c new file mode 100644 index 0000000..6204df8 --- /dev/null +++ b/enmallocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmallocz(int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmalloczn.c b/enmalloczn.c new file mode 100644 index 0000000..69636f5 --- /dev/null +++ b/enmalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmalloczn(int, int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalign.c b/enmemalign.c new file mode 100644 index 0000000..766317d --- /dev/null +++ b/enmemalign.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalign(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalignn.c b/enmemalignn.c new file mode 100644 index 0000000..d7f67c7 --- /dev/null +++ b/enmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalignn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalignz.c b/enmemalignz.c new file mode 100644 index 0000000..11fdb3a --- /dev/null +++ b/enmemalignz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalignz(int, int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalignzn.c b/enmemalignzn.c new file mode 100644 index 0000000..4a43192 --- /dev/null +++ b/enmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalignzn(int, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envaligned_allocn.c b/envaligned_allocn.c new file mode 100644 index 0000000..622eada --- /dev/null +++ b/envaligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envaligned_allocn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envalloc.c b/envalloc.c new file mode 100644 index 0000000..48f8fe2 --- /dev/null +++ b/envalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envalloc(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envallocn.c b/envallocn.c new file mode 100644 index 0000000..664d50c --- /dev/null +++ b/envallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envallocn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envcallocn.c b/envcallocn.c new file mode 100644 index 0000000..1e5a0dd --- /dev/null +++ b/envcallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envcallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envmallocn.c b/envmallocn.c new file mode 100644 index 0000000..531234e --- /dev/null +++ b/envmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envmallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envmemalignn.c b/envmemalignn.c new file mode 100644 index 0000000..8df18c0 --- /dev/null +++ b/envmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envmemalignn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envmemalignzn.c b/envmemalignzn.c new file mode 100644 index 0000000..278785f --- /dev/null +++ b/envmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envmemalignzn(int, int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envvallocn.c b/envvallocn.c new file mode 100644 index 0000000..93ea889 --- /dev/null +++ b/envvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_envvallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evaligned_allocn.c b/evaligned_allocn.c new file mode 100644 index 0000000..4f318fe --- /dev/null +++ b/evaligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evaligned_allocn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evaligned_alloczn.c b/evaligned_alloczn.c new file mode 100644 index 0000000..1e5d543 --- /dev/null +++ b/evaligned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evaligned_alloczn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evaligned_reallocn.c b/evaligned_reallocn.c new file mode 100644 index 0000000..676fbb6 --- /dev/null +++ b/evaligned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evaligned_reallocn(void *, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evalloc.c b/evalloc.c new file mode 100644 index 0000000..6103b9e --- /dev/null +++ b/evalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evalloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evallocn.c b/evallocn.c new file mode 100644 index 0000000..7f736fc --- /dev/null +++ b/evallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evcallocn.c b/evcallocn.c new file mode 100644 index 0000000..d577ebc --- /dev/null +++ b/evcallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evcallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evmallocn.c b/evmallocn.c new file mode 100644 index 0000000..f15b8d6 --- /dev/null +++ b/evmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evmallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evmalloczn.c b/evmalloczn.c new file mode 100644 index 0000000..3afa855 --- /dev/null +++ b/evmalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evmalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evmemalignn.c b/evmemalignn.c new file mode 100644 index 0000000..5cacc95 --- /dev/null +++ b/evmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evmemalignn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evmemalignzn.c b/evmemalignzn.c new file mode 100644 index 0000000..643d5a6 --- /dev/null +++ b/evmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evmemalignzn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evvallocn.c b/evvallocn.c new file mode 100644 index 0000000..a87d171 --- /dev/null +++ b/evvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_evvallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/libsimple/aligned_alloc.h b/libsimple/aligned_alloc.h index a4fe0fc..6916b9a 100644 --- a/libsimple/aligned_alloc.h +++ b/libsimple/aligned_alloc.h @@ -20,7 +20,7 @@ * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) -static inline void * +inline void * libsimple_valigned_allocn(size_t alignment__, size_t n__, va_list ap__) { return libsimple_valigned_alloczn(0, alignment__, n__, ap__); @@ -42,7 +42,7 @@ libsimple_valigned_allocn(size_t alignment__, size_t n__, va_list ap__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) -static inline void * +inline void * libsimple_aligned_allocn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -71,7 +71,7 @@ libsimple_aligned_allocn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enaligned_alloc(int status__, size_t alignment__, size_t n__) { return libsimple_enaligned_allocz(status__, 0, alignment__, n__); @@ -103,7 +103,7 @@ libsimple_enaligned_alloc(int status__, size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envaligned_allocn(int status__, size_t alignment__, size_t n__, va_list ap__) { return libsimple_envaligned_alloczn(status__, 0, alignment__, n__, ap__); @@ -135,7 +135,7 @@ libsimple_envaligned_allocn(int status__, size_t alignment__, size_t n__, va_lis * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enaligned_allocn(int status__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -163,7 +163,7 @@ libsimple_enaligned_allocn(int status__, size_t alignment__, size_t n__, ... /*, * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_alloc(size_t alignment__, size_t n__) { return libsimple_enaligned_alloc(libsimple_default_failure_exit, alignment__, n__); @@ -194,7 +194,7 @@ libsimple_ealigned_alloc(size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evaligned_allocn(size_t alignment__, size_t n__, va_list ap__) { return libsimple_envaligned_allocn(libsimple_default_failure_exit, alignment__, n__, ap__); @@ -225,7 +225,7 @@ libsimple_evaligned_allocn(size_t alignment__, size_t n__, va_list ap__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_allocn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/aligned_allocz.h b/libsimple/aligned_allocz.h index 7213c9b..b27a17b 100644 --- a/libsimple/aligned_allocz.h +++ b/libsimple/aligned_allocz.h @@ -41,7 +41,7 @@ void *libsimple_valigned_alloczn(int, size_t, size_t, va_list); * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) -static inline void * +inline void * libsimple_aligned_allocz(int clear__, size_t alignment__, size_t n__) { void *ret__ = aligned_alloc(alignment__, n__); @@ -74,7 +74,7 @@ libsimple_aligned_allocz(int clear__, size_t alignment__, size_t n__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_aligned_alloczn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -162,7 +162,7 @@ void *libsimple_envaligned_alloczn(int, int, size_t, size_t, va_list); * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enaligned_alloczn(int status__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -190,7 +190,7 @@ libsimple_enaligned_alloczn(int status__, int clear__, size_t alignment__, size_ * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_allocz(int clear__, size_t alignment__, size_t n__) { return libsimple_enaligned_allocz(libsimple_default_failure_exit, clear__, alignment__, n__); @@ -222,7 +222,7 @@ libsimple_ealigned_allocz(int clear__, size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evaligned_alloczn(int clear__, size_t alignment__, size_t n__, va_list ap__) { return libsimple_envaligned_alloczn(libsimple_default_failure_exit, clear__, alignment__, n__, ap__); @@ -254,7 +254,7 @@ libsimple_evaligned_alloczn(int clear__, size_t alignment__, size_t n__, va_list * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_alloczn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/aligned_realloc.h b/libsimple/aligned_realloc.h index bc66d84..0c81cd7 100644 --- a/libsimple/aligned_realloc.h +++ b/libsimple/aligned_realloc.h @@ -31,7 +31,7 @@ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __war #if defined(__GLIBC__) # define LIBSIMPLE_HAVE_ALIGNED_REALLOC # include -static inline void * +inline void * libsimple_aligned_realloc(void *ptr__, size_t alignment__, size_t n__) /* TODO musl */ { size_t old__ = malloc_usable_size(ptr__); @@ -48,7 +48,7 @@ libsimple_aligned_realloc(void *ptr__, size_t alignment__, size_t n__) /* TODO m return new__; } #else -static inline void * +inline void * libsimple_aligned_realloc(void *ptr__, size_t alignment__, size_t n__) { (void) ptr__; @@ -122,7 +122,7 @@ void *libsimple_enaligned_realloc(int, void *, size_t, size_t); * the specified size */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_realloc(void *ptr__, size_t alignment__, size_t n__) { return libsimple_enaligned_realloc(libsimple_default_failure_exit, ptr__, alignment__, n__); @@ -159,8 +159,8 @@ libsimple_ealigned_realloc(void *ptr__, size_t alignment__, size_t n__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) -static inline void * -libsimple_aligned_reallocf(void *ptr__, size_t alignment__, size_t n__) /* TODO test */ +inline void * +libsimple_aligned_reallocf(void *ptr__, size_t alignment__, size_t n__) { void *new__ = n__ ? libsimple_aligned_realloc(ptr__, alignment__, n__) : NULL; if (!new__) @@ -202,7 +202,7 @@ libsimple_aligned_reallocf(void *ptr__, size_t alignment__, size_t n__) /* TODO * @throws ENOSYS Not implemented (requires non-standard libc functions) */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) -static inline void * +inline void * libsimple_aligned_reallocarray(void *ptr__, size_t alignment__, size_t n__, size_t m__) { if (LIBSIMPLE_UMUL_OVERFLOW(n__, m__, &n__, SIZE_MAX)) { @@ -282,7 +282,7 @@ void *libsimple_enaligned_reallocarray(int, void *, size_t, size_t, size_t); * the specified size */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_reallocarray(void *ptr__, size_t alignment__, size_t n__, size_t m__) { return libsimple_enaligned_reallocarray(libsimple_default_failure_exit, ptr__, alignment__, n__, m__); @@ -318,8 +318,8 @@ libsimple_ealigned_reallocarray(void *ptr__, size_t alignment__, size_t n__, siz * @throws ENOSYS Not implemented (requires non-standard libc functions) */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) -static inline void * -libsimple_aligned_reallocarrayf(void *ptr__, size_t alignment__, size_t n__, size_t m__) /* TODO test */ +inline void * +libsimple_aligned_reallocarrayf(void *ptr__, size_t alignment__, size_t n__, size_t m__) { void *new__ = (n__ && m__) ? libsimple_aligned_reallocarray(ptr__, alignment__, n__, m__) : NULL; if (!new__) @@ -437,7 +437,7 @@ void *libsimple_envaligned_reallocn(int, void *, size_t, size_t, va_list); * the specified size */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evaligned_reallocn(void *ptr__, size_t alignment__, size_t n__, va_list ap__) { return libsimple_envaligned_reallocn(libsimple_default_failure_exit, ptr__, alignment__, n__, ap__); @@ -474,8 +474,8 @@ libsimple_evaligned_reallocn(void *ptr__, size_t alignment__, size_t n__, va_lis * @throws ENOSYS Not implemented (requires non-standard libc functions) */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) -static inline void * -libsimple_valigned_reallocfn(void *ptr__, size_t alignment__, size_t n__, va_list ap__) /* TODO test (aligned_reallocfn) */ +inline void * +libsimple_valigned_reallocfn(void *ptr__, size_t alignment__, size_t n__, va_list ap__) { void *new__ = libsimple_valigned_reallocn(ptr__, alignment__, n__, ap__); if (!new__) @@ -518,7 +518,7 @@ libsimple_valigned_reallocfn(void *ptr__, size_t alignment__, size_t n__, va_lis * @throws ENOSYS Not implemented (requires non-standard libc functions) */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_aligned_reallocn(void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -563,7 +563,7 @@ libsimple_aligned_reallocn(void *ptr__, size_t alignment__, size_t n__, ... /*, * the specified size */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enaligned_reallocn(int status__, void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -607,7 +607,7 @@ libsimple_enaligned_reallocn(int status__, void *ptr__, size_t alignment__, size * the specified size */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ealigned_reallocn(void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -651,7 +651,7 @@ libsimple_ealigned_reallocn(void *ptr__, size_t alignment__, size_t n__, ... /*, * @throws ENOSYS Not implemented (requires non-standard libc functions) */ LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_aligned_reallocfn(void *ptr__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/calloc.h b/libsimple/calloc.h index 28f284d..7e6500e 100644 --- a/libsimple/calloc.h +++ b/libsimple/calloc.h @@ -19,7 +19,7 @@ * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_vcallocn(size_t n__, va_list ap__) { return libsimple_vmalloczn(1, n__, ap__); @@ -47,7 +47,7 @@ libsimple_vcallocn(size_t n__, va_list ap__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_callocn(size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -106,7 +106,7 @@ void *libsimple_encalloc(int, size_t, size_t); * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envcallocn(int status__, size_t n__, va_list ap__) { return libsimple_envmalloczn(status__, 1, n__, ap__); @@ -136,7 +136,7 @@ libsimple_envcallocn(int status__, size_t n__, va_list ap__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_encallocn(int status__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -165,7 +165,7 @@ libsimple_encallocn(int status__, size_t n__, ... /*, (size_t)0 */) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1, 2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ecalloc(size_t n__, size_t m__) { return encalloc(libsimple_default_failure_exit, n__, m__); @@ -194,7 +194,7 @@ libsimple_ecalloc(size_t n__, size_t m__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evcallocn(size_t n__, va_list ap__) { return libsimple_envcallocn(libsimple_default_failure_exit, n__, ap__); @@ -223,7 +223,7 @@ libsimple_evcallocn(size_t n__, va_list ap__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ecallocn(size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/malloc.h b/libsimple/malloc.h index ca057da..df742a1 100644 --- a/libsimple/malloc.h +++ b/libsimple/malloc.h @@ -19,7 +19,7 @@ * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_vmallocn(size_t n__, va_list ap__) { return libsimple_vmalloczn(0, n__, ap__); @@ -47,7 +47,7 @@ libsimple_vmallocn(size_t n__, va_list ap__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_mallocn(size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -104,7 +104,7 @@ void *libsimple_enmalloc(int, size_t); * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envmallocn(int status__, size_t n__, va_list ap__) { return libsimple_envmalloczn(status__, 0, n__, ap__); @@ -134,7 +134,7 @@ libsimple_envmallocn(int status__, size_t n__, va_list ap__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmallocn(int status__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -161,7 +161,7 @@ libsimple_enmallocn(int status__, size_t n__, ... /*, (size_t)0 */) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_emalloc(size_t n__) { return libsimple_enmalloc(libsimple_default_failure_exit, n__); @@ -190,7 +190,7 @@ libsimple_emalloc(size_t n__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evmallocn(size_t n__, va_list ap__) { return libsimple_envmallocn(libsimple_default_failure_exit, n__, ap__); @@ -219,7 +219,7 @@ libsimple_evmallocn(size_t n__, va_list ap__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_emallocn(size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/mallocz.h b/libsimple/mallocz.h index 7bd9999..6909b1f 100644 --- a/libsimple/mallocz.h +++ b/libsimple/mallocz.h @@ -56,7 +56,7 @@ void *libsimple_vmalloczn(int, size_t, va_list); * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_mallocz(int clear__, size_t n__) { return clear__ ? calloc(1, n__) : malloc(n__); @@ -85,7 +85,7 @@ libsimple_mallocz(int clear__, size_t n__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_malloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -113,7 +113,7 @@ libsimple_malloczn(int clear__, size_t n__, ... /*, (size_t)0 */) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmallocz(int status__, int clear__, size_t n__) { return clear__ ? libsimple_encalloc(status__, 1, n__) : libsimple_enmalloc(status__, n__); @@ -173,7 +173,7 @@ void *libsimple_envmalloczn(int, int, size_t, va_list); * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmalloczn(int status__, int clear__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -200,7 +200,7 @@ libsimple_enmalloczn(int status__, int clear__, size_t n__, ... /*, (size_t)0 */ * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_emallocz(int clear__, size_t n__) { return libsimple_enmallocz(libsimple_default_failure_exit, clear__, n__); @@ -230,7 +230,7 @@ libsimple_emallocz(int clear__, size_t n__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evmalloczn(int clear__, size_t n__, va_list ap__) { return libsimple_envmalloczn(libsimple_default_failure_exit, clear__, n__, ap__); @@ -260,7 +260,7 @@ libsimple_evmalloczn(int clear__, size_t n__, va_list ap__) * and with the alignment `alignof(max_align_t)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_emalloczn(int clear__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/memalign.h b/libsimple/memalign.h index e36c6f9..bb6551f 100644 --- a/libsimple/memalign.h +++ b/libsimple/memalign.h @@ -20,7 +20,7 @@ * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) -static inline void * +inline void * libsimple_vmemalignn(size_t alignment__, size_t n__, va_list ap__) { return libsimple_vmemalignzn(0, alignment__, n__, ap__); @@ -42,7 +42,7 @@ libsimple_vmemalignn(size_t alignment__, size_t n__, va_list ap__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_memalign(size_t alignment__, size_t n__) { return libsimple_memalignz(0, alignment__, n__); @@ -71,7 +71,7 @@ libsimple_memalign(size_t alignment__, size_t n__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) -static inline void * +inline void * libsimple_memalignn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -100,7 +100,7 @@ libsimple_memalignn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmemalign(int status__, size_t alignment__, size_t n__) { return libsimple_enmemalignz(status__, 0, alignment__, n__); @@ -132,7 +132,7 @@ libsimple_enmemalign(int status__, size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envmemalignn(int status__, size_t alignment__, size_t n__, va_list ap__) { return libsimple_envmemalignzn(status__, 0, alignment__, n__, ap__); @@ -164,7 +164,7 @@ libsimple_envmemalignn(int status__, size_t alignment__, size_t n__, va_list ap_ * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmemalignn(int status__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -192,7 +192,7 @@ libsimple_enmemalignn(int status__, size_t alignment__, size_t n__, ... /*, (siz * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ememalign(size_t alignment__, size_t n__) { return libsimple_enmemalign(libsimple_default_failure_exit, alignment__, n__); @@ -224,7 +224,7 @@ libsimple_ememalign(size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evmemalignn(size_t alignment__, size_t n__, va_list ap__) { return libsimple_envmemalignn(libsimple_default_failure_exit, alignment__, n__, ap__); @@ -255,7 +255,7 @@ libsimple_evmemalignn(size_t alignment__, size_t n__, va_list ap__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ememalignn(size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/memalignz.h b/libsimple/memalignz.h index 62ab444..1630783 100644 --- a/libsimple/memalignz.h +++ b/libsimple/memalignz.h @@ -21,7 +21,7 @@ * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_vmemalignzn(int clear__, size_t alignment__, size_t n__, va_list ap__) { if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { @@ -51,7 +51,7 @@ libsimple_vmemalignzn(int clear__, size_t alignment__, size_t n__, va_list ap__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) -static inline void * +inline void * libsimple_memalignz(int clear__, size_t alignment__, size_t n__) { if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { @@ -88,7 +88,7 @@ libsimple_memalignz(int clear__, size_t alignment__, size_t n__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) -static inline void * +inline void * libsimple_memalignzn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -118,7 +118,7 @@ libsimple_memalignzn(int clear__, size_t alignment__, size_t n__, ... /*, (size_ * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmemalignz(int status__, int clear__, size_t alignment__, size_t n__) { if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { @@ -158,7 +158,7 @@ libsimple_enmemalignz(int status__, int clear__, size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envmemalignzn(int status__, int clear__, size_t alignment__, size_t n__, va_list ap__) { if (!alignment__ || (alignment__ & (alignment__ - 1UL))) { @@ -199,7 +199,7 @@ libsimple_envmemalignzn(int status__, int clear__, size_t alignment__, size_t n_ * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_enmemalignzn(int status__, int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -228,7 +228,7 @@ libsimple_enmemalignzn(int status__, int clear__, size_t alignment__, size_t n__ * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ememalignz(int clear__, size_t alignment__, size_t n__) { return libsimple_enmemalignz(libsimple_default_failure_exit, clear__, alignment__, n__); @@ -260,7 +260,7 @@ libsimple_ememalignz(int clear__, size_t alignment__, size_t n__) * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evmemalignzn(int clear__, size_t alignment__, size_t n__, va_list ap__) { return libsimple_envmemalignzn(libsimple_default_failure_exit, clear__, alignment__, n__, ap__); @@ -292,7 +292,7 @@ libsimple_evmemalignzn(int clear__, size_t alignment__, size_t n__, va_list ap__ * and alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_ememalignzn(int clear__, size_t alignment__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/libsimple/strn.h b/libsimple/strn.h index 8d10fff..a333ecd 100644 --- a/libsimple/strn.h +++ b/libsimple/strn.h @@ -366,7 +366,7 @@ char *libsimple_strrncasestr(const char *, const char *, size_t); * 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strncmpnul(const char *a__, const char *b__, size_t n__) { return (!a__ || !b__) ? !b__ - !a__ : strncmp(a__, b__, n__); @@ -389,7 +389,7 @@ libsimple_strncmpnul(const char *a__, const char *b__, size_t n__) * 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strncasecmpnul(const char *a__, const char *b__, size_t n__) { return (!a__ || !b__) ? !b__ - !a__ : strncasecmp(a__, b__, n__); @@ -410,7 +410,7 @@ libsimple_strncasecmpnul(const char *a__, const char *b__, size_t n__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_strneq(const char *a__, const char *b__, size_t n__) { return !strncmp(a__, b__, n__); @@ -431,7 +431,7 @@ libsimple_strneq(const char *a__, const char *b__, size_t n__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strneqnul(const char *a__, const char *b__, size_t n__) { return !strncmpnul(a__, b__, n__); @@ -452,7 +452,7 @@ libsimple_strneqnul(const char *a__, const char *b__, size_t n__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_strncaseeq(const char *a__, const char *b__, size_t n__) { return !strncasecmp(a__, b__, n__); @@ -473,7 +473,7 @@ libsimple_strncaseeq(const char *a__, const char *b__, size_t n__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strncaseeqnul(const char *a__, const char *b__, size_t n__) { return !libsimple_strncasecmpnul(a__, b__, n__); @@ -528,7 +528,7 @@ size_t libsimple_strncaseeqlen(const char *, const char *, size_t); * in common in their ends */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t +inline size_t libsimple_strrneqlen(const char *a__, const char *b__, size_t n__) { return libsimple_memreqlen(a__, strnlen(a__, n__), b__, strnlen(b__, n__)); @@ -549,7 +549,7 @@ libsimple_strrneqlen(const char *a__, const char *b__, size_t n__) * in common in their ends */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t +inline size_t libsimple_strrncaseeqlen(const char *a__, const char *b__, size_t n__) { return libsimple_memrcaseeqlen(a__, strnlen(a__, n__), b__, strnlen(b__, n__)); @@ -569,7 +569,7 @@ libsimple_strrncaseeqlen(const char *a__, const char *b__, size_t n__) * @return `d` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_strnmove(char *d__, const char *s__, size_t n__) { size_t len__ = strnlen(s__, n__); @@ -590,7 +590,7 @@ libsimple_strnmove(char *d__, const char *s__, size_t n__) * @return `&d[strnlen(s, n)]` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_stpnmove(char *d__, const char *s__, size_t n__) { size_t len__ = strnlen(s__, n__); @@ -611,7 +611,7 @@ libsimple_stpnmove(char *d__, const char *s__, size_t n__) * @return `s` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_strnset(char *s__, int c___, size_t n__) { char c__ = (char)c___, *r__ = s__; @@ -632,7 +632,7 @@ libsimple_strnset(char *s__, int c___, size_t n__) * @return `&s[strnlen(s, n)]` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_stpnset(char *s__, int c___, size_t n__) { char c__ = (char)c___; @@ -657,7 +657,7 @@ libsimple_stpnset(char *s__, int c___, size_t n__) * found in `s`, `NULL` otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_strnccpy(char *restrict d__, const char *restrict s__, int c___, size_t n__) { char c__ = (char)c___, *end__ = &d__[n__]; @@ -707,7 +707,7 @@ char *libsimple_strncmove(char *, const char *, int, size_t); * @return `strnchr(s, '\0', n)` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * +inline char * libsimple_strnreplace(char *s__, int old___, int new___, size_t n__) { char old__ = (char)old___, new__ = (char)new___; @@ -775,7 +775,7 @@ char *libsimple_stpntoupper(char *, const char *, size_t); * @return `d` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * +inline char * libsimple_strntolower(char *d__, const char *s__, size_t n__) { libsimple_stpntolower(d__, s__, n__); @@ -800,7 +800,7 @@ libsimple_strntolower(char *d__, const char *s__, size_t n__) * @return `d` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * +inline char * libsimple_strntoupper(char *d__, const char *s__, size_t n__) { libsimple_stpntoupper(d__, s__, n__); @@ -824,7 +824,7 @@ libsimple_strntoupper(char *d__, const char *s__, size_t n__) * @return 1 if good, 0 on encoding error */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_strnisutf8(const char *string__, size_t n__, int allow_modified_nul__) { return libsimple_memisutf8(string__, strnlen(string__, n__), allow_modified_nul__); diff --git a/libsimple/valloc.h b/libsimple/valloc.h index 55e8fd5..023425e 100644 --- a/libsimple/valloc.h +++ b/libsimple/valloc.h @@ -18,7 +18,7 @@ * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_vvallocn(size_t n__, va_list ap__) { return libsimple_vvalloczn(0, n__, ap__); @@ -39,7 +39,7 @@ libsimple_vvallocn(size_t n__, va_list ap__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__))) -static inline void * +inline void * libsimple_valloc(size_t n__) { return libsimple_vallocz(0, n__); @@ -66,7 +66,7 @@ libsimple_valloc(size_t n__) * @throws ENOMEM Could not allocated enough memory */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * +inline void * libsimple_vallocn(size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -94,7 +94,7 @@ libsimple_vallocn(size_t n__, ... /*, (size_t)0 */) * and with page size alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envalloc(int status__, size_t n__) { return libsimple_envallocz(status__, 0, n__); @@ -124,7 +124,7 @@ libsimple_envalloc(int status__, size_t n__) * and with page size alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envvallocn(int status__, size_t n__, va_list ap__) { return libsimple_envvalloczn(status__, 0, n__, ap__); @@ -154,7 +154,7 @@ libsimple_envvallocn(int status__, size_t n__, va_list ap__) * and with page size alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_envallocn(int status__, size_t n__, ... /*, (size_t)0 */) { va_list ap__; @@ -181,7 +181,7 @@ libsimple_envallocn(int status__, size_t n__, ... /*, (size_t)0 */) * and with page size alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __alloc_size__(1), __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evalloc(size_t n__) { return libsimple_envalloc(libsimple_default_failure_exit, n__); @@ -210,7 +210,7 @@ libsimple_evalloc(size_t n__) * and with page size alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evvallocn(size_t n__, va_list ap__) { return libsimple_envvallocn(libsimple_default_failure_exit, n__, ap__); @@ -239,7 +239,7 @@ libsimple_evvallocn(size_t n__, va_list ap__) * and with page size alignment */ LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * +inline void * libsimple_evallocn(size_t n__, ... /*, (size_t)0 */) { va_list ap__; diff --git a/mallocn.c b/mallocn.c new file mode 100644 index 0000000..168ccfa --- /dev/null +++ b/mallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_mallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/mallocz.c b/mallocz.c new file mode 100644 index 0000000..814c0fc --- /dev/null +++ b/mallocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_mallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/malloczn.c b/malloczn.c new file mode 100644 index 0000000..47e2711 --- /dev/null +++ b/malloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_malloczn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalign.c b/memalign.c new file mode 100644 index 0000000..38a3bda --- /dev/null +++ b/memalign.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memalign(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalignn.c b/memalignn.c new file mode 100644 index 0000000..14d1051 --- /dev/null +++ b/memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memalignn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalignz.c b/memalignz.c new file mode 100644 index 0000000..979f640 --- /dev/null +++ b/memalignz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memalignz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalignzn.c b/memalignzn.c new file mode 100644 index 0000000..42f3448 --- /dev/null +++ b/memalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_memalignzn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/stpnmove.c b/stpnmove.c new file mode 100644 index 0000000..e3fd9d3 --- /dev/null +++ b/stpnmove.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_stpnmove(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/stpnset.c b/stpnset.c new file mode 100644 index 0000000..42a810d --- /dev/null +++ b/stpnset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_stpnset(char *, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strncasecmpnul.c b/strncasecmpnul.c new file mode 100644 index 0000000..f4a208c --- /dev/null +++ b/strncasecmpnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strncasecmpnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strncaseeq.c b/strncaseeq.c new file mode 100644 index 0000000..bd60472 --- /dev/null +++ b/strncaseeq.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strncaseeq(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strncaseeqnul.c b/strncaseeqnul.c new file mode 100644 index 0000000..5330732 --- /dev/null +++ b/strncaseeqnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strncaseeqnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strnccpy.c b/strnccpy.c new file mode 100644 index 0000000..fe8063e --- /dev/null +++ b/strnccpy.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_strnccpy(char *restrict, const char *restrict, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strncmpnul.c b/strncmpnul.c new file mode 100644 index 0000000..05751a1 --- /dev/null +++ b/strncmpnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strncmpnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strneq.c b/strneq.c new file mode 100644 index 0000000..0432176 --- /dev/null +++ b/strneq.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strneq(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strneqnul.c b/strneqnul.c new file mode 100644 index 0000000..191c2d4 --- /dev/null +++ b/strneqnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strneqnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strnisutf8.c b/strnisutf8.c new file mode 100644 index 0000000..c62817c --- /dev/null +++ b/strnisutf8.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline int libsimple_strnisutf8(const char *, size_t, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strnmove.c b/strnmove.c new file mode 100644 index 0000000..bc94911 --- /dev/null +++ b/strnmove.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_strnmove(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strnreplace.c b/strnreplace.c new file mode 100644 index 0000000..9e735fb --- /dev/null +++ b/strnreplace.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_strnreplace(char *, int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strnset.c b/strnset.c new file mode 100644 index 0000000..000e770 --- /dev/null +++ b/strnset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_strnset(char *, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strntolower.c b/strntolower.c new file mode 100644 index 0000000..f88aac5 --- /dev/null +++ b/strntolower.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_strntolower(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strntoupper.c b/strntoupper.c new file mode 100644 index 0000000..58d8a0c --- /dev/null +++ b/strntoupper.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline char *libsimple_strntoupper(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strrncaseeqlen.c b/strrncaseeqlen.c new file mode 100644 index 0000000..82b1db3 --- /dev/null +++ b/strrncaseeqlen.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline size_t libsimple_strrncaseeqlen(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strrneqlen.c b/strrneqlen.c new file mode 100644 index 0000000..913b359 --- /dev/null +++ b/strrneqlen.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline size_t libsimple_strrneqlen(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/valigned_allocn.c b/valigned_allocn.c new file mode 100644 index 0000000..8f4faf3 --- /dev/null +++ b/valigned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_valigned_allocn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/valigned_reallocfn.c b/valigned_reallocfn.c new file mode 100644 index 0000000..fcafcd6 --- /dev/null +++ b/valigned_reallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_valigned_reallocfn(void *, size_t, size_t, va_list); /* TODO test (aligned_reallocfn) */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/valloc.c b/valloc.c new file mode 100644 index 0000000..5566b1c --- /dev/null +++ b/valloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_valloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vallocn.c b/vallocn.c new file mode 100644 index 0000000..5ea6723 --- /dev/null +++ b/vallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vcallocn.c b/vcallocn.c new file mode 100644 index 0000000..c590cf6 --- /dev/null +++ b/vcallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vcallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vmallocn.c b/vmallocn.c new file mode 100644 index 0000000..e9f97f1 --- /dev/null +++ b/vmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vmallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vmemalignn.c b/vmemalignn.c new file mode 100644 index 0000000..40abfb6 --- /dev/null +++ b/vmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vmemalignn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vmemalignzn.c b/vmemalignzn.c new file mode 100644 index 0000000..a0983e7 --- /dev/null +++ b/vmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vmemalignzn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vvallocn.c b/vvallocn.c new file mode 100644 index 0000000..67b473a --- /dev/null +++ b/vvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +extern inline void *libsimple_vvallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif -- cgit v1.2.3-70-g09d2 From 9b483673c0c8a52d81127a23788fa4c976f2b10f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Jun 2022 18:48:26 +0200 Subject: Replace to last static inline's with line + extern inline, and fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 24 +++- aligned_allocn.c | 2 +- aligned_allocz.c | 2 +- aligned_alloczn.c | 2 +- aligned_memdup.c | 2 +- aligned_realloc.c | 2 +- aligned_reallocarray.c | 2 +- aligned_reallocarrayf.c | 2 +- aligned_reallocf.c | 2 +- aligned_reallocfn.c | 2 +- aligned_reallocn.c | 2 +- aligned_strdup.c | 2 +- aligned_strndup.c | 2 +- aligned_wcsdup.c | 2 +- aligned_wcsndup.c | 2 +- aligned_wmemdup.c | 2 +- allocn.c | 2 +- asprintf.c | 2 +- callocn.c | 2 +- close.c | 2 +- cmptimespec.c | 260 ++++++++++++++++++++++++++++---------------- cmptimeval.c | 2 +- common.h | 11 ++ difftimespec.c | 104 ++++++++++++------ difftimeval.c | 2 +- doubletotimespec.c | 2 +- doubletotimeval.c | 2 +- ealigned_alloc.c | 2 +- ealigned_allocn.c | 2 +- ealigned_allocz.c | 2 +- ealigned_alloczn.c | 2 +- ealigned_memdup.c | 2 +- ealigned_realloc.c | 2 +- ealigned_reallocarray.c | 2 +- ealigned_reallocn.c | 2 +- ealigned_strdup.c | 2 +- ealigned_strndup.c | 2 +- ealigned_wcsdup.c | 2 +- ealigned_wcsndup.c | 2 +- ealigned_wmemdup.c | 2 +- ecalloc.c | 2 +- ecallocn.c | 2 +- egmtime.c | 2 +- elocaltime.c | 2 +- emalloc.c | 2 +- emallocn.c | 2 +- emallocz.c | 2 +- emalloczn.c | 2 +- ememalign.c | 2 +- ememalignn.c | 2 +- ememalignz.c | 2 +- ememalignzn.c | 2 +- ememalloc.c | 2 +- ememdup.c | 2 +- enaligned_alloc.c | 2 +- enaligned_allocn.c | 2 +- enaligned_allocz.c | 2 +- enaligned_alloczn.c | 2 +- enaligned_memdup.c | 2 +- enaligned_realloc.c | 2 +- enaligned_reallocarray.c | 2 +- enaligned_reallocn.c | 2 +- enaligned_strdup.c | 2 +- enaligned_strndup.c | 2 +- enaligned_wcsdup.c | 2 +- enaligned_wcsndup.c | 2 +- enaligned_wmemdup.c | 2 +- encalloc.c | 2 +- encallocn.c | 2 +- engmtime.c | 2 +- enlocaltime.c | 2 +- enmalloc.c | 2 +- enmallocn.c | 2 +- enmallocz.c | 2 +- enmalloczn.c | 2 +- enmemalign.c | 2 +- enmemalignn.c | 2 +- enmemalignz.c | 2 +- enmemalignzn.c | 2 +- enmemalloc.c | 2 +- enmemdup.c | 2 +- enposix_memalign.c | 2 +- enposix_memalignn.c | 2 +- enposix_memalignz.c | 2 +- enposix_memalignzn.c | 2 +- enprintf.c | 2 +- enputenvf.c | 2 +- enpvalloc.c | 2 +- enpvallocn.c | 2 +- enpvallocz.c | 2 +- enpvalloczn.c | 2 +- enrealloc.c | 2 +- enreallocarray.c | 6 +- enreallocn.c | 2 +- enstrdup.c | 2 +- enstrndup.c | 2 +- envaligned_allocn.c | 2 +- envaligned_alloczn.c | 2 +- envaligned_reallocn.c | 2 +- envalloc.c | 2 +- envallocn.c | 2 +- envallocz.c | 2 +- envalloczn.c | 2 +- envcallocn.c | 2 +- envmallocn.c | 2 +- envmalloczn.c | 2 +- envmemalignn.c | 2 +- envmemalignzn.c | 2 +- envmemalloc.c | 2 +- envposix_memalignn.c | 2 +- envposix_memalignzn.c | 2 +- envputenvf.c | 2 +- envpvallocn.c | 2 +- envpvalloczn.c | 2 +- envreallocn.c | 2 +- envvallocn.c | 2 +- envvalloczn.c | 2 +- enwcsdup.c | 2 +- enwcsndup.c | 2 +- enwmemdup.c | 2 +- eposix_memalign.c | 2 +- eposix_memalignn.c | 2 +- eposix_memalignz.c | 2 +- eposix_memalignzn.c | 2 +- eprintf.c | 2 +- eputenvf.c | 2 +- epvalloc.c | 2 +- epvallocn.c | 2 +- epvallocz.c | 2 +- epvalloczn.c | 2 +- erealloc.c | 2 +- ereallocarray.c | 6 +- ereallocn.c | 2 +- estrdup.c | 2 +- estrndup.c | 2 +- evaligned_allocn.c | 2 +- evaligned_alloczn.c | 2 +- evaligned_reallocn.c | 2 +- evalloc.c | 2 +- evallocn.c | 2 +- evallocz.c | 2 +- evalloczn.c | 2 +- evcallocn.c | 2 +- evmallocn.c | 2 +- evmalloczn.c | 2 +- evmemalignn.c | 2 +- evmemalignzn.c | 2 +- evmemalloc.c | 2 +- evposix_memalignn.c | 2 +- evposix_memalignzn.c | 2 +- evputenvf.c | 2 +- evpvallocn.c | 2 +- evpvalloczn.c | 2 +- evreallocn.c | 2 +- evvallocn.c | 2 +- evvalloczn.c | 2 +- ewcsdup.c | 2 +- ewcsndup.c | 2 +- ewmemdup.c | 2 +- getenv_e.c | 2 +- getenv_ne.c | 2 +- gmtime.c | 2 +- inchrcaseset.c | 18 +++ inchrset.c | 18 +++ libsimple-arg.c | 6 +- libsimple-arg.h | 29 +++-- libsimple.c | 171 ++++++++++++++++++----------- libsimple.h | 42 +++++-- libsimple/aligned_memdup.h | 28 ++--- libsimple/aligned_strdup.h | 2 +- libsimple/aligned_strndup.h | 2 +- libsimple/aligned_wcsdup.h | 2 +- libsimple/aligned_wcsndup.h | 2 +- libsimple/aligned_wmemdup.h | 2 +- libsimple/memdup.h | 2 +- libsimple/printf.h | 4 +- libsimple/str.h | 42 +++---- libsimple/strdup.h | 2 +- libsimple/strndup.h | 2 +- libsimple/wcsdup.h | 2 +- libsimple/wcsndup.h | 2 +- libsimple/wmemdup.h | 2 +- localtime.c | 2 +- mallocn.c | 2 +- mallocz.c | 2 +- malloczn.c | 2 +- memalign.c | 2 +- memalignn.c | 2 +- memalignz.c | 2 +- memalignzn.c | 2 +- memalloc.c | 2 +- memcasechr.c | 2 +- memcasechr_inv.c | 2 +- memcasecmp.c | 2 +- memcaseends.c | 2 +- memcaseeq.c | 2 +- memcaseeqlen.c | 2 +- memcasemem.c | 2 +- memcasescan.c | 2 +- memcasescan_inv.c | 2 +- memcasestarts.c | 2 +- memchr_inv.c | 2 +- memcmove.c | 29 +++-- memdup.c | 2 +- memelem.c | 2 +- memelem_inv.c | 2 +- memelemcpy.c | 68 ++++++++---- memelemmove.c | 182 ++++++++++++++++++++----------- memelemscan.c | 2 +- memelemscan_inv.c | 2 +- memends.c | 2 +- memeq.c | 2 +- memeqlen.c | 2 +- memisutf8.c | 2 +- memmem.c | 2 +- mempcpy.c | 2 +- mempmove.c | 11 +- mempset.c | 2 +- mempsetelem.c | 17 ++- memptolower.c | 2 +- memptoupper.c | 2 +- memrcasechr.c | 2 +- memrcasechr_inv.c | 2 +- memrcaseeqlen.c | 2 +- memrcasemem.c | 2 +- memrchr.c | 2 +- memrchr_inv.c | 2 +- memrelem.c | 2 +- memrelem_inv.c | 2 +- memreplace.c | 2 +- memreplaceelem.c | 2 +- memreqlen.c | 2 +- memrmem.c | 2 +- memscan.c | 2 +- memscan_inv.c | 2 +- memsetelem.c | 52 +++++---- memstarts.c | 2 +- memtolower.c | 2 +- memtoupper.c | 2 +- minimise_number_string.c | 2 +- multimespec.c | 83 +++++++++----- multimeval.c | 83 +++++++++----- posix_memalignn.c | 2 +- posix_memalignz.c | 2 +- posix_memalignzn.c | 2 +- putenvf.c | 2 +- pvalloc.c | 2 +- pvallocn.c | 2 +- pvallocz.c | 2 +- pvalloczn.c | 2 +- rawmemcasechr.c | 2 +- rawmemcasechr_inv.c | 2 +- rawmemccpy.c | 8 +- rawmemchr.c | 2 +- rawmemchr_inv.c | 2 +- rawmemcmove.c | 20 ++-- rawmemelem.c | 2 +- rawmemelem_inv.c | 2 +- rawmemelemcpy.c | 50 ++++++--- rawmemelemmove.c | 137 +++++++++++++++-------- rawmemrcasechr.c | 2 +- rawmemrcasechr_inv.c | 2 +- rawmemrchr.c | 2 +- rawmemrchr_inv.c | 2 +- rawmemrelem.c | 2 +- rawmemrelem_inv.c | 2 +- reallocarray.c | 6 +- reallocarrayf.c | 2 +- reallocf.c | 2 +- reallocfn.c | 2 +- reallocn.c | 2 +- stpmove.c | 18 +++ stpnmove.c | 2 +- stpnset.c | 2 +- stpntolower.c | 2 +- stpntoupper.c | 2 +- stpset.c | 18 +++ stptolower.c | 2 +- stptoupper.c | 2 +- strcasechr.c | 2 +- strcasechr_inv.c | 2 +- strcasechrnul.c | 2 +- strcasechrnul_inv.c | 2 +- strcasecmpnul.c | 18 +++ strcaseends.c | 2 +- strcaseeq.c | 18 +++ strcaseeqlen.c | 2 +- strcaseeqnul.c | 18 +++ strcasestarts.c | 18 +++ strcasestr.c | 2 +- strccpy.c | 18 +++ strchr_inv.c | 2 +- strchrnul.c | 2 +- strchrnul_inv.c | 2 +- strcmove.c | 38 ++++--- strcmpnul.c | 18 +++ strend.c | 18 +++ strends.c | 2 +- streq.c | 18 +++ streqlen.c | 2 +- streqnul.c | 18 +++ strisutf8.c | 18 +++ strmove.c | 18 +++ strncasechr.c | 2 +- strncasechr_inv.c | 2 +- strncasechrnul.c | 2 +- strncasechrnul_inv.c | 2 +- strncasecmpnul.c | 2 +- strncaseends.c | 2 +- strncaseeq.c | 2 +- strncaseeqlen.c | 2 +- strncaseeqnul.c | 2 +- strncasestarts.c | 2 +- strncasestr.c | 2 +- strnccpy.c | 2 +- strnchr.c | 2 +- strnchr_inv.c | 2 +- strnchrnul.c | 2 +- strnchrnul_inv.c | 2 +- strncmove.c | 158 ++++++++++++++++++--------- strncmpnul.c | 2 +- strnend.c | 2 +- strnends.c | 2 +- strneq.c | 2 +- strneqlen.c | 2 +- strneqnul.c | 2 +- strnisutf8.c | 2 +- strnmove.c | 2 +- strnreplace.c | 2 +- strnset.c | 2 +- strnstarts.c | 2 +- strnstr.c | 2 +- strntolower.c | 2 +- strntoupper.c | 2 +- strrcasechr.c | 2 +- strrcasechr_inv.c | 2 +- strrcaseeqlen.c | 18 +++ strrcasestr.c | 2 +- strrchr_inv.c | 2 +- strreplace.c | 18 +++ strreqlen.c | 18 +++ strrncasechr.c | 2 +- strrncasechr_inv.c | 2 +- strrncaseeqlen.c | 2 +- strrncasestr.c | 2 +- strrnchr.c | 2 +- strrnchr_inv.c | 2 +- strrneqlen.c | 2 +- strrnstr.c | 2 +- strrstr.c | 2 +- strset.c | 18 +++ strstarts.c | 2 +- strtoh.c | 2 +- strtohh.c | 2 +- strtoi.c | 2 +- strtoi16.c | 2 +- strtoi32.c | 2 +- strtoi64.c | 2 +- strtoi8.c | 2 +- strtolower.c | 18 +++ strtotimespec.c | 2 +- strtotimeval.c | 2 +- strtou.c | 2 +- strtou16.c | 2 +- strtou32.c | 2 +- strtou64.c | 2 +- strtou8.c | 2 +- strtouh.c | 2 +- strtouhh.c | 2 +- strtoupper.c | 18 +++ strtouz.c | 2 +- strtoz.c | 2 +- sumtimespec.c | 62 +++++++---- sumtimeval.c | 2 +- test.c | 7 +- test.h | 18 ++- timespec2timeval.c | 2 +- timespectodouble.c | 2 +- timespectostr.c | 2 +- timeval2timespec.c | 2 +- timevaltodouble.c | 2 +- timevaltostr.c | 2 +- unlist.c | 2 +- valigned_allocn.c | 2 +- valigned_reallocfn.c | 2 +- valloc.c | 2 +- vallocn.c | 2 +- vallocz.c | 2 +- valloczn.c | 2 +- vasprintf.c | 6 +- vcallocn.c | 2 +- venprintf.c | 2 +- veprintf.c | 2 +- vmallocn.c | 2 +- vmemalignn.c | 2 +- vmemalignzn.c | 2 +- vmemalloc.c | 2 +- vposix_memalignn.c | 2 +- vputenvf.c | 6 +- vpvallocn.c | 2 +- vpvalloczn.c | 2 +- vreallocfn.c | 2 +- vvallocn.c | 2 +- vvalloczn.c | 2 +- vweprintf.c | 13 ++- wcsndup.c | 2 +- weprintf.c | 2 +- wmemdup.c | 2 +- 408 files changed, 1915 insertions(+), 956 deletions(-) create mode 100644 common.h create mode 100644 inchrcaseset.c create mode 100644 inchrset.c create mode 100644 stpmove.c create mode 100644 stpset.c create mode 100644 strcasecmpnul.c create mode 100644 strcaseeq.c create mode 100644 strcaseeqnul.c create mode 100644 strcasestarts.c create mode 100644 strccpy.c create mode 100644 strcmpnul.c create mode 100644 strend.c create mode 100644 streq.c create mode 100644 streqnul.c create mode 100644 strisutf8.c create mode 100644 strmove.c create mode 100644 strrcaseeqlen.c create mode 100644 strreplace.c create mode 100644 strreqlen.c create mode 100644 strset.c create mode 100644 strtolower.c create mode 100644 strtoupper.c (limited to 'Makefile') diff --git a/Makefile b/Makefile index 57bc372..6976479 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,8 @@ SUBHDR =\ HDR =\ $(SUBHDR)\ - libsimple.h + libsimple.h\ + common.h OBJ =\ aligned_allocn.o\ @@ -209,6 +210,8 @@ OBJ =\ getenv_e.o\ getenv_ne.o\ gmtime.o\ + inchrcaseset.o\ + inchrset.o\ localtime.o\ mallocn.o\ mallocz.o\ @@ -298,25 +301,38 @@ OBJ =\ reallocf.o\ reallocfn.o\ reallocn.o\ + stpmove.o\ stpnmove.o\ stpnset.o\ stpntolower.o\ stpntoupper.o\ + stpset.o\ stptolower.o\ stptoupper.o\ strcasechr.o\ strcasechr_inv.o\ strcasechrnul.o\ strcasechrnul_inv.o\ + strcasecmpnul.o\ strcaseends.o\ + strcaseeq.o\ strcaseeqlen.o\ + strcaseeqnul.o\ + strcasestarts.o\ strcasestr.o\ + strccpy.o\ strchr_inv.o\ strchrnul.o\ strchrnul_inv.o\ strcmove.o\ + strcmpnul.o\ + strend.o\ strends.o\ + streq.o\ streqlen.o\ + streqnul.o\ + strisutf8.o\ + strmove.o\ strncasechr.o\ strncasechr_inv.o\ strncasechrnul.o\ @@ -350,8 +366,11 @@ OBJ =\ strntoupper.o\ strrcasechr.o\ strrcasechr_inv.o\ + strrcaseeqlen.o\ strrcasestr.o\ strrchr_inv.o\ + strreplace.o\ + strreqlen.o\ strrncasechr.o\ strrncasechr_inv.o\ strrncaseeqlen.o\ @@ -361,6 +380,7 @@ OBJ =\ strrneqlen.o\ strrnstr.o\ strrstr.o\ + strset.o\ strstarts.o\ strtoh.o\ strtohh.o\ @@ -369,6 +389,7 @@ OBJ =\ strtoi32.o\ strtoi64.o\ strtoi8.o\ + strtolower.o\ strtotimespec.o\ strtotimeval.o\ strtou.o\ @@ -378,6 +399,7 @@ OBJ =\ strtou8.o\ strtouh.o\ strtouhh.o\ + strtoupper.o\ strtouz.o\ strtoz.o\ sumtimespec.o\ diff --git a/aligned_allocn.c b/aligned_allocn.c index 42e614c..de4b69f 100644 --- a/aligned_allocn.c +++ b/aligned_allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_allocz.c b/aligned_allocz.c index ab18d1a..29e6644 100644 --- a/aligned_allocz.c +++ b/aligned_allocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_alloczn.c b/aligned_alloczn.c index 9b35a17..d7d199f 100644 --- a/aligned_alloczn.c +++ b/aligned_alloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_memdup.c b/aligned_memdup.c index 7b2ca71..d383dbd 100644 --- a/aligned_memdup.c +++ b/aligned_memdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_realloc.c b/aligned_realloc.c index 1aaa0b9..985afbc 100644 --- a/aligned_realloc.c +++ b/aligned_realloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_reallocarray.c b/aligned_reallocarray.c index 185f24a..96fd937 100644 --- a/aligned_reallocarray.c +++ b/aligned_reallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_reallocarrayf.c b/aligned_reallocarrayf.c index 561615f..485043f 100644 --- a/aligned_reallocarrayf.c +++ b/aligned_reallocarrayf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_reallocf.c b/aligned_reallocf.c index 9493fb9..397c328 100644 --- a/aligned_reallocf.c +++ b/aligned_reallocf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_reallocfn.c b/aligned_reallocfn.c index 21e97ec..a686a5f 100644 --- a/aligned_reallocfn.c +++ b/aligned_reallocfn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_reallocn.c b/aligned_reallocn.c index ffae2fd..0c63633 100644 --- a/aligned_reallocn.c +++ b/aligned_reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_strdup.c b/aligned_strdup.c index ed4ddf7..6838bed 100644 --- a/aligned_strdup.c +++ b/aligned_strdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_strndup.c b/aligned_strndup.c index f41fa8c..9f8cf68 100644 --- a/aligned_strndup.c +++ b/aligned_strndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_wcsdup.c b/aligned_wcsdup.c index abb98e0..2c2fb29 100644 --- a/aligned_wcsdup.c +++ b/aligned_wcsdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_wcsndup.c b/aligned_wcsndup.c index 90ce7f7..923c6b5 100644 --- a/aligned_wcsndup.c +++ b/aligned_wcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_wmemdup.c b/aligned_wmemdup.c index c92e17f..b8793e0 100644 --- a/aligned_wmemdup.c +++ b/aligned_wmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/allocn.c b/allocn.c index 540772e..fabedfa 100644 --- a/allocn.c +++ b/allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/asprintf.c b/asprintf.c index 9c23204..d2de1b3 100644 --- a/asprintf.c +++ b/asprintf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/callocn.c b/callocn.c index 70b95a6..2a6272f 100644 --- a/callocn.c +++ b/callocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/close.c b/close.c index 6ddcb1f..8fcfbe2 100644 --- a/close.c +++ b/close.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/cmptimespec.c b/cmptimespec.c index 5a8463b..025a946 100644 --- a/cmptimespec.c +++ b/cmptimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -13,119 +13,195 @@ int main(void) { struct timespec ts1, ts2; - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; + ts1.tv_sec = 0; + ts1.tv_nsec = 999999999L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; + ts1.tv_sec = 0; + ts1.tv_nsec = 999999999L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 999999999L; - ts2.tv_sec = 0, ts2.tv_nsec = 999999999L; + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 999999999L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 999999999L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 999999999L; + ts2.tv_sec = 0; + ts2.tv_nsec = 999999999L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; + ts1.tv_sec = 1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; + ts1.tv_sec = 1; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; + ts1.tv_sec = 1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; + ts1.tv_sec = 1; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = 1; + ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = 1; + ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = 1; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = 1; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; + ts1.tv_sec = 1; + ts1.tv_nsec = 1L; + ts2.tv_sec = 1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 1, ts1.tv_nsec = 1L; - ts2.tv_sec = 1, ts2.tv_nsec = 1L; + ts1.tv_sec = 1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 1; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 1; + ts1.tv_nsec = 1L; + ts2.tv_sec = 1; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = 0, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; + ts1.tv_sec = -1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1; + ts1.tv_nsec = 1L; + ts2.tv_sec = 0; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = -1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = -1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = -1; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = 0, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; + ts1.tv_sec = 0; + ts1.tv_nsec = 1L; + ts2.tv_sec = -1; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; + ts1.tv_sec = -1; + ts1.tv_nsec = 0L; + ts2.tv_sec = -1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; + ts1.tv_sec = -1; + ts1.tv_nsec = 1L; + ts2.tv_sec = -1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = -1, ts1.tv_nsec = 1L; - ts2.tv_sec = -1, ts2.tv_nsec = 1L; + ts1.tv_sec = -1; + ts1.tv_nsec = 0L; + ts2.tv_sec = -1; + ts2.tv_nsec = 1L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = -1; + ts1.tv_nsec = 1L; + ts2.tv_sec = -1; + ts2.tv_nsec = 1L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 0, ts1.tv_nsec = 0L; - ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; - assert(libsimple_cmptimespec(&ts1, &ts2) == -1); - ts1.tv_sec = TIME_MAX, ts1.tv_nsec = 0L; - ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L; + ts1.tv_sec = 0; + ts1.tv_nsec = 0L; + ts2.tv_sec = TIME_MAX; + ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = 1; + ts1.tv_nsec = 0L; + ts2.tv_sec = TIME_MAX; + ts2.tv_nsec = 0L; + assert(libsimple_cmptimespec(&ts1, &ts2) == -1); + ts1.tv_sec = TIME_MAX; + ts1.tv_nsec = 0L; + ts2.tv_sec = TIME_MAX; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 0); - ts1.tv_sec = 1, ts1.tv_nsec = 0L; - ts2.tv_sec = -1, ts2.tv_nsec = 0L; + ts1.tv_sec = 1; + ts1.tv_nsec = 0L; + ts2.tv_sec = -1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == 1); - ts1.tv_sec = -1, ts1.tv_nsec = 0L; - ts2.tv_sec = 1, ts2.tv_nsec = 0L; + ts1.tv_sec = -1; + ts1.tv_nsec = 0L; + ts2.tv_sec = 1; + ts2.tv_nsec = 0L; assert(libsimple_cmptimespec(&ts1, &ts2) == -1); return 0; } diff --git a/cmptimeval.c b/cmptimeval.c index 7324988..4723705 100644 --- a/cmptimeval.c +++ b/cmptimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/common.h b/common.h new file mode 100644 index 0000000..7f84f59 --- /dev/null +++ b/common.h @@ -0,0 +1,11 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +# pragma clang diagnostic ignored "-Wreserved-identifier" +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +# pragma clang diagnostic ignored "-Wc++98-compat" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +#endif diff --git a/difftimespec.c b/difftimespec.c index 86d3441..f756007 100644 --- a/difftimespec.c +++ b/difftimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -47,104 +47,138 @@ main(void) { struct timespec r, a, b; - a.tv_sec = 0, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 100L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 100L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 100L; - b.tv_sec = 1, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 100L; + b.tv_sec = 1; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 9); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 100L; - b.tv_sec = 0, b.tv_nsec = 1L; + a.tv_sec = 10; + a.tv_nsec = 100L; + b.tv_sec = 0; + b.tv_nsec = 1L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 99L); - a.tv_sec = -10, a.tv_nsec = 100L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = -10; + a.tv_nsec = 100L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 1L; - b.tv_sec = 1, b.tv_nsec = 100L; + a.tv_sec = 10; + a.tv_nsec = 1L; + b.tv_sec = 1; + b.tv_nsec = 100L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 8); assert(r.tv_nsec == 1000000001L - 100L); - a.tv_sec = 10, a.tv_nsec = 0L; - b.tv_sec = 20, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; + b.tv_sec = 20; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 10L; - b.tv_sec = 20, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10L; + b.tv_sec = 20; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 10L); - a.tv_sec = 10, a.tv_nsec = 10L; - b.tv_sec = 20, b.tv_nsec = 20L; + a.tv_sec = 10; + a.tv_nsec = 10L; + b.tv_sec = 20; + b.tv_nsec = 20L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10 - 1); assert(r.tv_nsec == 1000000010L - 20L); - a.tv_sec = 10, a.tv_nsec = 10L; - b.tv_sec = -20, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10L; + b.tv_sec = -20; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 30); assert(r.tv_nsec == 10L); - a.tv_sec = 0, a.tv_nsec = 10L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 10L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 10L); - a.tv_sec = 0, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 10L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -1); assert(r.tv_nsec == 1000000000L - 10L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 1L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 1L; assert(libsimple_difftimespec(&r, &a, &b) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = -1, b.tv_nsec = 1L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = -1; + b.tv_nsec = 1L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; - b.tv_sec = -1, b.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; + b.tv_sec = -1; + b.tv_nsec = 0L; assert(libsimple_difftimespec(&r, &a, &b) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); diff --git a/difftimeval.c b/difftimeval.c index e4c65e4..d9dcbf3 100644 --- a/difftimeval.c +++ b/difftimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/doubletotimespec.c b/doubletotimespec.c index 02f40e9..f993f04 100644 --- a/doubletotimespec.c +++ b/doubletotimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/doubletotimeval.c b/doubletotimeval.c index c603703..2977f42 100644 --- a/doubletotimeval.c +++ b/doubletotimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_alloc.c b/ealigned_alloc.c index 8076b23..38c512d 100644 --- a/ealigned_alloc.c +++ b/ealigned_alloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_allocn.c b/ealigned_allocn.c index e10399b..dd6d294 100644 --- a/ealigned_allocn.c +++ b/ealigned_allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_allocz.c b/ealigned_allocz.c index 586df48..6d6307c 100644 --- a/ealigned_allocz.c +++ b/ealigned_allocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_alloczn.c b/ealigned_alloczn.c index 2787549..31db576 100644 --- a/ealigned_alloczn.c +++ b/ealigned_alloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_memdup.c b/ealigned_memdup.c index 4209a77..1175c3e 100644 --- a/ealigned_memdup.c +++ b/ealigned_memdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_realloc.c b/ealigned_realloc.c index 40b8372..ecca369 100644 --- a/ealigned_realloc.c +++ b/ealigned_realloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_reallocarray.c b/ealigned_reallocarray.c index 8f44315..214c7cb 100644 --- a/ealigned_reallocarray.c +++ b/ealigned_reallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_reallocn.c b/ealigned_reallocn.c index 3292a5a..da78bac 100644 --- a/ealigned_reallocn.c +++ b/ealigned_reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_strdup.c b/ealigned_strdup.c index f0fd7e4..4f4a03d 100644 --- a/ealigned_strdup.c +++ b/ealigned_strdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_strndup.c b/ealigned_strndup.c index 1d8cc1d..368f77b 100644 --- a/ealigned_strndup.c +++ b/ealigned_strndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_wcsdup.c b/ealigned_wcsdup.c index a73a261..8f7a83e 100644 --- a/ealigned_wcsdup.c +++ b/ealigned_wcsdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_wcsndup.c b/ealigned_wcsndup.c index 2f70be3..f155e23 100644 --- a/ealigned_wcsndup.c +++ b/ealigned_wcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ealigned_wmemdup.c b/ealigned_wmemdup.c index dae7c33..99a24f1 100644 --- a/ealigned_wmemdup.c +++ b/ealigned_wmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ecalloc.c b/ecalloc.c index edf3549..9e8b907 100644 --- a/ecalloc.c +++ b/ecalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ecallocn.c b/ecallocn.c index d5cf8f4..329e007 100644 --- a/ecallocn.c +++ b/ecallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/egmtime.c b/egmtime.c index 85b62ee..d62146e 100644 --- a/egmtime.c +++ b/egmtime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/elocaltime.c b/elocaltime.c index b3accdd..f54f095 100644 --- a/elocaltime.c +++ b/elocaltime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/emalloc.c b/emalloc.c index 54da30d..e79de1e 100644 --- a/emalloc.c +++ b/emalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/emallocn.c b/emallocn.c index e742427..e6ccf3e 100644 --- a/emallocn.c +++ b/emallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/emallocz.c b/emallocz.c index ab52b36..6695153 100644 --- a/emallocz.c +++ b/emallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/emalloczn.c b/emalloczn.c index 760ee59..e85f436 100644 --- a/emalloczn.c +++ b/emalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ememalign.c b/ememalign.c index 422c08d..ef48af4 100644 --- a/ememalign.c +++ b/ememalign.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ememalignn.c b/ememalignn.c index cda6e99..eb259d4 100644 --- a/ememalignn.c +++ b/ememalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ememalignz.c b/ememalignz.c index 2ca550d..f45a04e 100644 --- a/ememalignz.c +++ b/ememalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ememalignzn.c b/ememalignzn.c index 72ab6f2..9f97d7f 100644 --- a/ememalignzn.c +++ b/ememalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ememalloc.c b/ememalloc.c index 79b2059..525e67f 100644 --- a/ememalloc.c +++ b/ememalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ememdup.c b/ememdup.c index 50295e3..08a90a5 100644 --- a/ememdup.c +++ b/ememdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_alloc.c b/enaligned_alloc.c index b7f8754..a6edf6b 100644 --- a/enaligned_alloc.c +++ b/enaligned_alloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_allocn.c b/enaligned_allocn.c index 2c10177..77ac1ae 100644 --- a/enaligned_allocn.c +++ b/enaligned_allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_allocz.c b/enaligned_allocz.c index f92df4f..b620e53 100644 --- a/enaligned_allocz.c +++ b/enaligned_allocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_alloczn.c b/enaligned_alloczn.c index 55f00d7..469eb45 100644 --- a/enaligned_alloczn.c +++ b/enaligned_alloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_memdup.c b/enaligned_memdup.c index ae8589f..dc3188e 100644 --- a/enaligned_memdup.c +++ b/enaligned_memdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_realloc.c b/enaligned_realloc.c index 6d5ac4e..117c62a 100644 --- a/enaligned_realloc.c +++ b/enaligned_realloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_reallocarray.c b/enaligned_reallocarray.c index 5a71207..5fd1d47 100644 --- a/enaligned_reallocarray.c +++ b/enaligned_reallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_reallocn.c b/enaligned_reallocn.c index 3b561d8..aa93740 100644 --- a/enaligned_reallocn.c +++ b/enaligned_reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_strdup.c b/enaligned_strdup.c index b2e505b..9312566 100644 --- a/enaligned_strdup.c +++ b/enaligned_strdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_strndup.c b/enaligned_strndup.c index 91825fd..1901628 100644 --- a/enaligned_strndup.c +++ b/enaligned_strndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_wcsdup.c b/enaligned_wcsdup.c index c048cc8..0293b62 100644 --- a/enaligned_wcsdup.c +++ b/enaligned_wcsdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_wcsndup.c b/enaligned_wcsndup.c index 840d180..b7deea0 100644 --- a/enaligned_wcsndup.c +++ b/enaligned_wcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_wmemdup.c b/enaligned_wmemdup.c index 657b644..df976bc 100644 --- a/enaligned_wmemdup.c +++ b/enaligned_wmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/encalloc.c b/encalloc.c index 82d25e3..82775a3 100644 --- a/encalloc.c +++ b/encalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/encallocn.c b/encallocn.c index 49336da..a43fcbb 100644 --- a/encallocn.c +++ b/encallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/engmtime.c b/engmtime.c index 5cc9a55..2c7a7ee 100644 --- a/engmtime.c +++ b/engmtime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enlocaltime.c b/enlocaltime.c index 73fc99e..e3df109 100644 --- a/enlocaltime.c +++ b/enlocaltime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmalloc.c b/enmalloc.c index 0da7c33..4a52e41 100644 --- a/enmalloc.c +++ b/enmalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmallocn.c b/enmallocn.c index 761f196..b3600f6 100644 --- a/enmallocn.c +++ b/enmallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmallocz.c b/enmallocz.c index 6204df8..7d51d9c 100644 --- a/enmallocz.c +++ b/enmallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmalloczn.c b/enmalloczn.c index 69636f5..ac8b874 100644 --- a/enmalloczn.c +++ b/enmalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmemalign.c b/enmemalign.c index 766317d..306a09e 100644 --- a/enmemalign.c +++ b/enmemalign.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmemalignn.c b/enmemalignn.c index d7f67c7..b6dc8a3 100644 --- a/enmemalignn.c +++ b/enmemalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmemalignz.c b/enmemalignz.c index 11fdb3a..b54ec4b 100644 --- a/enmemalignz.c +++ b/enmemalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmemalignzn.c b/enmemalignzn.c index 4a43192..27d2b84 100644 --- a/enmemalignzn.c +++ b/enmemalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmemalloc.c b/enmemalloc.c index b81147b..763dffa 100644 --- a/enmemalloc.c +++ b/enmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmemdup.c b/enmemdup.c index 6863733..7a6be0e 100644 --- a/enmemdup.c +++ b/enmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enposix_memalign.c b/enposix_memalign.c index e2978e4..f50a3d2 100644 --- a/enposix_memalign.c +++ b/enposix_memalign.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enposix_memalignn.c b/enposix_memalignn.c index 121d7c0..c8a6f0d 100644 --- a/enposix_memalignn.c +++ b/enposix_memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enposix_memalignz.c b/enposix_memalignz.c index 81844ea..9b6c1c7 100644 --- a/enposix_memalignz.c +++ b/enposix_memalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enposix_memalignzn.c b/enposix_memalignzn.c index 3606e74..e7e1417 100644 --- a/enposix_memalignzn.c +++ b/enposix_memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enprintf.c b/enprintf.c index e896228..de2db0d 100644 --- a/enprintf.c +++ b/enprintf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enputenvf.c b/enputenvf.c index 8447eae..8ee5241 100644 --- a/enputenvf.c +++ b/enputenvf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enpvalloc.c b/enpvalloc.c index ab5df3a..34621f4 100644 --- a/enpvalloc.c +++ b/enpvalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enpvallocn.c b/enpvallocn.c index e4692ec..ffe89ec 100644 --- a/enpvallocn.c +++ b/enpvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enpvallocz.c b/enpvallocz.c index d20e6f6..40661cc 100644 --- a/enpvallocz.c +++ b/enpvallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enpvalloczn.c b/enpvalloczn.c index 94d56bf..63c4746 100644 --- a/enpvalloczn.c +++ b/enpvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enrealloc.c b/enrealloc.c index fd3fa31..117fb06 100644 --- a/enrealloc.c +++ b/enrealloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enreallocarray.c b/enreallocarray.c index 48ac9bd..f0e5ddb 100644 --- a/enreallocarray.c +++ b/enreallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -51,7 +51,7 @@ main(void) assert(!alloc_fail_in); } -#if defined(__GNUC__) && !defined(__clang) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Walloc-size-larger-than=" #endif @@ -60,7 +60,7 @@ main(void) assert(exit_status == 3); assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); -#if defined(__GNUC__) && !defined(__clang) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic pop #endif diff --git a/enreallocn.c b/enreallocn.c index c1817d9..2bb12e8 100644 --- a/enreallocn.c +++ b/enreallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enstrdup.c b/enstrdup.c index 94160ef..8ccdbb7 100644 --- a/enstrdup.c +++ b/enstrdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enstrndup.c b/enstrndup.c index 755872d..9457352 100644 --- a/enstrndup.c +++ b/enstrndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envaligned_allocn.c b/envaligned_allocn.c index 622eada..fbb97f2 100644 --- a/envaligned_allocn.c +++ b/envaligned_allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envaligned_alloczn.c b/envaligned_alloczn.c index d79c6e7..37018d4 100644 --- a/envaligned_alloczn.c +++ b/envaligned_alloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envaligned_reallocn.c b/envaligned_reallocn.c index 747e8c8..ab24fe8 100644 --- a/envaligned_reallocn.c +++ b/envaligned_reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envalloc.c b/envalloc.c index 48f8fe2..1f5f38e 100644 --- a/envalloc.c +++ b/envalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envallocn.c b/envallocn.c index 664d50c..c253528 100644 --- a/envallocn.c +++ b/envallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envallocz.c b/envallocz.c index 8e8d9b3..5fcb8a2 100644 --- a/envallocz.c +++ b/envallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envalloczn.c b/envalloczn.c index c9a68fa..c5b6613 100644 --- a/envalloczn.c +++ b/envalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envcallocn.c b/envcallocn.c index 1e5a0dd..3c943ef 100644 --- a/envcallocn.c +++ b/envcallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envmallocn.c b/envmallocn.c index 531234e..9b37db4 100644 --- a/envmallocn.c +++ b/envmallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envmalloczn.c b/envmalloczn.c index 3e81b56..b2c3987 100644 --- a/envmalloczn.c +++ b/envmalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envmemalignn.c b/envmemalignn.c index 8df18c0..48a56fd 100644 --- a/envmemalignn.c +++ b/envmemalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envmemalignzn.c b/envmemalignzn.c index 278785f..fb4b464 100644 --- a/envmemalignzn.c +++ b/envmemalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envmemalloc.c b/envmemalloc.c index c500063..2a93adc 100644 --- a/envmemalloc.c +++ b/envmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envposix_memalignn.c b/envposix_memalignn.c index d408e1a..166f545 100644 --- a/envposix_memalignn.c +++ b/envposix_memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envposix_memalignzn.c b/envposix_memalignzn.c index 0693ac0..cb34725 100644 --- a/envposix_memalignzn.c +++ b/envposix_memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envputenvf.c b/envputenvf.c index 8b7fa72..71b9199 100644 --- a/envputenvf.c +++ b/envputenvf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envpvallocn.c b/envpvallocn.c index 46a3acd..2ad3ce7 100644 --- a/envpvallocn.c +++ b/envpvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envpvalloczn.c b/envpvalloczn.c index 16bd5c4..be4b753 100644 --- a/envpvalloczn.c +++ b/envpvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envreallocn.c b/envreallocn.c index 7fdc82e..642deb4 100644 --- a/envreallocn.c +++ b/envreallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envvallocn.c b/envvallocn.c index 93ea889..b351a14 100644 --- a/envvallocn.c +++ b/envvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envvalloczn.c b/envvalloczn.c index f7e7886..279dbf4 100644 --- a/envvalloczn.c +++ b/envvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enwcsdup.c b/enwcsdup.c index ca3ad56..b293f2f 100644 --- a/enwcsdup.c +++ b/enwcsdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enwcsndup.c b/enwcsndup.c index 04ff9fc..f642125 100644 --- a/enwcsndup.c +++ b/enwcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enwmemdup.c b/enwmemdup.c index 19dc6be..14b5871 100644 --- a/enwmemdup.c +++ b/enwmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/eposix_memalign.c b/eposix_memalign.c index b471235..27b787d 100644 --- a/eposix_memalign.c +++ b/eposix_memalign.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/eposix_memalignn.c b/eposix_memalignn.c index 2845fe6..9ae5e18 100644 --- a/eposix_memalignn.c +++ b/eposix_memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/eposix_memalignz.c b/eposix_memalignz.c index c0ac5c1..bfc2d98 100644 --- a/eposix_memalignz.c +++ b/eposix_memalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/eposix_memalignzn.c b/eposix_memalignzn.c index acb2153..76ea797 100644 --- a/eposix_memalignzn.c +++ b/eposix_memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/eprintf.c b/eprintf.c index 039a62f..10259f4 100644 --- a/eprintf.c +++ b/eprintf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/eputenvf.c b/eputenvf.c index aee4d47..a47665a 100644 --- a/eputenvf.c +++ b/eputenvf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/epvalloc.c b/epvalloc.c index e3e4788..81c03e3 100644 --- a/epvalloc.c +++ b/epvalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/epvallocn.c b/epvallocn.c index 4fcf347..8eef2d8 100644 --- a/epvallocn.c +++ b/epvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/epvallocz.c b/epvallocz.c index c9da7df..95ea4cf 100644 --- a/epvallocz.c +++ b/epvallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/epvalloczn.c b/epvalloczn.c index b6880c3..976813b 100644 --- a/epvalloczn.c +++ b/epvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/erealloc.c b/erealloc.c index 1150ca2..65689ae 100644 --- a/erealloc.c +++ b/erealloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ereallocarray.c b/ereallocarray.c index da022ae..2d07ee0 100644 --- a/ereallocarray.c +++ b/ereallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -46,7 +46,7 @@ main(void) libsimple_default_failure_exit = 1; } -#if defined(__GNUC__) && !defined(__clang) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Walloc-size-larger-than=" #endif @@ -57,7 +57,7 @@ main(void) assert_stderr("%s: reallocarray: %s\n", argv0, strerror(ENOMEM)); libsimple_default_failure_exit = 1; -#if defined(__GNUC__) && !defined(__clang) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic pop #endif diff --git a/ereallocn.c b/ereallocn.c index 17b1f09..f00fed3 100644 --- a/ereallocn.c +++ b/ereallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/estrdup.c b/estrdup.c index 3a67e0a..53d60c2 100644 --- a/estrdup.c +++ b/estrdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/estrndup.c b/estrndup.c index 3471db5..67f1ca4 100644 --- a/estrndup.c +++ b/estrndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evaligned_allocn.c b/evaligned_allocn.c index 4f318fe..2d14680 100644 --- a/evaligned_allocn.c +++ b/evaligned_allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evaligned_alloczn.c b/evaligned_alloczn.c index 1e5d543..ec2d305 100644 --- a/evaligned_alloczn.c +++ b/evaligned_alloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evaligned_reallocn.c b/evaligned_reallocn.c index 676fbb6..37e7133 100644 --- a/evaligned_reallocn.c +++ b/evaligned_reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evalloc.c b/evalloc.c index 6103b9e..83db54c 100644 --- a/evalloc.c +++ b/evalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evallocn.c b/evallocn.c index 7f736fc..e57c122 100644 --- a/evallocn.c +++ b/evallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evallocz.c b/evallocz.c index 1edd48c..b16cc9a 100644 --- a/evallocz.c +++ b/evallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evalloczn.c b/evalloczn.c index 9be9c16..9e231c3 100644 --- a/evalloczn.c +++ b/evalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evcallocn.c b/evcallocn.c index d577ebc..25770bc 100644 --- a/evcallocn.c +++ b/evcallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evmallocn.c b/evmallocn.c index f15b8d6..67003f0 100644 --- a/evmallocn.c +++ b/evmallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evmalloczn.c b/evmalloczn.c index 3afa855..7cf4abe 100644 --- a/evmalloczn.c +++ b/evmalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evmemalignn.c b/evmemalignn.c index 5cacc95..5e1de37 100644 --- a/evmemalignn.c +++ b/evmemalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evmemalignzn.c b/evmemalignzn.c index 643d5a6..304d5b8 100644 --- a/evmemalignzn.c +++ b/evmemalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evmemalloc.c b/evmemalloc.c index 2f04b4b..cb929ec 100644 --- a/evmemalloc.c +++ b/evmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evposix_memalignn.c b/evposix_memalignn.c index bd13743..e5e95bc 100644 --- a/evposix_memalignn.c +++ b/evposix_memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evposix_memalignzn.c b/evposix_memalignzn.c index 71a5250..e1a0b43 100644 --- a/evposix_memalignzn.c +++ b/evposix_memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evputenvf.c b/evputenvf.c index b35aae3..e3647ba 100644 --- a/evputenvf.c +++ b/evputenvf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evpvallocn.c b/evpvallocn.c index 4ce9e69..6dc643d 100644 --- a/evpvallocn.c +++ b/evpvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evpvalloczn.c b/evpvalloczn.c index ddc593b..dbec77c 100644 --- a/evpvalloczn.c +++ b/evpvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evreallocn.c b/evreallocn.c index 5bddb0e..e576866 100644 --- a/evreallocn.c +++ b/evreallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evvallocn.c b/evvallocn.c index a87d171..5e52d4f 100644 --- a/evvallocn.c +++ b/evvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/evvalloczn.c b/evvalloczn.c index dee0a1c..9776ab2 100644 --- a/evvalloczn.c +++ b/evvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ewcsdup.c b/ewcsdup.c index ca8e422..cf2b8b6 100644 --- a/ewcsdup.c +++ b/ewcsdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ewcsndup.c b/ewcsndup.c index 239cca0..9c17a5a 100644 --- a/ewcsndup.c +++ b/ewcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/ewmemdup.c b/ewmemdup.c index 0687fd5..ddef556 100644 --- a/ewmemdup.c +++ b/ewmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/getenv_e.c b/getenv_e.c index 95eb34e..9d0690a 100644 --- a/getenv_e.c +++ b/getenv_e.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/getenv_ne.c b/getenv_ne.c index e3b962a..6806992 100644 --- a/getenv_ne.c +++ b/getenv_ne.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/gmtime.c b/gmtime.c index 5868e8a..7a84289 100644 --- a/gmtime.c +++ b/gmtime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include #ifndef TEST diff --git a/inchrcaseset.c b/inchrcaseset.c new file mode 100644 index 0000000..bd50fa3 --- /dev/null +++ b/inchrcaseset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_inchrcaseset(int, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/inchrset.c b/inchrset.c new file mode 100644 index 0000000..7358ede --- /dev/null +++ b/inchrset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_inchrset(int, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/libsimple-arg.c b/libsimple-arg.c index 7fcb91a..0fafdde 100644 --- a/libsimple-arg.c +++ b/libsimple-arg.c @@ -475,7 +475,8 @@ parser8(int argc, char *argv[]) {"--missing", 'm', 1}, {NULL, '\0', 0}, })); - /* fall through */ + usage(); + break; default: usage(); } ARGALT('+') { @@ -495,7 +496,8 @@ parser8(int argc, char *argv[]) {"++missing", 'm', 1}, {NULL, '\0', 0}, })); - /* fall through */ + usage(); + break; default: usage(); } ARGEND; diff --git a/libsimple-arg.h b/libsimple-arg.h index 1d52b33..6aa3c2a 100644 --- a/libsimple-arg.h +++ b/libsimple-arg.h @@ -8,11 +8,11 @@ #ifdef LIBSIMPLY_CONFIG_MULTICALL_BINARY /* Define by the application */ -# define _LIBSIMPLY_IF_MULTICALL_BINARY(...) __VA_ARGS__ -# define _LIBSIMPLY_UNLESS_MULTICALL_BINARY(...) +# define LIBSIMPLY_IF_MULTICALL_BINARY__(...) __VA_ARGS__ +# define LIBSIMPLY_UNLESS_MULTICALL_BINARY__(...) #else -# define _LIBSIMPLY_IF_MULTICALL_BINARY(...) -# define _LIBSIMPLY_UNLESS_MULTICALL_BINARY(...) __VA_ARGS__ +# define LIBSIMPLY_IF_MULTICALL_BINARY__(...) +# define LIBSIMPLY_UNLESS_MULTICALL_BINARY__(...) __VA_ARGS__ #endif @@ -48,10 +48,19 @@ struct longopt { */ char short_flag; +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +#endif + /** * Whether the option takes an argument */ int with_arg; + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif }; @@ -410,11 +419,11 @@ struct longopt { /* Intended for internal use only */ #if __STDC_VERSION__ >= 201112L -# define _LIBSIMPLE_NORETURN _Noreturn +# define LIBSIMPLE_NORETURN__ _Noreturn #elif defined(__GNUC__) || defined(__clang__) -# define _LIBSIMPLE_NORETURN __attribute__((noreturn)) +# define LIBSIMPLE_NORETURN__ __attribute__((noreturn)) #else -# define _LIBSIMPLE_NORETURN +# define LIBSIMPLE_NORETURN__ #endif @@ -433,15 +442,15 @@ struct longopt { * @parma STATUS:int The exit value for the process */ #define NUSAGE(STATUS, SYNOPSIS)\ - static _LIBSIMPLE_NORETURN void\ + static LIBSIMPLE_NORETURN__ void\ usage(void)\ {\ const char *syn = (const char *)SYNOPSIS ? SYNOPSIS : "";\ fprintf(stderr, "usage: %s%s%s\n", argv0, *syn ? " " : "", syn);\ exit(STATUS);\ }\ - _LIBSIMPLY_UNLESS_MULTICALL_BINARY(char *argv0 = NULL)\ - _LIBSIMPLY_IF_MULTICALL_BINARY(int main(int, char *[])) + LIBSIMPLY_UNLESS_MULTICALL_BINARY__(char *argv0 = NULL)\ + LIBSIMPLY_IF_MULTICALL_BINARY__(int main(int, char *[])) #endif diff --git a/libsimple.c b/libsimple.c index 0140b84..3380e29 100644 --- a/libsimple.c +++ b/libsimple.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -223,20 +223,20 @@ main(void) assert(MAX3(-3, -1, -2) == -1); assert(MAX3(-3, -2, -1) == -1); -#define _1 0 -#define _2 0, 0 -#define _3 0, 0, 0 - assert(ELEMSOF((char []){_1}) == 1); - assert(ELEMSOF((char []){_2}) == 2); - assert(ELEMSOF((char []){_3}) == 3); - assert(ELEMSOF((short int []){_3}) == 3); - assert(ELEMSOF((int []){_3}) == 3); - assert(ELEMSOF((long int []){_3}) == 3); - assert(ELEMSOF((float []){_3}) == 3); - assert(ELEMSOF((double []){_3}) == 3); -#undef _1 -#undef _2 -#undef _3 +#define X1 0 +#define X2 0, 0 +#define X3 0, 0, 0 + assert(ELEMSOF((char []){X1}) == 1); + assert(ELEMSOF((char []){X2}) == 2); + assert(ELEMSOF((char []){X3}) == 3); + assert(ELEMSOF((short int []){X3}) == 3); + assert(ELEMSOF((int []){X3}) == 3); + assert(ELEMSOF((long int []){X3}) == 3); + assert(ELEMSOF((float []){X3}) == 3); + assert(ELEMSOF((double []){X3}) == 3); +#undef X1 +#undef X2 +#undef X3 assert(STRLEN("") == 0); assert(STRLEN("a") == 1); @@ -1700,229 +1700,276 @@ main(void) assert(!memcmp(buf, "hello world\0goodbye world", 26)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strmove(&buf[3], buf) == &buf[3]); assert(!strcmp(buf, "helhello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strmove(buf, &buf[3]) == buf); assert(!strcmp(buf, "lo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strmove(buf, buf) == buf); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]); assert(!strcmp(buf, "helhello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf); assert(!strcmp(buf, "lo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]); assert(!strcmp(buf, "helhello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, &buf[3], 9) == buf); assert(!strcmp(buf, "lo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, buf, 12) == buf); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]); assert(!strncmp(buf, "helhello worldx", 15)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, &buf[3], 8) == buf); assert(!strcmp(buf, "lo worldrld")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, buf, 11) == buf); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]); assert(!strcmp(buf, "helhe world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, &buf[3], 2) == buf); assert(!strcmp(buf, "lollo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_strnmove(buf, buf, 2) == buf); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]); assert(!strcmp(buf, "helhello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]); assert(!strcmp(buf, "lo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpmove(buf, buf) == &buf[11]); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]); assert(!strcmp(buf, "helhello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]); assert(!strcmp(buf, "lo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]); assert(!strcmp(buf, "helhello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]); assert(!strcmp(buf, "lo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]); assert(!strncmp(buf, "helhello worldx", 15)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]); assert(!strcmp(buf, "lo worldrld")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]); assert(!strcmp(buf, "helhe world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]); assert(!strcmp(buf, "lollo world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(buf, "hello world"); assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]); assert(!strcmp(buf, "hello world")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]); assert(!strcmp(buf, "hel")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strccpy(buf, "hello", 'x') == NULL); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]); assert(!strcmp(buf, "hel")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]); assert(!strcmp(buf, "hel")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL); assert(!strcmp(buf, "hello")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]); assert(!strcmp(buf, "hel")); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL); assert(!strncmp(buf, "helx", 4)); diff --git a/libsimple.h b/libsimple.h index 8af98e8..b9e263c 100644 --- a/libsimple.h +++ b/libsimple.h @@ -3,6 +3,14 @@ #define LIBSIMPLE_H +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +# pragma clang diagnostic ignored "-Wreserved-identifier" +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +#endif + #include #include #include @@ -49,6 +57,13 @@ +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Winline" +#endif + + + #if defined(__GNUC__) && !defined(__clang__) # define LIBSIMPLE_GCC_ONLY__(x) x # define LIBSIMPLE_NON_GCC_ONLY__(x) @@ -57,6 +72,12 @@ # define LIBSIMPLE_NON_GCC_ONLY__(x) x #endif +#if defined(__GNUC__) +# define LIBSIMPLE_EXTENSION__ __extension__ +#else +# define LIBSIMPLE_EXTENSION__ +#endif + #if __STDC_VERSION__ >= 199409L # define LIBSIMPLE_C95_ONLY__(x) x # define LIBSIMPLE_PRE_C95_ONLY__(x) @@ -218,13 +239,11 @@ libsimple_unlist(void *list__, size_t i__, size_t *np__, size_t width__) #define LIBSIMPLE_ASSUME_ALIGNED__(PTR, ALIGNMENT, ...)\ - LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ALIGNMENT)) -#if defined(__GNUC__) && !defined(__clang__) -# define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man */\ - LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\ - LIBSIMPLE_C11_ONLY__(_Alignof(PTR))\ - _LIBSIMPLE_PREC11_ONLY(__alignof(PTR)))) -#endif + LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ALIGNMENT))\ + LIBSIMPLE_NON_GCC_ONLY__(PTR) +#define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man */\ + LIBSIMPLE_ASSUME_ALIGNED__(PTR, ##__VA_ARGS__, LIBSIMPLE_C11_ONLY__(_Alignof(*PTR)) /* no , */\ + LIBSIMPLE_PRE_C11_ONLY__(__alignof(*PTR))) #ifndef ASSUME_ALIGNED # define ASSUME_ALIGNED(...) LIBSIMPLE_ASSUME_ALIGNED(__VA_ARGS__) #endif @@ -250,4 +269,13 @@ libsimple_unlist(void *list__, size_t i__, size_t *np__, size_t width__) +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + #endif diff --git a/libsimple/aligned_memdup.h b/libsimple/aligned_memdup.h index d612be0..6cb9415 100644 --- a/libsimple/aligned_memdup.h +++ b/libsimple/aligned_memdup.h @@ -11,21 +11,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_memdupa(s, alignment, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ - const char *__s = (s);\ - size_t __n = (n);\ - size_t __a = (alignment);\ - size_t __size;\ - uintptr_t __misalignment;\ - char *__r;\ - __a += !__a;\ - __size = __n + (__a - 1);\ - __r = alloca(__size + !__size);\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - memcpy(__r, __s, __n);\ + const char *s__ = (s);\ + size_t n__ = (n);\ + size_t a__ = (alignment);\ + size_t size__;\ + uintptr_t misalignment__;\ + char *r__;\ + a__ += !a__;\ + size__ = n__ + (a__ - 1);\ + r__ = alloca(size__ + !size__);\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + memcpy(r__, s__, n__);\ }) # ifndef aligned_memdupa # define aligned_memdupa(s, alignment, n) libsimple_aligned_memdupa(s, alignment, n) diff --git a/libsimple/aligned_strdup.h b/libsimple/aligned_strdup.h index c7b713e..2488f96 100644 --- a/libsimple/aligned_strdup.h +++ b/libsimple/aligned_strdup.h @@ -10,7 +10,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_strdupa(s, alignment)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *s__ = (s);\ size_t n__ = strlen(s__) + 1;\ diff --git a/libsimple/aligned_strndup.h b/libsimple/aligned_strndup.h index 201afef..84f2218 100644 --- a/libsimple/aligned_strndup.h +++ b/libsimple/aligned_strndup.h @@ -11,7 +11,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_strndupa(s, alignment, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *s__ = (s);\ size_t n__ = strnlen(s__, n);\ diff --git a/libsimple/aligned_wcsdup.h b/libsimple/aligned_wcsdup.h index c9fc0cf..3b33338 100644 --- a/libsimple/aligned_wcsdup.h +++ b/libsimple/aligned_wcsdup.h @@ -10,7 +10,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wcsdupa(s, alignment)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const wchar_t *s__ = (s);\ size_t n__ = wcslen(s__) + 1;\ diff --git a/libsimple/aligned_wcsndup.h b/libsimple/aligned_wcsndup.h index cd06ff8..a5d2641 100644 --- a/libsimple/aligned_wcsndup.h +++ b/libsimple/aligned_wcsndup.h @@ -11,7 +11,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wcsndupa(s, alignment, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const wchar_t *s__ = (s);\ size_t n__ = wcsnlen(s__, n);\ diff --git a/libsimple/aligned_wmemdup.h b/libsimple/aligned_wmemdup.h index 56148d8..51f00a9 100644 --- a/libsimple/aligned_wmemdup.h +++ b/libsimple/aligned_wmemdup.h @@ -11,7 +11,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wmemdupa(s, alignment, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const wchar_t *s__ = (s);\ size_t n__ = (n);\ diff --git a/libsimple/memdup.h b/libsimple/memdup.h index f799eee..528782f 100644 --- a/libsimple/memdup.h +++ b/libsimple/memdup.h @@ -10,7 +10,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_memdupa(s, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *s__ = (s);\ size_t n__ = (n);\ diff --git a/libsimple/printf.h b/libsimple/printf.h index 95f6935..3b426ec 100644 --- a/libsimple/printf.h +++ b/libsimple/printf.h @@ -96,7 +96,7 @@ int libsimple_vasprintf(char **, const char *, va_list); */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_asprintfa(fmt__, ...)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *f__ = (fmt__);\ char *ret__ = NULL;\ @@ -128,7 +128,7 @@ int libsimple_vasprintf(char **, const char *, va_list); */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_vasprintfa(fmt__, ap__)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *f__ = (fmt__);\ va_list a1__;\ diff --git a/libsimple/str.h b/libsimple/str.h index d01086e..b0345bd 100644 --- a/libsimple/str.h +++ b/libsimple/str.h @@ -164,7 +164,7 @@ char *libsimple_strrcasechr_inv(const char *, int); * @return `s` with an offset such `!*r`, where `r` is the returned pointer */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline char * +inline char * libsimple_strend(const char *s__) { return strchr(s__, '\0'); @@ -196,7 +196,7 @@ int libsimple_strstarts(const char *, const char *); * @return 1 if `s` starts with `t`, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_strcasestarts(const char *s__, const char *t__) { return !strncasecmp(s__, t__, strlen(t__)); @@ -293,7 +293,7 @@ char *libsimple_strrcasestr(const char *, const char *); * 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strcmpnul(const char *a__, const char *b__) { return (!a__ || !b__) ? !b__ - !a__ : strcmp(a__, b__); @@ -314,7 +314,7 @@ libsimple_strcmpnul(const char *a__, const char *b__) * 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strcasecmpnul(const char *a__, const char *b__) { return (!a__ || !b__) ? !b__ - !a__ : strcasecmp(a__, b__); @@ -333,7 +333,7 @@ libsimple_strcasecmpnul(const char *a__, const char *b__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_streq(const char *a__, const char *b__) { return !strcmp(a__, b__); @@ -352,7 +352,7 @@ libsimple_streq(const char *a__, const char *b__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_streqnul(const char *a__, const char *b__) { return !libsimple_strcmpnul(a__, b__); @@ -371,7 +371,7 @@ libsimple_streqnul(const char *a__, const char *b__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_strcaseeq(const char *a__, const char *b__) { return !strcasecmp(a__, b__); @@ -390,7 +390,7 @@ libsimple_strcaseeq(const char *a__, const char *b__) * @return 1 if the strings are equal, 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __warn_unused_result__))) -static inline int +inline int libsimple_strcaseeqnul(const char *a__, const char *b__) { return !libsimple_strcasecmpnul(a__, b__); @@ -439,7 +439,7 @@ size_t libsimple_strcaseeqlen(const char *, const char *); * in common in their ends */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t +inline size_t libsimple_strreqlen(const char *a__, const char *b__) { return libsimple_memreqlen(a__, strlen(a__), b__, strlen(b__)); @@ -458,7 +458,7 @@ libsimple_strreqlen(const char *a__, const char *b__) * in common in their ends */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline size_t +inline size_t libsimple_strrcaseeqlen(const char *a__, const char *b__) { return libsimple_memrcaseeqlen(a__, strlen(a__), b__, strlen(b__)); @@ -477,7 +477,7 @@ libsimple_strrcaseeqlen(const char *a__, const char *b__) * 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_inchrset(int c__, const char *s__) { return c__ && strchr(s__, c__); @@ -496,7 +496,7 @@ libsimple_inchrset(int c__, const char *s__) * 0 otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_inchrcaseset(int c__, const char *s__) { return c__ && strcasechr(s__, c__); @@ -515,7 +515,7 @@ libsimple_inchrcaseset(int c__, const char *s__) * @return `d` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_strmove(char *d__, const char *s__) { return memmove(d__, s__, strlen(s__) + 1); @@ -534,7 +534,7 @@ libsimple_strmove(char *d__, const char *s__) * @return `&d[strlen(s)]` (this byte will be a NUL byte) */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_stpmove(char *d__, const char *s__) { size_t n__ = strlen(s__); @@ -554,7 +554,7 @@ libsimple_stpmove(char *d__, const char *s__) * @return `s` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_strset(char *s__, int c___) { char c__ = (char)c___, *r__ = s__; @@ -574,7 +574,7 @@ libsimple_strset(char *s__, int c___) * @return `&s[strlen(s)]` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_stpset(char *s__, int c___) { char c__ = (char)c___; @@ -597,7 +597,7 @@ libsimple_stpset(char *s__, int c___) * found in `s`, `NULL` otherwise */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) -static inline char * +inline char * libsimple_strccpy(char *restrict d__, const char *restrict s__, int c___) { char c__ = (char)c___; @@ -640,7 +640,7 @@ char *libsimple_strcmove(char *, const char *, int); * @return `strchr(s, '\0')` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * +inline char * libsimple_strreplace(char *s__, int old___, int new___) { char old__ = (char)old___, new__ = (char)new___; @@ -705,7 +705,7 @@ char *libsimple_stptoupper(char *, const char *); * @return `d` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * +inline char * libsimple_strtolower(char *d__, const char *s__) { libsimple_stptolower(d__, s__); @@ -729,7 +729,7 @@ libsimple_strtolower(char *d__, const char *s__) * @return `d` */ LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * +inline char * libsimple_strtoupper(char *d__, const char *s__) { libsimple_stptoupper(d__, s__); @@ -749,7 +749,7 @@ libsimple_strtoupper(char *d__, const char *s__) * @return 1 if good, 0 on encoding error */ LIBSIMPLE_GCC_ONLY__(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -static inline int +inline int libsimple_strisutf8(const char *string__, int allow_modified_nul__) { return libsimple_memisutf8(string__, strlen(string__), allow_modified_nul__); diff --git a/libsimple/strdup.h b/libsimple/strdup.h index cc3b67a..cf48119 100644 --- a/libsimple/strdup.h +++ b/libsimple/strdup.h @@ -9,7 +9,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_strdupa(s)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *s__ = (s);\ size_t n__ = strlen(s__) + 1;\ diff --git a/libsimple/strndup.h b/libsimple/strndup.h index ccf3842..70c3db5 100644 --- a/libsimple/strndup.h +++ b/libsimple/strndup.h @@ -10,7 +10,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_strndupa(s, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const char *s__ = (s);\ size_t n__ = strnlen(s__, n);\ diff --git a/libsimple/wcsdup.h b/libsimple/wcsdup.h index 9b15103..0573d64 100644 --- a/libsimple/wcsdup.h +++ b/libsimple/wcsdup.h @@ -9,7 +9,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wcsdupa(s)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const wchar_t *s__ = (s);\ size_t n__ = wcslen(s__) + 1;\ diff --git a/libsimple/wcsndup.h b/libsimple/wcsndup.h index 0d36a25..d9ffaa5 100644 --- a/libsimple/wcsndup.h +++ b/libsimple/wcsndup.h @@ -10,7 +10,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wcsndupa(s, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const wchar_t *s__ = (s);\ size_t n__ = wcsnlen(s__, n);\ diff --git a/libsimple/wmemdup.h b/libsimple/wmemdup.h index 467aa61..898acdd 100644 --- a/libsimple/wmemdup.h +++ b/libsimple/wmemdup.h @@ -10,7 +10,7 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wmemdupa(s, n)\ - LIBSIMPLE_GCC_ONLY__(__extension__)\ + LIBSIMPLE_EXTENSION__\ ({\ const wchar_t *s__ = (s);\ size_t n__ = (n);\ diff --git a/localtime.c b/localtime.c index 0b075a0..96bd1e1 100644 --- a/localtime.c +++ b/localtime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include #ifndef TEST diff --git a/mallocn.c b/mallocn.c index 168ccfa..f8f51b4 100644 --- a/mallocn.c +++ b/mallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/mallocz.c b/mallocz.c index 814c0fc..22c3b03 100644 --- a/mallocz.c +++ b/mallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/malloczn.c b/malloczn.c index 47e2711..477b5bc 100644 --- a/malloczn.c +++ b/malloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memalign.c b/memalign.c index 38a3bda..66b1bee 100644 --- a/memalign.c +++ b/memalign.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memalignn.c b/memalignn.c index 14d1051..526ae3b 100644 --- a/memalignn.c +++ b/memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memalignz.c b/memalignz.c index 979f640..1802dbf 100644 --- a/memalignz.c +++ b/memalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memalignzn.c b/memalignzn.c index 42f3448..7b842aa 100644 --- a/memalignzn.c +++ b/memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memalloc.c b/memalloc.c index e0b9dc9..8f03933 100644 --- a/memalloc.c +++ b/memalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasechr.c b/memcasechr.c index 4277849..9abdd2b 100644 --- a/memcasechr.c +++ b/memcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasechr_inv.c b/memcasechr_inv.c index 6b89e66..0eb1cd3 100644 --- a/memcasechr_inv.c +++ b/memcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasecmp.c b/memcasecmp.c index efc9b47..357aedb 100644 --- a/memcasecmp.c +++ b/memcasecmp.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcaseends.c b/memcaseends.c index 8c938c4..09c12f7 100644 --- a/memcaseends.c +++ b/memcaseends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcaseeq.c b/memcaseeq.c index bbcf1b0..3c814f0 100644 --- a/memcaseeq.c +++ b/memcaseeq.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcaseeqlen.c b/memcaseeqlen.c index 79ab198..067eb96 100644 --- a/memcaseeqlen.c +++ b/memcaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasemem.c b/memcasemem.c index e118da8..b3ea476 100644 --- a/memcasemem.c +++ b/memcasemem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasescan.c b/memcasescan.c index a5b22b3..6c59089 100644 --- a/memcasescan.c +++ b/memcasescan.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasescan_inv.c b/memcasescan_inv.c index 28d7848..91f91e9 100644 --- a/memcasescan_inv.c +++ b/memcasescan_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasestarts.c b/memcasestarts.c index f9c30ee..4196e64 100644 --- a/memcasestarts.c +++ b/memcasestarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memchr_inv.c b/memchr_inv.c index 2eed2e0..2bca9cd 100644 --- a/memchr_inv.c +++ b/memchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcmove.c b/memcmove.c index 11fa9c4..a538250 100644 --- a/memcmove.c +++ b/memcmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -38,49 +38,58 @@ main(void) { char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'o', 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[3], &buf[5], 'o', 5) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[3], &buf[5], 'l', 5) == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[3], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[8], &buf[5], 'o', 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[8], &buf[5], 'l', 5) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[8], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); diff --git a/memdup.c b/memdup.c index 5d158b0..8775402 100644 --- a/memdup.c +++ b/memdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memelem.c b/memelem.c index 3344cd8..5777087 100644 --- a/memelem.c +++ b/memelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memelem_inv.c b/memelem_inv.c index 7e87d4c..5ec93d5 100644 --- a/memelem_inv.c +++ b/memelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memelemcpy.c b/memelemcpy.c index 3fafa65..19c937c 100644 --- a/memelemcpy.c +++ b/memelemcpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -91,96 +91,118 @@ main(void) char buf[1024]; - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "o", 0, 5) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "l", 0, 5) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "x", 0, 5) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "o", 1, 5) == &buf[5]); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "l", 1, 5) == &buf[3]); assert(!strncmp(buf, "helx", 4)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "x", 1, 5) == NULL); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.e.l.l.o", ".o", 2, 5) == &buf[5 * 2]); assert(!strncmp(buf, ".h.e.l.l.ox", 11)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.e.l.l.o", ".l", 2, 5) == &buf[3 * 2]); assert(!strncmp(buf, ".h.e.lx", 7)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.e.l.l.o", ".x", 2, 5) == NULL); assert(!strncmp(buf, ".h.e.l.l.ox", 11)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.l.ll..o", "l.", 2, 5) == &buf[4 * 2]); assert(!strncmp(buf, ".h.l.ll.x", 9)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..e..l..l..o", "..o", 3, 5) == &buf[5 * 3]); assert(!strncmp(buf, "..h..e..l..l..ox", 16)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..e..l..l..o", "..l", 3, 5) == &buf[3 * 3]); assert(!strncmp(buf, "..h..e..lx", 10)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..e..l..l..o", "..x", 3, 5) == NULL); assert(!strncmp(buf, "..h..e..l..l..ox", 16)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..l..ll....o", "l..", 3, 5) == &buf[4 * 3]); assert(!strncmp(buf, "..h..l..ll..x", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...e...l...l...o", "...o", 4, 5) == &buf[5 * 4]); assert(!strncmp(buf, "...h...e...l...l...ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...e...l...l...o", "...l", 4, 5) == &buf[3 * 4]); assert(!strncmp(buf, "...h...e...lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...e...l...l...o", "...x", 4, 5) == NULL); assert(!strncmp(buf, "...h...e...l...l...ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...l...ll......o", "l...", 4, 5) == &buf[4 * 4]); assert(!strncmp(buf, "...h...l...ll...x", 17)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......e.......l.......l.......o", ".......o", 8, 5) == &buf[5 * 8]); assert(!strncmp(buf, ".......h.......e.......l.......l.......ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......e.......l.......l.......o", ".......l", 8, 5) == &buf[3 * 8]); assert(!strncmp(buf, ".......h.......e.......lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......e.......l.......l.......o", ".......x", 8, 5) == NULL); assert(!strncmp(buf, ".......h.......e.......l.......l.......ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......l.......ll..............o", "l.......", 8, 5) == &buf[4 * 8]); assert(!strncmp(buf, ".......h.......l.......ll.......x", 21)); diff --git a/memelemmove.c b/memelemmove.c index d790a87..22908ca 100644 --- a/memelemmove.c +++ b/memelemmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -123,300 +123,360 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "", 0, 5) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "", 0, 5) == &buf[3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[3], "", 0, 5) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "o", 1, 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "l", 1, 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "x", 1, 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "o", 1, 5) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "l", 1, 5) == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "x", 1, 5) == NULL); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "o", 1, 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "l", 1, 5) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "x", 1, 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".o", 2, 5) == &buf[5 + 5 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".l", 2, 5) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".x", 2, 5) == NULL); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".o", 2, 5) == &buf[3 + 5 * 2]); assert(!strncmp(buf, "---.h.e.l.l.o.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".l", 2, 5) == &buf[3 + 3 * 2]); assert(!strncmp(buf, "---.h.e.l.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".x", 2, 5) == NULL); assert(!strncmp(buf, "---.h.e.l.l.o.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".o", 2, 5) == &buf[8 + 5 * 2]); assert(!strncmp(buf, "-----.h..h.e.l.l.o-", 19)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".l", 2, 5) == &buf[8 + 3 * 2]); assert(!strncmp(buf, "-----.h..h.e.lo-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".x", 2, 5) == NULL); assert(!strncmp(buf, "-----.h..h.e.l.l.o-", 19)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..o", 3, 5) == &buf[5 + 5 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..l", 3, 5) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..x", 3, 5) == NULL); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "..o", 3, 5) == &buf[3 + 5 * 3]); assert(!strncmp(buf, "---..h..e..l..l..o.o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "..l", 3, 5) == &buf[3 + 3 * 3]); assert(!strncmp(buf, "---..h..e..l.l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "..x", 3, 5) == NULL); assert(!strncmp(buf, "---..h..e..l..l..o.o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "..o", 3, 5) == &buf[8 + 5 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..l..o-", 24)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "..l", 3, 5) == &buf[8 + 3 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "..x", 3, 5) == NULL); assert(!strncmp(buf, "-----..h..h..e..l..l..o-", 24)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...o", 4, 5) == &buf[5 + 5 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...l", 4, 5) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...x", 4, 5) == NULL); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "...o", 4, 5) == &buf[3 + 5 * 4]); assert(!strncmp(buf, "---...h...e...l...l...o.o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "...l", 4, 5) == &buf[3 + 3 * 4]); assert(!strncmp(buf, "---...h...e...l.l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "...x", 4, 5) == NULL); assert(!strncmp(buf, "---...h...e...l...l...o.o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "...o", 4, 5) == &buf[8 + 5 * 4]); assert(!strncmp(buf, "-----......h...e...l...l...o-", 29)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "...l", 4, 5) == &buf[8 + 3 * 4]); assert(!strncmp(buf, "-----......h...e...ll...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "...x", 4, 5) == NULL); assert(!strncmp(buf, "-----......h...e...l...l...o-", 29)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......o", 8, 5) == &buf[5 + 5 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......l", 8, 5) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......x", 8, 5) == NULL); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".......o", 8, 5) == &buf[3 + 5 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.......l.......o.o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".......l", 8, 5) == &buf[3 + 3 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".......x", 8, 5) == NULL); assert(!strncmp(buf, "---.......h.......e.......l.......l.......o.o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".......o", 8, 5) == &buf[8 + 5 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l.......l.......o-", 49)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".......l", 8, 5) == &buf[8 + 3 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l....l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".......x", 8, 5) == NULL); assert(!strncmp(buf, "-----..........h.......e.......l.......l.......o-", 49)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a.", 2, 5) == &buf[5 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a.", 2, 5) == &buf[3 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a.", 2, 5) == &buf[8 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a..", 3, 5) == &buf[5 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a..", 3, 5) == &buf[3 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a..", 3, 5) == &buf[8 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a...", 4, 5) == &buf[5 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a...", 4, 5) == &buf[3 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a...", 4, 5) == &buf[8 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a.......", 8, 5) == &buf[5 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a.......", 8, 5) == &buf[3 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a.......", 8, 5) == &buf[8 + 4 * 8]); diff --git a/memelemscan.c b/memelemscan.c index b402570..b541319 100644 --- a/memelemscan.c +++ b/memelemscan.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memelemscan_inv.c b/memelemscan_inv.c index 48d35b2..cdbae3c 100644 --- a/memelemscan_inv.c +++ b/memelemscan_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memends.c b/memends.c index be4b1d4..cf09f65 100644 --- a/memends.c +++ b/memends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memeq.c b/memeq.c index f3eb30c..249df72 100644 --- a/memeq.c +++ b/memeq.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memeqlen.c b/memeqlen.c index f5a214c..19ff7d7 100644 --- a/memeqlen.c +++ b/memeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memisutf8.c b/memisutf8.c index b3d321e..c7ffbd8 100644 --- a/memisutf8.c +++ b/memisutf8.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memmem.c b/memmem.c index f05be99..847c4f0 100644 --- a/memmem.c +++ b/memmem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/mempcpy.c b/mempcpy.c index 8bac405..025cdbc 100644 --- a/mempcpy.c +++ b/mempcpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/mempmove.c b/mempmove.c index 2d42b0e..f2d2a03 100644 --- a/mempmove.c +++ b/mempmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -14,17 +14,20 @@ main(void) { char buf[100]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_mempmove(&buf[5], &buf[5], 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_mempmove(&buf[3], &buf[5], 5) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_mempmove(&buf[8], &buf[5], 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); diff --git a/mempset.c b/mempset.c index e69dcd1..4c793ac 100644 --- a/mempset.c +++ b/mempset.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/mempsetelem.c b/mempsetelem.c index cf84702..61b202b 100644 --- a/mempsetelem.c +++ b/mempsetelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -12,6 +12,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) case 1: return &((char *)memset(buf_, *(const char *)item, n))[n]; case 2: + if ((uintptr_t)buf_ % _Alignof(uint16_t) || (uintptr_t)item % _Alignof(uint16_t)) + goto misaligned; { uint16_t *buf = buf_; uint16_t *end = &buf[n]; @@ -21,6 +23,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) return buf; } case 4: + if ((uintptr_t)buf_ % _Alignof(uint32_t) || (uintptr_t)item % _Alignof(uint32_t)) + goto misaligned; { uint32_t *buf = buf_; uint32_t *end = &buf[n]; @@ -30,6 +34,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) return buf; } case 8: + if ((uintptr_t)buf_ % _Alignof(uint64_t) || (uintptr_t)item % _Alignof(uint64_t)) + goto misaligned; { uint64_t *buf = buf_; uint64_t *end = &buf[n]; @@ -39,6 +45,7 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) return buf; } default: + misaligned: { char *buf = buf_; size_t i; @@ -57,8 +64,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) int main(void) { - char buf_[4096]; - char *buf = buf_; + _Alignas(8) char buf_[4096]; + _Alignas(8) char *buf = buf_; size_t i; memset(buf, 0, sizeof(buf_)); @@ -76,6 +83,10 @@ main(void) assert(libsimple_mempsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == &buf[800]); assert(libsimple_mempsetelem(buf, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == &buf[48]); +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcast-align" +#endif + for (i = 0; i < 48; i++) assert(buf[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); for (; i < 800; i += 8) diff --git a/memptolower.c b/memptolower.c index f9b05e5..6ef3577 100644 --- a/memptolower.c +++ b/memptolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memptoupper.c b/memptoupper.c index c02cb3c..1ad61ce 100644 --- a/memptoupper.c +++ b/memptoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrcasechr.c b/memrcasechr.c index 1e6662e..e06586c 100644 --- a/memrcasechr.c +++ b/memrcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrcasechr_inv.c b/memrcasechr_inv.c index 1bcf221..ffb29a3 100644 --- a/memrcasechr_inv.c +++ b/memrcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrcaseeqlen.c b/memrcaseeqlen.c index 91b98d3..6042f4a 100644 --- a/memrcaseeqlen.c +++ b/memrcaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrcasemem.c b/memrcasemem.c index a7e9462..1ed9bb2 100644 --- a/memrcasemem.c +++ b/memrcasemem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrchr.c b/memrchr.c index 40186c4..7871894 100644 --- a/memrchr.c +++ b/memrchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrchr_inv.c b/memrchr_inv.c index 9ebba42..16dcbcd 100644 --- a/memrchr_inv.c +++ b/memrchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrelem.c b/memrelem.c index d23cb1b..c243671 100644 --- a/memrelem.c +++ b/memrelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrelem_inv.c b/memrelem_inv.c index 3bb0f89..a442eff 100644 --- a/memrelem_inv.c +++ b/memrelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memreplace.c b/memreplace.c index 563e76c..7a2eac4 100644 --- a/memreplace.c +++ b/memreplace.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memreplaceelem.c b/memreplaceelem.c index 9a56c98..c36d2e6 100644 --- a/memreplaceelem.c +++ b/memreplaceelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memreqlen.c b/memreqlen.c index 64a2e83..b3cba03 100644 --- a/memreqlen.c +++ b/memreqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memrmem.c b/memrmem.c index 68352c2..a06cdbf 100644 --- a/memrmem.c +++ b/memrmem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memscan.c b/memscan.c index 3fb2a2c..9e2c85f 100644 --- a/memscan.c +++ b/memscan.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memscan_inv.c b/memscan_inv.c index 29bdfce..f99c10f 100644 --- a/memscan_inv.c +++ b/memscan_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memsetelem.c b/memsetelem.c index 32c3f74..75190f2 100644 --- a/memsetelem.c +++ b/memsetelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -12,37 +12,41 @@ extern inline void *libsimple_memsetelem(void *, const void *, size_t, size_t); int main(void) { - char p_[4096]; - char *p = p_; + _Alignas(8) char buf_[4096]; + _Alignas(8) char *buf = buf_; size_t i; - memset(p, 0, sizeof(p_)); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 0, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 0, 10) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 1, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 2, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 4, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 8, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 16, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 3, 0) == p); - assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p); - assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p); - assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p); - assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p); - assert(libsimple_memsetelem(p, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == p); + memset(buf, 0, sizeof(buf_)); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 10) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 1, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 2, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 4, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 8, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 16, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 3, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint8_t){0x09}, 1, 3000) == buf); + assert(libsimple_memsetelem(buf, &(uint16_t){0x0807}, 2, 1000) == buf); + assert(libsimple_memsetelem(buf, &(uint32_t){0x10203040UL}, 4, 300) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == buf); + assert(libsimple_memsetelem(buf, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == buf); + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcast-align" +#endif for (i = 0; i < 48; i++) - assert(p[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); + assert(buf[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); for (; i < 800; i += 8) - assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL); + assert(*(uint64_t *)&buf[i] == 0x0102030450607080ULL); for (; i < 1200; i += 4) - assert(*(uint32_t *)&p[i] == 0x10203040UL); + assert(*(uint32_t *)&buf[i] == 0x10203040UL); for (; i < 2000; i += 2) - assert(*(uint16_t *)&p[i] == 0x0807); + assert(*(uint16_t *)&buf[i] == 0x0807); for (; i < 3000; i++) - assert(p[i] == 0x09); - for (; i < sizeof(p_); i++) - assert(p[i] == 0); + assert(buf[i] == 0x09); + for (; i < sizeof(buf_); i++) + assert(buf[i] == 0); return 0; } diff --git a/memstarts.c b/memstarts.c index ace2b70..aa128f7 100644 --- a/memstarts.c +++ b/memstarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memtolower.c b/memtolower.c index 364776a..30d66ad 100644 --- a/memtolower.c +++ b/memtolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memtoupper.c b/memtoupper.c index 376037a..38eb0ab 100644 --- a/memtoupper.c +++ b/memtoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/minimise_number_string.c b/minimise_number_string.c index 5993564..4a90916 100644 --- a/minimise_number_string.c +++ b/minimise_number_string.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/multimespec.c b/multimespec.c index bc73055..ee0e1f3 100644 --- a/multimespec.c +++ b/multimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -72,139 +72,166 @@ main(void) { struct timespec r, a; - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_nsec == 10L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_nsec == 10L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_nsec == 100L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -10); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -1); assert(r.tv_nsec == 1000000000L - 10L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -11); assert(r.tv_nsec == 1000000000L - 10L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == -100); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == -1); assert(r.tv_nsec == 1000000000L - 100L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == -101); assert(r.tv_nsec == 1000000000L - 100L); - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0); - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; assert(libsimple_multimespec(&r, &a, 2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; assert(libsimple_multimespec(&r, &a, -2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX); assert(r.tv_nsec == 0L); if (-TIME_MAX > TIME_MIN) { - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX - (time_t)1); assert(r.tv_nsec == 1L); } - a.tv_sec = 10, a.tv_nsec = 100000001L; + a.tv_sec = 10; + a.tv_nsec = 100000001L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 101); assert(r.tv_nsec == 10L); diff --git a/multimeval.c b/multimeval.c index 5f8010e..b974bf6 100644 --- a/multimeval.c +++ b/multimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -26,139 +26,166 @@ main(void) { struct timeval r, a; - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_usec == 10L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_usec == 10L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_usec == 100L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_usec == 100L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -10); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -1); assert(r.tv_usec == 1000000L - 10L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -11); assert(r.tv_usec == 1000000L - 10L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == -100); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == -1); assert(r.tv_usec == 1000000L - 100L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == -101); assert(r.tv_usec == 1000000L - 100L); - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0); - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; assert(libsimple_multimeval(&r, &a, 2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; assert(libsimple_multimeval(&r, &a, -2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 0L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX); assert(r.tv_usec == 0L); if (-TIME_MAX > TIME_MIN) { - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX - (time_t)1); assert(r.tv_usec == 1L); } - a.tv_sec = 10, a.tv_usec = 100001L; + a.tv_sec = 10; + a.tv_usec = 100001L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 101); assert(r.tv_usec == 10L); diff --git a/posix_memalignn.c b/posix_memalignn.c index 9f2617b..1400451 100644 --- a/posix_memalignn.c +++ b/posix_memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/posix_memalignz.c b/posix_memalignz.c index 18530ca..7c32bdd 100644 --- a/posix_memalignz.c +++ b/posix_memalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/posix_memalignzn.c b/posix_memalignzn.c index d91924e..a00ca84 100644 --- a/posix_memalignzn.c +++ b/posix_memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/putenvf.c b/putenvf.c index 45628ba..651f665 100644 --- a/putenvf.c +++ b/putenvf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/pvalloc.c b/pvalloc.c index e5a9c7b..b629abd 100644 --- a/pvalloc.c +++ b/pvalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/pvallocn.c b/pvallocn.c index 5a51408..2288816 100644 --- a/pvallocn.c +++ b/pvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/pvallocz.c b/pvallocz.c index 3e3f187..d65d08c 100644 --- a/pvallocz.c +++ b/pvallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/pvalloczn.c b/pvalloczn.c index 9349f47..b586863 100644 --- a/pvalloczn.c +++ b/pvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemcasechr.c b/rawmemcasechr.c index 3d3a101..b81d6d8 100644 --- a/rawmemcasechr.c +++ b/rawmemcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemcasechr_inv.c b/rawmemcasechr_inv.c index 13101cf..e0f2401 100644 --- a/rawmemcasechr_inv.c +++ b/rawmemcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemccpy.c b/rawmemccpy.c index cba8476..bdc4c7c 100644 --- a/rawmemccpy.c +++ b/rawmemccpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -14,11 +14,13 @@ main(void) { char buf[100]; - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemccpy(buf, "hello", 'o') == &buf[5]); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemccpy(buf, "hello", 'l') == &buf[3]); assert(!strncmp(buf, "helx", 4)); diff --git a/rawmemchr.c b/rawmemchr.c index 2ed1709..b694f79 100644 --- a/rawmemchr.c +++ b/rawmemchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemchr_inv.c b/rawmemchr_inv.c index d566aba..1b126aa 100644 --- a/rawmemchr_inv.c +++ b/rawmemchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemcmove.c b/rawmemcmove.c index fd831af..aeec55f 100644 --- a/rawmemcmove.c +++ b/rawmemcmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -14,34 +14,40 @@ main(void) { char buf[100]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'o') == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'l') == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'o') == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'l') == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'o') == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'l') == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); diff --git a/rawmemelem.c b/rawmemelem.c index 798f275..1564937 100644 --- a/rawmemelem.c +++ b/rawmemelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemelem_inv.c b/rawmemelem_inv.c index d9ed507..1e8bc00 100644 --- a/rawmemelem_inv.c +++ b/rawmemelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemelemcpy.c b/rawmemelemcpy.c index d5e52a2..ecd5337 100644 --- a/rawmemelemcpy.c +++ b/rawmemelemcpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -82,72 +82,88 @@ main(void) char buf[1024]; - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "o", 0) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "l", 0) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "o", 1) == &buf[5]); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "l", 1) == &buf[3]); assert(!strncmp(buf, "helx", 4)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".h.e.l.l.o", ".o", 2) == &buf[5 * 2]); assert(!strncmp(buf, ".h.e.l.l.ox", 11)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".h.e.l.l.o", ".l", 2) == &buf[3 * 2]); assert(!strncmp(buf, ".h.e.lx", 7)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".h.l.ll..o", "l.", 2) == &buf[4 * 2]); assert(!strncmp(buf, ".h.l.ll.x", 9)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "..h..e..l..l..o", "..o", 3) == &buf[5 * 3]); assert(!strncmp(buf, "..h..e..l..l..ox", 16)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "..h..e..l..l..o", "..l", 3) == &buf[3 * 3]); assert(!strncmp(buf, "..h..e..lx", 10)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "..h..l..ll....o", "l..", 3) == &buf[4 * 3]); assert(!strncmp(buf, "..h..l..ll..x", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "...h...e...l...l...o", "...o", 4) == &buf[5 * 4]); assert(!strncmp(buf, "...h...e...l...l...ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "...h...e...l...l...o", "...l", 4) == &buf[3 * 4]); assert(!strncmp(buf, "...h...e...lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "...h...l...ll......o", "l...", 4) == &buf[4 * 4]); assert(!strncmp(buf, "...h...l...ll...x", 17)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".......h.......e.......l.......l.......o", ".......o", 8) == &buf[5 * 8]); assert(!strncmp(buf, ".......h.......e.......l.......l.......ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".......h.......e.......l.......l.......o", ".......l", 8) == &buf[3 * 8]); assert(!strncmp(buf, ".......h.......e.......lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".......h.......l.......ll..............o", "l.......", 8) == &buf[4 * 8]); assert(!strncmp(buf, ".......h.......l.......ll.......x", 21)); diff --git a/rawmemelemmove.c b/rawmemelemmove.c index 717a590..a145e7e 100644 --- a/rawmemelemmove.c +++ b/rawmemelemmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -113,225 +113,270 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "", 0) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "", 0) == &buf[3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[3], "", 0) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "o", 1) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "l", 1) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "o", 1) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "l", 1) == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "o", 1) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "l", 1) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".o", 2) == &buf[5 + 5 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".l", 2) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".o", 2) == &buf[3 + 5 * 2]); assert(!strncmp(buf, "---.h.e.l.l.o.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".l", 2) == &buf[3 + 3 * 2]); assert(!strncmp(buf, "---.h.e.l.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".o", 2) == &buf[8 + 5 * 2]); assert(!strncmp(buf, "-----.h..h.e.l.l.o-", 19)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".l", 2) == &buf[8 + 3 * 2]); assert(!strncmp(buf, "-----.h..h.e.lo-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "..o", 3) == &buf[5 + 5 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "..l", 3) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "..o", 3) == &buf[3 + 5 * 3]); assert(!strncmp(buf, "---..h..e..l..l..o.o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "..l", 3) == &buf[3 + 3 * 3]); assert(!strncmp(buf, "---..h..e..l.l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "..o", 3) == &buf[8 + 5 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..l..o-", 24)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "..l", 3) == &buf[8 + 3 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "...o", 4) == &buf[5 + 5 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "...l", 4) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "...o", 4) == &buf[3 + 5 * 4]); assert(!strncmp(buf, "---...h...e...l...l...o.o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "...l", 4) == &buf[3 + 3 * 4]); assert(!strncmp(buf, "---...h...e...l.l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "...o", 4) == &buf[8 + 5 * 4]); assert(!strncmp(buf, "-----......h...e...l...l...o-", 29)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "...l", 4) == &buf[8 + 3 * 4]); assert(!strncmp(buf, "-----......h...e...ll...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".......o", 8) == &buf[5 + 5 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".......l", 8) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".......o", 8) == &buf[3 + 5 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.......l.......o.o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".......l", 8) == &buf[3 + 3 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".......o", 8) == &buf[8 + 5 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l.......l.......o-", 49)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".......l", 8) == &buf[8 + 3 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l....l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a.", 2) == &buf[5 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a.", 2) == &buf[3 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a.", 2) == &buf[8 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a..", 3) == &buf[5 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a..", 3) == &buf[3 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a..", 3) == &buf[8 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a...", 4) == &buf[5 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a...", 4) == &buf[3 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a...", 4) == &buf[8 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a.......", 8) == &buf[5 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a.......", 8) == &buf[3 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a.......", 8) == &buf[8 + 4 * 8]); diff --git a/rawmemrcasechr.c b/rawmemrcasechr.c index de33b8f..d562279 100644 --- a/rawmemrcasechr.c +++ b/rawmemrcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrcasechr_inv.c b/rawmemrcasechr_inv.c index 74ec992..63ef818 100644 --- a/rawmemrcasechr_inv.c +++ b/rawmemrcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrchr.c b/rawmemrchr.c index 80ddc41..7d08967 100644 --- a/rawmemrchr.c +++ b/rawmemrchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrchr_inv.c b/rawmemrchr_inv.c index c6a9b22..b703ae7 100644 --- a/rawmemrchr_inv.c +++ b/rawmemrchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrelem.c b/rawmemrelem.c index 08e3377..699ce03 100644 --- a/rawmemrelem.c +++ b/rawmemrelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrelem_inv.c b/rawmemrelem_inv.c index e39a271..25dc76b 100644 --- a/rawmemrelem_inv.c +++ b/rawmemrelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/reallocarray.c b/reallocarray.c index 640e84a..d54e2eb 100644 --- a/reallocarray.c +++ b/reallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -42,14 +42,14 @@ main(void) assert(!alloc_fail_in); } -#if defined(__GNUC__) && !defined(__clang) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Walloc-size-larger-than=" #endif assert(!libsimple_reallocarray(NULL, SIZE_MAX, SIZE_MAX) && errno == ENOMEM); -#if defined(__GNUC__) && !defined(__clang) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic pop #endif diff --git a/reallocarrayf.c b/reallocarrayf.c index f95c5ff..9d7e61e 100644 --- a/reallocarrayf.c +++ b/reallocarrayf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/reallocf.c b/reallocf.c index ded2f17..5180dd9 100644 --- a/reallocf.c +++ b/reallocf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/reallocfn.c b/reallocfn.c index b22b1c7..1432f78 100644 --- a/reallocfn.c +++ b/reallocfn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/reallocn.c b/reallocn.c index 75860bd..69863f2 100644 --- a/reallocn.c +++ b/reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/stpmove.c b/stpmove.c new file mode 100644 index 0000000..5457c21 --- /dev/null +++ b/stpmove.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_stpmove(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/stpnmove.c b/stpnmove.c index e3fd9d3..4f07cef 100644 --- a/stpnmove.c +++ b/stpnmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/stpnset.c b/stpnset.c index 42a810d..59ce182 100644 --- a/stpnset.c +++ b/stpnset.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/stpntolower.c b/stpntolower.c index 86adb89..90e38d0 100644 --- a/stpntolower.c +++ b/stpntolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/stpntoupper.c b/stpntoupper.c index a434153..732a9d3 100644 --- a/stpntoupper.c +++ b/stpntoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/stpset.c b/stpset.c new file mode 100644 index 0000000..4e5c134 --- /dev/null +++ b/stpset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_stpset(char *, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/stptolower.c b/stptolower.c index 73259f9..7c21372 100644 --- a/stptolower.c +++ b/stptolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/stptoupper.c b/stptoupper.c index ee56b75..3b5f008 100644 --- a/stptoupper.c +++ b/stptoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechr.c b/strcasechr.c index 83e8f73..3fe8ad1 100644 --- a/strcasechr.c +++ b/strcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechr_inv.c b/strcasechr_inv.c index 03e88c7..70e727c 100644 --- a/strcasechr_inv.c +++ b/strcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechrnul.c b/strcasechrnul.c index 5afcd54..2a09862 100644 --- a/strcasechrnul.c +++ b/strcasechrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechrnul_inv.c b/strcasechrnul_inv.c index 9c59d71..5a4c396 100644 --- a/strcasechrnul_inv.c +++ b/strcasechrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasecmpnul.c b/strcasecmpnul.c new file mode 100644 index 0000000..b6a9b7a --- /dev/null +++ b/strcasecmpnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcasecmpnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strcaseends.c b/strcaseends.c index adbebe4..7980b98 100644 --- a/strcaseends.c +++ b/strcaseends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcaseeq.c b/strcaseeq.c new file mode 100644 index 0000000..778c5b0 --- /dev/null +++ b/strcaseeq.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcaseeq(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strcaseeqlen.c b/strcaseeqlen.c index 625a3ad..256cb08 100644 --- a/strcaseeqlen.c +++ b/strcaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcaseeqnul.c b/strcaseeqnul.c new file mode 100644 index 0000000..a40aaf7 --- /dev/null +++ b/strcaseeqnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcaseeqnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strcasestarts.c b/strcasestarts.c new file mode 100644 index 0000000..7262f1e --- /dev/null +++ b/strcasestarts.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcasestarts(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strcasestr.c b/strcasestr.c index 071b7df..7449e64 100644 --- a/strcasestr.c +++ b/strcasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strccpy.c b/strccpy.c new file mode 100644 index 0000000..f4f7630 --- /dev/null +++ b/strccpy.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strccpy(char *restrict, const char *restrict, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strchr_inv.c b/strchr_inv.c index 4c1e242..13843f5 100644 --- a/strchr_inv.c +++ b/strchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strchrnul.c b/strchrnul.c index e4ed5ab..d22e761 100644 --- a/strchrnul.c +++ b/strchrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strchrnul_inv.c b/strchrnul_inv.c index 1f79eb3..26ff63d 100644 --- a/strchrnul_inv.c +++ b/strchrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcmove.c b/strcmove.c index c45fa47..49ea2f9 100644 --- a/strcmove.c +++ b/strcmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -40,64 +40,76 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], '\0') == &buf[5 + 6]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], 'o') == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], 'l') == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], 'x') == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], '\0') == &buf[3 + 6]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], 'o') == &buf[3 + 5]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], 'l') == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], 'x') == NULL); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], '\0') == &buf[8 + 6]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], 'o') == &buf[8 + 5]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], 'l') == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], 'x') == NULL); assert(!strcmp(buf, "-----helhello")); diff --git a/strcmpnul.c b/strcmpnul.c new file mode 100644 index 0000000..0a70610 --- /dev/null +++ b/strcmpnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcmpnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strend.c b/strend.c new file mode 100644 index 0000000..4754daf --- /dev/null +++ b/strend.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strend(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strends.c b/strends.c index 9934623..c175f1b 100644 --- a/strends.c +++ b/strends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/streq.c b/streq.c new file mode 100644 index 0000000..f54b8bb --- /dev/null +++ b/streq.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_streq(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/streqlen.c b/streqlen.c index d563ecc..a6e5d05 100644 --- a/streqlen.c +++ b/streqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/streqnul.c b/streqnul.c new file mode 100644 index 0000000..b557a9a --- /dev/null +++ b/streqnul.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_streqnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strisutf8.c b/strisutf8.c new file mode 100644 index 0000000..ac0f4ca --- /dev/null +++ b/strisutf8.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strisutf8(const char *, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strmove.c b/strmove.c new file mode 100644 index 0000000..bd1f89f --- /dev/null +++ b/strmove.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strmove(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strncasechr.c b/strncasechr.c index 9ba2b93..526acc0 100644 --- a/strncasechr.c +++ b/strncasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasechr_inv.c b/strncasechr_inv.c index cd30867..80bff5d 100644 --- a/strncasechr_inv.c +++ b/strncasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasechrnul.c b/strncasechrnul.c index 608f097..b49bf82 100644 --- a/strncasechrnul.c +++ b/strncasechrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasechrnul_inv.c b/strncasechrnul_inv.c index 6d6af35..0806195 100644 --- a/strncasechrnul_inv.c +++ b/strncasechrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasecmpnul.c b/strncasecmpnul.c index f4a208c..e15bcfd 100644 --- a/strncasecmpnul.c +++ b/strncasecmpnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncaseends.c b/strncaseends.c index 708c16a..6d69acc 100644 --- a/strncaseends.c +++ b/strncaseends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncaseeq.c b/strncaseeq.c index bd60472..4cec369 100644 --- a/strncaseeq.c +++ b/strncaseeq.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncaseeqlen.c b/strncaseeqlen.c index 56ace80..c70f1e7 100644 --- a/strncaseeqlen.c +++ b/strncaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncaseeqnul.c b/strncaseeqnul.c index 5330732..6a4c42e 100644 --- a/strncaseeqnul.c +++ b/strncaseeqnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasestarts.c b/strncasestarts.c index d7c6350..f8646c9 100644 --- a/strncasestarts.c +++ b/strncasestarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasestr.c b/strncasestr.c index 08adaf2..3543002 100644 --- a/strncasestr.c +++ b/strncasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnccpy.c b/strnccpy.c index fe8063e..3d91c08 100644 --- a/strnccpy.c +++ b/strnccpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchr.c b/strnchr.c index e03df86..f43c45f 100644 --- a/strnchr.c +++ b/strnchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchr_inv.c b/strnchr_inv.c index 7854d13..66f5238 100644 --- a/strnchr_inv.c +++ b/strnchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchrnul.c b/strnchrnul.c index 4e7e1b8..b6b3a39 100644 --- a/strnchrnul.c +++ b/strnchrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchrnul_inv.c b/strnchrnul_inv.c index a887221..8bbbdab 100644 --- a/strnchrnul_inv.c +++ b/strnchrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncmove.c b/strncmove.c index 1a03d2d..37b2bb4 100644 --- a/strncmove.c +++ b/strncmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -50,277 +50,329 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 1024) == &buf[5 + 6]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 1024) == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 1024) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 1024) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 1024) == &buf[3 + 6]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 1024) == &buf[3 + 5]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 1024) == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 1024) == NULL); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 1024) == &buf[8 + 6]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 1024) == &buf[8 + 5]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 1024) == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 1024) == NULL); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 6) == &buf[5 + 6]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 6) == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 6) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 6) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 6) == &buf[3 + 6]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 6) == &buf[3 + 5]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 6) == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 6) == NULL); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 6) == &buf[8 + 6]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 6) == &buf[8 + 5]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 6) == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 6) == NULL); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 5) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 5) == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 5) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 5) == NULL); assert(!strcmp(buf, "---hellolo")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 5) == &buf[3 + 5]); assert(!strcmp(buf, "---hellolo")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 5) == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 5) == NULL); assert(!strcmp(buf, "---hellolo")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 5) == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 3) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 3) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 3) == &buf[5 + 3]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 3) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 3) == NULL); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 3) == NULL); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 3) == &buf[3 + 3]); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 3) == NULL); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 3) == NULL); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 3) == NULL); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 3) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 3) == NULL); assert(!strncmp(buf, "-----helhel-", 12)); diff --git a/strncmpnul.c b/strncmpnul.c index 05751a1..a5c9d7a 100644 --- a/strncmpnul.c +++ b/strncmpnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnend.c b/strnend.c index df950cf..00687cd 100644 --- a/strnend.c +++ b/strnend.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnends.c b/strnends.c index 3d92ca0..eb6fed1 100644 --- a/strnends.c +++ b/strnends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strneq.c b/strneq.c index 0432176..6946bef 100644 --- a/strneq.c +++ b/strneq.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strneqlen.c b/strneqlen.c index 5ef50e3..09d3b8f 100644 --- a/strneqlen.c +++ b/strneqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strneqnul.c b/strneqnul.c index 191c2d4..b21fbe2 100644 --- a/strneqnul.c +++ b/strneqnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnisutf8.c b/strnisutf8.c index c62817c..dc76fd5 100644 --- a/strnisutf8.c +++ b/strnisutf8.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnmove.c b/strnmove.c index bc94911..d88c662 100644 --- a/strnmove.c +++ b/strnmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnreplace.c b/strnreplace.c index 9e735fb..f8a2036 100644 --- a/strnreplace.c +++ b/strnreplace.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnset.c b/strnset.c index 000e770..909222f 100644 --- a/strnset.c +++ b/strnset.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnstarts.c b/strnstarts.c index 727cf3e..1fbeed3 100644 --- a/strnstarts.c +++ b/strnstarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnstr.c b/strnstr.c index fe9305d..d678138 100644 --- a/strnstr.c +++ b/strnstr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strntolower.c b/strntolower.c index f88aac5..0dcad2a 100644 --- a/strntolower.c +++ b/strntolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strntoupper.c b/strntoupper.c index 58d8a0c..801a7f3 100644 --- a/strntoupper.c +++ b/strntoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrcasechr.c b/strrcasechr.c index 979e61b..26abb7e 100644 --- a/strrcasechr.c +++ b/strrcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrcasechr_inv.c b/strrcasechr_inv.c index 5572a38..091779d 100644 --- a/strrcasechr_inv.c +++ b/strrcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrcaseeqlen.c b/strrcaseeqlen.c new file mode 100644 index 0000000..d5176a1 --- /dev/null +++ b/strrcaseeqlen.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strrcaseeqlen(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strrcasestr.c b/strrcasestr.c index 3a3edce..7a17051 100644 --- a/strrcasestr.c +++ b/strrcasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrchr_inv.c b/strrchr_inv.c index 37b7e79..eb93c0e 100644 --- a/strrchr_inv.c +++ b/strrchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strreplace.c b/strreplace.c new file mode 100644 index 0000000..f32da11 --- /dev/null +++ b/strreplace.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strreplace(char *, int, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strreqlen.c b/strreqlen.c new file mode 100644 index 0000000..29f85fc --- /dev/null +++ b/strreqlen.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strreqlen(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strrncasechr.c b/strrncasechr.c index f4046d1..60ab4ac 100644 --- a/strrncasechr.c +++ b/strrncasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrncasechr_inv.c b/strrncasechr_inv.c index eb68b49..a471420 100644 --- a/strrncasechr_inv.c +++ b/strrncasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrncaseeqlen.c b/strrncaseeqlen.c index 82b1db3..5963afc 100644 --- a/strrncaseeqlen.c +++ b/strrncaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrncasestr.c b/strrncasestr.c index f1874c7..be57822 100644 --- a/strrncasestr.c +++ b/strrncasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrnchr.c b/strrnchr.c index d67775e..133f47e 100644 --- a/strrnchr.c +++ b/strrnchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrnchr_inv.c b/strrnchr_inv.c index fe657f9..060d3b0 100644 --- a/strrnchr_inv.c +++ b/strrnchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrneqlen.c b/strrneqlen.c index 913b359..b5f56b4 100644 --- a/strrneqlen.c +++ b/strrneqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrnstr.c b/strrnstr.c index fb1c49d..bc3e237 100644 --- a/strrnstr.c +++ b/strrnstr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrstr.c b/strrstr.c index 9e4190f..d5781c6 100644 --- a/strrstr.c +++ b/strrstr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strset.c b/strset.c new file mode 100644 index 0000000..2c62c0d --- /dev/null +++ b/strset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strset(char *, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strstarts.c b/strstarts.c index b476222..321d3c5 100644 --- a/strstarts.c +++ b/strstarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtoh.c b/strtoh.c index 47ea6d3..990673a 100644 --- a/strtoh.c +++ b/strtoh.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtohh.c b/strtohh.c index 67da198..da68c86 100644 --- a/strtohh.c +++ b/strtohh.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtoi.c b/strtoi.c index 448e485..fe559f8 100644 --- a/strtoi.c +++ b/strtoi.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtoi16.c b/strtoi16.c index 2960603..3d8cb44 100644 --- a/strtoi16.c +++ b/strtoi16.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 32767LL diff --git a/strtoi32.c b/strtoi32.c index ce4a7f4..a19cc73 100644 --- a/strtoi32.c +++ b/strtoi32.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 2147483647LL diff --git a/strtoi64.c b/strtoi64.c index 963574b..d34940c 100644 --- a/strtoi64.c +++ b/strtoi64.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 9223372036854775807LL diff --git a/strtoi8.c b/strtoi8.c index f6fecc6..a5d59a3 100644 --- a/strtoi8.c +++ b/strtoi8.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 127LL diff --git a/strtolower.c b/strtolower.c new file mode 100644 index 0000000..34006d7 --- /dev/null +++ b/strtolower.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strtolower(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strtotimespec.c b/strtotimespec.c index 7c1494e..eb02112 100644 --- a/strtotimespec.c +++ b/strtotimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtotimeval.c b/strtotimeval.c index 0305fb9..1e3dc9b 100644 --- a/strtotimeval.c +++ b/strtotimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtou.c b/strtou.c index 1faee3c..b731ca4 100644 --- a/strtou.c +++ b/strtou.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtou16.c b/strtou16.c index dea2678..c64488b 100644 --- a/strtou16.c +++ b/strtou16.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 65535ULL diff --git a/strtou32.c b/strtou32.c index 0260d4f..336071a 100644 --- a/strtou32.c +++ b/strtou32.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 4294967295ULL diff --git a/strtou64.c b/strtou64.c index 1deb3a5..b13ee1d 100644 --- a/strtou64.c +++ b/strtou64.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 18446744073709551615ULL diff --git a/strtou8.c b/strtou8.c index 5a8bcf5..1721d85 100644 --- a/strtou8.c +++ b/strtou8.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #define RET_MAX 255ULL diff --git a/strtouh.c b/strtouh.c index 9033930..7de6434 100644 --- a/strtouh.c +++ b/strtouh.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtouhh.c b/strtouhh.c index 72dbd7c..c6ec130 100644 --- a/strtouhh.c +++ b/strtouhh.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtoupper.c b/strtoupper.c new file mode 100644 index 0000000..ce7c147 --- /dev/null +++ b/strtoupper.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strtoupper(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strtouz.c b/strtouz.c index 57d218d..40ed549 100644 --- a/strtouz.c +++ b/strtouz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtoz.c b/strtoz.c index d07be33..44779df 100644 --- a/strtoz.c +++ b/strtoz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/sumtimespec.c b/sumtimespec.c index 2b2e935..b9dfdd6 100644 --- a/sumtimespec.c +++ b/sumtimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -47,62 +47,82 @@ main(void) { struct timespec r, a, b; - a.tv_sec = 0, a.tv_nsec = 0; - b.tv_sec = 0, b.tv_nsec = 0; + a.tv_sec = 0; + a.tv_nsec = 0; + b.tv_sec = 0; + b.tv_nsec = 0; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0); - a.tv_sec = 10, a.tv_nsec = 10000L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10000L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 10000L); - a.tv_sec = 10, a.tv_nsec = 10000L; - b.tv_sec = -10, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10000L; + b.tv_sec = -10; + b.tv_nsec = 0L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 10000L); - a.tv_sec = 10, a.tv_nsec = 10000L; - b.tv_sec = -20, b.tv_nsec = 20000L; + a.tv_sec = 10; + a.tv_nsec = 10000L; + b.tv_sec = -20; + b.tv_nsec = 20000L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 30000L); - a.tv_sec = 1, a.tv_nsec = 999999999L; - b.tv_sec = 1, b.tv_nsec = 1L; + a.tv_sec = 1; + a.tv_nsec = 999999999L; + b.tv_sec = 1; + b.tv_nsec = 1L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 3); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; - b.tv_sec = TIME_MAX, b.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; + b.tv_sec = TIME_MAX; + b.tv_nsec = 0L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; - b.tv_sec = 0, b.tv_nsec = 1L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; + b.tv_sec = 0; + b.tv_nsec = 1L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 1L; - b.tv_sec = 0, b.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 1L; + b.tv_sec = 0; + b.tv_nsec = 999999999L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = TIME_MIN, b.tv_nsec = 0L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = TIME_MIN; + b.tv_nsec = 0L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MIN, a.tv_nsec = 100L; - b.tv_sec = TIME_MIN, b.tv_nsec = 100L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 100L; + b.tv_sec = TIME_MIN; + b.tv_nsec = 100L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); diff --git a/sumtimeval.c b/sumtimeval.c index 09cadb1..5cc01ac 100644 --- a/sumtimeval.c +++ b/sumtimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/test.c b/test.c index 29a501b..3b1f559 100644 --- a/test.c +++ b/test.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include "test.h" #include @@ -337,7 +337,7 @@ test_vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) va_list ap2; int r; char *buf; - size_t n; + size_t i, n; va_copy(ap2, ap); r = vsnprintf(NULL, 0, format, ap2); @@ -353,7 +353,8 @@ test_vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } else { assert(stderr_ok); assert(stderr_n + n <= sizeof(stderr_buf)); - memcpy((char *)(void *)(&stderr_buf[stderr_n]), buf, n); + for (i = 0; i < n; i++) + stderr_buf[stderr_n + i] = buf[i]; stderr_n += n; } free(buf); diff --git a/test.h b/test.h index a961e13..261bdc8 100644 --- a/test.h +++ b/test.h @@ -1,6 +1,18 @@ /* See LICENSE file for copyright and license details. */ +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +# pragma clang diagnostic ignored "-Walloca" +#endif + + #define assert(EXPR)\ do {\ if (EXPR)\ @@ -48,10 +60,14 @@ do {\ char buf__[1024];\ int len__;\ + size_t i__;\ + int not_same__ = 0;\ len__ = sprintf(buf__, __VA_ARGS__);\ assert(len__ >= 0);\ assert((size_t)len__ == stderr_n);\ - assert(!memcmp(buf__, (char **)(void *)(&stderr_buf), stderr_n)); \ + for (i__ = 0; i__ < stderr_n; i__++)\ + not_same__ |= buf__[i__] ^ stderr_buf[i__];\ + assert(!not_same__);\ } while (0) diff --git a/timespec2timeval.c b/timespec2timeval.c index e71585a..c7ab175 100644 --- a/timespec2timeval.c +++ b/timespec2timeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timespectodouble.c b/timespectodouble.c index e2d1bcc..325709b 100644 --- a/timespectodouble.c +++ b/timespectodouble.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timespectostr.c b/timespectostr.c index bd99fe1..9440620 100644 --- a/timespectostr.c +++ b/timespectostr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timeval2timespec.c b/timeval2timespec.c index e7e529e..4d2a71f 100644 --- a/timeval2timespec.c +++ b/timeval2timespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timevaltodouble.c b/timevaltodouble.c index 1d3dacb..d8bf8d9 100644 --- a/timevaltodouble.c +++ b/timevaltodouble.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timevaltostr.c b/timevaltostr.c index 702b46b..daa2ff0 100644 --- a/timevaltostr.c +++ b/timevaltostr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/unlist.c b/unlist.c index 92b7f8f..edc69cf 100644 --- a/unlist.c +++ b/unlist.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/valigned_allocn.c b/valigned_allocn.c index 8f4faf3..0fa84ac 100644 --- a/valigned_allocn.c +++ b/valigned_allocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/valigned_reallocfn.c b/valigned_reallocfn.c index fcafcd6..3c116b4 100644 --- a/valigned_reallocfn.c +++ b/valigned_reallocfn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/valloc.c b/valloc.c index 5566b1c..eb9781f 100644 --- a/valloc.c +++ b/valloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vallocn.c b/vallocn.c index 5ea6723..73dc9ab 100644 --- a/vallocn.c +++ b/vallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vallocz.c b/vallocz.c index 06263ed..2fbf4a4 100644 --- a/vallocz.c +++ b/vallocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/valloczn.c b/valloczn.c index 27d6d1b..3016443 100644 --- a/valloczn.c +++ b/valloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vasprintf.c b/vasprintf.c index fd14650..65c494e 100644 --- a/vasprintf.c +++ b/vasprintf.c @@ -1,7 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif + int libsimple_vasprintf(char **strp, const char *fmt, va_list ap) diff --git a/vcallocn.c b/vcallocn.c index c590cf6..7007739 100644 --- a/vcallocn.c +++ b/vcallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/venprintf.c b/venprintf.c index 1657954..a8a39aa 100644 --- a/venprintf.c +++ b/venprintf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/veprintf.c b/veprintf.c index 36d6f14..9082db2 100644 --- a/veprintf.c +++ b/veprintf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vmallocn.c b/vmallocn.c index e9f97f1..ab3a340 100644 --- a/vmallocn.c +++ b/vmallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vmemalignn.c b/vmemalignn.c index 40abfb6..f0eae81 100644 --- a/vmemalignn.c +++ b/vmemalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vmemalignzn.c b/vmemalignzn.c index a0983e7..8ae1831 100644 --- a/vmemalignzn.c +++ b/vmemalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vmemalloc.c b/vmemalloc.c index cbaecea..450affb 100644 --- a/vmemalloc.c +++ b/vmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include #ifndef TEST diff --git a/vposix_memalignn.c b/vposix_memalignn.c index 6001cdc..9179b09 100644 --- a/vposix_memalignn.c +++ b/vposix_memalignn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vputenvf.c b/vputenvf.c index ea97ae6..cb09a0d 100644 --- a/vputenvf.c +++ b/vputenvf.c @@ -1,7 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif + int libsimple_vputenvf(const char *fmt, va_list ap) diff --git a/vpvallocn.c b/vpvallocn.c index 2a17882..f90224c 100644 --- a/vpvallocn.c +++ b/vpvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vpvalloczn.c b/vpvalloczn.c index 0aad778..3f3fbc1 100644 --- a/vpvalloczn.c +++ b/vpvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vreallocfn.c b/vreallocfn.c index fcd9c84..1aa770d 100644 --- a/vreallocfn.c +++ b/vreallocfn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vvallocn.c b/vvallocn.c index 67b473a..84c0ef7 100644 --- a/vvallocn.c +++ b/vvallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vvalloczn.c b/vvalloczn.c index c387583..d3e1b55 100644 --- a/vvalloczn.c +++ b/vvalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/vweprintf.c b/vweprintf.c index 9c93037..f684553 100644 --- a/vweprintf.c +++ b/vweprintf.c @@ -1,7 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif + extern char *argv0; @@ -32,8 +36,15 @@ libsimple_vweprintf(const char *fmt, va_list ap) va_copy(ap2, ap); r = vsnprintf(NULL, 0, fmt, ap1); if (0 <= r && r < 8096) { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Walloca" +#endif message = alloca((size_t)r + 1); vsprintf(message, fmt, ap2); +#if defined(__clang__) +# pragma clang diagnostic pop +#endif } va_end(ap2); va_end(ap1); diff --git a/wcsndup.c b/wcsndup.c index 5621084..a4129db 100644 --- a/wcsndup.c +++ b/wcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/weprintf.c b/weprintf.c index 14984c6..df80abb 100644 --- a/weprintf.c +++ b/weprintf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/wmemdup.c b/wmemdup.c index 2e9cc1c..d3455c9 100644 --- a/wmemdup.c +++ b/wmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST -- cgit v1.2.3-70-g09d2 From 3dd9089913623ccfa54ec7a2b5e876d17316c838 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 19 Jul 2022 13:47:08 +0200 Subject: Improve makefile and fix a bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 49 +++++++++++++++++++++++++++++++++++++++---------- config.mk | 2 +- mk/linux.mk | 6 ++++++ mk/macos.mk | 6 ++++++ mk/windows.mk | 6 ++++++ strtoi64.c | 6 +++--- 6 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 mk/linux.mk create mode 100644 mk/macos.mk create mode 100644 mk/windows.mk (limited to 'Makefile') diff --git a/Makefile b/Makefile index 6976479..5d45bc4 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,19 @@ CONFIGFILE = config.mk include $(CONFIGFILE) +OS = linux +# Linux: linux +# Mac OS: macos +# Windows: windows +include mk/$(OS).mk + + +LIB_MAJOR = 1 +LIB_MINOR = 0 +LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) +LIB_NAME = simple + + SUBHDR =\ libsimple/aligned_alloc.h\ libsimple/aligned_allocz.h\ @@ -449,52 +462,68 @@ MAN3 =\ TESTS = $(OBJ:.o=.test) libsimple-arg.test -all: libsimple.a $(TESTS) +LOBJ = $(OBJ:.o=.lo) + +all: libsimple.a libsimple.$(LIBEXT) $(TESTS) tests: $(TESTS) $(OBJ): $(HDR) $(TESTS): test.o libsimple.a $(TESTS:.test=.to): $(HDR) test.h test.o: test.c $(HDR) test.h - $(CC) -c -o $@ test.c $(CFLAGS) -DTEST -O0 -ffreestanding + $(CC) -c -o $@ test.c $(CFLAGS) $(CPPFLAGS) -DTEST -O0 -ffreestanding libsimple.a: $(OBJ) @rm -f -- $@ $(AR) rc $@ $(OBJ) $(AR) -s $@ +libsimple.$(LIBEXT): $(LOBJ) + $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS) + .to.test: $(CC) -o $@ $< test.o libsimple.a $(LDFLAGS) .c.to: - $(CC) -c -o $@ $< $(CFLAGS) -DTEST -O0 + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -DTEST -O0 + +.c.o: + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) + +.c.lo: + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) check: $(TESTS) @set -e; for t in $(TESTS); do printf '%s\n' "./$$t"; $(CHECK_PREFIX) "./$$t"; done -install: libsimple.a +install: libsimple.a libsimple.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include/libsimple" - mkdir -p -- "$(DESTDIR)$(PREFIX)/share/man/man0" - mkdir -p -- "$(DESTDIR)$(PREFIX)/share/man/man3" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man0" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3" cp -- libsimple.a "$(DESTDIR)$(PREFIX)/lib" + cp -- libsimple.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMINOREXT)" + $(FIX_INSTALL_NAME) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMINOREXT)" + ln -sf -- libsimple.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMAJOREXT)" + ln -sf -- libsimple.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBEXT)" cp -- libsimple.h "$(DESTDIR)$(PREFIX)/include" cp -- libsimple-arg.h "$(DESTDIR)$(PREFIX)/include" cp -- $(SUBHDR) "$(DESTDIR)$(PREFIX)/include/libsimple" - cp -- $(MAN0) "$(DESTDIR)$(PREFIX)/share/man/man0" - cp -P -- $(MAN3) "$(DESTDIR)$(PREFIX)/share/man/man3" + cp -P -- $(MAN0) "$(DESTDIR)$(MANPREFIX)/man0" + cp -P -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3" uninstall: -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libsimple.a" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libsimple.h" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libsimple-arg.h" -rm -rf -- "$(DESTDIR)$(PREFIX)/include/libsimple" - -cd -- "$(DESTDIR)$(PREFIX)/share/man" && rm -f -- $(MAN0) $(MAN3) + -cd -- "$(DESTDIR)$(MANPREFIX)/man0" && rm -f -- $(MAN0) + -cd -- "$(DESTDIR)$(MANPREFIX)/man3" && rm -f -- $(MAN3) clean: -rm -rf -- *.o *.su *.a *.so *.so.* *.gch *.gcda *.gcno *.gcov *.lo *.test *.to .SUFFIXES: -.SUFFIXES: .test .to .o .c +.SUFFIXES: .test .to .lo .o .c .PHONY: all check install uninstall clean diff --git a/config.mk b/config.mk index 605a704..c9919fd 100644 --- a/config.mk +++ b/config.mk @@ -4,5 +4,5 @@ MANPREFIX = $(PREFIX)/share/man CC = cc CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -CFLAGS = -std=c11 -Wall -Wextra -O2 $(CPPFLAGS) +CFLAGS = -std=c11 -Wall -Wextra -O2 LDFLAGS = -s diff --git a/mk/linux.mk b/mk/linux.mk new file mode 100644 index 0000000..ad58f69 --- /dev/null +++ b/mk/linux.mk @@ -0,0 +1,6 @@ +LIBEXT = so +LIBFLAGS = -shared -Wl,-soname,lib$(LIB_NAME).$(LIBEXT).$(LIB_MAJOR) +LIBMAJOREXT = $(LIBEXT).$(LIB_MAJOR) +LIBMINOREXT = $(LIBEXT).$(LIB_VERSION) + +FIX_INSTALL_NAME = : diff --git a/mk/macos.mk b/mk/macos.mk new file mode 100644 index 0000000..00e8236 --- /dev/null +++ b/mk/macos.mk @@ -0,0 +1,6 @@ +LIBEXT = dylib +LIBFLAGS = -dynamiclib -Wl,-compatibility_version,$(LIB_MAJOR) -Wl,-current_version,$(LIB_VERSION) +LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT) +LIBMINOREXT = $(LIB_VERSION).$(LIBEXT) + +FIX_INSTALL_NAME = install_name_tool -id "$(PREFIX)/lib/lib$(LIB_NAME).$(LIBMAJOREXT)" diff --git a/mk/windows.mk b/mk/windows.mk new file mode 100644 index 0000000..ed5ec8d --- /dev/null +++ b/mk/windows.mk @@ -0,0 +1,6 @@ +LIBEXT = dll +LIBFLAGS = -shared +LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT) +LIBMINOREXT = $(LIB_VERSION).$(LIBEXT) + +FIX_INSTALL_NAME = : diff --git a/strtoi64.c b/strtoi64.c index d34940c..6e0a898 100644 --- a/strtoi64.c +++ b/strtoi64.c @@ -6,8 +6,8 @@ #define RET_MIN (-RET_MAX - 1LL) -int_least32_t -libsimple_strtoi32(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ +int_least64_t +libsimple_strtoi64(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ { intmax_t r = strtoimax(nptr, end, base); if(r < RET_MIN) { @@ -17,7 +17,7 @@ libsimple_strtoi32(const char *restrict nptr, char **restrict end, int base) /* r = RET_MAX; errno = ERANGE; } - return (int_least32_t)r; + return (int_least64_t)r; } -- cgit v1.2.3-70-g09d2 From aab65f6d1793d2ded2629437afab007ba3db0bf1 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 4 Jul 2023 19:37:10 +0200 Subject: Add bindex and bindex_r MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- LICENSE | 2 +- Makefile | 3 +++ bindex.c | 39 ++++++++++++++++++++++++++++++ bindex_r.c | 39 ++++++++++++++++++++++++++++++ libsimple.h | 1 + libsimple/search.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 bindex.c create mode 100644 bindex_r.c create mode 100644 libsimple/search.h (limited to 'Makefile') diff --git a/LICENSE b/LICENSE index f4e0c18..68df9b2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ISC License -© 2017, 2018, 2021, 2022 Mattias Andrée +© 2017, 2018, 2021, 2022, 2023 Mattias Andrée Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Makefile b/Makefile index 5d45bc4..7ea4e6e 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ SUBHDR =\ libsimple/pvalloc.h\ libsimple/pvallocz.h\ libsimple/realloc.h\ + libsimple/search.h\ libsimple/str.h\ libsimple/strdup.h\ libsimple/strn.h\ @@ -80,6 +81,8 @@ OBJ =\ aligned_wmemdup.o\ allocn.o\ asprintf.o\ + bindex.o\ + bindex_r.o\ callocn.o\ close.o\ cmptimespec.o\ diff --git a/bindex.c b/bindex.c new file mode 100644 index 0000000..e93803f --- /dev/null +++ b/bindex.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +ssize_t +libsimple_bindex(const void *key, const void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)) +{ + size_t index = 0, offset = 0; + int cmp; + + while (nel) { + index = offset + nel / 2; + cmp = (*compar)(key, (const char *)base + width * index); + if (cmp < 0) { + nel /= 2; + } else if (cmp > 0) { + offset = index += 1; + nel -= nel / 2 + 1; + } else { + return (ssize_t)index; + } + } + + return ~(ssize_t)index; +} + + +#else +#include "test.h" + +int +main(void) /* TODO add test */ +{ + return 0; +} + +#endif diff --git a/bindex_r.c b/bindex_r.c new file mode 100644 index 0000000..805e74a --- /dev/null +++ b/bindex_r.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +ssize_t +libsimple_bindex_r(const void *key, const void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *, void *), void *arg) +{ + size_t index = 0, offset = 0; + int cmp; + + while (nel) { + index = offset + nel / 2; + cmp = (*compar)(key, (const char *)base + width * index, arg); + if (cmp < 0) { + nel /= 2; + } else if (cmp > 0) { + offset = index += 1; + nel -= nel / 2 + 1; + } else { + return (ssize_t)index; + } + } + + return ~(ssize_t)index; +} + + +#else +#include "test.h" + +int +main(void) /* TODO add test */ +{ + return 0; +} + +#endif diff --git a/libsimple.h b/libsimple.h index ffb8f8a..f4238cb 100644 --- a/libsimple.h +++ b/libsimple.h @@ -164,6 +164,7 @@ #include "libsimple/str.h" #include "libsimple/strn.h" #include "libsimple/strtoint.h" +#include "libsimple/search.h" /** diff --git a/libsimple/search.h b/libsimple/search.h new file mode 100644 index 0000000..19c1f85 --- /dev/null +++ b/libsimple/search.h @@ -0,0 +1,69 @@ +/* See LICENSE file for copyright and license details. */ + + +/** + * Find, using binary search, the position where an item in + * sorted list is located or should be located + * + * @param key The item to find the position for + * @param base Sorted array to search + * @param nel The number of elements in `base` + * @param width The byte-width of each element in `base` + * @param compar Function used to compare `key` against an element + * in the array. The function be given two arguments: + * the first argument will always be `key`, the other + * will be an element in `base`. The function shall + * return a negative value if first argument shall + * precede the second argument when sorted into the + * list, or a positive value if the first argument + * shall succeed the second argument, but if the + * two argument are equal, the function shall return 0. + * @return If the function finds `key` in `base`, it returns + * the index (starting from 0) of some such element + * in `base`, however if `key` is not found, the + * function returns the bitwise complement the index + * to each `key` may be inserted. + * + * @seealso bsearch(3p) + * @seealso libsimple_bindex_r(3p) + */ +ssize_t libsimple_bindex(const void *key, const void *base, size_t nel, size_t width, /* TODO man */ + int (*compar)(const void *, const void *)); +#ifndef bindex +# define bindex(...) libsimple_bindex(__VA_ARGS__) +#endif + +/** + * Find, using binary search, the position where an item in + * sorted list is located or should be located + * + * @param key The item to find the position for + * @param base Sorted array to search + * @param nel The number of elements in `base` + * @param width The byte-width of each element in `base` + * @param compar Function used to compare `key` against an element + * in the array. The function be given three arguments: + * the first argument will always be `key`, the second + * will be an element in `base`, and the third will + * always be `arg`. The function shall return a negative + * value if first argument shall precede the second + * argument when sorted into the list, or a positive + * value if the first argument shall succeed the second + * argument, but if the two argument are equal, the + * function shall return 0. + * @param arg User-defined value that is passed directly into + * `compar` as the third argument at each callback + * @return If the function finds `key` in `base`, it returns + * the index (starting from 0) of some such element + * in `base`, however if `key` is not found, the + * function returns the bitwise complement the index + * to each `key` may be inserted. + * + * @seealso bsearch(3p) + * @seealso libsimple_bindex(3p) + */ +ssize_t libsimple_bindex_r(const void *key, const void *base, size_t nel, size_t width, /* TODO man */ + int (*compar)(const void *, const void *, void *), void *arg); +#ifndef bindex_r +# define bindex_r(...) libsimple_bindex_r(__VA_ARGS__) +#endif -- cgit v1.2.3-70-g09d2 From 49d537dcc675d4fd824469518813a722d29b130b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 4 Jul 2023 19:41:37 +0200 Subject: Update VERSION_MINOR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 7ea4e6e..1a86fa7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ include mk/$(OS).mk LIB_MAJOR = 1 -LIB_MINOR = 0 +LIB_MINOR = 4 LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) LIB_NAME = simple -- cgit v1.2.3-70-g09d2