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 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