diff options
Diffstat (limited to '')
296 files changed, 5894 insertions, 3540 deletions
@@ -12,3 +12,4 @@ *.gcno *.gcov *.lo +*.to @@ -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 @@ -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; @@ -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; @@ -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 @@ -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 <stdio.h> #include <stdlib.h> #include <string.h> -#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)); @@ -1981,14 +1325,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); @@ -2039,42 +1375,6 @@ main(void) 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); assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM)); @@ -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); @@ -2443,15 +1671,6 @@ main(void) 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 <wctype.h> +#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 <malloc.h> 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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> 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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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 <libsimple.h> -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; } @@ -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)); @@ -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 *); } } } @@ -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; } @@ -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; @@ -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; @@ -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]; } @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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; @@ -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); @@ -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 { @@ -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 @@ -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 |