diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-18 09:58:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-18 09:58:23 +0200 |
commit | a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9 (patch) | |
tree | d976683461a0f427d2f1ef79a8732a048dd0c67b | |
parent | Merge tag '1.3' into since (diff) | |
parent | Update VERSION_MINOR (diff) | |
download | libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.gz libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.bz2 libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.xz |
Merge tag '1.4' into since
Version 1.4
580 files changed, 12951 insertions, 5388 deletions
@@ -12,3 +12,4 @@ *.gcno *.gcov *.lo +*.to @@ -1,6 +1,6 @@ ISC License -© 2017, 2018 Mattias Andrée <maandree@kth.se> +© 2017, 2018, 2021, 2022, 2023 Mattias Andrée <maandree@kth.se> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -3,6 +3,19 @@ CONFIGFILE = config.mk include $(CONFIGFILE) +OS = linux +# Linux: linux +# Mac OS: macos +# Windows: windows +include mk/$(OS).mk + + +LIB_MAJOR = 1 +LIB_MINOR = 4 +LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) +LIB_NAME = simple + + SUBHDR =\ libsimple/aligned_alloc.h\ libsimple/aligned_allocz.h\ @@ -32,10 +45,12 @@ SUBHDR =\ libsimple/pvalloc.h\ libsimple/pvallocz.h\ libsimple/realloc.h\ + libsimple/search.h\ libsimple/str.h\ libsimple/strdup.h\ libsimple/strn.h\ libsimple/strndup.h\ + libsimple/strtoint.h\ libsimple/time.h\ libsimple/valloc.h\ libsimple/vallocz.h\ @@ -45,54 +60,188 @@ SUBHDR =\ HDR =\ $(SUBHDR)\ - libsimple.h + libsimple.h\ + common.h OBJ =\ + aligned_allocn.o\ + aligned_allocz.o\ + aligned_alloczn.o\ aligned_memdup.o\ + aligned_realloc.o\ + aligned_reallocarray.o\ + aligned_reallocarrayf.o\ + aligned_reallocf.o\ + aligned_reallocfn.o\ + aligned_reallocn.o\ + aligned_strdup.o\ aligned_strndup.o\ + aligned_wcsdup.o\ aligned_wcsndup.o\ aligned_wmemdup.o\ allocn.o\ asprintf.o\ + bindex.o\ + bindex_r.o\ + callocn.o\ + close.o\ + cmptimespec.o\ + cmptimeval.o\ difftimespec.o\ difftimeval.o\ doubletotimespec.o\ doubletotimeval.o\ + ealigned_alloc.o\ + ealigned_allocn.o\ + ealigned_allocz.o\ + ealigned_alloczn.o\ + ealigned_memdup.o\ + ealigned_realloc.o\ + ealigned_reallocarray.o\ + ealigned_reallocn.o\ + ealigned_strdup.o\ + ealigned_strndup.o\ + ealigned_wcsdup.o\ + ealigned_wcsndup.o\ + ealigned_wmemdup.o\ + ecalloc.o\ + ecallocn.o\ + egmtime.o\ + elocaltime.o\ + emalloc.o\ + emallocn.o\ + emallocz.o\ + emalloczn.o\ + ememalign.o\ + ememalignn.o\ + ememalignz.o\ + ememalignzn.o\ + ememalloc.o\ + ememdup.o\ + enaligned_alloc.o\ + enaligned_allocn.o\ enaligned_allocz.o\ + enaligned_alloczn.o\ enaligned_memdup.o\ enaligned_realloc.o\ enaligned_reallocarray.o\ + enaligned_reallocn.o\ enaligned_strdup.o\ enaligned_strndup.o\ enaligned_wcsdup.o\ enaligned_wcsndup.o\ enaligned_wmemdup.o\ encalloc.o\ + encallocn.o\ engmtime.o\ enlocaltime.o\ enmalloc.o\ + enmallocn.o\ + enmallocz.o\ + enmalloczn.o\ + enmemalign.o\ + enmemalignn.o\ + enmemalignz.o\ + enmemalignzn.o\ + enmemalloc.o\ enmemdup.o\ + enposix_memalign.o\ + 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_allocn.o\ envaligned_alloczn.o\ envaligned_reallocn.o\ + envalloc.o\ + envallocn.o\ + envallocz.o\ + envalloczn.o\ + envcallocn.o\ + envmallocn.o\ envmalloczn.o\ + envmemalignn.o\ + envmemalignzn.o\ envmemalloc.o\ + envposix_memalignn.o\ envposix_memalignzn.o\ envputenvf.o\ + envpvallocn.o\ + envpvalloczn.o\ envreallocn.o\ + envvallocn.o\ + envvalloczn.o\ enwcsdup.o\ enwcsndup.o\ enwmemdup.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\ + evaligned_allocn.o\ + evaligned_alloczn.o\ + evaligned_reallocn.o\ + evalloc.o\ + evallocn.o\ + evallocz.o\ + evalloczn.o\ + evcallocn.o\ + evmallocn.o\ + evmalloczn.o\ + evmemalignn.o\ + evmemalignzn.o\ + evmemalloc.o\ + evposix_memalignn.o\ + evposix_memalignzn.o\ + evputenvf.o\ + evpvallocn.o\ + evpvalloczn.o\ + evreallocn.o\ + evvallocn.o\ + evvalloczn.o\ + ewcsdup.o\ + ewcsndup.o\ + ewmemdup.o\ + getenv_e.o\ + getenv_ne.o\ gmtime.o\ + inchrcaseset.o\ + inchrset.o\ localtime.o\ + mallocn.o\ + mallocz.o\ + malloczn.o\ + memalign.o\ + memalignn.o\ + memalignz.o\ + memalignzn.o\ + memalloc.o\ memcasechr.o\ memcasechr_inv.o\ memcasecmp.o\ memcaseends.o\ + memcaseeq.o\ memcaseeqlen.o\ memcasemem.o\ memcasescan.o\ @@ -108,9 +257,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\ @@ -122,19 +275,33 @@ OBJ =\ memrchr_inv.o\ memrelem.o\ memrelem_inv.o\ + memreplace.o\ memreplaceelem.o\ memreqlen.o\ memrmem.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\ @@ -145,65 +312,145 @@ OBJ =\ rawmemrchr_inv.o\ rawmemrelem.o\ rawmemrelem_inv.o\ + reallocarray.o\ + reallocarrayf.o\ + reallocf.o\ + reallocfn.o\ + reallocn.o\ + stpmove.o\ + stpnmove.o\ + stpnset.o\ stpntolower.o\ stpntoupper.o\ + stpset.o\ stptolower.o\ stptoupper.o\ strcasechr.o\ strcasechr_inv.o\ strcasechrnul.o\ strcasechrnul_inv.o\ + strcasecmpnul.o\ strcaseends.o\ + strcaseeq.o\ strcaseeqlen.o\ + strcaseeqnul.o\ + strcasestarts.o\ strcasestr.o\ + strccpy.o\ strchr_inv.o\ strchrnul.o\ strchrnul_inv.o\ strcmove.o\ + strcmpnul.o\ + strend.o\ strends.o\ + streq.o\ streqlen.o\ + streqnul.o\ + strisutf8.o\ + strmove.o\ strncasechr.o\ strncasechr_inv.o\ strncasechrnul.o\ strncasechrnul_inv.o\ + strncasecmpnul.o\ strncaseends.o\ + strncaseeq.o\ strncaseeqlen.o\ + strncaseeqnul.o\ strncasestarts.o\ strncasestr.o\ + strnccpy.o\ strnchr.o\ strnchr_inv.o\ strnchrnul.o\ strnchrnul_inv.o\ strncmove.o\ + strncmpnul.o\ strnend.o\ strnends.o\ + strneq.o\ strneqlen.o\ + strneqnul.o\ + strnisutf8.o\ + strnmove.o\ + strnreplace.o\ + strnset.o\ strnstarts.o\ strnstr.o\ + strntolower.o\ + strntoupper.o\ strrcasechr.o\ strrcasechr_inv.o\ + strrcaseeqlen.o\ strrcasestr.o\ strrchr_inv.o\ + strreplace.o\ + strreqlen.o\ strrncasechr.o\ strrncasechr_inv.o\ + strrncaseeqlen.o\ strrncasestr.o\ strrnchr.o\ strrnchr_inv.o\ + strrneqlen.o\ strrnstr.o\ strrstr.o\ + strset.o\ strstarts.o\ + strtoh.o\ + strtohh.o\ + strtoi.o\ + strtoi16.o\ + strtoi32.o\ + strtoi64.o\ + strtoi8.o\ + strtolower.o\ strtotimespec.o\ strtotimeval.o\ + strtou.o\ + strtou16.o\ + strtou32.o\ + strtou64.o\ + strtou8.o\ + strtouh.o\ + strtouhh.o\ + strtoupper.o\ + strtouz.o\ + strtoz.o\ sumtimespec.o\ sumtimeval.o\ timespec2timeval.o\ + timespectodouble.o\ timespectostr.o\ + timeval2timespec.o\ + timevaltodouble.o\ timevaltostr.o\ + unlist.o\ + valigned_allocn.o\ + valigned_reallocfn.o\ + valloc.o\ + vallocn.o\ + vallocz.o\ + valloczn.o\ vasprintf.o\ + vcallocn.o\ + venprintf.o\ + veprintf.o\ + vmallocn.o\ + vmemalignn.o\ + vmemalignzn.o\ vmemalloc.o\ + vposix_memalignn.o\ vputenvf.o\ + vpvallocn.o\ + vpvalloczn.o\ + vreallocfn.o\ + vvallocn.o\ + vvalloczn.o\ vweprintf.o\ wcsndup.o\ + weprintf.o\ wmemdup.o\ libsimple.o @@ -218,50 +465,68 @@ 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 +LOBJ = $(OBJ:.o=.lo) + +all: libsimple.a libsimple.$(LIBEXT) $(TESTS) +tests: $(TESTS) +$(OBJ): $(HDR) +$(TESTS): test.o libsimple.a +$(TESTS:.test=.to): $(HDR) test.h test.o: test.c $(HDR) test.h - $(CC) -c -o $@ test.c $(CFLAGS) -DTEST -O0 -ffreestanding + $(CC) -c -o $@ test.c $(CFLAGS) $(CPPFLAGS) -DTEST -O0 -ffreestanding libsimple.a: $(OBJ) - $(AR) rc $@ $? + @rm -f -- $@ + $(AR) rc $@ $(OBJ) $(AR) -s $@ -.test.o.test: +libsimple.$(LIBEXT): $(LOBJ) + $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS) + +.to.test: $(CC) -o $@ $< test.o libsimple.a $(LDFLAGS) -.c.test.o: - $(CC) -c -o $@ $< $(CFLAGS) -DTEST -O0 +.c.to: + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -DTEST -O0 + +.c.o: + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) + +.c.lo: + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) check: $(TESTS) @set -e; for t in $(TESTS); do printf '%s\n' "./$$t"; $(CHECK_PREFIX) "./$$t"; done -install: libsimple.a +install: libsimple.a libsimple.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include/libsimple" - mkdir -p -- "$(DESTDIR)$(PREFIX)/share/man/man0" - mkdir -p -- "$(DESTDIR)$(PREFIX)/share/man/man3" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man0" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3" cp -- libsimple.a "$(DESTDIR)$(PREFIX)/lib" + cp -- libsimple.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMINOREXT)" + $(FIX_INSTALL_NAME) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMINOREXT)" + ln -sf -- libsimple.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMAJOREXT)" + ln -sf -- libsimple.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBEXT)" cp -- libsimple.h "$(DESTDIR)$(PREFIX)/include" cp -- libsimple-arg.h "$(DESTDIR)$(PREFIX)/include" cp -- $(SUBHDR) "$(DESTDIR)$(PREFIX)/include/libsimple" - cp -- $(MAN0) "$(DESTDIR)$(PREFIX)/share/man/man0" - cp -P -- $(MAN3) "$(DESTDIR)$(PREFIX)/share/man/man3" + cp -P -- $(MAN0) "$(DESTDIR)$(MANPREFIX)/man0" + cp -P -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3" uninstall: -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libsimple.a" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libsimple.h" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libsimple-arg.h" -rm -rf -- "$(DESTDIR)$(PREFIX)/include/libsimple" - -cd -- "$(DESTDIR)$(PREFIX)/share/man" && rm -f -- $(MAN0) $(MAN3) + -cd -- "$(DESTDIR)$(MANPREFIX)/man0" && rm -f -- $(MAN0) + -cd -- "$(DESTDIR)$(MANPREFIX)/man3" && rm -f -- $(MAN3) clean: - -rm -rf -- *.o *.su *.a *.so *.so.* *.gch *.gcda *.gcno *.gcov *.lo *.test + -rm -rf -- *.o *.su *.a *.so *.so.* *.gch *.gcda *.gcno *.gcov *.lo *.test *.to .SUFFIXES: -.SUFFIXES: .test .test.o .o .c +.SUFFIXES: .test .to .lo .o .c .PHONY: all check install uninstall clean diff --git a/aligned_allocn.c b/aligned_allocn.c new file mode 100644 index 0000000..de4b69f --- /dev/null +++ b/aligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_allocn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_allocz.c b/aligned_allocz.c new file mode 100644 index 0000000..29e6644 --- /dev/null +++ b/aligned_allocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_allocz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_alloczn.c b/aligned_alloczn.c new file mode 100644 index 0000000..d7d199f --- /dev/null +++ b/aligned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_alloczn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_memdup.c b/aligned_memdup.c index 7b2ca71..d383dbd 100644 --- a/aligned_memdup.c +++ b/aligned_memdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_realloc.c b/aligned_realloc.c new file mode 100644 index 0000000..985afbc --- /dev/null +++ b/aligned_realloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_realloc(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocarray.c b/aligned_reallocarray.c new file mode 100644 index 0000000..96fd937 --- /dev/null +++ b/aligned_reallocarray.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocarray(void *, size_t, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocarrayf.c b/aligned_reallocarrayf.c new file mode 100644 index 0000000..485043f --- /dev/null +++ b/aligned_reallocarrayf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocarrayf(void *, size_t, size_t, size_t); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocf.c b/aligned_reallocf.c new file mode 100644 index 0000000..397c328 --- /dev/null +++ b/aligned_reallocf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocf(void *, size_t, size_t); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocfn.c b/aligned_reallocfn.c new file mode 100644 index 0000000..a686a5f --- /dev/null +++ b/aligned_reallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocfn(void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_reallocn.c b/aligned_reallocn.c new file mode 100644 index 0000000..0c63633 --- /dev/null +++ b/aligned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_aligned_reallocn(void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/aligned_strdup.c b/aligned_strdup.c new file mode 100644 index 0000000..6838bed --- /dev/null +++ b/aligned_strdup.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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_strndup.c b/aligned_strndup.c index f41fa8c..9f8cf68 100644 --- a/aligned_strndup.c +++ b/aligned_strndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_wcsdup.c b/aligned_wcsdup.c new file mode 100644 index 0000000..2c2fb29 --- /dev/null +++ b/aligned_wcsdup.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_aligned_wcsdup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_aligned_wcsdup(L"test", 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (4 - 5 * sizeof(wchar_t) % 4) % 4); + assert(info->alignment == 4); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_aligned_wcsdup(L"test", 16) && errno == ENOMEM); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/aligned_wcsndup.c b/aligned_wcsndup.c index 90ce7f7..923c6b5 100644 --- a/aligned_wcsndup.c +++ b/aligned_wcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/aligned_wmemdup.c b/aligned_wmemdup.c index c92e17f..b8793e0 100644 --- a/aligned_wmemdup.c +++ b/aligned_wmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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; @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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/bindex.c b/bindex.c new file mode 100644 index 0000000..e93803f --- /dev/null +++ b/bindex.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +ssize_t +libsimple_bindex(const void *key, const void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)) +{ + size_t index = 0, offset = 0; + int cmp; + + while (nel) { + index = offset + nel / 2; + cmp = (*compar)(key, (const char *)base + width * index); + if (cmp < 0) { + nel /= 2; + } else if (cmp > 0) { + offset = index += 1; + nel -= nel / 2 + 1; + } else { + return (ssize_t)index; + } + } + + return ~(ssize_t)index; +} + + +#else +#include "test.h" + +int +main(void) /* TODO add test */ +{ + return 0; +} + +#endif diff --git a/bindex_r.c b/bindex_r.c new file mode 100644 index 0000000..805e74a --- /dev/null +++ b/bindex_r.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +ssize_t +libsimple_bindex_r(const void *key, const void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *, void *), void *arg) +{ + size_t index = 0, offset = 0; + int cmp; + + while (nel) { + index = offset + nel / 2; + cmp = (*compar)(key, (const char *)base + width * index, arg); + if (cmp < 0) { + nel /= 2; + } else if (cmp > 0) { + offset = index += 1; + nel -= nel / 2 + 1; + } else { + return (ssize_t)index; + } + } + + return ~(ssize_t)index; +} + + +#else +#include "test.h" + +int +main(void) /* TODO add test */ +{ + return 0; +} + +#endif diff --git a/callocn.c b/callocn.c new file mode 100644 index 0000000..2a6272f --- /dev/null +++ b/callocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_callocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_close(int *); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/cmptimespec.c b/cmptimespec.c new file mode 100644 index 0000000..025a946 --- /dev/null +++ b/cmptimespec.c @@ -0,0 +1,209 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..4723705 --- /dev/null +++ b/cmptimeval.c @@ -0,0 +1,248 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/common.h b/common.h new file mode 100644 index 0000000..7f84f59 --- /dev/null +++ b/common.h @@ -0,0 +1,11 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +# pragma clang diagnostic ignored "-Wreserved-identifier" +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +# pragma clang diagnostic ignored "-Wc++98-compat" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +#endif @@ -4,5 +4,5 @@ MANPREFIX = $(PREFIX)/share/man CC = cc CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -CFLAGS = -std=c11 -Wall -Wextra -O2 $(CPPFLAGS) +CFLAGS = -std=c11 -Wall -Wextra -O2 LDFLAGS = -s diff --git a/difftimespec.c b/difftimespec.c index 86d3441..f756007 100644 --- a/difftimespec.c +++ b/difftimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -47,104 +47,138 @@ main(void) { struct timespec r, a, b; - a.tv_sec = 0, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 100L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 100L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 100L; - b.tv_sec = 1, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 100L; + b.tv_sec = 1; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 9); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 100L; - b.tv_sec = 0, b.tv_nsec = 1L; + a.tv_sec = 10; + a.tv_nsec = 100L; + b.tv_sec = 0; + b.tv_nsec = 1L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 99L); - a.tv_sec = -10, a.tv_nsec = 100L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = -10; + a.tv_nsec = 100L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 1L; - b.tv_sec = 1, b.tv_nsec = 100L; + a.tv_sec = 10; + a.tv_nsec = 1L; + b.tv_sec = 1; + b.tv_nsec = 100L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 8); assert(r.tv_nsec == 1000000001L - 100L); - a.tv_sec = 10, a.tv_nsec = 0L; - b.tv_sec = 20, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; + b.tv_sec = 20; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 10L; - b.tv_sec = 20, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10L; + b.tv_sec = 20; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 10L); - a.tv_sec = 10, a.tv_nsec = 10L; - b.tv_sec = 20, b.tv_nsec = 20L; + a.tv_sec = 10; + a.tv_nsec = 10L; + b.tv_sec = 20; + b.tv_nsec = 20L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -10 - 1); assert(r.tv_nsec == 1000000010L - 20L); - a.tv_sec = 10, a.tv_nsec = 10L; - b.tv_sec = -20, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10L; + b.tv_sec = -20; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 30); assert(r.tv_nsec == 10L); - a.tv_sec = 0, a.tv_nsec = 10L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 10L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 10L); - a.tv_sec = 0, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 10L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == -1); assert(r.tv_nsec == 1000000000L - 10L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = 0, b.tv_nsec = 1L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = 0; + b.tv_nsec = 1L; assert(libsimple_difftimespec(&r, &a, &b) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = -1, b.tv_nsec = 1L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = -1; + b.tv_nsec = 1L; assert(!libsimple_difftimespec(&r, &a, &b)); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; - b.tv_sec = -1, b.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; + b.tv_sec = -1; + b.tv_nsec = 0L; assert(libsimple_difftimespec(&r, &a, &b) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); diff --git a/difftimeval.c b/difftimeval.c index 2f633a2..d9dcbf3 100644 --- a/difftimeval.c +++ b/difftimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..f993f04 100644 --- a/doubletotimespec.c +++ b/doubletotimespec.c @@ -1,12 +1,13 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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..2977f42 100644 --- a/doubletotimeval.c +++ b/doubletotimeval.c @@ -1,12 +1,13 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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_alloc.c b/ealigned_alloc.c new file mode 100644 index 0000000..38c512d --- /dev/null +++ b/ealigned_alloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_alloc(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_allocn.c b/ealigned_allocn.c new file mode 100644 index 0000000..dd6d294 --- /dev/null +++ b/ealigned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_allocn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_allocz.c b/ealigned_allocz.c new file mode 100644 index 0000000..6d6307c --- /dev/null +++ b/ealigned_allocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_allocz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_alloczn.c b/ealigned_alloczn.c new file mode 100644 index 0000000..31db576 --- /dev/null +++ b/ealigned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_alloczn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_memdup.c b/ealigned_memdup.c new file mode 100644 index 0000000..1175c3e --- /dev/null +++ b/ealigned_memdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_memdup(const void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_memdup("test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_memdup("test", 8, 2)); + assert(exit_status == 55); + assert_stderr("%s: aligned_memdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_realloc.c b/ealigned_realloc.c new file mode 100644 index 0000000..ecca369 --- /dev/null +++ b/ealigned_realloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_realloc(void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_reallocarray.c b/ealigned_reallocarray.c new file mode 100644 index 0000000..214c7cb --- /dev/null +++ b/ealigned_reallocarray.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_reallocarray(void *, size_t, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_reallocn.c b/ealigned_reallocn.c new file mode 100644 index 0000000..da78bac --- /dev/null +++ b/ealigned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ealigned_reallocn(void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ealigned_strdup.c b/ealigned_strdup.c new file mode 100644 index 0000000..4f4a03d --- /dev/null +++ b/ealigned_strdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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_strndup.c b/ealigned_strndup.c new file mode 100644 index 0000000..368f77b --- /dev/null +++ b/ealigned_strndup.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_ealigned_strndup(const char *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_strndup("test", 8, SIZE_MAX))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + assert((s = libsimple_ealigned_strndup("test", 8, 100))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + assert((s = libsimple_ealigned_strndup("test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + assert((s = libsimple_ealigned_strndup("test", 8, 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_strndup("test", 8, 10)); + assert(exit_status == 55); + assert_stderr("%s: aligned_strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_wcsdup.c b/ealigned_wcsdup.c new file mode 100644 index 0000000..8f7a83e --- /dev/null +++ b/ealigned_wcsdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/ealigned_wcsndup.c b/ealigned_wcsndup.c new file mode 100644 index 0000000..f155e23 --- /dev/null +++ b/ealigned_wcsndup.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ealigned_wcsndup(const wchar_t *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, SIZE_MAX))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, 100))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + assert((s = libsimple_ealigned_wcsndup(L"test", 8, 4))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_wcsndup(L"test", 8, 10)); + assert(exit_status == 55); + assert_stderr("%s: aligned_wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ealigned_wmemdup.c b/ealigned_wmemdup.c new file mode 100644 index 0000000..99a24f1 --- /dev/null +++ b/ealigned_wmemdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ealigned_wmemdup(const wchar_t *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ealigned_wmemdup(L"test", 8, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); + assert(info->alignment == 8); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ealigned_wmemdup(L"test", 8, 2)); + assert(exit_status == 55); + assert_stderr("%s: aligned_wmemdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ecalloc.c b/ecalloc.c new file mode 100644 index 0000000..9e8b907 --- /dev/null +++ b/ecalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ecalloc(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ecallocn.c b/ecallocn.c new file mode 100644 index 0000000..329e007 --- /dev/null +++ b/ecallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ecallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/egmtime.c b/egmtime.c new file mode 100644 index 0000000..d62146e --- /dev/null +++ b/egmtime.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..f54f095 --- /dev/null +++ b/elocaltime.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/emalloc.c b/emalloc.c new file mode 100644 index 0000000..e79de1e --- /dev/null +++ b/emalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_emalloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emallocn.c b/emallocn.c new file mode 100644 index 0000000..e6ccf3e --- /dev/null +++ b/emallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_emallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emallocz.c b/emallocz.c new file mode 100644 index 0000000..6695153 --- /dev/null +++ b/emallocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_emallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/emalloczn.c b/emalloczn.c new file mode 100644 index 0000000..e85f436 --- /dev/null +++ b/emalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_emalloczn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalign.c b/ememalign.c new file mode 100644 index 0000000..ef48af4 --- /dev/null +++ b/ememalign.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ememalign(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalignn.c b/ememalignn.c new file mode 100644 index 0000000..eb259d4 --- /dev/null +++ b/ememalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ememalignn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalignz.c b/ememalignz.c new file mode 100644 index 0000000..f45a04e --- /dev/null +++ b/ememalignz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ememalignz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalignzn.c b/ememalignzn.c new file mode 100644 index 0000000..9f97d7f --- /dev/null +++ b/ememalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ememalignzn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememalloc.c b/ememalloc.c new file mode 100644 index 0000000..525e67f --- /dev/null +++ b/ememalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ememalloc(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/ememdup.c b/ememdup.c new file mode 100644 index 0000000..08a90a5 --- /dev/null +++ b/ememdup.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_ememdup(const void *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + void *s; + + assert((s = libsimple_ememdup("test", 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5); + assert(!info->zeroed); + } + assert(!memcmp(s, "test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ememdup("test", 2)); + assert(exit_status == 55); + assert_stderr("%s: memdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/enaligned_alloc.c b/enaligned_alloc.c new file mode 100644 index 0000000..a6edf6b --- /dev/null +++ b/enaligned_alloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_alloc(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_allocn.c b/enaligned_allocn.c new file mode 100644 index 0000000..77ac1ae --- /dev/null +++ b/enaligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_allocn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_allocz.c b/enaligned_allocz.c index f92df4f..b620e53 100644 --- a/enaligned_allocz.c +++ b/enaligned_allocz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_alloczn.c b/enaligned_alloczn.c new file mode 100644 index 0000000..469eb45 --- /dev/null +++ b/enaligned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_alloczn(int, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_memdup.c b/enaligned_memdup.c index ac94746..dc3188e 100644 --- a/enaligned_memdup.c +++ b/enaligned_memdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,30 +32,12 @@ main(void) assert(!memcmp(s, "hello", 5)); free(s); - assert((s = libsimple_ealigned_memdup("test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_memdup(44, "hello", 2, 2)); assert(exit_status == 44); assert_stderr("%s: aligned_memdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_memdup("test", 8, 2)); - assert(exit_status == 55); - assert_stderr("%s: aligned_memdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enaligned_realloc.c b/enaligned_realloc.c index 6d5ac4e..117c62a 100644 --- a/enaligned_realloc.c +++ b/enaligned_realloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_reallocarray.c b/enaligned_reallocarray.c index 5a71207..5fd1d47 100644 --- a/enaligned_reallocarray.c +++ b/enaligned_reallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enaligned_reallocn.c b/enaligned_reallocn.c new file mode 100644 index 0000000..aa93740 --- /dev/null +++ b/enaligned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enaligned_reallocn(int, void *, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enaligned_strdup.c b/enaligned_strdup.c index 533ff56..9312566 100644 --- a/enaligned_strdup.c +++ b/enaligned_strdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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_strndup.c b/enaligned_strndup.c index 6812d1c..1901628 100644 --- a/enaligned_strndup.c +++ b/enaligned_strndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,16 +32,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, SIZE_MAX))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 100))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, 100))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 6))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 5))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -92,16 +62,6 @@ main(void) assert(!memcmp(s, "hello", 6)); free(s); - assert((s = libsimple_ealigned_strndup("test", 8, 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - assert((s = libsimple_enaligned_strndup(1, "hello", 2, 4))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -118,14 +78,6 @@ main(void) assert(exit_status == 44); assert_stderr("%s: aligned_strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_strndup("test", 8, 10)); - assert(exit_status == 55); - assert_stderr("%s: aligned_strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enaligned_wcsdup.c b/enaligned_wcsdup.c index 10d9669..0293b62 100644 --- a/enaligned_wcsdup.c +++ b/enaligned_wcsdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,44 +32,12 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsdup(L"test", 8))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - - assert((s = libsimple_aligned_wcsdup(L"test", 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (4 - 5 * sizeof(wchar_t) % 4) % 4); - assert(info->alignment == 4); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_wcsdup(44, L"hello", 2)); assert(exit_status == 44); assert_stderr("%s: aligned_wcsdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_wcsdup(L"test", 8)); - assert(exit_status == 55); - assert_stderr("%s: aligned_wcsdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - - alloc_fail_in = 1; - assert(!libsimple_aligned_wcsdup(L"test", 16) && errno == ENOMEM); - assert(!alloc_fail_in); } return 0; diff --git a/enaligned_wcsndup.c b/enaligned_wcsndup.c index 32cce57..b7deea0 100644 --- a/enaligned_wcsndup.c +++ b/enaligned_wcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,16 +32,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, SIZE_MAX))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 100))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, 100))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 6))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 5))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -92,16 +62,6 @@ main(void) assert(!wmemcmp(s, L"hello", 6)); free(s); - assert((s = libsimple_ealigned_wcsndup(L"test", 8, 4))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - assert((s = libsimple_enaligned_wcsndup(1, L"hello", 2, 4))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -118,14 +78,6 @@ main(void) assert(exit_status == 44); assert_stderr("%s: aligned_wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_wcsndup(L"test", 8, 10)); - assert(exit_status == 55); - assert_stderr("%s: aligned_wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enaligned_wmemdup.c b/enaligned_wmemdup.c index ad36238..df976bc 100644 --- a/enaligned_wmemdup.c +++ b/enaligned_wmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,30 +32,12 @@ main(void) assert(!wmemcmp(s, L"hello", 5)); free(s); - assert((s = libsimple_ealigned_wmemdup(L"test", 8, 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t) + (8 - 5 * sizeof(wchar_t) % 8) % 8); - assert(info->alignment == 8); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enaligned_wmemdup(44, L"hello", 2, 2)); assert(exit_status == 44); assert_stderr("%s: aligned_wmemdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ealigned_wmemdup(L"test", 8, 2)); - assert(exit_status == 55); - assert_stderr("%s: aligned_wmemdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/encallocn.c b/encallocn.c new file mode 100644 index 0000000..a43fcbb --- /dev/null +++ b/encallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_encallocn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif @@ -1,10 +1,10 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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..e3df109 100644 --- a/enlocaltime.c +++ b/enlocaltime.c @@ -1,10 +1,10 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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; } @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/enmallocn.c b/enmallocn.c new file mode 100644 index 0000000..b3600f6 --- /dev/null +++ b/enmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmallocn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmallocz.c b/enmallocz.c new file mode 100644 index 0000000..7d51d9c --- /dev/null +++ b/enmallocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmallocz(int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmalloczn.c b/enmalloczn.c new file mode 100644 index 0000000..ac8b874 --- /dev/null +++ b/enmalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmalloczn(int, int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalign.c b/enmemalign.c new file mode 100644 index 0000000..306a09e --- /dev/null +++ b/enmemalign.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalign(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalignn.c b/enmemalignn.c new file mode 100644 index 0000000..b6dc8a3 --- /dev/null +++ b/enmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalignn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalignz.c b/enmemalignz.c new file mode 100644 index 0000000..b54ec4b --- /dev/null +++ b/enmemalignz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalignz(int, int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalignzn.c b/enmemalignzn.c new file mode 100644 index 0000000..27d2b84 --- /dev/null +++ b/enmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalignzn(int, int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/enmemalloc.c b/enmemalloc.c new file mode 100644 index 0000000..763dffa --- /dev/null +++ b/enmemalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_enmemalloc(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -31,29 +31,12 @@ main(void) assert(!memcmp(s, "hello", 5)); free(s); - assert((s = libsimple_ememdup("test", 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5); - assert(!info->zeroed); - } - assert(!memcmp(s, "test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enmemdup(44, "hello", 2)); assert(exit_status == 44); assert_stderr("%s: memdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ememdup("test", 2)); - assert(exit_status == 55); - assert_stderr("%s: memdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enposix_memalign.c b/enposix_memalign.c new file mode 100644 index 0000000..f50a3d2 --- /dev/null +++ b/enposix_memalign.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..c8a6f0d --- /dev/null +++ b/enposix_memalignn.c @@ -0,0 +1,45 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..9b6c1c7 100644 --- a/enposix_memalignz.c +++ b/enposix_memalignz.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..e7e1417 --- /dev/null +++ b/enposix_memalignzn.c @@ -0,0 +1,68 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..de2db0d --- /dev/null +++ b/enprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/enputenvf.c b/enputenvf.c new file mode 100644 index 0000000..8ee5241 --- /dev/null +++ b/enputenvf.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void libsimple_enputenvf(int, const char *, ...); + + +#else +#include "test.h" + +int +main(void) +{ + enputenvf(1, "X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + enputenvf(1, "Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + enputenvf(1, "X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + enputenvf(1, "Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + enputenvf(1, "X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + enputenvf(1, "Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert_exit(enputenvf(100, "X=xyz")); + assert(exit_status == 100); + assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/enpvalloc.c b/enpvalloc.c new file mode 100644 index 0000000..34621f4 --- /dev/null +++ b/enpvalloc.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..ffe89ec --- /dev/null +++ b/enpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..40661cc --- /dev/null +++ b/enpvallocz.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..63c4746 --- /dev/null +++ b/enpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..117fb06 100644 --- a/enrealloc.c +++ b/enrealloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..f0e5ddb 100644 --- a/enreallocarray.c +++ b/enreallocarray.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -43,69 +43,15 @@ 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) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Walloc-size-larger-than=" #endif @@ -114,15 +60,7 @@ 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) +#if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic pop #endif diff --git a/enreallocn.c b/enreallocn.c new file mode 100644 index 0000000..2bb12e8 --- /dev/null +++ b/enreallocn.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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 @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -34,30 +34,12 @@ main(void) assert(!strcmp(s, "hello")); free(s); - assert((s = libsimple_estrdup("test"))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "test")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrdup(14, "hello")); assert(exit_status == 14); assert_stderr("%s: strdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 15; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrdup("test")); - assert(exit_status == 15); - assert_stderr("%s: strdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enstrndup.c b/enstrndup.c index c02c0fd..9457352 100644 --- a/enstrndup.c +++ b/enstrndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,16 +32,6 @@ main(void) assert(!strcmp(s, "hello")); free(s); - assert((s = libsimple_estrndup("test", 10))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "test")); - free(s); - assert((s = libsimple_enstrndup(1, "hello", 2))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!strcmp(s, "he")); free(s); - assert((s = libsimple_estrndup("test", 3))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 4); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "tes")); - free(s); - assert((s = libsimple_enstrndup(1, "hello", 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!strcmp(s, "")); free(s); - assert((s = libsimple_estrndup("test", 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 1); - assert(info->alignment == 1); - assert(!info->zeroed); - } - assert(!strcmp(s, "")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrndup(14, "hello", 10)); @@ -89,41 +59,17 @@ main(void) assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 15; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrndup("test", 10)); - assert(exit_status == 15); - assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrndup(16, "hello", 1)); assert(exit_status == 16); assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 17; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrndup("test", 2)); - assert(exit_status == 17); - assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enstrndup(18, "hello", 0)); assert(exit_status == 18); assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 19; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_estrndup("test", 0)); - assert(exit_status == 19); - assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/envaligned_allocn.c b/envaligned_allocn.c new file mode 100644 index 0000000..2c8611a --- /dev/null +++ b/envaligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envaligned_allocn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enaligned_allocn */ +} + +#endif diff --git a/envaligned_alloczn.c b/envaligned_alloczn.c index d79c6e7..37018d4 100644 --- a/envaligned_alloczn.c +++ b/envaligned_alloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envaligned_reallocn.c b/envaligned_reallocn.c index 747e8c8..ab24fe8 100644 --- a/envaligned_reallocn.c +++ b/envaligned_reallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envalloc.c b/envalloc.c new file mode 100644 index 0000000..1f5f38e --- /dev/null +++ b/envalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envalloc(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envallocn.c b/envallocn.c new file mode 100644 index 0000000..c253528 --- /dev/null +++ b/envallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envallocn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/envallocz.c b/envallocz.c new file mode 100644 index 0000000..5fcb8a2 --- /dev/null +++ b/envallocz.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..c5b6613 --- /dev/null +++ b/envalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/envcallocn.c b/envcallocn.c new file mode 100644 index 0000000..96aa31c --- /dev/null +++ b/envcallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envcallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_encallocn */ +} + +#endif diff --git a/envmallocn.c b/envmallocn.c new file mode 100644 index 0000000..68b2ab6 --- /dev/null +++ b/envmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envmallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enmallocn */ +} + +#endif diff --git a/envmalloczn.c b/envmalloczn.c index 3e81b56..b2c3987 100644 --- a/envmalloczn.c +++ b/envmalloczn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envmemalignn.c b/envmemalignn.c new file mode 100644 index 0000000..25f9142 --- /dev/null +++ b/envmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envmemalignn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enmemalignn */ +} + +#endif diff --git a/envmemalignzn.c b/envmemalignzn.c new file mode 100644 index 0000000..ca4e16d --- /dev/null +++ b/envmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envmemalignzn(int, int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_enmemalignzn */ +} + +#endif diff --git a/envmemalloc.c b/envmemalloc.c index c500063..2a93adc 100644 --- a/envmemalloc.c +++ b/envmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/envposix_memalignn.c b/envposix_memalignn.c new file mode 100644 index 0000000..166f545 --- /dev/null +++ b/envposix_memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..cb34725 100644 --- a/envposix_memalignzn.c +++ b/envposix_memalignzn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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/envputenvf.c b/envputenvf.c index b4568fd..71b9199 100644 --- a/envputenvf.c +++ b/envputenvf.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -17,52 +17,7 @@ libsimple_envputenvf(int status, const char *fmt, va_list ap) int main(void) { - eputenvf("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - eputenvf("Y=xyz"); - assert(!strcmpnul(getenv("Y"), "xyz")); - - eputenvf("X=x%sz", "abc"); - assert(!strcmpnul(getenv("X"), "xabcz")); - eputenvf("Y=x%sz", "abc"); - assert(!strcmpnul(getenv("Y"), "xabcz")); - - eputenvf("X=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("X"), "10xabcz-11")); - eputenvf("Y=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("Y"), "10xabcz-11")); - - enputenvf(1, "X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - enputenvf(1, "Y=xyz"); - assert(!strcmpnul(getenv("Y"), "xyz")); - - enputenvf(1, "X=x%sz", "abc"); - assert(!strcmpnul(getenv("X"), "xabcz")); - enputenvf(1, "Y=x%sz", "abc"); - assert(!strcmpnul(getenv("Y"), "xabcz")); - - enputenvf(1, "X=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("X"), "10xabcz-11")); - enputenvf(1, "Y=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("Y"), "10xabcz-11")); - - if (have_custom_malloc()) { - alloc_fail_in = 1; - assert_exit(enputenvf(100, "X=xyz")); - assert(exit_status == 100); - assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - - libsimple_default_failure_exit = 102; - alloc_fail_in = 1; - assert_exit(eputenvf("X=xyz")); - assert(exit_status == 102); - assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - } - - return 0; + return 0; /* Tested via libsimple_enputenvf */ } #endif diff --git a/envpvallocn.c b/envpvallocn.c new file mode 100644 index 0000000..2ad3ce7 --- /dev/null +++ b/envpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..be4b753 --- /dev/null +++ b/envpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..642deb4 100644 --- a/envreallocn.c +++ b/envreallocn.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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/envvallocn.c b/envvallocn.c new file mode 100644 index 0000000..9dc333f --- /dev/null +++ b/envvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_envvallocn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_envallocn */ +} + +#endif diff --git a/envvalloczn.c b/envvalloczn.c new file mode 100644 index 0000000..279dbf4 --- /dev/null +++ b/envvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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 @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -39,30 +39,12 @@ main(void) assert(!wcscmp(s, L"hello")); free(s); - assert((s = libsimple_ewcsdup(L"test"))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"test")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsdup(18, L"hello")); assert(exit_status == 18); assert_stderr("%s: wcsdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 5; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsdup(L"test")); - assert(exit_status == 5); - assert_stderr("%s: wcsdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enwcsndup.c b/enwcsndup.c index 105542c..f642125 100644 --- a/enwcsndup.c +++ b/enwcsndup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -32,16 +32,6 @@ main(void) assert(!wcscmp(s, L"hello")); free(s); - assert((s = libsimple_ewcsndup(L"test", 10))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"test")); - free(s); - assert((s = libsimple_enwcsndup(1, L"hello", 2))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -52,16 +42,6 @@ main(void) assert(!wcscmp(s, L"he")); free(s); - assert((s = libsimple_ewcsndup(L"test", 3))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 4 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"tes")); - free(s); - assert((s = libsimple_enwcsndup(1, L"hello", 0))); if (have_custom_malloc()) { assert((info = get_allocinfo(s))); @@ -72,16 +52,6 @@ main(void) assert(!wcscmp(s, L"")); free(s); - assert((s = libsimple_ewcsndup(L"test", 0))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 1 * sizeof(wchar_t)); - assert(info->alignment == _Alignof(wchar_t)); - assert(!info->zeroed); - } - assert(!wcscmp(s, L"")); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsndup(24, L"hello", 10)); @@ -89,41 +59,17 @@ main(void) assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 25; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsndup(L"test", 10)); - assert(exit_status == 25); - assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsndup(26, L"hello", 1)); assert(exit_status == 26); assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 27; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsndup(L"test", 2)); - assert(exit_status == 27); - assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - alloc_fail_in = 1; assert_exit_ptr(libsimple_enwcsndup(28, L"hello", 0)); assert(exit_status == 28); assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - - libsimple_default_failure_exit = 29; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewcsndup(L"test", 0)); - assert(exit_status == 29); - assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; } return 0; diff --git a/enwmemdup.c b/enwmemdup.c index 243c99e..14b5871 100644 --- a/enwmemdup.c +++ b/enwmemdup.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -31,15 +31,6 @@ main(void) assert(!wmemcmp(s, L"hello", 5)); free(s); - assert((s = libsimple_ewmemdup(L"test", 5))); - if (have_custom_malloc()) { - assert((info = get_allocinfo(s))); - assert(info->size == 5 * sizeof(wchar_t)); - assert(!info->zeroed); - } - assert(!wmemcmp(s, L"test", 5)); - free(s); - if (have_custom_malloc()) { alloc_fail_in = 1; assert_exit_ptr(libsimple_enwmemdup(44, L"hello", 2)); @@ -47,23 +38,9 @@ main(void) assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); assert(!alloc_fail_in); - libsimple_default_failure_exit = 55; - alloc_fail_in = 1; - assert_exit_ptr(libsimple_ewmemdup(L"test", 2)); - assert(exit_status == 55); - assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); - assert(!alloc_fail_in); - libsimple_default_failure_exit = 1; - assert_exit_ptr(libsimple_enwmemdup(41, NULL, SSIZE_MAX)); assert(exit_status == 41); assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); - - libsimple_default_failure_exit = 51; - assert_exit_ptr(libsimple_ewmemdup(NULL, SSIZE_MAX)); - assert(exit_status == 51); - assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); - libsimple_default_failure_exit = 1; } return 0; diff --git a/eposix_memalign.c b/eposix_memalign.c new file mode 100644 index 0000000..27b787d --- /dev/null +++ b/eposix_memalign.c @@ -0,0 +1,43 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..9ae5e18 --- /dev/null +++ b/eposix_memalignn.c @@ -0,0 +1,47 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..bfc2d98 --- /dev/null +++ b/eposix_memalignz.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..76ea797 --- /dev/null +++ b/eposix_memalignzn.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..10259f4 --- /dev/null +++ b/eprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/eputenvf.c b/eputenvf.c new file mode 100644 index 0000000..a47665a --- /dev/null +++ b/eputenvf.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void libsimple_eputenvf(const char *, ...); + + +#else +#include "test.h" + +int +main(void) +{ + eputenvf("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + eputenvf("Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + eputenvf("X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + eputenvf("Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + eputenvf("X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + eputenvf("Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 102; + alloc_fail_in = 1; + assert_exit(eputenvf("X=xyz")); + assert(exit_status == 102); + assert_stderr("%s: putenvf: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + } + + return 0; +} + +#endif diff --git a/epvalloc.c b/epvalloc.c new file mode 100644 index 0000000..81c03e3 --- /dev/null +++ b/epvalloc.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..8eef2d8 --- /dev/null +++ b/epvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..95ea4cf --- /dev/null +++ b/epvallocz.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..976813b --- /dev/null +++ b/epvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..65689ae --- /dev/null +++ b/erealloc.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..2d07ee0 --- /dev/null +++ b/ereallocarray.c @@ -0,0 +1,67 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..f00fed3 --- /dev/null +++ b/ereallocn.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/estrdup.c b/estrdup.c new file mode 100644 index 0000000..53d60c2 --- /dev/null +++ b/estrdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_estrdup(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + char *s; + + assert((s = libsimple_estrdup("test"))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "test")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 15; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrdup("test")); + assert(exit_status == 15); + assert_stderr("%s: strdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/estrndup.c b/estrndup.c new file mode 100644 index 0000000..67f1ca4 --- /dev/null +++ b/estrndup.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_estrndup(const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + char *s; + + assert((s = libsimple_estrndup("test", 10))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "test")); + free(s); + + assert((s = libsimple_estrndup("test", 3))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 4); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "tes")); + free(s); + + assert((s = libsimple_estrndup("test", 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 1); + assert(info->alignment == 1); + assert(!info->zeroed); + } + assert(!strcmp(s, "")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 15; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrndup("test", 10)); + assert(exit_status == 15); + assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 17; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrndup("test", 2)); + assert(exit_status == 17); + assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 19; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_estrndup("test", 0)); + assert(exit_status == 19); + assert_stderr("%s: strndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/evaligned_allocn.c b/evaligned_allocn.c new file mode 100644 index 0000000..00dad49 --- /dev/null +++ b/evaligned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evaligned_allocn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ealigned_allocn */ +} + +#endif diff --git a/evaligned_alloczn.c b/evaligned_alloczn.c new file mode 100644 index 0000000..26b9e1f --- /dev/null +++ b/evaligned_alloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evaligned_alloczn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ealigned_alloczn */ +} + +#endif diff --git a/evaligned_reallocn.c b/evaligned_reallocn.c new file mode 100644 index 0000000..e17545e --- /dev/null +++ b/evaligned_reallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evaligned_reallocn(void *, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ealigned_reallocn */ +} + +#endif diff --git a/evalloc.c b/evalloc.c new file mode 100644 index 0000000..83db54c --- /dev/null +++ b/evalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evalloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evallocn.c b/evallocn.c new file mode 100644 index 0000000..e57c122 --- /dev/null +++ b/evallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/evallocz.c b/evallocz.c new file mode 100644 index 0000000..b16cc9a --- /dev/null +++ b/evallocz.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..9e231c3 --- /dev/null +++ b/evalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/evcallocn.c b/evcallocn.c new file mode 100644 index 0000000..1fe842d --- /dev/null +++ b/evcallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evcallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ecallocn */ +} + +#endif diff --git a/evmallocn.c b/evmallocn.c new file mode 100644 index 0000000..d61142d --- /dev/null +++ b/evmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evmallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_emallocn */ +} + +#endif diff --git a/evmalloczn.c b/evmalloczn.c new file mode 100644 index 0000000..bae8f87 --- /dev/null +++ b/evmalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evmalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_emalloczn */ +} + +#endif diff --git a/evmemalignn.c b/evmemalignn.c new file mode 100644 index 0000000..99006ec --- /dev/null +++ b/evmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evmemalignn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ememalignn */ +} + +#endif diff --git a/evmemalignzn.c b/evmemalignzn.c new file mode 100644 index 0000000..34d9495 --- /dev/null +++ b/evmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evmemalignzn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_ememalignzn */ +} + +#endif diff --git a/evmemalloc.c b/evmemalloc.c new file mode 100644 index 0000000..cb929ec --- /dev/null +++ b/evmemalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..e5e95bc --- /dev/null +++ b/evposix_memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..e1a0b43 --- /dev/null +++ b/evposix_memalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/evputenvf.c b/evputenvf.c new file mode 100644 index 0000000..e3647ba --- /dev/null +++ b/evputenvf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void libsimple_evputenvf(const char *, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_eputenvf */ +} + +#endif diff --git a/evpvallocn.c b/evpvallocn.c new file mode 100644 index 0000000..6dc643d --- /dev/null +++ b/evpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..dbec77c --- /dev/null +++ b/evpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..e576866 --- /dev/null +++ b/evreallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/evvallocn.c b/evvallocn.c new file mode 100644 index 0000000..5776f63 --- /dev/null +++ b/evvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evvallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_evallocn */ +} + +#endif diff --git a/evvalloczn.c b/evvalloczn.c new file mode 100644 index 0000000..9776ab2 --- /dev/null +++ b/evvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_evvalloczn(int, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_evalloczn */ +} + +#endif diff --git a/ewcsdup.c b/ewcsdup.c new file mode 100644 index 0000000..cf2b8b6 --- /dev/null +++ b/ewcsdup.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ewcsdup(const wchar_t *); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + wchar_t *s; + + assert((s = libsimple_ewcsdup(L"test"))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"test")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 5; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsdup(L"test")); + assert(exit_status == 5); + assert_stderr("%s: wcsdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ewcsndup.c b/ewcsndup.c new file mode 100644 index 0000000..9c17a5a --- /dev/null +++ b/ewcsndup.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ewcsndup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + wchar_t *s; + + assert((s = libsimple_ewcsndup(L"test", 10))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"test")); + free(s); + + assert((s = libsimple_ewcsndup(L"test", 3))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 4 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"tes")); + free(s); + + assert((s = libsimple_ewcsndup(L"test", 0))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 1 * sizeof(wchar_t)); + assert(info->alignment == _Alignof(wchar_t)); + assert(!info->zeroed); + } + assert(!wcscmp(s, L"")); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 25; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsndup(L"test", 10)); + assert(exit_status == 25); + assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 27; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsndup(L"test", 2)); + assert(exit_status == 27); + assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 29; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewcsndup(L"test", 0)); + assert(exit_status == 29); + assert_stderr("%s: wcsndup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/ewmemdup.c b/ewmemdup.c new file mode 100644 index 0000000..ddef556 --- /dev/null +++ b/ewmemdup.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline wchar_t *libsimple_ewmemdup(const wchar_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + struct allocinfo *info; + wchar_t *s; + + assert((s = libsimple_ewmemdup(L"test", 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(s))); + assert(info->size == 5 * sizeof(wchar_t)); + assert(!info->zeroed); + } + assert(!wmemcmp(s, L"test", 5)); + free(s); + + if (have_custom_malloc()) { + libsimple_default_failure_exit = 55; + alloc_fail_in = 1; + assert_exit_ptr(libsimple_ewmemdup(L"test", 2)); + assert(exit_status == 55); + assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); + assert(!alloc_fail_in); + libsimple_default_failure_exit = 1; + + libsimple_default_failure_exit = 51; + assert_exit_ptr(libsimple_ewmemdup(NULL, SSIZE_MAX)); + assert(exit_status == 51); + assert_stderr("%s: wmemdup: %s\n", argv0, strerror(ENOMEM)); + libsimple_default_failure_exit = 1; + } + + return 0; +} + +#endif diff --git a/getenv_e.c b/getenv_e.c new file mode 100644 index 0000000..9d0690a --- /dev/null +++ b/getenv_e.c @@ -0,0 +1,31 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline const char *libsimple_getenv_e(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + char env1[] = "X=xyz"; + char env2[] = "X="; + + unsetenv("X"); + assert(!getenv("X")); + assert(!strcmpnul(libsimple_getenv_e("X"), "")); + putenv(env1); + assert(!strcmpnul(getenv("X"), "xyz")); + assert(!strcmpnul(libsimple_getenv_e("X"), "xyz")); + putenv(env2); + assert(!strcmpnul(getenv("X"), "")); + assert(!strcmpnul(libsimple_getenv_e("X"), "")); + + return 0; +} + +#endif diff --git a/getenv_ne.c b/getenv_ne.c new file mode 100644 index 0000000..6806992 --- /dev/null +++ b/getenv_ne.c @@ -0,0 +1,31 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_getenv_ne(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + char env1[] = "X=xyz"; + char env2[] = "X="; + + unsetenv("X"); + assert(!getenv("X")); + assert(!libsimple_getenv_ne("X")); + putenv(env1); + assert(!strcmpnul(getenv("X"), "xyz")); + assert(!strcmpnul(libsimple_getenv_ne("X"), "xyz")); + putenv(env2); + assert(!strcmpnul(getenv("X"), "")); + assert(!libsimple_getenv_ne("X")); + + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include <sys/timex.h> #ifndef TEST diff --git a/inchrcaseset.c b/inchrcaseset.c new file mode 100644 index 0000000..bd92cf5 --- /dev/null +++ b/inchrcaseset.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_inchrcaseset(int, const char *); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/inchrset.c b/inchrset.c new file mode 100644 index 0000000..591c2e9 --- /dev/null +++ b/inchrset.c @@ -0,0 +1,25 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_inchrset(int, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_inchrset('a', "xyz") == 0); + assert(libsimple_inchrset('b', "xyz") == 0); + assert(libsimple_inchrset('c', "xyz") == 0); + assert(libsimple_inchrset('x', "xyz") == 1); + assert(libsimple_inchrset('y', "xyz") == 1); + assert(libsimple_inchrset('z', "xyz") == 1); + assert(libsimple_inchrset('\0', "xyz") == 0); + return 0; +} + +#endif diff --git a/libsimple-arg.c b/libsimple-arg.c index 95581bf..0fafdde 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,255 @@ 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}, + })); + usage(); + break; + 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}, + })); + usage(); + break; + default: + usage(); + } ARGEND; + } PARSER_END; } int main(void) { + char buf[10]; const char *a1; size_t i; @@ -696,22 +699,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 bc7d4ae..3662b70 100644 --- a/libsimple-arg.h +++ b/libsimple-arg.h @@ -8,11 +8,11 @@ #ifdef LIBSIMPLY_CONFIG_MULTICALL_BINARY /* Define by the application */ -# define _LIBSIMPLY_IF_MULTICALL_BINARY(...) __VA_ARGS__ -# define _LIBSIMPLY_UNLESS_MULTICALL_BINARY(...) +# define LIBSIMPLY_IF_MULTICALL_BINARY__(...) __VA_ARGS__ +# define LIBSIMPLY_UNLESS_MULTICALL_BINARY__(...) #else -# define _LIBSIMPLY_IF_MULTICALL_BINARY(...) -# define _LIBSIMPLY_UNLESS_MULTICALL_BINARY(...) __VA_ARGS__ +# define LIBSIMPLY_IF_MULTICALL_BINARY__(...) +# define LIBSIMPLY_UNLESS_MULTICALL_BINARY__(...) __VA_ARGS__ #endif @@ -52,10 +52,19 @@ struct longopt { */ char short_flag; +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +#endif + /** * Whether the option takes an argument */ int with_arg; + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif }; @@ -444,11 +453,11 @@ struct longopt { /* Intended for internal use only */ #if __STDC_VERSION__ >= 201112L -# define _LIBSIMPLE_NORETURN _Noreturn +# define LIBSIMPLE_NORETURN__ _Noreturn #elif defined(__GNUC__) || defined(__clang__) -# define _LIBSIMPLE_NORETURN __attribute__((noreturn)) +# define LIBSIMPLE_NORETURN__ __attribute__((noreturn)) #else -# define _LIBSIMPLE_NORETURN +# define LIBSIMPLE_NORETURN__ #endif @@ -469,15 +478,15 @@ struct longopt { * @since 1.0 */ #define NUSAGE(STATUS, SYNOPSIS)\ - static _LIBSIMPLE_NORETURN void\ + 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);\ }\ - _LIBSIMPLY_UNLESS_MULTICALL_BINARY(char *argv0 = NULL)\ - _LIBSIMPLY_IF_MULTICALL_BINARY(int main(int, char *[])) + LIBSIMPLY_UNLESS_MULTICALL_BINARY__(char *argv0 = NULL)\ + LIBSIMPLY_IF_MULTICALL_BINARY__(int main(int, char *[])) #endif diff --git a/libsimple.c b/libsimple.c index 5232833..2bb5139 100644 --- a/libsimple.c +++ b/libsimple.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -70,6 +70,7 @@ test_timeval(double d, time_t sec, long int usec, double rd, const char *s, cons } #ifdef libsimple_vasprintfa +LIBSIMPLE_GCC_ONLY__(__attribute__((__format__(__printf__, 2, 0)))) static int test_vasprintfa(const char *expected, const char *format, ...) { @@ -89,14 +90,11 @@ 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; + char *s; wchar_t *ws; - int intarray[10]; - size_t i, j, n; + size_t i, n; DEFINE_PAGESIZE; DEFINE_CACHELINE; @@ -226,14 +224,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 X1 0 +#define X2 0, 0 +#define X3 0, 0, 0 + assert(ELEMSOF((char []){X1}) == 1); + assert(ELEMSOF((char []){X2}) == 2); + assert(ELEMSOF((char []){X3}) == 3); + assert(ELEMSOF((short int []){X3}) == 3); + assert(ELEMSOF((int []){X3}) == 3); + assert(ELEMSOF((long int []){X3}) == 3); + assert(ELEMSOF((float []){X3}) == 3); + assert(ELEMSOF((double []){X3}) == 3); +#undef X1 +#undef X2 +#undef X3 assert(STRLEN("") == 0); assert(STRLEN("a") == 1); @@ -276,374 +280,6 @@ main(void) assert(TYPE_MIN(int64_t) == INT64_MIN); assert(TYPE_MIN(uint64_t) == 0); - assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz")); - - assert(libsimple_inchrset('a', "xyz") == 0); - assert(libsimple_inchrset('b', "xyz") == 0); - assert(libsimple_inchrset('c', "xyz") == 0); - assert(libsimple_inchrset('x', "xyz") == 1); - assert(libsimple_inchrset('y', "xyz") == 1); - 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); - assert(libsimple_streq("ab", "xy") == 0); - assert(libsimple_streq("xy", "ab") == 0); - assert(libsimple_streq("", "1") == 0); - assert(libsimple_streq("1", "") == 0); - assert(libsimple_streq("", "") == 1); - assert(libsimple_streq("abc", "ABC") == 0); - assert(libsimple_streq("ABC", "abc") == 0); - - assert(libsimple_strneq("abc", "abc", 5) == 1); - assert(libsimple_strneq("abc", "ab", 5) == 0); - assert(libsimple_strneq("ab", "abc", 5) == 0); - assert(libsimple_strneq("ab", "xy", 5) == 0); - assert(libsimple_strneq("xy", "ab", 5) == 0); - assert(libsimple_strneq("", "1", 5) == 0); - assert(libsimple_strneq("1", "", 5) == 0); - assert(libsimple_strneq("", "", 5) == 1); - assert(libsimple_strneq("abc", "ABC", 5) == 0); - assert(libsimple_strneq("ABC", "abc", 5) == 0); - assert(libsimple_strneq("abc", "abc", 1) == 1); - assert(libsimple_strneq("abc", "ab", 1) == 1); - assert(libsimple_strneq("ab", "abc", 1) == 1); - assert(libsimple_strneq("ab", "xy", 1) == 0); - assert(libsimple_strneq("xy", "ab", 1) == 0); - assert(libsimple_strneq("", "1", 1) == 0); - assert(libsimple_strneq("1", "", 1) == 0); - assert(libsimple_strneq("", "", 1) == 1); - assert(libsimple_strneq("abc", "ABC", 1) == 0); - assert(libsimple_strneq("ABC", "abc", 1) == 0); - assert(libsimple_strneq("abc", "abc", 0) == 1); - assert(libsimple_strneq("abc", "ab", 0) == 1); - assert(libsimple_strneq("ab", "abc", 0) == 1); - assert(libsimple_strneq("ab", "xy", 0) == 1); - assert(libsimple_strneq("xy", "ab", 0) == 1); - assert(libsimple_strneq("", "1", 0) == 1); - assert(libsimple_strneq("1", "", 0) == 1); - assert(libsimple_strneq("", "", 0) == 1); - assert(libsimple_strneq("abc", "ABC", 0) == 1); - assert(libsimple_strneq("ABC", "abc", 0) == 1); - - assert(libsimple_streqnul("abc", "abc") == 1); - assert(libsimple_streqnul("abc", "ab") == 0); - assert(libsimple_streqnul("ab", "abc") == 0); - assert(libsimple_streqnul("ab", "xy") == 0); - assert(libsimple_streqnul("xy", "ab") == 0); - assert(libsimple_streqnul("", "1") == 0); - assert(libsimple_streqnul("1", "") == 0); - assert(libsimple_streqnul("", "") == 1); - assert(libsimple_streqnul("abc", "ABC") == 0); - assert(libsimple_streqnul("ABC", "abc") == 0); - assert(libsimple_streqnul("", NULL) == 0); - assert(libsimple_streqnul("1", NULL) == 0); - assert(libsimple_streqnul(NULL, "") == 0); - assert(libsimple_streqnul(NULL, "1") == 0); - assert(libsimple_streqnul(NULL, NULL) == 1); - - assert(libsimple_strneqnul("abc", "abc", 5) == 1); - assert(libsimple_strneqnul("abc", "ab", 5) == 0); - assert(libsimple_strneqnul("ab", "abc", 5) == 0); - assert(libsimple_strneqnul("ab", "xy", 5) == 0); - assert(libsimple_strneqnul("xy", "ab", 5) == 0); - assert(libsimple_strneqnul("", "1", 5) == 0); - assert(libsimple_strneqnul("1", "", 5) == 0); - assert(libsimple_strneqnul("", "", 5) == 1); - assert(libsimple_strneqnul("abc", "ABC", 5) == 0); - assert(libsimple_strneqnul("ABC", "abc", 5) == 0); - assert(libsimple_strneqnul("", NULL, 5) == 0); - assert(libsimple_strneqnul("1", NULL, 5) == 0); - assert(libsimple_strneqnul(NULL, "", 5) == 0); - assert(libsimple_strneqnul(NULL, "1", 5) == 0); - assert(libsimple_strneqnul(NULL, NULL, 5) == 1); - assert(libsimple_strneqnul("abc", "abc", 1) == 1); - assert(libsimple_strneqnul("abc", "ab", 1) == 1); - assert(libsimple_strneqnul("ab", "abc", 1) == 1); - assert(libsimple_strneqnul("ab", "xy", 1) == 0); - assert(libsimple_strneqnul("xy", "ab", 1) == 0); - assert(libsimple_strneqnul("", "1", 1) == 0); - assert(libsimple_strneqnul("1", "", 1) == 0); - assert(libsimple_strneqnul("", "", 1) == 1); - assert(libsimple_strneqnul("abc", "ABC", 1) == 0); - assert(libsimple_strneqnul("ABC", "abc", 1) == 0); - assert(libsimple_strneqnul("", NULL, 1) == 0); - assert(libsimple_strneqnul("1", NULL, 1) == 0); - assert(libsimple_strneqnul(NULL, "", 1) == 0); - assert(libsimple_strneqnul(NULL, "1", 1) == 0); - assert(libsimple_strneqnul(NULL, NULL, 1) == 1); - assert(libsimple_strneqnul("abc", "abc", 0) == 1); - assert(libsimple_strneqnul("abc", "ab", 0) == 1); - assert(libsimple_strneqnul("ab", "abc", 0) == 1); - assert(libsimple_strneqnul("ab", "xy", 0) == 1); - assert(libsimple_strneqnul("xy", "ab", 0) == 1); - assert(libsimple_strneqnul("", "1", 0) == 1); - assert(libsimple_strneqnul("1", "", 0) == 1); - assert(libsimple_strneqnul("", "", 0) == 1); - assert(libsimple_strneqnul("abc", "ABC", 0) == 1); - assert(libsimple_strneqnul("ABC", "abc", 0) == 1); - assert(libsimple_strneqnul("", NULL, 0) == 0); - assert(libsimple_strneqnul("1", NULL, 0) == 0); - assert(libsimple_strneqnul(NULL, "", 0) == 0); - assert(libsimple_strneqnul(NULL, "1", 0) == 0); - assert(libsimple_strneqnul(NULL, NULL, 0) == 1); - - assert(libsimple_strcaseeq("abc", "abc") == 1); - assert(libsimple_strcaseeq("abc", "ab") == 0); - assert(libsimple_strcaseeq("ab", "abc") == 0); - assert(libsimple_strcaseeq("ab", "xy") == 0); - assert(libsimple_strcaseeq("xy", "ab") == 0); - assert(libsimple_strcaseeq("", "1") == 0); - assert(libsimple_strcaseeq("1", "") == 0); - assert(libsimple_strcaseeq("", "") == 1); - assert(libsimple_strcaseeq("abc", "ABC") == 1); - assert(libsimple_strcaseeq("ABC", "abc") == 1); - - assert(libsimple_strncaseeq("abc", "abc", 5) == 1); - assert(libsimple_strncaseeq("abc", "ab", 5) == 0); - assert(libsimple_strncaseeq("ab", "abc", 5) == 0); - assert(libsimple_strncaseeq("ab", "xy", 5) == 0); - assert(libsimple_strncaseeq("xy", "ab", 5) == 0); - assert(libsimple_strncaseeq("", "1", 5) == 0); - assert(libsimple_strncaseeq("1", "", 5) == 0); - assert(libsimple_strncaseeq("", "", 5) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 5) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 5) == 1); - assert(libsimple_strncaseeq("abc", "abc", 1) == 1); - assert(libsimple_strncaseeq("abc", "ab", 1) == 1); - assert(libsimple_strncaseeq("ab", "abc", 1) == 1); - assert(libsimple_strncaseeq("ab", "xy", 1) == 0); - assert(libsimple_strncaseeq("xy", "ab", 1) == 0); - assert(libsimple_strncaseeq("", "1", 1) == 0); - assert(libsimple_strncaseeq("1", "", 1) == 0); - assert(libsimple_strncaseeq("", "", 1) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 1) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 1) == 1); - assert(libsimple_strncaseeq("abc", "abc", 0) == 1); - assert(libsimple_strncaseeq("abc", "ab", 0) == 1); - assert(libsimple_strncaseeq("ab", "abc", 0) == 1); - assert(libsimple_strncaseeq("ab", "xy", 0) == 1); - assert(libsimple_strncaseeq("xy", "ab", 0) == 1); - assert(libsimple_strncaseeq("", "1", 0) == 1); - assert(libsimple_strncaseeq("1", "", 0) == 1); - assert(libsimple_strncaseeq("", "", 0) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 0) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 0) == 1); - - assert(libsimple_strcaseeqnul("abc", "abc") == 1); - assert(libsimple_strcaseeqnul("abc", "ab") == 0); - assert(libsimple_strcaseeqnul("ab", "abc") == 0); - assert(libsimple_strcaseeqnul("ab", "xy") == 0); - assert(libsimple_strcaseeqnul("xy", "ab") == 0); - assert(libsimple_strcaseeqnul("", "1") == 0); - assert(libsimple_strcaseeqnul("1", "") == 0); - assert(libsimple_strcaseeqnul("", "") == 1); - assert(libsimple_strcaseeqnul("abc", "ABC") == 1); - assert(libsimple_strcaseeqnul("ABC", "abc") == 1); - assert(libsimple_strcaseeqnul("", NULL) == 0); - assert(libsimple_strcaseeqnul("1", NULL) == 0); - assert(libsimple_strcaseeqnul(NULL, "") == 0); - assert(libsimple_strcaseeqnul(NULL, "1") == 0); - assert(libsimple_strcaseeqnul(NULL, NULL) == 1); - - assert(libsimple_strncaseeqnul("abc", "abc", 5) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 5) == 0); - assert(libsimple_strncaseeqnul("ab", "abc", 5) == 0); - assert(libsimple_strncaseeqnul("ab", "xy", 5) == 0); - assert(libsimple_strncaseeqnul("xy", "ab", 5) == 0); - assert(libsimple_strncaseeqnul("", "1", 5) == 0); - assert(libsimple_strncaseeqnul("1", "", 5) == 0); - assert(libsimple_strncaseeqnul("", "", 5) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 5) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 5) == 1); - assert(libsimple_strncaseeqnul("", NULL, 5) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 5) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 5) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 5) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 5) == 1); - assert(libsimple_strncaseeqnul("abc", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 1) == 1); - assert(libsimple_strncaseeqnul("ab", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("ab", "xy", 1) == 0); - assert(libsimple_strncaseeqnul("xy", "ab", 1) == 0); - assert(libsimple_strncaseeqnul("", "1", 1) == 0); - assert(libsimple_strncaseeqnul("1", "", 1) == 0); - assert(libsimple_strncaseeqnul("", "", 1) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 1) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("", NULL, 1) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 1) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 1) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 1) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 1) == 1); - assert(libsimple_strncaseeqnul("abc", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 0) == 1); - assert(libsimple_strncaseeqnul("ab", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("ab", "xy", 0) == 1); - assert(libsimple_strncaseeqnul("xy", "ab", 0) == 1); - assert(libsimple_strncaseeqnul("", "1", 0) == 1); - assert(libsimple_strncaseeqnul("1", "", 0) == 1); - assert(libsimple_strncaseeqnul("", "", 0) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 0) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("", NULL, 0) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 0) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 0) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1); - - for (i = 0, n = 10; i < n; i++) - buf[i] = i; - LIBSIMPLE_UNLIST(buf, 4, &n); - LIBSIMPLE_UNLIST(buf, 9 - 1, &n); - LIBSIMPLE_UNLIST(buf, 6 - 1, &n); - assert(n == 7); - assert(buf[0] == 0); - assert(buf[1] == 1); - assert(buf[2] == 2); - assert(buf[3] == 3); - assert(buf[4] == 5); - assert(buf[5] == 7); - assert(buf[6] == 8); - - for (i = 0, n = 10; i < n; i++) - intarray[i] = i; - LIBSIMPLE_UNLIST(intarray, 4, &n); - LIBSIMPLE_UNLIST(intarray, 9 - 1, &n); - LIBSIMPLE_UNLIST(intarray, 6 - 1, &n); - assert(n == 7); - assert(intarray[0] == 0); - assert(intarray[1] == 1); - assert(intarray[2] == 2); - assert(intarray[3] == 3); - assert(intarray[4] == 5); - assert(intarray[5] == 7); - assert(intarray[6] == 8); - - assert(libsimple_strcmpnul(NULL, NULL) == 0); - assert(libsimple_strcmpnul(NULL, "") < 0); - assert(libsimple_strcmpnul("", NULL) > 0); - assert(libsimple_strcmpnul("", "") == 0); - assert(libsimple_strcmpnul(NULL, "x") < 0); - assert(libsimple_strcmpnul("x", NULL) > 0); - assert(libsimple_strcmpnul("x", "x") == 0); - assert(libsimple_strcmpnul("a", "b") < 0); - assert(libsimple_strcmpnul("b", "a") > 0); - assert(libsimple_strcmpnul("aa", "ab") < 0); - assert(libsimple_strcmpnul("ab", "aa") > 0); - assert(libsimple_strcmpnul("aa", "aa") == 0); - assert(libsimple_strcmpnul("A", "a") < 0); - assert(libsimple_strcmpnul("a", "A") > 0); - assert(libsimple_strcmpnul("AA", "Aa") < 0); - assert(libsimple_strcmpnul("Aa", "AA") > 0); - assert(libsimple_strcmpnul("AA", "AA") == 0); - - assert(libsimple_strcasecmpnul(NULL, NULL) == 0); - assert(libsimple_strcasecmpnul(NULL, "") < 0); - assert(libsimple_strcasecmpnul("", NULL) > 0); - assert(libsimple_strcasecmpnul("", "") == 0); - assert(libsimple_strcasecmpnul(NULL, "x") < 0); - assert(libsimple_strcasecmpnul("x", NULL) > 0); - assert(libsimple_strcasecmpnul("x", "x") == 0); - assert(libsimple_strcasecmpnul("a", "b") < 0); - assert(libsimple_strcasecmpnul("b", "a") > 0); - assert(libsimple_strcasecmpnul("aa", "ab") < 0); - assert(libsimple_strcasecmpnul("ab", "aa") > 0); - assert(libsimple_strcasecmpnul("aa", "aa") == 0); - assert(libsimple_strcasecmpnul("A", "a") == 0); - assert(libsimple_strcasecmpnul("a", "A") == 0); - assert(libsimple_strcasecmpnul("AA", "Aa") == 0); - assert(libsimple_strcasecmpnul("Aa", "AA") == 0); - assert(libsimple_strcasecmpnul("AA", "AA") == 0); - - assert(libsimple_strncmpnul(NULL, NULL, 5) == 0); - assert(libsimple_strncmpnul(NULL, "", 5) < 0); - assert(libsimple_strncmpnul("", NULL, 5) > 0); - assert(libsimple_strncmpnul("", "", 5) == 0); - assert(libsimple_strncmpnul(NULL, "x", 5) < 0); - assert(libsimple_strncmpnul("x", NULL, 5) > 0); - assert(libsimple_strncmpnul("x", "x", 5) == 0); - assert(libsimple_strncmpnul("a", "b", 5) < 0); - assert(libsimple_strncmpnul("b", "a", 5) > 0); - assert(libsimple_strncmpnul("aa", "ab", 5) < 0); - assert(libsimple_strncmpnul("ab", "aa", 5) > 0); - assert(libsimple_strncmpnul("aa", "aa", 5) == 0); - assert(libsimple_strncmpnul("A", "a", 5) < 0); - assert(libsimple_strncmpnul("a", "A", 5) > 0); - assert(libsimple_strncmpnul("AA", "Aa", 5) < 0); - assert(libsimple_strncmpnul("Aa", "AA", 5) > 0); - assert(libsimple_strncmpnul("AA", "AA", 5) == 0); - assert(libsimple_strncmpnul("aa", "ab", 1) == 0); - assert(libsimple_strncmpnul("ab", "aa", 1) == 0); - assert(libsimple_strncmpnul("aa", "aa", 1) == 0); - assert(libsimple_strncmpnul("AA", "Aa", 1) == 0); - assert(libsimple_strncmpnul("Aa", "AA", 1) == 0); - assert(libsimple_strncmpnul("AA", "AA", 1) == 0); - assert(libsimple_strncmpnul(NULL, NULL, 0) == 0); - assert(libsimple_strncmpnul(NULL, "", 0) < 0); - assert(libsimple_strncmpnul("", NULL, 0) > 0); - assert(libsimple_strncmpnul("", "", 0) == 0); - assert(libsimple_strncmpnul(NULL, "x", 0) < 0); - assert(libsimple_strncmpnul("x", NULL, 0) > 0); - assert(libsimple_strncmpnul("x", "x", 0) == 0); - assert(libsimple_strncmpnul("a", "b", 0) == 0); - assert(libsimple_strncmpnul("b", "a", 0) == 0); - assert(libsimple_strncmpnul("aa", "ab", 0) == 0); - assert(libsimple_strncmpnul("ab", "aa", 0) == 0); - assert(libsimple_strncmpnul("aa", "aa", 0) == 0); - assert(libsimple_strncmpnul("A", "a", 0) == 0); - assert(libsimple_strncmpnul("a", "A", 0) == 0); - assert(libsimple_strncmpnul("AA", "Aa", 0) == 0); - assert(libsimple_strncmpnul("Aa", "AA", 0) == 0); - assert(libsimple_strncmpnul("AA", "AA", 0) == 0); - - assert(libsimple_strncasecmpnul(NULL, NULL, 5) == 0); - assert(libsimple_strncasecmpnul(NULL, "", 5) < 0); - assert(libsimple_strncasecmpnul("", NULL, 5) > 0); - assert(libsimple_strncasecmpnul("", "", 5) == 0); - assert(libsimple_strncasecmpnul(NULL, "x", 5) < 0); - assert(libsimple_strncasecmpnul("x", NULL, 5) > 0); - assert(libsimple_strncasecmpnul("x", "x", 5) == 0); - assert(libsimple_strncasecmpnul("a", "b", 5) < 0); - assert(libsimple_strncasecmpnul("b", "a", 5) > 0); - assert(libsimple_strncasecmpnul("aa", "ab", 5) < 0); - assert(libsimple_strncasecmpnul("ab", "aa", 5) > 0); - assert(libsimple_strncasecmpnul("aa", "aa", 5) == 0); - assert(libsimple_strncasecmpnul("A", "a", 5) == 0); - assert(libsimple_strncasecmpnul("a", "A", 5) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 5) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 5) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 5) == 0); - assert(libsimple_strncasecmpnul("aa", "ab", 1) == 0); - assert(libsimple_strncasecmpnul("ab", "aa", 1) == 0); - assert(libsimple_strncasecmpnul("aa", "aa", 1) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 1) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 1) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 1) == 0); - assert(libsimple_strncasecmpnul(NULL, NULL, 0) == 0); - assert(libsimple_strncasecmpnul(NULL, "", 0) < 0); - assert(libsimple_strncasecmpnul("", NULL, 0) > 0); - assert(libsimple_strncasecmpnul("", "", 0) == 0); - assert(libsimple_strncasecmpnul(NULL, "x", 0) < 0); - assert(libsimple_strncasecmpnul("x", NULL, 0) > 0); - assert(libsimple_strncasecmpnul("x", "x", 0) == 0); - assert(libsimple_strncasecmpnul("a", "b", 0) == 0); - assert(libsimple_strncasecmpnul("b", "a", 0) == 0); - assert(libsimple_strncasecmpnul("aa", "ab", 0) == 0); - assert(libsimple_strncasecmpnul("ab", "aa", 0) == 0); - assert(libsimple_strncasecmpnul("aa", "aa", 0) == 0); - assert(libsimple_strncasecmpnul("A", "a", 0) == 0); - assert(libsimple_strncasecmpnul("a", "A", 0) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 0) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 0) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 0) == 0); - #ifdef libsimple_strdupa cs = ""; s = libsimple_strdupa(cs); @@ -967,26 +603,6 @@ main(void) fprintf(stderr, "warning: libsimple_aligned_wcsndupa missing\n"); #endif - unsetenv("X"); - assert(!getenv("X")); - assert(!libsimple_getenv_ne("X")); - putenv("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - assert(!strcmpnul(libsimple_getenv_ne("X"), "xyz")); - putenv("X="); - assert(!strcmpnul(getenv("X"), "")); - assert(!libsimple_getenv_ne("X")); - - unsetenv("X"); - assert(!getenv("X")); - assert(!strcmpnul(libsimple_getenv_e("X"), "")); - putenv("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - assert(!strcmpnul(libsimple_getenv_e("X"), "xyz")); - putenv("X="); - assert(!strcmpnul(getenv("X"), "")); - assert(!strcmpnul(libsimple_getenv_e("X"), "")); - assert(test_timespec(10.3000200010, 10, 300020001L, 10.300020001, "+10.300020001", "10.300020001")); assert(test_timespec(10.3000200014, 10, 300020001L, 10.300020001, "+10.300020001", "10.300020001")); assert(test_timespec(10.3000200015, 10, 300020002L, 10.300020002, "+10.300020002", "10.300020002")); @@ -1011,258 +627,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))); @@ -1338,30 +702,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))); @@ -1533,28 +873,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))); @@ -1566,28 +884,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))); @@ -1599,28 +895,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))); @@ -1632,186 +906,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))); @@ -1822,50 +922,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))); @@ -1888,102 +944,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)); @@ -2030,14 +990,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); @@ -2088,42 +1040,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)); @@ -2136,56 +1052,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)); @@ -2308,28 +1174,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); @@ -2344,509 +1188,6 @@ main(void) fprintf(stderr, "warning: libsimple_vasprintfa missing\n"); #endif - { - char a[] = "abcdefgh", b[] = "abcdefgh"; - assert(libsimple_strreqlen("", "") == 0); - assert(libsimple_strreqlen("x", "") == 0); - assert(libsimple_strreqlen("x", "y") == 0); - assert(libsimple_strreqlen("", "y") == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - assert(libsimple_strreqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); - a[i] = b[j] = '\0'; - assert(libsimple_strreqlen(a, b) == (i == j ? i : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "abcdefgh"[j]; - } - } - assert(libsimple_strreqlen("abc", "ABC") == 0); - assert(libsimple_strreqlen("123", "123") == 3); - } - - { - char a[] = "abcdefgh", b[] = "ABCDEFGH"; - assert(libsimple_strrcaseeqlen("", "") == 0); - assert(libsimple_strrcaseeqlen("x", "") == 0); - assert(libsimple_strrcaseeqlen("x", "y") == 0); - assert(libsimple_strrcaseeqlen("", "y") == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - assert(libsimple_strrcaseeqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); - assert(libsimple_strrcaseeqlen(&b[i], &a[j]) == 8 - (i > j ? i : j)); - a[i] = b[j] = '\0'; - assert(libsimple_strrcaseeqlen(a, b) == (i == j ? i : 0)); - assert(libsimple_strrcaseeqlen(b, a) == (i == j ? i : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "ABCDEFGH"[j]; - } - } - assert(libsimple_strrcaseeqlen("abc", "abc") == 3); - assert(libsimple_strrcaseeqlen("123", "123") == 3); - } - - for (n = 0; n < 10; n++) { - char a[] = "abcdefgh", b[] = "abcdefgh"; - size_t I, J; - assert(libsimple_strrneqlen("", "", n) == 0); - assert(libsimple_strrneqlen("x", "", n) == 0); - assert(libsimple_strrneqlen("x", "y", n) == 0); - assert(libsimple_strrneqlen("", "y", n) == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - I = 8 - i; - J = 8 - j; - assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - a[i] = b[j] = '\0'; - assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "abcdefgh"[j]; - } - } - assert(libsimple_strrneqlen("abc", "ABC", n) == 0); - assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n)); - } - - for (n = 0; n < 10; n++) { - char a[] = "abcdefgh", b[] = "ABCDEFGH"; - size_t I, J; - assert(libsimple_strrncaseeqlen("", "", n) == 0); - assert(libsimple_strrncaseeqlen("x", "", n) == 0); - assert(libsimple_strrncaseeqlen("x", "y", n) == 0); - assert(libsimple_strrncaseeqlen("", "y", n) == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - I = 8 - i; - J = 8 - j; - assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - a[i] = b[j] = '\0'; - assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "ABCDEFGH"[j]; - } - } - assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n)); - assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); - } - - { - char p_[4096]; - char *p = p_; - - memset(p, 0, sizeof(p_)); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 10) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 1, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 2, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 4, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 8, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 16, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~0}, 3, 0) == p); - assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p); - assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p); - assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p); - assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p); - assert(libsimple_memsetelem(p, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == p); - - for (i = 0; i < 48; i++) - assert(p[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]); - for (; i < 800; i += 8) - assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL); - for (; i < 1200; i += 4) - assert(*(uint32_t *)&p[i] == 0x10203040UL); - for (; i < 2000; i += 2) - assert(*(uint16_t *)&p[i] == 0x0807); - for (; i < 3000; i++) - assert(p[i] == 0x09); - for (; i < sizeof(p_); i++) - assert(p[i] == 0); - } - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strset(buf, 'x') == buf); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strset(buf, '\0') == buf); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpset(buf, 'x') == &buf[11]); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpset(buf, '\0') == &buf[11]); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, 'x', SIZE_MAX) == buf); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, '\0', SIZE_MAX) == buf); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, 'x', SIZE_MAX) == &buf[11]); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, '\0', SIZE_MAX) == &buf[11]); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, 'x', 5) == buf); - assert(!strcmp(buf, "xxxxx world")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, '\0', 5) == buf); - assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, 'x', 5) == &buf[5]); - assert(!strcmp(buf, "xxxxx world")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, '\0', 5) == &buf[5]); - assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_memreplace(buf, 'o', 'x', 46) == &buf[46]); - assert(!memcmp(buf, "hellx wxrld\0gxxdbye wxrld", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_memreplace(buf, 'o', 'x', 12) == &buf[12]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', SIZE_MAX) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 12) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 11) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 6) == &buf[6]); - assert(!memcmp(buf, "hellx world\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 5) == &buf[5]); - assert(!memcmp(buf, "hellx world\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 4) == &buf[4]); - assert(!memcmp(buf, "hello world\0goodbye world", 26)); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(&buf[3], buf) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(buf, &buf[3]) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(buf, buf) == buf); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 9) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 12) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]); - assert(!strncmp(buf, "helhello worldx", 15)); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 8) == buf); - assert(!strcmp(buf, "lo worldrld")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 11) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]); - assert(!strcmp(buf, "helhe world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 2) == buf); - assert(!strcmp(buf, "lollo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 2) == buf); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(buf, buf) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]); - assert(!strncmp(buf, "helhello worldx", 15)); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]); - assert(!strcmp(buf, "lo worldrld")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]); - assert(!strcmp(buf, "helhe world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]); - assert(!strcmp(buf, "lollo world")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'x') == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL); - assert(!strncmp(buf, "hellox", 6)); - - - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL); - 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; diff --git a/libsimple.h b/libsimple.h index 3ee1e90..430dbe0 100644 --- a/libsimple.h +++ b/libsimple.h @@ -3,6 +3,14 @@ #define LIBSIMPLE_H +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +# pragma clang diagnostic ignored "-Wreserved-identifier" +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +#endif + #include <arpa/inet.h> #include <netinet/in.h> #include <netinet/tcp.h> @@ -43,51 +51,78 @@ #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__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Winline" +#endif + + #if defined(__GNUC__) && !defined(__clang__) -# define _LIBSIMPLE_GCC_ONLY(x) x -# define _LIBSIMPLE_NON_GCC_ONLY(x) +# 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 defined(__GNUC__) +# define LIBSIMPLE_EXTENSION__ __extension__ +#else +# define LIBSIMPLE_EXTENSION__ #endif #if __STDC_VERSION__ >= 199409L -# define _LIBSIMPLE_C95_ONLY(x) x -# define _LIBSIMPLE_PRE_C95_ONLY(x) +# 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)))) + + +#if __STDC_VERSION__ >= 201112L +# define LIBSIMPLE_NORETURN _Noreturn /* TODO doc, man */ +#elif defined(__GNUC__) || defined(__clang__) +# define LIBSIMPLE_NORETURN __attribute__((noreturn)) +#else +# define LIBSIMPLE_NORETURN +#endif #include "libsimple/overflow.h" @@ -128,6 +163,8 @@ #include "libsimple/array.h" #include "libsimple/str.h" #include "libsimple/strn.h" +#include "libsimple/strtoint.h" +#include "libsimple/search.h" /** @@ -142,16 +179,16 @@ * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline int -libsimple_close(int *__fdp) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline int +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__; } @@ -184,47 +221,45 @@ libsimple_close(int *__fdp) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline void -libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline void +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 (since 1.2) */ +#define LIBSIMPLE_REMOVE_CONST__(X, TYPE, ...) (*(TYPE *)(void *)&(X)) +#define LIBSIMPLE_REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST__(__VA_ARGS__, void *) /* TODO test, doc, man (since 1.2) */ #ifndef REMOVE_CONST # define REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST(__VA_ARGS__) #endif #define LIBSIMPLE_PREFETCH_RDONLY(ADDRESS, LOCALITY) /* void */ /* TODO test, doc, man (since 1.2) */\ - _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 (since 1.2) */\ - _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)) -#if defined(__GNUC__) && !defined(__clang__) -# define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man (since 1.2) */\ - _LIBSIMPLE_GCC_ONLY(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\ - _LIBSIMPLE_C11_ONLY(_Alignof(PTR))\ - _LIBSIMPLE_PREC11_ONLY(__alignof(PTR)))) -#endif +#define LIBSIMPLE_ASSUME_ALIGNED__(PTR, ALIGNMENT, ...)\ + LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ALIGNMENT))\ + LIBSIMPLE_NON_GCC_ONLY__(PTR) +#define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man (since 1.2) */\ + LIBSIMPLE_ASSUME_ALIGNED__(PTR, ##__VA_ARGS__, LIBSIMPLE_C11_ONLY__(_Alignof(*PTR)) /* no , */\ + LIBSIMPLE_PRE_C11_ONLY__(__alignof(*PTR))) #ifndef ASSUME_ALIGNED # define ASSUME_ALIGNED(...) LIBSIMPLE_ASSUME_ALIGNED(__VA_ARGS__) #endif @@ -237,17 +272,27 @@ 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 (since 1.2) */ +#define LIBSIMPLE_UNROLLED(N) LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC unroll "#N))) /* TODO test, doc, man (since 1.2) */ #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 (since 1.2) */ +#define LIBSIMPLE_SIMDLOOP LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC ivdep"))) /* TODO test, doc, man (since 1.2) */ #ifndef SIMDLOOP # define SIMDLOOP LIBSIMPLE_SIMDLOOP #endif + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + #endif diff --git a/libsimple/aligned_alloc.h b/libsimple/aligned_alloc.h index fd81053..9e05533 100644 --- a/libsimple/aligned_alloc.h +++ b/libsimple/aligned_alloc.h @@ -21,9 +21,12 @@ * * @since 1.1 */ -_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__))) +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 @@ -42,14 +45,14 @@ static inline void *libsimple_valigned_allocn(size_t __alignment, size_t __n, va * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) +inline void * +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 @@ -73,9 +76,12 @@ libsimple_aligned_allocn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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__))) +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 @@ -104,9 +110,12 @@ static inline void *libsimple_enaligned_alloc(int __status, size_t __alignment, * * @since 1.1 */ -_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__))) +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 @@ -135,14 +144,14 @@ static inline void *libsimple_envaligned_allocn(int __status, size_t __alignment * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -165,9 +174,12 @@ libsimple_enaligned_allocn(int __status, size_t __alignment, size_t __n, ... /*, * * @since 1.1 */ -_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__))) +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 @@ -195,9 +207,12 @@ static inline void *libsimple_ealigned_alloc(size_t __alignment, size_t __n) * * @since 1.1 */ -_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__))) +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 @@ -225,14 +240,14 @@ static inline void *libsimple_evaligned_allocn(size_t __alignment, size_t __n, v * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 be290d2..ea65c40 100644 --- a/libsimple/aligned_allocz.h +++ b/libsimple/aligned_allocz.h @@ -22,7 +22,7 @@ * * @since 1.1 */ -_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 @@ -44,14 +44,14 @@ void *libsimple_valigned_alloczn(int, size_t, size_t, va_list); * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +inline void * +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 @@ -79,14 +79,14 @@ libsimple_aligned_allocz(int __clear, size_t __alignment, size_t __n) * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +inline void * +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 @@ -111,7 +111,7 @@ libsimple_aligned_alloczn(int __clear, size_t __alignment, size_t __n, ... /*, ( * * @since 1.1 */ -_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 @@ -142,7 +142,7 @@ void *libsimple_enaligned_allocz(int, int, size_t, size_t); * * @since 1.1 */ -_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 @@ -173,14 +173,14 @@ void *libsimple_envaligned_alloczn(int, int, size_t, size_t, va_list); * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -203,9 +203,12 @@ libsimple_enaligned_alloczn(int __status, int __clear, size_t __alignment, size_ * * @since 1.1 */ -_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__))) +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 @@ -234,9 +237,12 @@ static inline void *libsimple_ealigned_allocz(int __clear, size_t __alignment, s * * @since 1.1 */ -_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__))) +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 @@ -265,14 +271,14 @@ static inline void *libsimple_evaligned_alloczn(int __clear, size_t __alignment, * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 36b085f..1bea686 100644 --- a/libsimple/aligned_memdup.h +++ b/libsimple/aligned_memdup.h @@ -13,20 +13,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_memdupa(s, alignment, n)\ + LIBSIMPLE_EXTENSION__\ ({\ - const char *__s = (s);\ - size_t __n = (n);\ - size_t __a = (alignment);\ - size_t __size;\ - uintptr_t __misalignment;\ - char *__r;\ - __a += !__a;\ - __size = __n + (__a - 1);\ - __r = alloca(__size + !__size);\ - __misalignment = (uintptr_t)__r % (uintptr_t)__a;\ - if (__misalignment)\ - __r += (uintptr_t)__a - __misalignment;\ - memcpy(__r, __s, __n);\ + const char *s__ = (s);\ + size_t n__ = (n);\ + size_t a__ = (alignment);\ + size_t size__;\ + uintptr_t misalignment__;\ + char *r__;\ + a__ += !a__;\ + size__ = n__ + (a__ - 1);\ + r__ = alloca(size__ + !size__);\ + misalignment__ = (uintptr_t)r__ % (uintptr_t)a__;\ + if (misalignment__)\ + r__ += (uintptr_t)a__ - misalignment__;\ + memcpy(r__, s__, n__);\ }) # ifndef aligned_memdupa # define aligned_memdupa(s, alignment, n) libsimple_aligned_memdupa(s, alignment, n) @@ -44,7 +45,7 @@ * * @since 1.1 */ -_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 @@ -62,7 +63,7 @@ void *libsimple_aligned_memdup(const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -79,9 +80,12 @@ void *libsimple_enaligned_memdup(int, const void *, size_t, size_t); * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ealigned_memdup(const void *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_memdup(libsimple_default_failure_exit, __s, __alignment, __n); } +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__) +{ + return libsimple_enaligned_memdup(libsimple_default_failure_exit, s__, alignment__, n__); +} #ifndef ealigned_memdup # define ealigned_memdup libsimple_ealigned_memdup #endif diff --git a/libsimple/aligned_realloc.h b/libsimple/aligned_realloc.h index b4926e4..10238ba 100644 --- a/libsimple/aligned_realloc.h +++ b/libsimple/aligned_realloc.h @@ -29,33 +29,33 @@ * * @since 1.2 */ -_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 */ +inline void * +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) +inline void * +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; } @@ -93,7 +93,7 @@ libsimple_aligned_realloc(void *__ptr, size_t __alignment, size_t __n) * * @since 1.2 */ -_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 @@ -127,9 +127,12 @@ void *libsimple_enaligned_realloc(int, void *, size_t, size_t); * * @since 1.2 */ -_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__))) +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 @@ -163,13 +166,13 @@ static inline void *libsimple_ealigned_realloc(void *__ptr, size_t __alignment, * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +inline void * +libsimple_aligned_reallocf(void *ptr__, size_t alignment__, size_t n__) { - void *__new = __n ? libsimple_aligned_realloc(__ptr, __alignment, __n) : NULL; - if (!__new) - free(__ptr); + void *new__ = n__ ? libsimple_aligned_realloc(ptr__, alignment__, n__) : NULL; + if (!new__) + free(ptr__); return NULL; } #ifndef aligned_reallocf @@ -208,15 +211,15 @@ libsimple_aligned_reallocf(void *__ptr, size_t __alignment, size_t __n) /* TODO * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) +inline void * +libsimple_aligned_reallocarray(void *ptr__, size_t alignment__, size_t n__, size_t m__) { - if (LIBSIMPLE_UMUL_OVERFLOW(__n, __m, &__n, SIZE_MAX)) { + 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 @@ -254,7 +257,7 @@ libsimple_aligned_reallocarray(void *__ptr, size_t __alignment, size_t __n, size * * @since 1.2 */ -_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 @@ -292,9 +295,12 @@ void *libsimple_enaligned_reallocarray(int, void *, size_t, size_t, size_t); * * @since 1.2 */ -_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__))) +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 @@ -327,13 +333,13 @@ static inline void *libsimple_ealigned_reallocarray(void *__ptr, size_t __alignm * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __alloc_size__(3, 4), __warn_unused_result__))) +inline void * +libsimple_aligned_reallocarrayf(void *ptr__, size_t alignment__, size_t n__, size_t m__) { - void *__new = (__n && __m) ? libsimple_aligned_reallocarray(__ptr, __alignment, __n, __m) : NULL; - if (!__new) - free(__ptr); + void *new__ = (n__ && m__) ? libsimple_aligned_reallocarray(ptr__, alignment__, n__, m__) : NULL; + if (!new__) + free(ptr__); return NULL; } #ifndef aligned_reallocarrayf @@ -373,7 +379,7 @@ libsimple_aligned_reallocarrayf(void *__ptr, size_t __alignment, size_t __n, siz * * @since 1.2 */ -_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 @@ -413,7 +419,7 @@ void *libsimple_valigned_reallocn(void *, size_t, size_t, va_list); * * @since 1.2 */ -_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 @@ -452,9 +458,12 @@ void *libsimple_envaligned_reallocn(int, void *, size_t, size_t, va_list); * * @since 1.2 */ -_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__))) +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 @@ -488,14 +497,14 @@ static inline void *libsimple_evaligned_reallocn(void *__ptr, size_t __alignment * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) +inline void * +libsimple_valigned_reallocfn(void *ptr__, size_t alignment__, size_t n__, va_list ap__) { - void *__new = libsimple_valigned_reallocn(__ptr, __alignment, __n, __ap); - if (!__new) - 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 @@ -534,14 +543,14 @@ libsimple_valigned_reallocfn(void *__ptr, size_t __alignment, size_t __n, va_lis * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) +inline void * +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 @@ -581,14 +590,14 @@ libsimple_aligned_reallocn(void *__ptr, size_t __alignment, size_t __n, ... /*, * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -627,14 +636,14 @@ libsimple_enaligned_reallocn(int __status, void *__ptr, size_t __alignment, size * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -673,14 +682,14 @@ libsimple_ealigned_reallocn(void *__ptr, size_t __alignment, size_t __n, ... /*, * * @since 1.2 */ -_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_GCC_ONLY__(__attribute__((__alloc_align__(2), __warn_unused_result__))) +inline void * +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 44b0b5e..a69669d 100644 --- a/libsimple/aligned_strdup.h +++ b/libsimple/aligned_strdup.h @@ -12,18 +12,19 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_strdupa(s, alignment)\ + LIBSIMPLE_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) @@ -40,9 +41,12 @@ * * @since 1.2 */ -_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 @@ -58,7 +62,7 @@ static inline char *libsimple_aligned_strdup(const char * __s, size_t __alignmen * * @since 1.2 */ -_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 @@ -74,9 +78,12 @@ char *libsimple_enaligned_strdup(int, const char *, size_t); * * @since 1.2 */ -_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 5a8ca79..d5b85fd 100644 --- a/libsimple/aligned_strndup.h +++ b/libsimple/aligned_strndup.h @@ -13,20 +13,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_strndupa(s, alignment, n)\ + LIBSIMPLE_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) @@ -44,8 +45,8 @@ * * @since 1.2 */ -_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 @@ -62,7 +63,7 @@ char *libsimple_aligned_strndup(const char * __s, size_t __alignment, size_t __n * * @since 1.2 */ -_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 @@ -79,9 +80,12 @@ char *libsimple_enaligned_strndup(int, const char *, size_t, size_t); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_ealigned_strndup(const char *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_strndup(libsimple_default_failure_exit, __s, __alignment, __n); } +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__) +{ + return libsimple_enaligned_strndup(libsimple_default_failure_exit, s__, alignment__, n__); +} #ifndef ealigned_strndup # define ealigned_strndup libsimple_ealigned_strndup #endif diff --git a/libsimple/aligned_wcsdup.h b/libsimple/aligned_wcsdup.h index d08bcbf..2ea0579 100644 --- a/libsimple/aligned_wcsdup.h +++ b/libsimple/aligned_wcsdup.h @@ -12,18 +12,19 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wcsdupa(s, alignment)\ + LIBSIMPLE_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) @@ -40,9 +41,12 @@ * * @since 1.2 */ -_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 @@ -58,7 +62,7 @@ static inline wchar_t *libsimple_aligned_wcsdup(const wchar_t * __s, size_t __al * * @since 1.2 */ -_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 @@ -74,9 +78,12 @@ wchar_t *libsimple_enaligned_wcsdup(int, const wchar_t *, size_t); * * @since 1.2 */ -_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 5982c0b..faae22d 100644 --- a/libsimple/aligned_wcsndup.h +++ b/libsimple/aligned_wcsndup.h @@ -13,20 +13,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wcsndupa(s, alignment, n)\ + LIBSIMPLE_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) @@ -44,8 +45,8 @@ * * @since 1.2 */ -_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 @@ -62,7 +63,7 @@ wchar_t *libsimple_aligned_wcsndup(const wchar_t * __s, size_t __alignment, size * * @since 1.2 */ -_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 @@ -79,9 +80,12 @@ wchar_t *libsimple_enaligned_wcsndup(int, const wchar_t *, size_t, size_t); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ealigned_wcsndup(const wchar_t *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_wcsndup(libsimple_default_failure_exit, __s, __alignment, __n); } +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__) +{ + return libsimple_enaligned_wcsndup(libsimple_default_failure_exit, s__, alignment__, n__); +} #ifndef ealigned_wcsndup # define ealigned_wcsndup libsimple_ealigned_wcsndup #endif diff --git a/libsimple/aligned_wmemdup.h b/libsimple/aligned_wmemdup.h index d19b826..e6e68d9 100644 --- a/libsimple/aligned_wmemdup.h +++ b/libsimple/aligned_wmemdup.h @@ -13,20 +13,21 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_aligned_wmemdupa(s, alignment, n)\ + LIBSIMPLE_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) @@ -44,7 +45,7 @@ * * @since 1.2 */ -_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 @@ -62,7 +63,7 @@ wchar_t *libsimple_aligned_wmemdup(const wchar_t *, size_t, size_t); * * @since 1.2 */ -_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 @@ -79,9 +80,12 @@ wchar_t *libsimple_enaligned_wmemdup(int, const wchar_t *, size_t, size_t); * * @since 1.2 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__, __returns_nonnull__))) -static inline wchar_t *libsimple_ealigned_wmemdup(const wchar_t *__s, size_t __alignment, size_t __n) -{ return libsimple_enaligned_wmemdup(libsimple_default_failure_exit, __s, __alignment, __n); } +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__) +{ + return libsimple_enaligned_wmemdup(libsimple_default_failure_exit, s__, alignment__, n__); +} #ifndef ealigned_wmemdup # define ealigned_wmemdup libsimple_ealigned_wmemdup #endif diff --git a/libsimple/calloc.h b/libsimple/calloc.h index 2f1bcc6..80a21d4 100644 --- a/libsimple/calloc.h +++ b/libsimple/calloc.h @@ -20,9 +20,12 @@ * * @since 1.0 */ -_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__))) +inline void * +libsimple_vcallocn(size_t n__, va_list ap__) +{ + return libsimple_vmalloczn(1, n__, ap__); +} #ifndef vcallocn # define vcallocn libsimple_vcallocn #endif @@ -47,14 +50,14 @@ static inline void *libsimple_vcallocn(size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_callocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +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 @@ -79,8 +82,11 @@ libsimple_callocn(size_t __n, ... /*, (size_t)0 */) * * @since 1.0 */ -_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 @@ -107,9 +113,12 @@ void *libsimple_encalloc(int, size_t, size_t); * * @since 1.0 */ -_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__))) +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 @@ -136,14 +145,14 @@ static inline void *libsimple_envcallocn(int __status, size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_encallocn(int __status, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -167,9 +176,12 @@ libsimple_encallocn(int __status, size_t __n, ... /*, (size_t)0 */) * * @since 1.0 */ -_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__))) +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 @@ -195,9 +207,12 @@ static inline void *libsimple_ecalloc(size_t __n, size_t __m) * * @since 1.0 */ -_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__))) +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 @@ -223,14 +238,14 @@ static inline void *libsimple_evcallocn(size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_ecallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 b8ae988..4a26b31 100644 --- a/libsimple/env.h +++ b/libsimple/env.h @@ -9,12 +9,12 @@ * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__))) -static inline char * -libsimple_getenv_ne(const char *__name) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__))) +inline char * +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 @@ -29,12 +29,12 @@ libsimple_getenv_ne(const char *__name) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline const char * -libsimple_getenv_e(const char *__name) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __returns_nonnull__))) +inline const char * +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 @@ -56,7 +56,7 @@ libsimple_getenv_e(const char *__name) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 1, 0)))) int libsimple_vputenvf(const char *, va_list); #ifndef vputenvf # define vputenvf libsimple_vputenvf @@ -78,14 +78,14 @@ int libsimple_vputenvf(const char *, va_list); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) -static inline int -libsimple_putenvf(const char *__fmt, ...) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) +inline int +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 @@ -111,7 +111,7 @@ libsimple_putenvf(const char *__fmt, ...) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 2, 0)))) void libsimple_envputenvf(int, const char *, va_list); #ifndef envputenvf # define envputenvf libsimple_envputenvf @@ -137,14 +137,14 @@ void libsimple_envputenvf(int, const char *, va_list); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 2, 3)))) -static inline void -libsimple_enputenvf(int __status, const char *__fmt, ...) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 2, 3)))) +inline void +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 @@ -169,9 +169,12 @@ libsimple_enputenvf(int __status, const char *__fmt, ...) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline void libsimple_evputenvf(const char *__fmt, va_list __ap) -{ libsimple_envputenvf(libsimple_default_failure_exit, __fmt, __ap); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 1, 0)))) +inline void +libsimple_evputenvf(const char *fmt__, va_list ap__) +{ + libsimple_envputenvf(libsimple_default_failure_exit, fmt__, ap__); +} #ifndef evputenvf # define evputenvf libsimple_evputenvf #endif @@ -195,14 +198,14 @@ static inline void libsimple_evputenvf(const char *__fmt, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) -static inline void -libsimple_eputenvf(const char *__fmt, ...) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __format__(__printf__, 1, 2)))) +inline void +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 4309c6d..27c54ba 100644 --- a/libsimple/malloc.h +++ b/libsimple/malloc.h @@ -20,9 +20,12 @@ * * @since 1.0 */ -_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__))) +inline void * +libsimple_vmallocn(size_t n__, va_list ap__) +{ + return libsimple_vmalloczn(0, n__, ap__); +} #ifndef vmallocn # define vmallocn libsimple_vmallocn #endif @@ -47,14 +50,14 @@ static inline void *libsimple_vmallocn(size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_mallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +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 @@ -77,8 +80,11 @@ libsimple_mallocn(size_t __n, ... /*, (size_t)0 */) * * @since 1.0 */ -_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 @@ -105,9 +111,12 @@ void *libsimple_enmalloc(int, size_t); * * @since 1.0 */ -_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__))) +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 @@ -134,14 +143,14 @@ static inline void *libsimple_envmallocn(int __status, size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_enmallocn(int __status, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -163,9 +172,12 @@ libsimple_enmallocn(int __status, size_t __n, ... /*, (size_t)0 */) * * @since 1.0 */ -_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__))) +inline void * +libsimple_emalloc(size_t n__) +{ + return libsimple_enmalloc(libsimple_default_failure_exit, n__); +} #ifndef emalloc # define emalloc libsimple_emalloc #endif @@ -191,9 +203,12 @@ static inline void *libsimple_emalloc(size_t __n) * * @since 1.0 */ -_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__))) +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 @@ -219,14 +234,14 @@ static inline void *libsimple_evmallocn(size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_emallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 6932915..80cdd5f 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 /* } */ @@ -32,7 +38,7 @@ void *libsimple_enmalloc(int, size_t); * * @since 1.0 */ -_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 @@ -53,9 +59,12 @@ void *libsimple_vmalloczn(int, size_t, va_list); * * @since 1.0 */ -_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__))) +inline void * +libsimple_mallocz(int clear__, size_t n__) +{ + return clear__ ? calloc(1, n__) : malloc(n__); +} #ifndef mallocz # define mallocz libsimple_mallocz #endif @@ -81,14 +90,14 @@ static inline void *libsimple_mallocz(int __clear, size_t __n) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_malloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +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 @@ -111,9 +120,12 @@ libsimple_malloczn(int __clear, size_t __n, ... /*, (size_t)0 */) * * @since 1.0 */ -_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__))) +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 @@ -142,7 +154,7 @@ static inline void *libsimple_enmallocz(int __status, int __clear, size_t __n) * * @since 1.0 */ -_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 @@ -172,14 +184,14 @@ void *libsimple_envmalloczn(int, int, size_t, va_list); * * @since 1.0 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -201,9 +213,12 @@ libsimple_enmalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */ * * @since 1.0 */ -_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__))) +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 @@ -230,9 +245,12 @@ static inline void *libsimple_emallocz(int __clear, size_t __n) * * @since 1.0 */ -_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__))) +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 @@ -259,14 +277,14 @@ static inline void *libsimple_evmalloczn(int __clear, size_t __n, va_list __ap) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_emalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 718a99e..2155967 100644 --- a/libsimple/mem.h +++ b/libsimple/mem.h @@ -14,7 +14,7 @@ * * @since 1.1 */ -_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 @@ -34,7 +34,7 @@ void *libsimple_memscan(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -54,7 +54,7 @@ void *libsimple_memcasechr(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -77,7 +77,7 @@ void *libsimple_memcasescan(const void *, int, size_t); * * @since 1.0 */ -_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 @@ -100,7 +100,7 @@ void *libsimple_rawmemchr(const void *, int); * * @since 1.1 */ -_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 @@ -120,7 +120,7 @@ void *libsimple_rawmemcasechr(const void *, int); * * @since 1.0 */ -_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 @@ -140,7 +140,7 @@ void *libsimple_memrchr(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -164,7 +164,7 @@ void *libsimple_memrcasechr(const void *, int, size_t); * * @since 1.0 */ -_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 @@ -188,7 +188,7 @@ void *libsimple_rawmemrchr(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -208,7 +208,7 @@ void *libsimple_rawmemrcasechr(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -228,7 +228,7 @@ void *libsimple_memchr_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -248,7 +248,7 @@ void *libsimple_memscan_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -268,7 +268,7 @@ void *libsimple_memcasechr_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -291,7 +291,7 @@ void *libsimple_memcasescan_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -314,7 +314,7 @@ void *libsimple_rawmemchr_inv(const void *, int); * * @since 1.1 */ -_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 @@ -334,7 +334,7 @@ void *libsimple_rawmemcasechr_inv(const void *, int); * * @since 1.1 */ -_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 @@ -354,7 +354,7 @@ void *libsimple_memrchr_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -378,7 +378,7 @@ void *libsimple_memrcasechr_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -402,7 +402,7 @@ void *libsimple_rawmemrchr_inv(const void *, int, size_t); * * @since 1.1 */ -_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 @@ -422,7 +422,7 @@ void *libsimple_rawmemrcasechr_inv(const void *, int, size_t); * * @since 1.0 */ -_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 @@ -442,7 +442,7 @@ void *libsimple_memmem(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -462,7 +462,7 @@ void *libsimple_memcasemem(const void *, size_t, const void *, size_t); * * @since 1.0 */ -_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 @@ -482,7 +482,7 @@ void *libsimple_memrmem(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -500,7 +500,7 @@ void *libsimple_memrcasemem(const void *, size_t, const void *, size_t); * * @since 1.0 */ -_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 @@ -518,7 +518,7 @@ int libsimple_memstarts(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -536,7 +536,7 @@ int libsimple_memcasestarts(const void *, size_t, const void *, size_t); * * @since 1.0 */ -_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 @@ -554,7 +554,7 @@ int libsimple_memends(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -571,7 +571,7 @@ int libsimple_memcaseends(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -588,9 +588,12 @@ int libsimple_memcasecmp(const void *, const void *, size_t); * * @since 1.1 */ -_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 @@ -606,9 +609,12 @@ static inline int libsimple_memeq(const void *__a, const void *__b, size_t __n) * * @since 1.1 */ -_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 @@ -624,8 +630,11 @@ static inline int libsimple_memcaseeq(const void *__a, const void *__b, size_t _ * * @since 1.0 */ -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 @@ -641,8 +650,11 @@ static inline void *libsimple_mempcpy(void *restrict __d, const void *restrict _ * * @since 1.1 */ -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 @@ -658,8 +670,11 @@ static inline void *libsimple_mempmove(void *__d, const void *__s, size_t __n) * * @since 1.1 */ -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 @@ -680,13 +695,13 @@ static inline void *libsimple_mempset(void *__s, int __c, size_t __n) * * @since 1.1 */ -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 @@ -727,24 +742,24 @@ void *libsimple_memcmove(void *, const void *, int, size_t); * * @since 1.1 */ -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 @@ -763,15 +778,15 @@ libsimple_rawmemcmove(void *__d_, const void *__s_, int __c_) * * @since 1.1 */ -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 @@ -835,8 +850,12 @@ void *libsimple_memptoupper(void *, const void *, size_t); * * @since 1.1 */ -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 @@ -857,8 +876,12 @@ static inline void *libsimple_memtolower(void *__d, const void *__s, size_t __n) * * @since 1.1 */ -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 @@ -876,7 +899,7 @@ static inline void *libsimple_memtoupper(void *__d, const void *__s, size_t __n) * * @since 1.1 */ -_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 @@ -895,7 +918,7 @@ size_t libsimple_memeqlen(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -914,7 +937,7 @@ size_t libsimple_memcaseeqlen(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -933,7 +956,7 @@ size_t libsimple_memreqlen(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 @@ -951,7 +974,7 @@ size_t libsimple_memrcaseeqlen(const void *, size_t, const void *, size_t); * * @since 1.1 */ -_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 20dfebb..4936661 100644 --- a/libsimple/memalign.h +++ b/libsimple/memalign.h @@ -21,9 +21,12 @@ * * @since 1.1 */ -_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__))) +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 @@ -42,9 +45,12 @@ static inline void *libsimple_vmemalignn(size_t __alignment, size_t __n, va_list * * @since 1.1 */ -_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__))) +inline void * +libsimple_memalign(size_t alignment__, size_t n__) +{ + return libsimple_memalignz(0, alignment__, n__); +} #ifndef memalign # define memalign libsimple_memalign #endif @@ -70,14 +76,14 @@ static inline void *libsimple_memalign(size_t __alignment, size_t __n) * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__))) +inline void * +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 @@ -101,9 +107,12 @@ libsimple_memalignn(size_t __alignment, size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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__))) +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 @@ -132,9 +141,12 @@ static inline void *libsimple_enmemalign(int __status, size_t __alignment, size_ * * @since 1.1 */ -_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__))) +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 @@ -163,14 +175,14 @@ static inline void *libsimple_envmemalignn(int __status, size_t __alignment, siz * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -193,9 +205,12 @@ libsimple_enmemalignn(int __status, size_t __alignment, size_t __n, ... /*, (siz * * @since 1.1 */ -_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__))) +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 @@ -224,9 +239,12 @@ static inline void *libsimple_ememalign(size_t __alignment, size_t __n) * * @since 1.1 */ -_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__))) +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 @@ -254,14 +272,14 @@ static inline void *libsimple_evmemalignn(size_t __alignment, size_t __n, va_lis * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(1), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 387e568..9972124 100644 --- a/libsimple/memalignz.h +++ b/libsimple/memalignz.h @@ -22,17 +22,17 @@ * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +inline void * +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 @@ -54,17 +54,17 @@ libsimple_vmemalignzn(int __clear, size_t __alignment, size_t __n, va_list __ap) * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __alloc_size__(3), __warn_unused_result__))) +inline void * +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 @@ -93,14 +93,14 @@ libsimple_memalignz(int __clear, size_t __alignment, size_t __n) * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__))) +inline void * +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 @@ -125,17 +125,17 @@ libsimple_memalignzn(int __clear, size_t __alignment, size_t __n, ... /*, (size_ * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __alloc_size__(4), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -167,18 +167,18 @@ libsimple_enmemalignz(int __status, int __clear, size_t __alignment, size_t __n) * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -210,14 +210,14 @@ libsimple_envmemalignzn(int __status, int __clear, size_t __alignment, size_t __ * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(3), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -241,9 +241,12 @@ libsimple_enmemalignzn(int __status, int __clear, size_t __alignment, size_t __n * * @since 1.1 */ -_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__))) +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 @@ -272,9 +275,12 @@ static inline void *libsimple_ememalignz(int __clear, size_t __alignment, size_t * * @since 1.1 */ -_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__))) +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 @@ -303,14 +309,14 @@ static inline void *libsimple_evmemalignzn(int __clear, size_t __alignment, size * * @since 1.1 */ -_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_GCC_ONLY__(__attribute__((__malloc__, __alloc_align__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +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 13ef889..105bb50 100644 --- a/libsimple/memalloc.h +++ b/libsimple/memalloc.h @@ -93,47 +93,50 @@ enum libsimple_memalloc_option { __VA_ARGS__) /* @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) void *libsimple_vmemalloc(size_t, va_list); /* @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) void *libsimple_envmemalloc(int, size_t, va_list); /* @since 1.1 */ -_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__); +} /* @since 1.1 */ -_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__); } /* @since 1.1 */ -_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__); } /* @since 1.1 */ -_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 8e5b41f..8ab610f 100644 --- a/libsimple/memdup.h +++ b/libsimple/memdup.h @@ -12,11 +12,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_memdupa(s, n)\ + LIBSIMPLE_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) @@ -33,7 +34,7 @@ * * @since 1.0 */ -_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 @@ -50,7 +51,7 @@ void *libsimple_memdup(const void *, size_t); * * @since 1.0 */ -_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 @@ -66,9 +67,12 @@ void *libsimple_enmemdup(int, const void *, size_t); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) -static inline void *libsimple_ememdup(const void *__s, size_t __n) -{ return libsimple_enmemdup(libsimple_default_failure_exit, __s, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__alloc_size__(2), __warn_unused_result__, __returns_nonnull__))) +inline void * +libsimple_ememdup(const void *s__, size_t n__) +{ + return libsimple_enmemdup(libsimple_default_failure_exit, s__, n__); +} #ifndef ememdup # define ememdup libsimple_ememdup #endif diff --git a/libsimple/memelem.h b/libsimple/memelem.h index 10aaef1..f92ac8a 100644 --- a/libsimple/memelem.h +++ b/libsimple/memelem.h @@ -15,7 +15,7 @@ * * @since 1.1 */ -_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 @@ -39,7 +39,7 @@ void *libsimple_memelem(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -61,7 +61,7 @@ void *libsimple_rawmemelem(const void *, const void *, size_t); * * @since 1.1 */ -_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 @@ -82,7 +82,7 @@ void *libsimple_memelemscan(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -107,7 +107,7 @@ void *libsimple_memrelem(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -129,7 +129,7 @@ void *libsimple_rawmemrelem(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -154,7 +154,7 @@ void *libsimple_memelem_inv(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -177,7 +177,7 @@ void *libsimple_rawmemelem_inv(const void *, const void *, size_t); * * @since 1.1 */ -_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 @@ -199,7 +199,7 @@ void *libsimple_memelemscan_inv(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -225,7 +225,7 @@ void *libsimple_memrelem_inv(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -243,7 +243,7 @@ void *libsimple_rawmemrelem_inv(const void *, const void *, size_t, size_t); * * @since 1.1 */ -_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 @@ -261,9 +261,13 @@ void *libsimple_mempsetelem(void *, const void *, size_t, size_t); * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__))) -static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __width, size_t __n) -{ return __item = libsimple_mempsetelem(__buf, __item, __width, __n), __buf; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__warn_unused_result__))) +inline void * +libsimple_memsetelem(void *buf__, const void *item__, size_t width__, size_t n__) +{ + item__ = libsimple_mempsetelem(buf__, item__, width__, n__); + return buf__; +} #ifndef memsetelem # define memsetelem libsimple_memsetelem #endif diff --git a/libsimple/posix_memalign.h b/libsimple/posix_memalign.h index 56e205f..f537d93 100644 --- a/libsimple/posix_memalign.h +++ b/libsimple/posix_memalign.h @@ -27,9 +27,12 @@ * * @since 1.1 */ -_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 @@ -61,14 +64,14 @@ static inline int libsimple_vposix_memalignn(void **__memptr, size_t __alignment * * @since 1.1 */ -_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 @@ -94,9 +97,12 @@ libsimple_posix_memalignn(void **__memptr, size_t __alignment, size_t __n, ... / * * @since 1.1 */ -_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 @@ -127,9 +133,12 @@ static inline void libsimple_enposix_memalign(int __status, void **__memptr, siz * * @since 1.1 */ -_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 @@ -160,14 +169,14 @@ static inline void libsimple_envposix_memalignn(int __status, void **__memptr, s * * @since 1.1 */ -_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 @@ -192,9 +201,12 @@ libsimple_enposix_memalignn(int __status, void **__memptr, size_t __alignment, s * * @since 1.1 */ -_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 @@ -224,9 +236,12 @@ static inline void libsimple_eposix_memalign(void **__memptr, size_t __alignment * * @since 1.1 */ -_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 @@ -256,14 +271,14 @@ static inline void libsimple_evposix_memalignn(void **__memptr, size_t __alignme * * @since 1.1 */ -_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 e604b7d..cf23cd0 100644 --- a/libsimple/posix_memalignz.h +++ b/libsimple/posix_memalignz.h @@ -28,7 +28,7 @@ * * @since 1.1 */ -_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 @@ -56,14 +56,14 @@ int libsimple_vposix_memalignzn(void **, int, size_t, size_t, va_list); * * @since 1.1 */ -_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 @@ -97,14 +97,14 @@ libsimple_posix_memalignz(void **__memptr, int __clear, size_t __alignment, size * * @since 1.1 */ -_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 @@ -131,7 +131,7 @@ libsimple_posix_memalignzn(void **__memptr, int __clear, size_t __alignment, siz * * @since 1.1 */ -_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 @@ -164,7 +164,7 @@ void libsimple_enposix_memalignz(int, void **, int, size_t, size_t); * * @since 1.1 */ -_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 @@ -197,14 +197,14 @@ void libsimple_envposix_memalignzn(int, void **, int, size_t, size_t, va_list); * * @since 1.1 */ -_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 @@ -230,9 +230,12 @@ libsimple_enposix_memalignzn(int __status, void **__memptr, int __clear, size_t * * @since 1.1 */ -_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 @@ -263,9 +266,12 @@ static inline void libsimple_eposix_memalignz(void **__memptr, int __clear, size * * @since 1.1 */ -_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 @@ -296,14 +302,14 @@ static inline void libsimple_evposix_memalignzn(void **__memptr, int __clear, si * * @since 1.1 */ -_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 6bdab79..dd31857 100644 --- a/libsimple/printf.h +++ b/libsimple/printf.h @@ -59,7 +59,7 @@ extern void (*libsimple_eprintf_postprint)(void); * * @since 1.0 */ -_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 @@ -84,7 +84,7 @@ int libsimple_asprintf(char **, const char *, ...); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1, 2)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1, 2), __format__(__printf__, 2, 0)))) int libsimple_vasprintf(char **, const char *, va_list); #ifndef vasprintf # define vasprintf libsimple_vasprintf @@ -107,16 +107,17 @@ int libsimple_vasprintf(char **, const char *, va_list); * @since 1.0 */ #if defined(__GNUC__) || defined(__clang__) -# define libsimple_asprintfa(__fmt, ...)\ +# define libsimple_asprintfa(fmt__, ...)\ + LIBSIMPLE_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__) @@ -140,23 +141,24 @@ int libsimple_vasprintf(char **, const char *, va_list); * @since 1.0 */ #if defined(__GNUC__) || defined(__clang__) -# define libsimple_vasprintfa(__fmt, __ap)\ +# define libsimple_vasprintfa(fmt__, ap__)\ + LIBSIMPLE_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) @@ -183,7 +185,7 @@ int libsimple_vasprintf(char **, const char *, va_list); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1)))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __format__(__printf__, 1, 0)))) void libsimple_vweprintf(const char *, va_list); #ifndef vweprintf # define vweprintf libsimple_vweprintf @@ -209,14 +211,14 @@ void libsimple_vweprintf(const char *, va_list); * * @since 1.0 */ -_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 @@ -245,12 +247,12 @@ libsimple_weprintf(const char *__fmt, ...) * * @since 1.0 */ -_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), __format__(__printf__, 2, 0)))) +inline LIBSIMPLE_NORETURN 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 @@ -279,14 +281,14 @@ libsimple_venprintf(int __status, const char *__fmt, va_list __ap) * * @since 1.0 */ -_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)))) +inline LIBSIMPLE_NORETURN 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 @@ -315,11 +317,11 @@ libsimple_enprintf(int __status, const char *__fmt, ...) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(1), __noreturn__))) -static inline void -libsimple_veprintf(const char *__fmt, va_list __ap) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __format__(__printf__, 1, 0)))) +inline LIBSIMPLE_NORETURN void +libsimple_veprintf(const char *fmt__, va_list ap__) { - libsimple_vweprintf(__fmt, __ap); + libsimple_vweprintf(fmt__, ap__); exit(libsimple_default_failure_exit); } #ifndef veprintf @@ -349,14 +351,14 @@ libsimple_veprintf(const char *__fmt, va_list __ap) * * @since 1.0 */ -_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)))) +inline LIBSIMPLE_NORETURN 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 a858221..84aadef 100644 --- a/libsimple/pvalloc.h +++ b/libsimple/pvalloc.h @@ -23,9 +23,12 @@ * * @since 1.1 */ -_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 @@ -47,9 +50,12 @@ static inline void *libsimple_vpvallocn(size_t __n, va_list __ap) * * @since 1.1 */ -_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 @@ -77,14 +83,14 @@ static inline void *libsimple_pvalloc(size_t __n) * * @since 1.1 */ -_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 @@ -111,9 +117,12 @@ libsimple_pvallocn(size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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 @@ -144,9 +153,12 @@ static inline void *libsimple_enpvalloc(int __status, size_t __n) * * @since 1.1 */ -_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 @@ -177,14 +189,14 @@ static inline void *libsimple_envpvallocn(int __status, size_t __n, va_list __ap * * @since 1.1 */ -_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 @@ -210,9 +222,12 @@ libsimple_enpvallocn(int __status, size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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 @@ -242,9 +257,12 @@ static inline void *libsimple_epvalloc(size_t __n) * * @since 1.1 */ -_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 @@ -274,14 +292,14 @@ static inline void *libsimple_evpvallocn(size_t __n, va_list __ap) * * @since 1.1 */ -_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 5809df7..a4a6498 100644 --- a/libsimple/pvallocz.h +++ b/libsimple/pvallocz.h @@ -24,12 +24,12 @@ * * @since 1.1 */ -_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); @@ -56,12 +56,12 @@ libsimple_vpvalloczn(int __clear, size_t __n, va_list __ap) * * @since 1.1 */ -_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); @@ -94,14 +94,14 @@ libsimple_pvallocz(int __clear, size_t __n) * * @since 1.1 */ -_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 @@ -129,12 +129,12 @@ libsimple_pvalloczn(int __clear, size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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); @@ -171,13 +171,13 @@ libsimple_enpvallocz(int __status, int __clear, size_t __n) * * @since 1.1 */ -_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); @@ -214,14 +214,14 @@ libsimple_envpvalloczn(int __status, int __clear, size_t __n, va_list __ap) * * @since 1.1 */ -_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 @@ -248,9 +248,12 @@ libsimple_enpvalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 * * * @since 1.1 */ -_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 @@ -281,9 +284,12 @@ static inline void *libsimple_epvallocz(int __clear, size_t __n) * * @since 1.1 */ -_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 @@ -314,14 +320,14 @@ static inline void *libsimple_evpvalloczn(int __clear, size_t __n, va_list __ap) * * @since 1.1 */ -_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 0d487f5..37d4031 100644 --- a/libsimple/realloc.h +++ b/libsimple/realloc.h @@ -28,7 +28,7 @@ * * @since 1.0 */ -_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 @@ -62,14 +62,14 @@ void *libsimple_vreallocn(void *, size_t, va_list); * * @since 1.0 */ -_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 @@ -101,7 +101,7 @@ libsimple_reallocn(void *__ptr, size_t __n, ... /*, (size_t)0 */) * * @since 1.0 */ -_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 @@ -138,7 +138,7 @@ void *libsimple_enrealloc(int, void *, size_t); * * @since 1.0 */ -_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 @@ -175,14 +175,14 @@ void *libsimple_envreallocn(int, void *, size_t, va_list); * * @since 1.0 */ -_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 @@ -213,9 +213,12 @@ libsimple_enreallocn(int __status, void *__ptr, size_t __n, ... /*, (size_t)0 */ * * @since 1.0 */ -_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 @@ -250,9 +253,12 @@ static inline void *libsimple_erealloc(void *__ptr, size_t __n) * * @since 1.0 */ -_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 @@ -287,14 +293,14 @@ static inline void *libsimple_evreallocn(void *__ptr, size_t __n, va_list __ap) * * @since 1.0 */ -_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 @@ -325,14 +331,14 @@ libsimple_ereallocn(void *__ptr, size_t __n, ... /*, (size_t)0 */) * * @since 1.2 */ -_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 @@ -365,15 +371,15 @@ libsimple_reallocf(void *__ptr, size_t __n) /* TODO test */ * * @since 1.2 */ -_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 @@ -408,7 +414,7 @@ libsimple_reallocarray(void *__ptr, size_t __n, size_t __m) * * @since 1.2 */ -_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 @@ -443,9 +449,12 @@ void *libsimple_enreallocarray(int, void *, size_t, size_t); * * @since 1.2 */ -_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 @@ -477,14 +486,14 @@ static inline void *libsimple_ereallocarray(void *__ptr, size_t __n, size_t __m) * * @since 1.2 */ -_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 @@ -518,14 +527,14 @@ libsimple_reallocarrayf(void *__ptr, size_t __n, size_t __m) /* TODO test */ * * @since 1.2 */ -_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 @@ -559,14 +568,14 @@ libsimple_vreallocfn(void *__ptr, size_t __n, va_list __ap) /* TODO test (reallo * * @since 1.2 */ -_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/search.h b/libsimple/search.h new file mode 100644 index 0000000..19c1f85 --- /dev/null +++ b/libsimple/search.h @@ -0,0 +1,69 @@ +/* See LICENSE file for copyright and license details. */ + + +/** + * Find, using binary search, the position where an item in + * sorted list is located or should be located + * + * @param key The item to find the position for + * @param base Sorted array to search + * @param nel The number of elements in `base` + * @param width The byte-width of each element in `base` + * @param compar Function used to compare `key` against an element + * in the array. The function be given two arguments: + * the first argument will always be `key`, the other + * will be an element in `base`. The function shall + * return a negative value if first argument shall + * precede the second argument when sorted into the + * list, or a positive value if the first argument + * shall succeed the second argument, but if the + * two argument are equal, the function shall return 0. + * @return If the function finds `key` in `base`, it returns + * the index (starting from 0) of some such element + * in `base`, however if `key` is not found, the + * function returns the bitwise complement the index + * to each `key` may be inserted. + * + * @seealso bsearch(3p) + * @seealso libsimple_bindex_r(3p) + */ +ssize_t libsimple_bindex(const void *key, const void *base, size_t nel, size_t width, /* TODO man */ + int (*compar)(const void *, const void *)); +#ifndef bindex +# define bindex(...) libsimple_bindex(__VA_ARGS__) +#endif + +/** + * Find, using binary search, the position where an item in + * sorted list is located or should be located + * + * @param key The item to find the position for + * @param base Sorted array to search + * @param nel The number of elements in `base` + * @param width The byte-width of each element in `base` + * @param compar Function used to compare `key` against an element + * in the array. The function be given three arguments: + * the first argument will always be `key`, the second + * will be an element in `base`, and the third will + * always be `arg`. The function shall return a negative + * value if first argument shall precede the second + * argument when sorted into the list, or a positive + * value if the first argument shall succeed the second + * argument, but if the two argument are equal, the + * function shall return 0. + * @param arg User-defined value that is passed directly into + * `compar` as the third argument at each callback + * @return If the function finds `key` in `base`, it returns + * the index (starting from 0) of some such element + * in `base`, however if `key` is not found, the + * function returns the bitwise complement the index + * to each `key` may be inserted. + * + * @seealso bsearch(3p) + * @seealso libsimple_bindex(3p) + */ +ssize_t libsimple_bindex_r(const void *key, const void *base, size_t nel, size_t width, /* TODO man */ + int (*compar)(const void *, const void *, void *), void *arg); +#ifndef bindex_r +# define bindex_r(...) libsimple_bindex_r(__VA_ARGS__) +#endif diff --git a/libsimple/str.h b/libsimple/str.h index 4c17a0a..8970bf7 100644 --- a/libsimple/str.h +++ b/libsimple/str.h @@ -11,7 +11,7 @@ * * @since 1.0 */ -_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 @@ -28,7 +28,7 @@ char *libsimple_strchrnul(const char *, int); * * @since 1.1 */ -_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 @@ -45,7 +45,7 @@ char *libsimple_strcasechr(const char *, int); * * @since 1.1 */ -_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 @@ -62,7 +62,7 @@ char *libsimple_strcasechrnul(const char *, int); * * @since 1.1 */ -_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 @@ -80,7 +80,7 @@ char *libsimple_strrcasechr(const char *, int); * * @since 1.1 */ -_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 @@ -98,7 +98,7 @@ char *libsimple_strchr_inv(const char *, int); * * @since 1.1 */ -_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 @@ -116,7 +116,7 @@ char *libsimple_strchrnul_inv(const char *, int); * * @since 1.1 */ -_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 @@ -134,7 +134,7 @@ char *libsimple_strcasechr_inv(const char *, int); * * @since 1.1 */ -_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 @@ -152,7 +152,7 @@ char *libsimple_strcasechrnul_inv(const char *, int); * * @since 1.1 */ -_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 @@ -170,7 +170,7 @@ char *libsimple_strrchr_inv(const char *, int); * * @since 1.1 */ -_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 @@ -185,9 +185,12 @@ char *libsimple_strrcasechr_inv(const char *, int); * * @since 1.0 */ -_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__))) +inline char * +libsimple_strend(const char *s__) +{ + return strchr(s__, '\0'); +} #ifndef strend # define strend libsimple_strend #endif @@ -202,7 +205,7 @@ static inline char *libsimple_strend(const char *__s) * * @since 1.0 */ -_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 @@ -218,9 +221,12 @@ int libsimple_strstarts(const char *, const char *); * * @since 1.0 */ -_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__))) +inline int +libsimple_strcasestarts(const char *s__, const char *t__) +{ + return !strncasecmp(s__, t__, strlen(t__)); +} #ifndef strcasestarts # define strcasestarts libsimple_strcasestarts #endif @@ -235,7 +241,7 @@ static inline int libsimple_strcasestarts(const char *__s, const char *__t) * * @since 1.0 */ -_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 @@ -251,7 +257,7 @@ int libsimple_strends(const char *, const char *); * * @since 1.0 */ -_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 @@ -269,7 +275,7 @@ int libsimple_strcaseends(const char *, const char *); * * @since 1.0 */ -_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 @@ -287,7 +293,7 @@ char *libsimple_strrstr(const char *, const char *); * * @since 1.0 */ -_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 @@ -305,7 +311,7 @@ char *libsimple_strcasestr(const char *, const char *); * * @since 1.0 */ -_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 @@ -324,9 +330,12 @@ char *libsimple_strrcasestr(const char *, const char *); * * @since 1.0 */ -_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__))) +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 @@ -344,9 +353,12 @@ static inline int libsimple_strcmpnul(const char *__a, const char *__b) * * @since 1.0 */ -_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__))) +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 @@ -362,9 +374,12 @@ static inline int libsimple_strcasecmpnul(const char *__a, const char *__b) * * @since 1.0 */ -_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__))) +inline int +libsimple_streq(const char *a__, const char *b__) +{ + return !strcmp(a__, b__); +} #ifndef streq # define streq libsimple_streq #endif @@ -380,9 +395,12 @@ static inline int libsimple_streq(const char *__a, const char *__b) * * @since 1.0 */ -_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__))) +inline int +libsimple_streqnul(const char *a__, const char *b__) +{ + return !libsimple_strcmpnul(a__, b__); +} #ifndef streqnul # define streqnul libsimple_streqnul #endif @@ -398,9 +416,12 @@ static inline int libsimple_streqnul(const char *__a, const char *__b) * * @since 1.0 */ -_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__))) +inline int +libsimple_strcaseeq(const char *a__, const char *b__) +{ + return !strcasecmp(a__, b__); +} #ifndef strcaseeq # define strcaseeq libsimple_strcaseeq #endif @@ -416,9 +437,12 @@ static inline int libsimple_strcaseeq(const char *__a, const char *__b) * * @since 1.0 */ -_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__))) +inline int +libsimple_strcaseeqnul(const char *a__, const char *b__) +{ + return !libsimple_strcasecmpnul(a__, b__); +} #ifndef strcaseeqnul # define strcaseeqnul libsimple_strcaseeqnul #endif @@ -434,7 +458,7 @@ static inline int libsimple_strcaseeqnul(const char *__a, const char *__b) * * @since 1.1 */ -_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 @@ -451,7 +475,7 @@ size_t libsimple_streqlen(const char *, const char *); * * @since 1.1 */ -_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 @@ -468,9 +492,12 @@ size_t libsimple_strcaseeqlen(const char *, const char *); * * @since 1.1 */ -_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__))) +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 @@ -486,9 +513,12 @@ static inline size_t libsimple_strreqlen(const char *__a, const char *__b) * * @since 1.1 */ -_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__))) +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 @@ -504,9 +534,12 @@ static inline size_t libsimple_strrcaseeqlen(const char *__a, const char *__b) * * @since 1.0 */ -_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__))) +inline int +libsimple_inchrset(int c__, const char *s__) +{ + return c__ && strchr(s__, c__); +} #ifndef inchrset # define inchrset libsimple_inchrset #endif @@ -522,9 +555,12 @@ static inline int libsimple_inchrset(int __c, const char *__s) * * @since 1.1 */ -_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__))) +inline int +libsimple_inchrcaseset(int c__, const char *s__) +{ + return c__ && strcasechr(s__, c__); +} #ifndef inchrcaseset # define inchrcaseset libsimple_inchrcaseset #endif @@ -540,9 +576,12 @@ static inline int libsimple_inchrcaseset(int __c, const char *__s) * * @since 1.1 */ -_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__))) +inline char * +libsimple_strmove(char *d__, const char *s__) +{ + return memmove(d__, s__, strlen(s__) + 1); +} #ifndef strmove # define strmove libsimple_strmove #endif @@ -558,9 +597,14 @@ static inline char *libsimple_strmove(char *__d, const char *__s) * * @since 1.1 */ -_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__))) +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 @@ -575,13 +619,13 @@ static inline char *libsimple_stpmove(char *__d, const char *__s) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_strset(char *__s, int __c_) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -597,13 +641,13 @@ libsimple_strset(char *__s, int __c_) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_stpset(char *__s, int __c_) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -622,15 +666,17 @@ libsimple_stpset(char *__s, int __c_) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_strccpy(char *restrict __d, const char *restrict __s, int __c_) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -649,7 +695,7 @@ libsimple_strccpy(char *restrict __d, const char *restrict __s, int __c_) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) char *libsimple_strcmove(char *, const char *, int); #ifndef strcmove # define strcmove libsimple_strcmove @@ -667,15 +713,15 @@ char *libsimple_strcmove(char *, const char *, int); * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * -libsimple_strreplace(char *__s, int __old_, int __new_) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) +inline char * +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 @@ -696,7 +742,7 @@ libsimple_strreplace(char *__s, int __old_, int __new_) * * @since 1.1 */ -_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 @@ -717,7 +763,7 @@ char *libsimple_stptolower(char *, const char *); * * @since 1.1 */ -_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 @@ -738,9 +784,13 @@ char *libsimple_stptoupper(char *, const char *); * * @since 1.1 */ -_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__))) +inline char * +libsimple_strtolower(char *d__, const char *s__) +{ + libsimple_stptolower(d__, s__); + return d__; +} #ifndef strtolower # define strtolower libsimple_strtolower #endif @@ -760,9 +810,13 @@ static inline char *libsimple_strtolower(char *__d, const char *__s) * * @since 1.1 */ -_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__))) +inline char * +libsimple_strtoupper(char *d__, const char *s__) +{ + libsimple_stptoupper(d__, s__); + return d__; +} #ifndef strtoupper # define strtoupper libsimple_strtoupper #endif @@ -778,9 +832,12 @@ static inline char *libsimple_strtoupper(char *__d, const char *__s) * * @since 1.1 */ -_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__))) +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 3db9d95..ed1e9e4 100644 --- a/libsimple/strdup.h +++ b/libsimple/strdup.h @@ -11,11 +11,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_strdupa(s)\ + LIBSIMPLE_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) @@ -32,7 +33,7 @@ * * @since 1.0 */ -_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 @@ -47,9 +48,12 @@ char *libsimple_enstrdup(int, const char *); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_estrdup(const char *__s) -{ return libsimple_enstrdup(libsimple_default_failure_exit, __s); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +inline char * +libsimple_estrdup(const char *s__) +{ + return libsimple_enstrdup(libsimple_default_failure_exit, s__); +} #ifndef estrdup # define estrdup libsimple_estrdup #endif diff --git a/libsimple/strn.h b/libsimple/strn.h index dc6e695..91bce69 100644 --- a/libsimple/strn.h +++ b/libsimple/strn.h @@ -13,7 +13,7 @@ * * @since 1.1 */ -_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 @@ -32,7 +32,7 @@ char *libsimple_strnchr(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -51,7 +51,7 @@ char *libsimple_strncasechr(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -70,7 +70,7 @@ char *libsimple_strnchrnul(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -88,7 +88,7 @@ char *libsimple_strncasechrnul(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -107,7 +107,7 @@ char *libsimple_strrnchr(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -127,7 +127,7 @@ char *libsimple_strrncasechr(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -147,7 +147,7 @@ char *libsimple_strnchr_inv(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -167,7 +167,7 @@ char *libsimple_strncasechr_inv(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -187,7 +187,7 @@ char *libsimple_strnchrnul_inv(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -206,7 +206,7 @@ char *libsimple_strncasechrnul_inv(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -225,7 +225,7 @@ char *libsimple_strrnchr_inv(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -244,7 +244,7 @@ char *libsimple_strrncasechr_inv(const char *, int, size_t); * * @since 1.1 */ -_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 @@ -261,7 +261,7 @@ char *libsimple_strnend(const char *, size_t); * * @since 1.1 */ -_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 @@ -278,7 +278,7 @@ int libsimple_strnstarts(const char *, const char *, size_t); * * @since 1.1 */ -_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 @@ -295,7 +295,7 @@ int libsimple_strncasestarts(const char *, const char *, size_t); * * @since 1.1 */ -_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 @@ -312,7 +312,7 @@ int libsimple_strnends(const char *, const char *, size_t); * * @since 1.1 */ -_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 @@ -331,7 +331,7 @@ int libsimple_strncaseends(const char *, const char *, size_t); * * @since 1.0 */ -_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 @@ -350,7 +350,7 @@ char *libsimple_strnstr(const char *, const char *, size_t); * * @since 1.0 */ -_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 @@ -369,7 +369,7 @@ char *libsimple_strncasestr(const char *, const char *, size_t); * * @since 1.0 */ -_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 @@ -388,7 +388,7 @@ char *libsimple_strrnstr(const char *, const char *, size_t); * * @since 1.0 */ -_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 @@ -409,9 +409,12 @@ char *libsimple_strrncasestr(const char *, const char *, size_t); * * @since 1.0 */ -_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__))) +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 @@ -431,9 +434,12 @@ static inline int libsimple_strncmpnul(const char *__a, const char *__b, size_t * * @since 1.0 */ -_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__))) +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 @@ -451,9 +457,12 @@ static inline int libsimple_strncasecmpnul(const char *__a, const char *__b, siz * * @since 1.0 */ -_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__))) +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 @@ -471,9 +480,12 @@ static inline int libsimple_strneq(const char *__a, const char *__b, size_t __n) * * @since 1.0 */ -_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__))) +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 @@ -491,9 +503,12 @@ static inline int libsimple_strneqnul(const char *__a, const char *__b, size_t _ * * @since 1.0 */ -_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__))) +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 @@ -511,9 +526,12 @@ static inline int libsimple_strncaseeq(const char *__a, const char *__b, size_t * * @since 1.0 */ -_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__))) +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 @@ -531,7 +549,7 @@ static inline int libsimple_strncaseeqnul(const char *__a, const char *__b, size * * @since 1.1 */ -_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 @@ -550,7 +568,7 @@ size_t libsimple_strneqlen(const char *, const char *, size_t); * * @since 1.1 */ -_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 @@ -569,9 +587,12 @@ size_t libsimple_strncaseeqlen(const char *, const char *, size_t); * * @since 1.1 */ -_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__))) +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 @@ -589,9 +610,12 @@ static inline size_t libsimple_strrneqlen(const char *__a, const char *__b, size * * @since 1.1 */ -_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__))) +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 @@ -608,9 +632,13 @@ static inline size_t libsimple_strrncaseeqlen(const char *__a, const char *__b, * * @since 1.1 */ -_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__))) +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 @@ -627,13 +655,13 @@ static inline char *libsimple_strnmove(char *__d, const char *__s, size_t __n) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_stpnmove(char *__d, const char *__s, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -650,13 +678,13 @@ libsimple_stpnmove(char *__d, const char *__s, size_t __n) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_strnset(char *__s, int __c_, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -673,13 +701,13 @@ libsimple_strnset(char *__s, int __c_, size_t __n) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_stpnset(char *__s, int __c_, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -700,21 +728,21 @@ libsimple_stpnset(char *__s, int __c_, size_t __n) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) -static inline char * -libsimple_strnccpy(char *restrict __d, const char *restrict __s, int __c_, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) +inline char * +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 @@ -735,7 +763,7 @@ libsimple_strnccpy(char *restrict __d, const char *restrict __s, int __c_, size_ * * @since 1.1 */ -_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 @@ -754,15 +782,15 @@ char *libsimple_strncmove(char *, const char *, int, size_t); * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__))) -static inline char * -libsimple_strnreplace(char *__s, int __old_, int __new_, size_t __n) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__, __returns_nonnull__))) +inline char * +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 @@ -784,7 +812,7 @@ libsimple_strnreplace(char *__s, int __old_, int __new_, size_t __n) * * @since 1.1 */ -_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 @@ -806,7 +834,7 @@ char *libsimple_stpntolower(char *, const char *, size_t); * * @since 1.1 */ -_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 @@ -828,9 +856,13 @@ char *libsimple_stpntoupper(char *, const char *, size_t); * * @since 1.1 */ -_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__))) +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 @@ -851,9 +883,13 @@ static inline char *libsimple_strntolower(char *__d, const char *__s, size_t __n * * @since 1.1 */ -_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__))) +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 @@ -873,9 +909,12 @@ static inline char *libsimple_strntoupper(char *__d, const char *__s, size_t __n * * @since 1.1 */ -_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__))) +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 b3229d5..3229e01 100644 --- a/libsimple/strndup.h +++ b/libsimple/strndup.h @@ -12,14 +12,15 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_strndupa(s, n)\ + LIBSIMPLE_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) @@ -37,7 +38,7 @@ * * @since 1.0 */ -_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 @@ -53,9 +54,12 @@ char *libsimple_enstrndup(int, const char *, size_t); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) -static inline char *libsimple_estrndup(const char *__s, size_t __n) -{ return libsimple_enstrndup(libsimple_default_failure_exit, __s, __n); } +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __assume_aligned__(1), __nonnull__, __warn_unused_result__, __returns_nonnull__))) +inline char * +libsimple_estrndup(const char *s__, size_t n__) +{ + return libsimple_enstrndup(libsimple_default_failure_exit, s__, n__); +} #ifndef estrndup # define estrndup libsimple_estrndup #endif diff --git a/libsimple/strtoint.h b/libsimple/strtoint.h new file mode 100644 index 0000000..d7fc292 --- /dev/null +++ b/libsimple/strtoint.h @@ -0,0 +1,377 @@ +/* See LICENSE file for copyright and license details. */ + + +/** + * Converts a string to a `signed char` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +signed char libsimple_strtohh(const char *restrict, char **restrict, int); +#ifndef strtohh +# define strtohh libsimple_strtohh +#endif + + +/** + * Converts a string to a `unsigned char` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +unsigned char libsimple_strtouhh(const char *restrict, char **restrict, int); +#ifndef strtouhh +# define strtouhh libsimple_strtouhh +#endif + + +/** + * Converts a string to a `signed short int` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +signed short int libsimple_strtoh(const char *restrict, char **restrict, int); +#ifndef strtoh +# define strtoh libsimple_strtoh +#endif + + +/** + * Converts a string to a `unsigned short int` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +unsigned short int libsimple_strtouh(const char *restrict, char **restrict, int); +#ifndef strtouh +# define strtouh libsimple_strtouh +#endif + + +/** + * Converts a string to a `signed int` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +signed int libsimple_strtoi(const char *restrict, char **restrict, int); +#ifndef strtoi +# define strtoi libsimple_strtoi +#endif + + +/** + * Converts a string to a `unsigned int` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +unsigned int libsimple_strtou(const char *restrict, char **restrict, int); +#ifndef strtou +# define strtou libsimple_strtou +#endif + + +/** + * Converts a string to a `ssize_t` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +inline ssize_t +libsimple_strtoz(const char *restrict nptr__, char **restrict endptr__, int base__) +{ + return (ssize_t)strtol(nptr__, endptr__, base__); +} +#ifndef strtoz +# define strtoz libsimple_strtoz +#endif + + +/** + * Converts a string to a `size_t` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +inline size_t +libsimple_strtouz(const char *restrict nptr__, char **restrict endptr__, int base__) +{ + return (size_t)strtoul(nptr__, endptr__, base__); +} +#ifndef strtouz +# define strtouz libsimple_strtouz +#endif + + +/** + * Converts a string to a `int8_t` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +int_least8_t libsimple_strtoi8(const char *restrict, char **restrict, int); +#ifndef strtoi8 +# define strtoi8 libsimple_strtoi8 +#endif + + +/** + * Converts a string to a `uint8_t` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +uint_least8_t libsimple_strtou8(const char *restrict, char **restrict, int); +#ifndef strtou8 +# define strtou8 libsimple_strtou8 +#endif + + +/** + * Converts a string to a `int16_t` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +int_least16_t libsimple_strtoi16(const char *restrict, char **restrict, int); +#ifndef strtoi16 +# define strtoi16 libsimple_strtoi16 +#endif + + +/** + * Converts a string to a `uint16_t` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +uint_least16_t libsimple_strtou16(const char *restrict, char **restrict, int); +#ifndef strtou16 +# define strtou16 libsimple_strtou16 +#endif + + +/** + * Converts a string to a `int32_t` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +int_least32_t libsimple_strtoi32(const char *restrict, char **restrict, int); +#ifndef strtoi32 +# define strtoi32 libsimple_strtoi32 +#endif + + +/** + * Converts a string to a `uint32_t` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +uint_least32_t libsimple_strtou32(const char *restrict, char **restrict, int); +#ifndef strtou32 +# define strtou32 libsimple_strtou32 +#endif + + +/** + * Converts a string to a `int64_t` + * according to the rules of strtol(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +int_least64_t libsimple_strtoi64(const char *restrict, char **restrict, int); +#ifndef strtoi64 +# define strtoi64 libsimple_strtoi64 +#endif + + +/** + * Converts a string to a `uint64_t` + * according to the rules of strtoul(3) + * + * @param nptr The string to parse + * @param endptr Output parameter for the position in `nptr` + * where the first character that is not part + * of the interpreted value resides + * @param base The base the value is encoded in, 0 if + * the function shall accept a prefix to + * specify the base if it is not 10 + * @return The encoded value (`errno` is unchanges), or + * if out of range (`errno` set to `ERANGE`), the + * closed value that can be represented; 0 on + * failure (unless `errno` not set to `ERANGE`) + */ +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__))) +uint_least64_t libsimple_strtou64(const char *restrict, char **restrict, int); +#ifndef strtou64 +# define strtou64 libsimple_strtou64 +#endif diff --git a/libsimple/time.h b/libsimple/time.h index aa92314..b873635 100644 --- a/libsimple/time.h +++ b/libsimple/time.h @@ -15,7 +15,7 @@ * * @since 1.0 */ -_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 @@ -36,7 +36,7 @@ int libsimple_sumtimespec(struct timespec *, const struct timespec *, const stru * * @since 1.0 */ -_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 @@ -57,7 +57,7 @@ int libsimple_difftimespec(struct timespec *, const struct timespec *, const str * * @since 1.0 */ -_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 @@ -73,13 +73,13 @@ int libsimple_multimespec(struct timespec *, const struct timespec *, int); * * @since 1.0 */ -_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 @@ -100,7 +100,7 @@ libsimple_cmptimespec(const struct timespec *__a, const struct timespec *__b) * * @since 1.0 */ -_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 @@ -121,7 +121,7 @@ int libsimple_sumtimeval(struct timeval *, const struct timeval *, const struct * * @since 1.0 */ -_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 @@ -142,7 +142,7 @@ int libsimple_difftimeval(struct timeval *, const struct timeval *, const struct * * @since 1.0 */ -_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 @@ -158,13 +158,13 @@ int libsimple_multimeval(struct timeval *, const struct timeval *, int); * * @since 1.0 */ -_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 @@ -179,13 +179,13 @@ libsimple_cmptimeval(const struct timeval *__a, const struct timeval *__b) * * @since 1.0 */ -_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 @@ -203,7 +203,7 @@ libsimple_timeval2timespec(struct timespec *restrict __ts, const struct timeval * * @since 1.0 */ -_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 @@ -230,7 +230,7 @@ int libsimple_timespec2timeval(struct timeval *restrict, const struct timespec * * * @since 1.0 */ -_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 @@ -257,7 +257,7 @@ int libsimple_strtotimespec(struct timespec *restrict, const char *restrict, cha * * @since 1.0 */ -_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 @@ -278,7 +278,7 @@ int libsimple_strtotimeval(struct timeval *restrict, const char *restrict, char * * @since 1.0 */ -_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 @@ -299,7 +299,7 @@ char *libsimple_timespectostr(char *restrict, const struct timespec *restrict); * * @since 1.0 */ -_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 @@ -314,14 +314,14 @@ char *libsimple_timevaltostr(char *restrict, const struct timeval *restrict); * * @since 1.0 */ -_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 @@ -336,14 +336,14 @@ libsimple_timespectodouble(const struct timespec *__ts) * * @since 1.0 */ -_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 @@ -360,7 +360,7 @@ libsimple_timevaltodouble(const struct timeval *__tv) * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) void libsimple_doubletotimespec(struct timespec *, double); #ifndef doubletotimespec # define doubletotimespec libsimple_doubletotimespec @@ -377,7 +377,7 @@ void libsimple_doubletotimespec(struct timespec *, double); * * @since 1.0 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__))) +LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__))) void libsimple_doubletotimeval(struct timeval *, double); #ifndef doubletotimeval # define doubletotimeval libsimple_doubletotimeval @@ -394,7 +394,7 @@ void libsimple_doubletotimeval(struct timeval *, double); * * @since 1.0 */ -_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 @@ -412,7 +412,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 *); /** @@ -430,7 +430,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 *); /** @@ -447,9 +447,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__); +} /** @@ -463,7 +466,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 *); /** @@ -481,7 +484,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 *); /** @@ -498,6 +501,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 07e9b95..eb86e08 100644 --- a/libsimple/valloc.h +++ b/libsimple/valloc.h @@ -19,9 +19,12 @@ * * @since 1.1 */ -_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__))) +inline void * +libsimple_vvallocn(size_t n__, va_list ap__) +{ + return libsimple_vvalloczn(0, n__, ap__); +} #ifndef vvallocn # define vvallocn libsimple_vvallocn #endif @@ -39,9 +42,12 @@ static inline void *libsimple_vvallocn(size_t __n, va_list __ap) * * @since 1.1 */ -_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__))) +inline void * +libsimple_valloc(size_t n__) +{ + return libsimple_vallocz(0, n__); +} #ifndef valloc # define valloc libsimple_valloc #endif @@ -65,14 +71,14 @@ static inline void *libsimple_valloc(size_t __n) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__))) -static inline void * -libsimple_vallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__))) +inline void * +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 @@ -95,9 +101,12 @@ libsimple_vallocn(size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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__))) +inline void * +libsimple_envalloc(int status__, size_t n__) +{ + return libsimple_envallocz(status__, 0, n__); +} #ifndef envalloc # define envalloc libsimple_envalloc #endif @@ -124,9 +133,12 @@ static inline void *libsimple_envalloc(int __status, size_t __n) * * @since 1.1 */ -_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__))) +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 @@ -153,14 +165,14 @@ static inline void *libsimple_envvallocn(int __status, size_t __n, va_list __ap) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_envallocn(int __status, size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 @@ -182,9 +194,12 @@ libsimple_envallocn(int __status, size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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__))) +inline void * +libsimple_evalloc(size_t n__) +{ + return libsimple_envalloc(libsimple_default_failure_exit, n__); +} #ifndef evalloc # define evalloc libsimple_evalloc #endif @@ -210,9 +225,12 @@ static inline void *libsimple_evalloc(size_t __n) * * @since 1.1 */ -_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__))) +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 @@ -238,14 +256,14 @@ static inline void *libsimple_evvallocn(size_t __n, va_list __ap) * * @since 1.1 */ -_LIBSIMPLE_GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) -static inline void * -libsimple_evallocn(size_t __n, ... /*, (size_t)0 */) +LIBSIMPLE_GCC_ONLY__(__attribute__((__malloc__, __warn_unused_result__, __returns_nonnull__))) +inline void * +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 f651584..337dc88 100644 --- a/libsimple/vallocz.h +++ b/libsimple/vallocz.h @@ -20,12 +20,12 @@ * * @since 1.1 */ -_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); } @@ -47,12 +47,12 @@ libsimple_vvalloczn(int __clear, size_t __n, va_list __ap) * * @since 1.1 */ -_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); } @@ -80,14 +80,14 @@ libsimple_vallocz(int __clear, size_t __n) * * @since 1.1 */ -_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 @@ -111,12 +111,12 @@ libsimple_valloczn(int __clear, size_t __n, ... /*, (size_t)0 */) * * @since 1.1 */ -_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); } @@ -148,13 +148,13 @@ libsimple_envallocz(int __status, int __clear, size_t __n) * * @since 1.1 */ -_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); } @@ -186,14 +186,14 @@ libsimple_envvalloczn(int __status, int __clear, size_t __n, va_list __ap) * * @since 1.1 */ -_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 @@ -216,9 +216,12 @@ libsimple_envalloczn(int __status, int __clear, size_t __n, ... /*, (size_t)0 */ * * @since 1.1 */ -_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 @@ -245,9 +248,12 @@ static inline void *libsimple_evallocz(int __clear, size_t __n) * * @since 1.1 */ -_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 @@ -274,14 +280,14 @@ static inline void *libsimple_evvalloczn(int __clear, size_t __n, va_list __ap) * * @since 1.1 */ -_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 153d1eb..84e7ee6 100644 --- a/libsimple/wcsdup.h +++ b/libsimple/wcsdup.h @@ -11,11 +11,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wcsdupa(s)\ + LIBSIMPLE_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) @@ -32,7 +33,7 @@ * * @since 1.2 */ -_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 @@ -48,10 +49,13 @@ wchar_t *libsimple_enwcsdup(int, const wchar_t *); * * @since 1.2 */ -_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__))) -static inline wchar_t *libsimple_ewcsdup(const wchar_t *__s) -{ return enwcsdup(libsimple_default_failure_exit, __s); } +inline wchar_t * +libsimple_ewcsdup(const wchar_t *s__) +{ + return enwcsdup(libsimple_default_failure_exit, s__); +} #ifndef ewcsdup # define ewcsdup libsimple_ewcsdup #endif diff --git a/libsimple/wcsndup.h b/libsimple/wcsndup.h index c68da7d..1fc37ce 100644 --- a/libsimple/wcsndup.h +++ b/libsimple/wcsndup.h @@ -12,14 +12,15 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wcsndupa(s, n)\ + LIBSIMPLE_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) @@ -36,7 +37,7 @@ * * @since 1.2 */ -_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 @@ -54,7 +55,7 @@ wchar_t *libsimple_wcsndup(const wchar_t *, size_t); * * @since 1.2 */ -_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 @@ -71,10 +72,13 @@ wchar_t *libsimple_enwcsndup(int, const wchar_t *, size_t); * * @since 1.2 */ -_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__))) -static inline wchar_t *libsimple_ewcsndup(const wchar_t *__s, size_t __n) -{ return libsimple_enwcsndup(libsimple_default_failure_exit, __s, __n); } +inline wchar_t * +libsimple_ewcsndup(const wchar_t *s__, size_t n__) +{ + return libsimple_enwcsndup(libsimple_default_failure_exit, s__, n__); +} #ifndef ewcsndup # define ewcsndup libsimple_ewcsndup #endif diff --git a/libsimple/wmemdup.h b/libsimple/wmemdup.h index 2b213cb..22cd1cc 100644 --- a/libsimple/wmemdup.h +++ b/libsimple/wmemdup.h @@ -12,11 +12,12 @@ */ #if defined(__GNUC__) || defined(__clang__) # define libsimple_wmemdupa(s, n)\ + LIBSIMPLE_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) @@ -33,7 +34,7 @@ * * @since 1.2 */ -_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 @@ -50,7 +51,7 @@ wchar_t *libsimple_wmemdup(const wchar_t *, size_t); * * @since 1.2 */ -_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 @@ -67,10 +68,13 @@ wchar_t *libsimple_enwmemdup(int, const wchar_t *, size_t); * * @since 1.2 */ -_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__))) -static inline wchar_t *libsimple_ewmemdup(const wchar_t *__s, size_t __n) -{ return libsimple_enwmemdup(libsimple_default_failure_exit, __s, __n); } +inline wchar_t * +libsimple_ewmemdup(const wchar_t *s__, size_t n__) +{ + return libsimple_enwmemdup(libsimple_default_failure_exit, s__, n__); +} #ifndef ewmemdup # define ewmemdup libsimple_ewmemdup #endif diff --git a/localtime.c b/localtime.c index 0b075a0..96bd1e1 100644 --- a/localtime.c +++ b/localtime.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include <sys/timex.h> #ifndef TEST diff --git a/mallocn.c b/mallocn.c new file mode 100644 index 0000000..f8f51b4 --- /dev/null +++ b/mallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_mallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/mallocz.c b/mallocz.c new file mode 100644 index 0000000..22c3b03 --- /dev/null +++ b/mallocz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_mallocz(int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/malloczn.c b/malloczn.c new file mode 100644 index 0000000..477b5bc --- /dev/null +++ b/malloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_malloczn(int, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif 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..f23bbb1 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\fP, struct tm *\fItm\fP, struct timespec *\fIts\fP); +inline void libsimple_elocaltime(struct tm *\fItm\fP, struct timespec *\fIts\fP); .fi .PP Link with @@ -33,7 +33,7 @@ On failure, the process's exit value will be if the .BR libsimple_enlocaltime () function is used or -.IR libsimple_default_failure_exit (3) +.BR libsimple_default_failure_exit (3) if the .BR libsimple_elocaltime () fucntion is used. @@ -49,9 +49,9 @@ is .IR NULL . .I tm may -.I not +.B not be -.RI NULL . +.IR NULL . .SH RETURN VALUE The 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_strtoh.3 b/man3/libsimple_strtoh.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtoh.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file diff --git a/man3/libsimple_strtohh.3 b/man3/libsimple_strtohh.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtohh.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file diff --git a/man3/libsimple_strtoi.3 b/man3/libsimple_strtoi.3 new file mode 100644 index 0000000..3def194 --- /dev/null +++ b/man3/libsimple_strtoi.3 @@ -0,0 +1,202 @@ +.TH LIBSIMPLE_STRTOI 3 libsimple +.SH NAME +libsimple_strto{i,h,hh,z,i8,i16,i32,i64} \- parse a string as a signed integer + +.SH SYNOPSIS +.nf +#include <libsimple.h> + +signed int libsimple_strtoi(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +signed short int libsimple_strtoh(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +signed char libsimple_strtohh(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +inline ssize_t libsimple_strtoz(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +int_least8_t libsimple_strtoi8(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +int_least16_t libsimple_strtoi16(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +int_least32_t libsimple_strtoi32(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +int_least64_t libsimple_strtoi64(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); + +#ifndef strtoi +# define strtoi libsimple_strtoi +#endif +#ifndef strtoh +# define strtoh libsimple_strtoh +#endif +#ifndef strtohh +# define strtohh libsimple_strtohh +#endif +#ifndef strtoz +# define strtoz libsimple_strtoz +#endif +#ifndef strtoi8 +# define strtoi8 libsimple_strtoi8 +#endif +#ifndef strtoi16 +# define strtoi16 libsimple_strtoi16 +#endif +#ifndef strtoi32 +# define strtoi32 libsimple_strtoi32 +#endif +#ifndef strtoi64 +# define strtoi64 libsimple_strtoi64 +#endif +.fi +.PP +Link with +.IR \-lsimple . + +.SH DESCRIPTION +The +.BR libsimple_strtoi () +function is a version of the +.BR strtol (3) +function, that returns a +.BR "signed int" . +.PP +The +.BR libsimple_strtoh () +function is a version of the +.BR strtol (3) +function, that returns a +.BR "signed short int" . +.PP +The +.BR libsimple_strtohh () +function is a version of the +.BR strtol (3) +function, that returns a +.BR "signed char" . +.PP +The +.BR libsimple_strtoz () +function is a version of the +.BR strtol (3) +function, that returns a +.BR ssize_t . +.PP +The +.BR libsimple_strtoi8 () +function is a version of the +.BR strtol (3) +function, that returns an +.B int_least8_t +restricted to the range of +.BR int8_t . +.PP +The +.BR libsimple_strtoi16 () +function is a version of the +.BR strtol (3) +function, that returns an +.B int_least16_t +restricted to the range of +.BR int16_t . +.PP +The +.BR libsimple_strtoi32 () +function is a version of the +.BR strtol (3) +function, that returns an +.B int_least32_t +restricted to the range of +.BR int32_t . +.PP +The +.BR libsimple_strtoi64 () +function is a version of the +.BR strtol (3) +function, that returns an +.B int_least64_t +restricted to the range of +.BR int64_t . + +.SH RETURN VALUE +See +.BR strtol (3). + +.SH ERRORS +See +.BR strtol (3). + +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7). +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR libsimple_strtoi (), +.br +.BR libsimple_strtoh (), +.br +.BR libsimple_strtohh (), +.br +.BR libsimple_strtoz (), +.br +.BR libsimple_strtoi8 (), +.br +.BR libsimple_strtoi16 (), +.br +.BR libsimple_strtoi32 (), +.br +.BR libsimple_strtoi64 () +T} Thread safety MT-Safe +T{ +.BR libsimple_strtoi (), +.br +.BR libsimple_strtoh (), +.br +.BR libsimple_strtohh (), +.br +.BR libsimple_strtoz (), +.br +.BR libsimple_strtoi8 (), +.br +.BR libsimple_strtoi16 (), +.br +.BR libsimple_strtoi32 (), +.br +.BR libsimple_strtoi64 () +T} Async-signal safety AS-Safe +T{ +.BR libsimple_strtoi (), +.br +.BR libsimple_strtoh (), +.br +.BR libsimple_strtohh (), +.br +.BR libsimple_strtoz (), +.br +.BR libsimple_strtoi8 (), +.br +.BR libsimple_strtoi16 (), +.br +.BR libsimple_strtoi32 (), +.br +.BR libsimple_strtoi64 () +T} Async-cancel safety AC-Safe +.TE + +.SH EXAMPLES +None. + +.SH APPLICATION USAGE +None. + +.SH RATIONALE +None. + +.SH FUTURE DIRECTIONS +None. + +.SH NOTES +None. + +.SH BUGS +None. + +.SH SEE ALSO +.BR libsimple_strtou (3), +.BR strtol (3), +.BR strtoll (3) diff --git a/man3/libsimple_strtoi16.3 b/man3/libsimple_strtoi16.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtoi16.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file diff --git a/man3/libsimple_strtoi32.3 b/man3/libsimple_strtoi32.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtoi32.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file diff --git a/man3/libsimple_strtoi64.3 b/man3/libsimple_strtoi64.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtoi64.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file diff --git a/man3/libsimple_strtoi8.3 b/man3/libsimple_strtoi8.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtoi8.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file 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_strtou.3 b/man3/libsimple_strtou.3 new file mode 100644 index 0000000..4e4bb33 --- /dev/null +++ b/man3/libsimple_strtou.3 @@ -0,0 +1,202 @@ +.TH LIBSIMPLE_STRTOU 3 libsimple +.SH NAME +libsimple_strto{u,uh,uhh,uz,u8,u16,u32,u64} \- parse a string as an unsigned integer + +.SH SYNOPSIS +.nf +#include <libsimple.h> + +unsigned int libsimple_strtou(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +unsigned short int libsimple_strtouh(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +unsigned char libsimple_strtouhh(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +inline size_t libsimple_strtouz(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +uint_least8_t libsimple_strtou8(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +uint_least16_t libsimple_strtou16(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +uint_least32_t libsimple_strtou32(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); +uint_least64_t libsimple_strtou64(const char *\fInptr\fP, char **\fIend\fP, int \fIbase\fP); + +#ifndef strtou +# define strtou libsimple_strtou +#endif +#ifndef strtouh +# define strtouh libsimple_strtouh +#endif +#ifndef strtouhh +# define strtouhh libsimple_strtouhh +#endif +#ifndef strtouz +# define strtouz libsimple_strtouz +#endif +#ifndef strtou8 +# define strtou8 libsimple_strtou8 +#endif +#ifndef strtou16 +# define strtou16 libsimple_strtou16 +#endif +#ifndef strtou32 +# define strtou32 libsimple_strtou32 +#endif +#ifndef strtou64 +# define strtou64 libsimple_strtou64 +#endif +.fi +.PP +Link with +.IR \-lsimple . + +.SH DESCRIPTION +The +.BR libsimple_strtou () +function is a version of the +.BR strtoul (3) +function, that returns au +.BR "unsigned int" . +.PP +The +.BR libsimple_strtouh () +function is a version of the +.BR strtoul (3) +function, that returns au +.BR "unsigned short int" . +.PP +The +.BR libsimple_strtouhh () +function is a version of the +.BR strtoul (3) +function, that returns au +.BR "unsigned char" . +.PP +The +.BR libsimple_strtouz () +function is a version of the +.BR strtoul (3) +function, that returns a +.BR size_t . +.PP +The +.BR libsimple_strtou8 () +function is a version of the +.BR strtoul (3) +function, that returns a +.B uint_least8_t +restricted to the range of +.BR uint8_t . +.PP +The +.BR libsimple_strtou16 () +function is a version of the +.BR strtoul (3) +function, that returns a +.B uint_least16_t +restricted to the range of +.BR uint16_t . +.PP +The +.BR libsimple_strtou32 () +function is a version of the +.BR strtoul (3) +function, that returns a +.B uint_least32_t +restricted to the range of +.BR uint32_t . +.PP +The +.BR libsimple_strtou64 () +function is a version of the +.BR strtoul (3) +function, that returns a +.B uint_least64_t +restricted to the range of +.BR uint64_t . + +.SH RETURN VALUE +See +.BR strtoul (3). + +.SH ERRORS +See +.BR strtoul (3). + +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7). +.TS +allbox; +lb lb lb +l l l. +Interface Attribute Value +T{ +.BR libsimple_strtou (), +.br +.BR libsimple_strtouh (), +.br +.BR libsimple_strtouhh (), +.br +.BR libsimple_strtouz (), +.br +.BR libsimple_strtou8 (), +.br +.BR libsimple_strtou16 (), +.br +.BR libsimple_strtou32 (), +.br +.BR libsimple_strtou64 () +T} Thread safety MT-Safe +T{ +.BR libsimple_strtou (), +.br +.BR libsimple_strtouh (), +.br +.BR libsimple_strtouhh (), +.br +.BR libsimple_strtouz (), +.br +.BR libsimple_strtou8 (), +.br +.BR libsimple_strtou16 (), +.br +.BR libsimple_strtou32 (), +.br +.BR libsimple_strtou64 () +T} Async-signal safety AS-Safe +T{ +.BR libsimple_strtou (), +.br +.BR libsimple_strtouh (), +.br +.BR libsimple_strtouhh (), +.br +.BR libsimple_strtouz (), +.br +.BR libsimple_strtou8 (), +.br +.BR libsimple_strtou16 (), +.br +.BR libsimple_strtou32 (), +.br +.BR libsimple_strtou64 () +T} Async-cancel safety AC-Safe +.TE + +.SH EXAMPLES +None. + +.SH APPLICATION USAGE +None. + +.SH RATIONALE +None. + +.SH FUTURE DIRECTIONS +None. + +.SH NOTES +None. + +.SH BUGS +None. + +.SH SEE ALSO +.BR libsimple_strtoi (3), +.BR strtoul (3), +.BR strtoull (3) diff --git a/man3/libsimple_strtou16.3 b/man3/libsimple_strtou16.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtou16.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/libsimple_strtou32.3 b/man3/libsimple_strtou32.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtou32.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/libsimple_strtou64.3 b/man3/libsimple_strtou64.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtou64.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/libsimple_strtou8.3 b/man3/libsimple_strtou8.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtou8.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/libsimple_strtouh.3 b/man3/libsimple_strtouh.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtouh.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/libsimple_strtouhh.3 b/man3/libsimple_strtouhh.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtouhh.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file 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_strtouz.3 b/man3/libsimple_strtouz.3 new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/libsimple_strtouz.3 @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/libsimple_strtoz.3 b/man3/libsimple_strtoz.3 new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/libsimple_strtoz.3 @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file 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 8db6f0a..b40799d 100644 --- a/man3/libsimple_vweprintf.3 +++ b/man3/libsimple_vweprintf.3 @@ -7,15 +7,15 @@ libsimple_vweprintf \- print an error message #include <libsimple.h> extern int libsimple_default_failure_exit; -extern void (*libsimple_eprint_preprint)(void); -extern void (*libsimple_eprint_postprint)(void); +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 @@ -124,18 +124,18 @@ The and .BR libsimple_eprintf () functions call -.I libsimple_eprint_preprint +.I libsimple_eprintf_preprint unless it is .B NULL before they print the message, after printing the message they call -.I libsimple_eprint_postprint +.I libsimple_eprintf_postprint unless it is .BR NULL . The -.I libsimple_eprint_preprint +.I libsimple_eprintf_preprint and -.I libsimple_eprint_postprint +.I libsimple_eprintf_postprint variables are .B NULL byte default. @@ -149,9 +149,9 @@ may have a different value from when the or .BR libsimple_eprintf () function called when -.I libsimple_eprint_preprint +.I libsimple_eprintf_preprint or -.I libsimple_eprint_postprint +.I libsimple_eprintf_postprint is called. .SH RETURN VALUE 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/man3/strtoh.3libsimple b/man3/strtoh.3libsimple new file mode 120000 index 0000000..58751cb --- /dev/null +++ b/man3/strtoh.3libsimple @@ -0,0 +1 @@ +libsimple_strtoh.3
\ No newline at end of file diff --git a/man3/strtohh.3libsimple b/man3/strtohh.3libsimple new file mode 120000 index 0000000..890ee2c --- /dev/null +++ b/man3/strtohh.3libsimple @@ -0,0 +1 @@ +libsimple_strtohh.3
\ No newline at end of file diff --git a/man3/strtoi.3libsimple b/man3/strtoi.3libsimple new file mode 120000 index 0000000..debbfef --- /dev/null +++ b/man3/strtoi.3libsimple @@ -0,0 +1 @@ +libsimple_strtoi.3
\ No newline at end of file diff --git a/man3/strtoi16.3libsimple b/man3/strtoi16.3libsimple new file mode 120000 index 0000000..de1c0dc --- /dev/null +++ b/man3/strtoi16.3libsimple @@ -0,0 +1 @@ +libsimple_strtoi16.3
\ No newline at end of file diff --git a/man3/strtoi32.3libsimple b/man3/strtoi32.3libsimple new file mode 120000 index 0000000..c2256df --- /dev/null +++ b/man3/strtoi32.3libsimple @@ -0,0 +1 @@ +libsimple_strtoi32.3
\ No newline at end of file diff --git a/man3/strtoi64.3libsimple b/man3/strtoi64.3libsimple new file mode 120000 index 0000000..051af78 --- /dev/null +++ b/man3/strtoi64.3libsimple @@ -0,0 +1 @@ +libsimple_strtoi64.3
\ No newline at end of file diff --git a/man3/strtoi8.3libsimple b/man3/strtoi8.3libsimple new file mode 120000 index 0000000..7a10a91 --- /dev/null +++ b/man3/strtoi8.3libsimple @@ -0,0 +1 @@ +libsimple_strtoi8.3
\ No newline at end of file diff --git a/man3/strtou.3libsimple b/man3/strtou.3libsimple new file mode 120000 index 0000000..513cee9 --- /dev/null +++ b/man3/strtou.3libsimple @@ -0,0 +1 @@ +libsimple_strtou.3
\ No newline at end of file diff --git a/man3/strtou16.3libsimple b/man3/strtou16.3libsimple new file mode 120000 index 0000000..4265fbd --- /dev/null +++ b/man3/strtou16.3libsimple @@ -0,0 +1 @@ +libsimple_strtou16.3
\ No newline at end of file diff --git a/man3/strtou32.3libsimple b/man3/strtou32.3libsimple new file mode 120000 index 0000000..38ae14a --- /dev/null +++ b/man3/strtou32.3libsimple @@ -0,0 +1 @@ +libsimple_strtou32.3
\ No newline at end of file diff --git a/man3/strtou64.3libsimple b/man3/strtou64.3libsimple new file mode 120000 index 0000000..e71f91d --- /dev/null +++ b/man3/strtou64.3libsimple @@ -0,0 +1 @@ +libsimple_strtou64.3
\ No newline at end of file diff --git a/man3/strtou8.3libsimple b/man3/strtou8.3libsimple new file mode 120000 index 0000000..0554888 --- /dev/null +++ b/man3/strtou8.3libsimple @@ -0,0 +1 @@ +libsimple_strtou8.3
\ No newline at end of file diff --git a/man3/strtouh.3libsimple b/man3/strtouh.3libsimple new file mode 120000 index 0000000..fac2341 --- /dev/null +++ b/man3/strtouh.3libsimple @@ -0,0 +1 @@ +libsimple_strtouh.3
\ No newline at end of file diff --git a/man3/strtouhh.3libsimple b/man3/strtouhh.3libsimple new file mode 120000 index 0000000..9933519 --- /dev/null +++ b/man3/strtouhh.3libsimple @@ -0,0 +1 @@ +libsimple_strtouhh.3
\ No newline at end of file diff --git a/man3/strtouz.3libsimple b/man3/strtouz.3libsimple new file mode 120000 index 0000000..af00600 --- /dev/null +++ b/man3/strtouz.3libsimple @@ -0,0 +1 @@ +libsimple_strtouz.3
\ No newline at end of file diff --git a/man3/strtoz.3libsimple b/man3/strtoz.3libsimple new file mode 120000 index 0000000..157c5c8 --- /dev/null +++ b/man3/strtoz.3libsimple @@ -0,0 +1 @@ +libsimple_strtoz.3
\ No newline at end of file diff --git a/memalign.c b/memalign.c new file mode 100644 index 0000000..66b1bee --- /dev/null +++ b/memalign.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_memalign(size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalignn.c b/memalignn.c new file mode 100644 index 0000000..526ae3b --- /dev/null +++ b/memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_memalignn(size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalignz.c b/memalignz.c new file mode 100644 index 0000000..1802dbf --- /dev/null +++ b/memalignz.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_memalignz(int, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalignzn.c b/memalignzn.c new file mode 100644 index 0000000..7b842aa --- /dev/null +++ b/memalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_memalignzn(int, size_t, size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memalloc.c b/memalloc.c new file mode 100644 index 0000000..8f03933 --- /dev/null +++ b/memalloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_memalloc(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/memcasechr.c b/memcasechr.c index 4277849..9abdd2b 100644 --- a/memcasechr.c +++ b/memcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasechr_inv.c b/memcasechr_inv.c index 6b89e66..0eb1cd3 100644 --- a/memcasechr_inv.c +++ b/memcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasecmp.c b/memcasecmp.c index efc9b47..357aedb 100644 --- a/memcasecmp.c +++ b/memcasecmp.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcaseends.c b/memcaseends.c index 0a673f7..09c12f7 100644 --- a/memcaseends.c +++ b/memcaseends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..3c814f0 --- /dev/null +++ b/memcaseeq.c @@ -0,0 +1,26 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/memcaseeqlen.c b/memcaseeqlen.c index 79ab198..067eb96 100644 --- a/memcaseeqlen.c +++ b/memcaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasemem.c b/memcasemem.c index 244042b..b3ea476 100644 --- a/memcasemem.c +++ b/memcasemem.c @@ -1,16 +1,17 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST void * libsimple_memcasemem(const void *hay_, size_t hayn, const void *sub_, size_t subn) { - char *hay = (void *)hay_, *end; + const char *hay = hay_; const char *sub = sub_; + const char *end; if (!subn) - return hay; + return REMOVE_CONST(hay, char *); if (hayn < subn) return NULL; if (subn == 1) @@ -18,7 +19,7 @@ libsimple_memcasemem(const void *hay_, size_t hayn, const void *sub_, size_t sub for (end = &hay[hayn - subn + 1]; hay != end; hay++) if (tolower(*hay) == tolower(*sub) && !libsimple_memcasecmp(hay, sub, subn)) - return hay; + return REMOVE_CONST(hay, char *); return NULL; } diff --git a/memcasescan.c b/memcasescan.c index a5b22b3..6c59089 100644 --- a/memcasescan.c +++ b/memcasescan.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasescan_inv.c b/memcasescan_inv.c index 28d7848..91f91e9 100644 --- a/memcasescan_inv.c +++ b/memcasescan_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memcasestarts.c b/memcasestarts.c index f9c30ee..4196e64 100644 --- a/memcasestarts.c +++ b/memcasestarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memchr_inv.c b/memchr_inv.c index 2eed2e0..2bca9cd 100644 --- a/memchr_inv.c +++ b/memchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -38,49 +38,58 @@ main(void) { char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'o', 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[5], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[3], &buf[5], 'o', 5) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[3], &buf[5], 'l', 5) == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[3], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[8], &buf[5], 'o', 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[8], &buf[5], 'l', 5) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memcmove(&buf[8], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..5ec93d5 100644 --- a/memelem_inv.c +++ b/memelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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/memelemcpy.c b/memelemcpy.c index 3fafa65..19c937c 100644 --- a/memelemcpy.c +++ b/memelemcpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -91,96 +91,118 @@ main(void) char buf[1024]; - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "o", 0, 5) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "l", 0, 5) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "x", 0, 5) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "o", 1, 5) == &buf[5]); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "l", 1, 5) == &buf[3]); assert(!strncmp(buf, "helx", 4)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "hello", "x", 1, 5) == NULL); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.e.l.l.o", ".o", 2, 5) == &buf[5 * 2]); assert(!strncmp(buf, ".h.e.l.l.ox", 11)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.e.l.l.o", ".l", 2, 5) == &buf[3 * 2]); assert(!strncmp(buf, ".h.e.lx", 7)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.e.l.l.o", ".x", 2, 5) == NULL); assert(!strncmp(buf, ".h.e.l.l.ox", 11)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".h.l.ll..o", "l.", 2, 5) == &buf[4 * 2]); assert(!strncmp(buf, ".h.l.ll.x", 9)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..e..l..l..o", "..o", 3, 5) == &buf[5 * 3]); assert(!strncmp(buf, "..h..e..l..l..ox", 16)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..e..l..l..o", "..l", 3, 5) == &buf[3 * 3]); assert(!strncmp(buf, "..h..e..lx", 10)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..e..l..l..o", "..x", 3, 5) == NULL); assert(!strncmp(buf, "..h..e..l..l..ox", 16)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "..h..l..ll....o", "l..", 3, 5) == &buf[4 * 3]); assert(!strncmp(buf, "..h..l..ll..x", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...e...l...l...o", "...o", 4, 5) == &buf[5 * 4]); assert(!strncmp(buf, "...h...e...l...l...ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...e...l...l...o", "...l", 4, 5) == &buf[3 * 4]); assert(!strncmp(buf, "...h...e...lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...e...l...l...o", "...x", 4, 5) == NULL); assert(!strncmp(buf, "...h...e...l...l...ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, "...h...l...ll......o", "l...", 4, 5) == &buf[4 * 4]); assert(!strncmp(buf, "...h...l...ll...x", 17)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......e.......l.......l.......o", ".......o", 8, 5) == &buf[5 * 8]); assert(!strncmp(buf, ".......h.......e.......l.......l.......ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......e.......l.......l.......o", ".......l", 8, 5) == &buf[3 * 8]); assert(!strncmp(buf, ".......h.......e.......lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......e.......l.......l.......o", ".......x", 8, 5) == NULL); assert(!strncmp(buf, ".......h.......e.......l.......l.......ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_memelemcpy(buf, ".......h.......l.......ll..............o", "l.......", 8, 5) == &buf[4 * 8]); assert(!strncmp(buf, ".......h.......l.......ll.......x", 21)); diff --git a/memelemmove.c b/memelemmove.c index 7becbc2..22908ca 100644 --- a/memelemmove.c +++ b/memelemmove.c @@ -1,22 +1,23 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #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; } } @@ -121,300 +123,360 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "", 0, 5) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "", 0, 5) == &buf[3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[3], "", 0, 5) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "o", 1, 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "l", 1, 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "x", 1, 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "o", 1, 5) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "l", 1, 5) == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "x", 1, 5) == NULL); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "o", 1, 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "l", 1, 5) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "x", 1, 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".o", 2, 5) == &buf[5 + 5 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".l", 2, 5) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".x", 2, 5) == NULL); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".o", 2, 5) == &buf[3 + 5 * 2]); assert(!strncmp(buf, "---.h.e.l.l.o.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".l", 2, 5) == &buf[3 + 3 * 2]); assert(!strncmp(buf, "---.h.e.l.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".x", 2, 5) == NULL); assert(!strncmp(buf, "---.h.e.l.l.o.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".o", 2, 5) == &buf[8 + 5 * 2]); assert(!strncmp(buf, "-----.h..h.e.l.l.o-", 19)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".l", 2, 5) == &buf[8 + 3 * 2]); assert(!strncmp(buf, "-----.h..h.e.lo-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".x", 2, 5) == NULL); assert(!strncmp(buf, "-----.h..h.e.l.l.o-", 19)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..o", 3, 5) == &buf[5 + 5 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..l", 3, 5) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..x", 3, 5) == NULL); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "..o", 3, 5) == &buf[3 + 5 * 3]); assert(!strncmp(buf, "---..h..e..l..l..o.o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "..l", 3, 5) == &buf[3 + 3 * 3]); assert(!strncmp(buf, "---..h..e..l.l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "..x", 3, 5) == NULL); assert(!strncmp(buf, "---..h..e..l..l..o.o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "..o", 3, 5) == &buf[8 + 5 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..l..o-", 24)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "..l", 3, 5) == &buf[8 + 3 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "..x", 3, 5) == NULL); assert(!strncmp(buf, "-----..h..h..e..l..l..o-", 24)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...o", 4, 5) == &buf[5 + 5 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...l", 4, 5) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...x", 4, 5) == NULL); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "...o", 4, 5) == &buf[3 + 5 * 4]); assert(!strncmp(buf, "---...h...e...l...l...o.o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "...l", 4, 5) == &buf[3 + 3 * 4]); assert(!strncmp(buf, "---...h...e...l.l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "...x", 4, 5) == NULL); assert(!strncmp(buf, "---...h...e...l...l...o.o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "...o", 4, 5) == &buf[8 + 5 * 4]); assert(!strncmp(buf, "-----......h...e...l...l...o-", 29)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "...l", 4, 5) == &buf[8 + 3 * 4]); assert(!strncmp(buf, "-----......h...e...ll...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "...x", 4, 5) == NULL); assert(!strncmp(buf, "-----......h...e...l...l...o-", 29)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......o", 8, 5) == &buf[5 + 5 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......l", 8, 5) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......x", 8, 5) == NULL); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".......o", 8, 5) == &buf[3 + 5 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.......l.......o.o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".......l", 8, 5) == &buf[3 + 3 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], ".......x", 8, 5) == NULL); assert(!strncmp(buf, "---.......h.......e.......l.......l.......o.o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".......o", 8, 5) == &buf[8 + 5 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l.......l.......o-", 49)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".......l", 8, 5) == &buf[8 + 3 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l....l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], ".......x", 8, 5) == NULL); assert(!strncmp(buf, "-----..........h.......e.......l.......l.......o-", 49)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a.", 2, 5) == &buf[5 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a.", 2, 5) == &buf[3 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a.", 2, 5) == &buf[8 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a..", 3, 5) == &buf[5 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a..", 3, 5) == &buf[3 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a..", 3, 5) == &buf[8 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a...", 4, 5) == &buf[5 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a...", 4, 5) == &buf[3 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a...", 4, 5) == &buf[8 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "a.......", 8, 5) == &buf[5 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_memelemmove(&buf[3], &buf[5], "a.......", 8, 5) == &buf[3 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_memelemmove(&buf[8], &buf[5], "a.......", 8, 5) == &buf[8 + 4 * 8]); diff --git a/memelemscan.c b/memelemscan.c index d17297a..b541319 100644 --- a/memelemscan.c +++ b/memelemscan.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..cdbae3c 100644 --- a/memelemscan_inv.c +++ b/memelemscan_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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 *); } } } @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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 "common.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 @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memisutf8.c b/memisutf8.c index 96a8b6b..b477ab8 100644 --- a/memisutf8.c +++ b/memisutf8.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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; @@ -85,10 +91,6 @@ main(void) assert(libsimple_memisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\ assert(libsimple_memisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\ assert(libsimple_memisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\ - assert(libsimple_strisutf8(STRING, i) == (GOOD));\ - assert(libsimple_strnisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\ - assert(libsimple_strnisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\ - assert(libsimple_strnisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\ } while (0) int i; @@ -1,16 +1,16 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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..025cdbc --- /dev/null +++ b/mempcpy.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..f2d2a03 --- /dev/null +++ b/mempmove.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..4c793ac --- /dev/null +++ b/mempset.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..61b202b 100644 --- a/mempsetelem.c +++ b/mempsetelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -10,32 +10,42 @@ 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: + if ((uintptr_t)buf_ % _Alignof(uint16_t) || (uintptr_t)item % _Alignof(uint16_t)) + goto misaligned; { - 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: + if ((uintptr_t)buf_ % _Alignof(uint32_t) || (uintptr_t)item % _Alignof(uint32_t)) + goto misaligned; { - 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: + if ((uintptr_t)buf_ % _Alignof(uint64_t) || (uintptr_t)item % _Alignof(uint64_t)) + goto misaligned; { - 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; } default: + misaligned: { char *buf = buf_; size_t i; @@ -54,27 +64,31 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n) int main(void) { - char buf_[4096]; - char *buf = buf_; + _Alignas(8) char buf_[4096]; + _Alignas(8) char *buf = buf_; size_t i; memset(buf, 0, sizeof(buf_)); - 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]); + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcast-align" +#endif 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..6ef3577 100644 --- a/memptolower.c +++ b/memptolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..1ad61ce 100644 --- a/memptoupper.c +++ b/memptoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..e06586c 100644 --- a/memrcasechr.c +++ b/memrcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..ffb29a3 100644 --- a/memrcasechr_inv.c +++ b/memrcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..6042f4a 100644 --- a/memrcaseeqlen.c +++ b/memrcaseeqlen.c @@ -1,14 +1,20 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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..1ed9bb2 100644 --- a/memrcasemem.c +++ b/memrcasemem.c @@ -1,16 +1,17 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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; @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..16dcbcd 100644 --- a/memrchr_inv.c +++ b/memrchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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]; } @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..a442eff 100644 --- a/memrelem_inv.c +++ b/memrelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..7a2eac4 --- /dev/null +++ b/memreplace.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/memreplaceelem.c b/memreplaceelem.c index 9a56c98..c36d2e6 100644 --- a/memreplaceelem.c +++ b/memreplaceelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memreqlen.c b/memreqlen.c index c276b8d..b3cba03 100644 --- a/memreqlen.c +++ b/memreqlen.c @@ -1,12 +1,13 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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; @@ -1,16 +1,16 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST 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; @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memscan_inv.c b/memscan_inv.c index 29bdfce..f99c10f 100644 --- a/memscan_inv.c +++ b/memscan_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memsetelem.c b/memsetelem.c new file mode 100644 index 0000000..75190f2 --- /dev/null +++ b/memsetelem.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_memsetelem(void *, const void *, size_t, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + _Alignas(8) char buf_[4096]; + _Alignas(8) char *buf = buf_; + size_t i; + + memset(buf, 0, sizeof(buf_)); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 10) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 1, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 2, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 4, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 8, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 16, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 3, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint8_t){0x09}, 1, 3000) == buf); + assert(libsimple_memsetelem(buf, &(uint16_t){0x0807}, 2, 1000) == buf); + assert(libsimple_memsetelem(buf, &(uint32_t){0x10203040UL}, 4, 300) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == buf); + assert(libsimple_memsetelem(buf, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == buf); + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcast-align" +#endif + + for (i = 0; i < 48; i++) + assert(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) + assert(*(uint32_t *)&buf[i] == 0x10203040UL); + for (; i < 2000; i += 2) + assert(*(uint16_t *)&buf[i] == 0x0807); + for (; i < 3000; i++) + assert(buf[i] == 0x09); + for (; i < sizeof(buf_); i++) + assert(buf[i] == 0); + + return 0; +} + +#endif diff --git a/memstarts.c b/memstarts.c index ace2b70..aa128f7 100644 --- a/memstarts.c +++ b/memstarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/memtolower.c b/memtolower.c new file mode 100644 index 0000000..30d66ad --- /dev/null +++ b/memtolower.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..38eb0ab --- /dev/null +++ b/memtoupper.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/minimise_number_string.c b/minimise_number_string.c index 5993564..4a90916 100644 --- a/minimise_number_string.c +++ b/minimise_number_string.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/mk/linux.mk b/mk/linux.mk new file mode 100644 index 0000000..ad58f69 --- /dev/null +++ b/mk/linux.mk @@ -0,0 +1,6 @@ +LIBEXT = so +LIBFLAGS = -shared -Wl,-soname,lib$(LIB_NAME).$(LIBEXT).$(LIB_MAJOR) +LIBMAJOREXT = $(LIBEXT).$(LIB_MAJOR) +LIBMINOREXT = $(LIBEXT).$(LIB_VERSION) + +FIX_INSTALL_NAME = : diff --git a/mk/macos.mk b/mk/macos.mk new file mode 100644 index 0000000..00e8236 --- /dev/null +++ b/mk/macos.mk @@ -0,0 +1,6 @@ +LIBEXT = dylib +LIBFLAGS = -dynamiclib -Wl,-compatibility_version,$(LIB_MAJOR) -Wl,-current_version,$(LIB_VERSION) +LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT) +LIBMINOREXT = $(LIB_VERSION).$(LIBEXT) + +FIX_INSTALL_NAME = install_name_tool -id "$(PREFIX)/lib/lib$(LIB_NAME).$(LIBMAJOREXT)" diff --git a/mk/windows.mk b/mk/windows.mk new file mode 100644 index 0000000..ed5ec8d --- /dev/null +++ b/mk/windows.mk @@ -0,0 +1,6 @@ +LIBEXT = dll +LIBFLAGS = -shared +LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT) +LIBMINOREXT = $(LIB_VERSION).$(LIBEXT) + +FIX_INSTALL_NAME = : diff --git a/multimespec.c b/multimespec.c index bc73055..ee0e1f3 100644 --- a/multimespec.c +++ b/multimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -72,139 +72,166 @@ main(void) { struct timespec r, a; - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_nsec == 10L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_nsec == 10L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_nsec == 100L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_nsec == 100L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -10); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -1); assert(r.tv_nsec == 1000000000L - 10L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -11); assert(r.tv_nsec == 1000000000L - 10L); - a.tv_sec = 0, a.tv_nsec = 0L; + a.tv_sec = 0; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0L); - a.tv_sec = 10, a.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == -100); assert(r.tv_nsec == 0L); - a.tv_sec = 0, a.tv_nsec = 10L; + a.tv_sec = 0; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == -1); assert(r.tv_nsec == 1000000000L - 100L); - a.tv_sec = 10, a.tv_nsec = 10L; + a.tv_sec = 10; + a.tv_nsec = 10L; assert(!libsimple_multimespec(&r, &a, -10)); assert(r.tv_sec == -101); assert(r.tv_nsec == 1000000000L - 100L); - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; assert(!libsimple_multimespec(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0); - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; assert(!libsimple_multimespec(&r, &a, 1)); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; assert(libsimple_multimespec(&r, &a, 2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; assert(libsimple_multimespec(&r, &a, -2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX); assert(r.tv_nsec == 0L); if (-TIME_MAX > TIME_MIN) { - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; assert(!libsimple_multimespec(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX - (time_t)1); assert(r.tv_nsec == 1L); } - a.tv_sec = 10, a.tv_nsec = 100000001L; + a.tv_sec = 10; + a.tv_nsec = 100000001L; assert(!libsimple_multimespec(&r, &a, 10)); assert(r.tv_sec == 101); assert(r.tv_nsec == 10L); diff --git a/multimeval.c b/multimeval.c index 5f8010e..b974bf6 100644 --- a/multimeval.c +++ b/multimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -26,139 +26,166 @@ main(void) { struct timeval r, a; - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 0); assert(r.tv_usec == 10L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == 10); assert(r.tv_usec == 10L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 0); assert(r.tv_usec == 100L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 100); assert(r.tv_usec == 100L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -10); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -1); assert(r.tv_usec == 1000000L - 10L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -11); assert(r.tv_usec == 1000000L - 10L); - a.tv_sec = 0, a.tv_usec = 0L; + a.tv_sec = 0; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == 0); assert(r.tv_usec == 0L); - a.tv_sec = 10, a.tv_usec = 0L; + a.tv_sec = 10; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == -100); assert(r.tv_usec == 0L); - a.tv_sec = 0, a.tv_usec = 10L; + a.tv_sec = 0; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == -1); assert(r.tv_usec == 1000000L - 100L); - a.tv_sec = 10, a.tv_usec = 10L; + a.tv_sec = 10; + a.tv_usec = 10L; assert(!libsimple_multimeval(&r, &a, -10)); assert(r.tv_sec == -101); assert(r.tv_usec == 1000000L - 100L); - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; assert(!libsimple_multimeval(&r, &a, 0)); assert(r.tv_sec == 0); assert(r.tv_usec == 0); - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; assert(!libsimple_multimeval(&r, &a, 1)); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; assert(libsimple_multimeval(&r, &a, 2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MAX); assert(r.tv_usec == 999999L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; assert(libsimple_multimeval(&r, &a, -2) == -1 && errno == ERANGE); assert(r.tv_sec == TIME_MIN); assert(r.tv_usec == 0L); - a.tv_sec = TIME_MAX, a.tv_usec = 0L; + a.tv_sec = TIME_MAX; + a.tv_usec = 0L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX); assert(r.tv_usec == 0L); if (-TIME_MAX > TIME_MIN) { - a.tv_sec = TIME_MAX, a.tv_usec = 999999L; + a.tv_sec = TIME_MAX; + a.tv_usec = 999999L; assert(!libsimple_multimeval(&r, &a, -1)); assert(r.tv_sec == -TIME_MAX - (time_t)1); assert(r.tv_usec == 1L); } - a.tv_sec = 10, a.tv_usec = 100001L; + a.tv_sec = 10; + a.tv_usec = 100001L; assert(!libsimple_multimeval(&r, &a, 10)); assert(r.tv_sec == 101); assert(r.tv_usec == 10L); diff --git a/posix_memalignn.c b/posix_memalignn.c new file mode 100644 index 0000000..1400451 --- /dev/null +++ b/posix_memalignn.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..7c32bdd --- /dev/null +++ b/posix_memalignz.c @@ -0,0 +1,56 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..a00ca84 --- /dev/null +++ b/posix_memalignzn.c @@ -0,0 +1,49 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/putenvf.c b/putenvf.c new file mode 100644 index 0000000..651f665 --- /dev/null +++ b/putenvf.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_putenvf(const char *, ...); + + +#else +#include "test.h" + +int +main(void) +{ + unsetenv("X"); + assert(!getenv("X")); + unsetenv("Y"); + assert(!getenv("Y")); + + putenvf("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + putenvf("Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + putenvf("X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + putenvf("Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + putenvf("X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + putenvf("Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + return 0; +} + +#endif diff --git a/pvalloc.c b/pvalloc.c new file mode 100644 index 0000000..b629abd --- /dev/null +++ b/pvalloc.c @@ -0,0 +1,45 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..2288816 --- /dev/null +++ b/pvallocn.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..d65d08c --- /dev/null +++ b/pvallocz.c @@ -0,0 +1,110 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..b586863 --- /dev/null +++ b/pvalloczn.c @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/rawmemcasechr.c b/rawmemcasechr.c index 3d3a101..b81d6d8 100644 --- a/rawmemcasechr.c +++ b/rawmemcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemcasechr_inv.c b/rawmemcasechr_inv.c index 13101cf..e0f2401 100644 --- a/rawmemcasechr_inv.c +++ b/rawmemcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemccpy.c b/rawmemccpy.c new file mode 100644 index 0000000..bdc4c7c --- /dev/null +++ b/rawmemccpy.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/rawmemchr.c b/rawmemchr.c index 2ed1709..b694f79 100644 --- a/rawmemchr.c +++ b/rawmemchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemchr_inv.c b/rawmemchr_inv.c index d566aba..1b126aa 100644 --- a/rawmemchr_inv.c +++ b/rawmemchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemcmove.c b/rawmemcmove.c new file mode 100644 index 0000000..aeec55f --- /dev/null +++ b/rawmemcmove.c @@ -0,0 +1,58 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..1564937 100644 --- a/rawmemelem.c +++ b/rawmemelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..1e8bc00 100644 --- a/rawmemelem_inv.c +++ b/rawmemelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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/rawmemelemcpy.c b/rawmemelemcpy.c index d5e52a2..ecd5337 100644 --- a/rawmemelemcpy.c +++ b/rawmemelemcpy.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -82,72 +82,88 @@ main(void) char buf[1024]; - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "o", 0) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "l", 0) == &buf[0]); assert(!strncmp(buf, "x", 1)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "o", 1) == &buf[5]); assert(!strncmp(buf, "hellox", 6)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "hello", "l", 1) == &buf[3]); assert(!strncmp(buf, "helx", 4)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".h.e.l.l.o", ".o", 2) == &buf[5 * 2]); assert(!strncmp(buf, ".h.e.l.l.ox", 11)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".h.e.l.l.o", ".l", 2) == &buf[3 * 2]); assert(!strncmp(buf, ".h.e.lx", 7)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".h.l.ll..o", "l.", 2) == &buf[4 * 2]); assert(!strncmp(buf, ".h.l.ll.x", 9)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "..h..e..l..l..o", "..o", 3) == &buf[5 * 3]); assert(!strncmp(buf, "..h..e..l..l..ox", 16)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "..h..e..l..l..o", "..l", 3) == &buf[3 * 3]); assert(!strncmp(buf, "..h..e..lx", 10)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "..h..l..ll....o", "l..", 3) == &buf[4 * 3]); assert(!strncmp(buf, "..h..l..ll..x", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "...h...e...l...l...o", "...o", 4) == &buf[5 * 4]); assert(!strncmp(buf, "...h...e...l...l...ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "...h...e...l...l...o", "...l", 4) == &buf[3 * 4]); assert(!strncmp(buf, "...h...e...lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, "...h...l...ll......o", "l...", 4) == &buf[4 * 4]); assert(!strncmp(buf, "...h...l...ll...x", 17)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".......h.......e.......l.......l.......o", ".......o", 8) == &buf[5 * 8]); assert(!strncmp(buf, ".......h.......e.......l.......l.......ox", 21)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".......h.......e.......l.......l.......o", ".......l", 8) == &buf[3 * 8]); assert(!strncmp(buf, ".......h.......e.......lx", 13)); - memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; assert(libsimple_rawmemelemcpy(buf, ".......h.......l.......ll..............o", "l.......", 8) == &buf[4 * 8]); assert(!strncmp(buf, ".......h.......l.......ll.......x", 21)); diff --git a/rawmemelemmove.c b/rawmemelemmove.c index 8903ae8..a145e7e 100644 --- a/rawmemelemmove.c +++ b/rawmemelemmove.c @@ -1,24 +1,25 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST #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; } } @@ -111,225 +113,270 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "", 0) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "", 0) == &buf[3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[3], "", 0) == &buf[5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "o", 1) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "l", 1) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "o", 1) == &buf[3 + 5]); assert(!strncmp(buf, "---hellolo-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "l", 1) == &buf[3 + 3]); assert(!strncmp(buf, "---helello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "o", 1) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "l", 1) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".o", 2) == &buf[5 + 5 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".l", 2) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".o", 2) == &buf[3 + 5 * 2]); assert(!strncmp(buf, "---.h.e.l.l.o.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".l", 2) == &buf[3 + 3 * 2]); assert(!strncmp(buf, "---.h.e.l.l.l.o-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".o", 2) == &buf[8 + 5 * 2]); assert(!strncmp(buf, "-----.h..h.e.l.l.o-", 19)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".l", 2) == &buf[8 + 3 * 2]); assert(!strncmp(buf, "-----.h..h.e.lo-", 16)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "..o", 3) == &buf[5 + 5 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "..l", 3) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "..o", 3) == &buf[3 + 5 * 3]); assert(!strncmp(buf, "---..h..e..l..l..o.o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "..l", 3) == &buf[3 + 3 * 3]); assert(!strncmp(buf, "---..h..e..l.l..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "..o", 3) == &buf[8 + 5 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..l..o-", 24)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "..l", 3) == &buf[8 + 3 * 3]); assert(!strncmp(buf, "-----..h..h..e..l..o-", 21)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "...o", 4) == &buf[5 + 5 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "...l", 4) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "...o", 4) == &buf[3 + 5 * 4]); assert(!strncmp(buf, "---...h...e...l...l...o.o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "...l", 4) == &buf[3 + 3 * 4]); assert(!strncmp(buf, "---...h...e...l.l...l...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "...o", 4) == &buf[8 + 5 * 4]); assert(!strncmp(buf, "-----......h...e...l...l...o-", 29)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "...l", 4) == &buf[8 + 3 * 4]); assert(!strncmp(buf, "-----......h...e...ll...o-", 26)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".......o", 8) == &buf[5 + 5 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-';; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], ".......l", 8) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".......o", 8) == &buf[3 + 5 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.......l.......o.o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], ".......l", 8) == &buf[3 + 3 * 8]); assert(!strncmp(buf, "---.......h.......e.......l.l.......l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".......o", 8) == &buf[8 + 5 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l.......l.......o-", 49)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], ".......l", 8) == &buf[8 + 3 * 8]); assert(!strncmp(buf, "-----..........h.......e.......l....l.......o-", 46)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a.", 2) == &buf[5 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a.", 2) == &buf[3 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".a.a.aa..a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a.", 2) == &buf[8 + 4 * 2]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a..", 3) == &buf[5 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a..", 3) == &buf[3 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "..a..a..aa....a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a..", 3) == &buf[8 + 4 * 3]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a...", 4) == &buf[5 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a...", 4) == &buf[3 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "...a...a...aa......a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a...", 4) == &buf[8 + 4 * 4]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[5], &buf[5], "a.......", 8) == &buf[5 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[3], &buf[5], "a.......", 8) == &buf[3 + 4 * 8]); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], ".......a.......a.......aa..............a")[0] = '-'; assert(libsimple_rawmemelemmove(&buf[8], &buf[5], "a.......", 8) == &buf[8 + 4 * 8]); diff --git a/rawmemrcasechr.c b/rawmemrcasechr.c index 68c5645..d562279 100644 --- a/rawmemrcasechr.c +++ b/rawmemrcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..63ef818 100644 --- a/rawmemrcasechr_inv.c +++ b/rawmemrcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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/rawmemrchr.c b/rawmemrchr.c index 80ddc41..7d08967 100644 --- a/rawmemrchr.c +++ b/rawmemrchr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrchr_inv.c b/rawmemrchr_inv.c index c6a9b22..b703ae7 100644 --- a/rawmemrchr_inv.c +++ b/rawmemrchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/rawmemrelem.c b/rawmemrelem.c index d8507b3..699ce03 100644 --- a/rawmemrelem.c +++ b/rawmemrelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..25dc76b 100644 --- a/rawmemrelem_inv.c +++ b/rawmemrelem_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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..d54e2eb --- /dev/null +++ b/reallocarray.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..9d7e61e --- /dev/null +++ b/reallocarrayf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..5180dd9 --- /dev/null +++ b/reallocf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..1432f78 --- /dev/null +++ b/reallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..69863f2 --- /dev/null +++ b/reallocn.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/stpmove.c b/stpmove.c new file mode 100644 index 0000000..e691c23 --- /dev/null +++ b/stpmove.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_stpmove(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpmove(buf, buf) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + return 0; +} + +#endif diff --git a/stpnmove.c b/stpnmove.c new file mode 100644 index 0000000..f96499e --- /dev/null +++ b/stpnmove.c @@ -0,0 +1,92 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_stpnmove(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]); + assert(!strncmp(buf, "helhello worldx", 15)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]); + assert(!strcmp(buf, "lo worldrld")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]); + assert(!strcmp(buf, "helhe world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]); + assert(!strcmp(buf, "lollo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]); + assert(!strcmp(buf, "hello world")); + + return 0; +} + +#endif diff --git a/stpnset.c b/stpnset.c new file mode 100644 index 0000000..20da276 --- /dev/null +++ b/stpnset.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_stpnset(char *, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, 'x', SIZE_MAX) == &buf[11]); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, '\0', SIZE_MAX) == &buf[11]); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, 'x', 5) == &buf[5]); + assert(!strcmp(buf, "xxxxx world")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, '\0', 5) == &buf[5]); + assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/stpntolower.c b/stpntolower.c index 9aca9f9..de4e74e 100644 --- a/stpntolower.c +++ b/stpntolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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; } } @@ -47,15 +47,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(!strcmpnul(libsimple_stpntolower(&buf[0], &buf[0], SIZE_MAX), "")); assert(!strcmp(buf, "abcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], SIZE_MAX), "abcdeabcde12345")); - assert(!strcmp(buf, "ABCabcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], SIZE_MAX), "deabcde12345")); - assert(!strcmp(buf, "deabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], SIZE_MAX), "abcdeabcde12345")); - assert(!strcmp(buf, "abcdeabcde12345")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "ABCDEabcde12345"); @@ -70,19 +61,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345X"); assert(!strcmpnul(libsimple_stpntolower(&buf[0], &buf[0], 15), "X")); assert(!strcmp(buf, "abcdeabcde12345X")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - buf[18] = 'X'; - assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 15), "abcdeabcde12345X")); - assert(!strcmp(buf, "ABCabcdeabcde12345X")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 12), "deabcde12345345")); - assert(!strcmp(buf, "deabcde12345345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345X"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 15), "abcdeabcde12345X")); - assert(!strcmp(buf, "abcdeabcde12345X")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "ABCDEabcde12345"); @@ -96,18 +74,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(!strcmpnul(libsimple_stpntolower(&buf[0], &buf[0], 0), "ABCDEabcde12345")); assert(!strcmp(buf, "ABCDEabcde12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 0), "DEabcde12345")); - assert(!strcmp(buf, "ABCDEabcde12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 0), "ABCDEabcde12345")); - assert(!strcmp(buf, "ABCDEabcde12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 0), "ABCDEabcde12345")); - assert(!strcmp(buf, "ABCDEabcde12345")); return 0; } diff --git a/stpntoupper.c b/stpntoupper.c index a6e3769..40552d7 100644 --- a/stpntoupper.c +++ b/stpntoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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; } } @@ -47,15 +47,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(!strcmpnul(libsimple_stpntoupper(&buf[0], &buf[0], SIZE_MAX), "")); assert(!strcmp(buf, "ABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); - assert(!strcmp(buf, "abcABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], SIZE_MAX), "DEABCDE12345")); - assert(!strcmp(buf, "DEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); - assert(!strcmp(buf, "ABCDEABCDE12345")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "abcdeABCDE12345"); @@ -70,19 +61,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345x"); assert(!strcmpnul(libsimple_stpntoupper(&buf[0], &buf[0], 15), "x")); assert(!strcmp(buf, "ABCDEABCDE12345x")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - buf[18] = 'x'; - assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 15), "ABCDEABCDE12345x")); - assert(!strcmp(buf, "abcABCDEABCDE12345x")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 12), "DEABCDE12345345")); - assert(!strcmp(buf, "DEABCDE12345345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345x"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 15), "ABCDEABCDE12345x")); - assert(!strcmp(buf, "ABCDEABCDE12345x")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "abcdeABCDE12345"); @@ -96,18 +74,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(!strcmpnul(libsimple_stpntoupper(&buf[0], &buf[0], 0), "abcdeABCDE12345")); assert(!strcmp(buf, "abcdeABCDE12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 0), "deABCDE12345")); - assert(!strcmp(buf, "abcdeABCDE12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 0), "abcdeABCDE12345")); - assert(!strcmp(buf, "abcdeABCDE12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 0), "abcdeABCDE12345")); - assert(!strcmp(buf, "abcdeABCDE12345")); return 0; } diff --git a/stpset.c b/stpset.c new file mode 100644 index 0000000..08651fa --- /dev/null +++ b/stpset.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_stpset(char *, int); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpset(buf, 'x') == &buf[11]); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpset(buf, '\0') == &buf[11]); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/stptolower.c b/stptolower.c index 61108ad..db63bf0 100644 --- a/stptolower.c +++ b/stptolower.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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; } @@ -45,15 +45,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(!strcmpnul(libsimple_stptolower(&buf[0], &buf[0]), "")); assert(!strcmp(buf, "abcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strtolower(&buf[3], &buf[0]), "abcdeabcde12345")); - assert(!strcmp(buf, "ABCabcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[3]), "deabcde12345")); - assert(!strcmp(buf, "deabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[0]), "abcdeabcde12345")); - assert(!strcmp(buf, "abcdeabcde12345")); return 0; } diff --git a/stptoupper.c b/stptoupper.c index ad6c73e..cbfc184 100644 --- a/stptoupper.c +++ b/stptoupper.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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; } @@ -45,15 +45,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(!strcmpnul(libsimple_stptoupper(&buf[0], &buf[0]), "")); assert(!strcmp(buf, "ABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strtoupper(&buf[3], &buf[0]), "ABCDEABCDE12345")); - assert(!strcmp(buf, "abcABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[3]), "DEABCDE12345")); - assert(!strcmp(buf, "DEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[0]), "ABCDEABCDE12345")); - assert(!strcmp(buf, "ABCDEABCDE12345")); return 0; } diff --git a/strcasechr.c b/strcasechr.c index 83e8f73..3fe8ad1 100644 --- a/strcasechr.c +++ b/strcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechr_inv.c b/strcasechr_inv.c index 03e88c7..70e727c 100644 --- a/strcasechr_inv.c +++ b/strcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechrnul.c b/strcasechrnul.c index 5afcd54..2a09862 100644 --- a/strcasechrnul.c +++ b/strcasechrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasechrnul_inv.c b/strcasechrnul_inv.c index 9c59d71..5a4c396 100644 --- a/strcasechrnul_inv.c +++ b/strcasechrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcasecmpnul.c b/strcasecmpnul.c new file mode 100644 index 0000000..e996e01 --- /dev/null +++ b/strcasecmpnul.c @@ -0,0 +1,35 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcasecmpnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strcasecmpnul(NULL, NULL) == 0); + assert(libsimple_strcasecmpnul(NULL, "") < 0); + assert(libsimple_strcasecmpnul("", NULL) > 0); + assert(libsimple_strcasecmpnul("", "") == 0); + assert(libsimple_strcasecmpnul(NULL, "x") < 0); + assert(libsimple_strcasecmpnul("x", NULL) > 0); + assert(libsimple_strcasecmpnul("x", "x") == 0); + assert(libsimple_strcasecmpnul("a", "b") < 0); + assert(libsimple_strcasecmpnul("b", "a") > 0); + assert(libsimple_strcasecmpnul("aa", "ab") < 0); + assert(libsimple_strcasecmpnul("ab", "aa") > 0); + assert(libsimple_strcasecmpnul("aa", "aa") == 0); + assert(libsimple_strcasecmpnul("A", "a") == 0); + assert(libsimple_strcasecmpnul("a", "A") == 0); + assert(libsimple_strcasecmpnul("AA", "Aa") == 0); + assert(libsimple_strcasecmpnul("Aa", "AA") == 0); + assert(libsimple_strcasecmpnul("AA", "AA") == 0); + return 0; +} + +#endif diff --git a/strcaseends.c b/strcaseends.c index adbebe4..7980b98 100644 --- a/strcaseends.c +++ b/strcaseends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcaseeq.c b/strcaseeq.c new file mode 100644 index 0000000..52e654c --- /dev/null +++ b/strcaseeq.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcaseeq(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strcaseeq("abc", "abc") == 1); + assert(libsimple_strcaseeq("abc", "ab") == 0); + assert(libsimple_strcaseeq("ab", "abc") == 0); + assert(libsimple_strcaseeq("ab", "xy") == 0); + assert(libsimple_strcaseeq("xy", "ab") == 0); + assert(libsimple_strcaseeq("", "1") == 0); + assert(libsimple_strcaseeq("1", "") == 0); + assert(libsimple_strcaseeq("", "") == 1); + assert(libsimple_strcaseeq("abc", "ABC") == 1); + assert(libsimple_strcaseeq("ABC", "abc") == 1); + return 0; +} + +#endif diff --git a/strcaseeqlen.c b/strcaseeqlen.c index 625a3ad..256cb08 100644 --- a/strcaseeqlen.c +++ b/strcaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strcaseeqnul.c b/strcaseeqnul.c new file mode 100644 index 0000000..bd900d6 --- /dev/null +++ b/strcaseeqnul.c @@ -0,0 +1,33 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcaseeqnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strcaseeqnul("abc", "abc") == 1); + assert(libsimple_strcaseeqnul("abc", "ab") == 0); + assert(libsimple_strcaseeqnul("ab", "abc") == 0); + assert(libsimple_strcaseeqnul("ab", "xy") == 0); + assert(libsimple_strcaseeqnul("xy", "ab") == 0); + assert(libsimple_strcaseeqnul("", "1") == 0); + assert(libsimple_strcaseeqnul("1", "") == 0); + assert(libsimple_strcaseeqnul("", "") == 1); + assert(libsimple_strcaseeqnul("abc", "ABC") == 1); + assert(libsimple_strcaseeqnul("ABC", "abc") == 1); + assert(libsimple_strcaseeqnul("", NULL) == 0); + assert(libsimple_strcaseeqnul("1", NULL) == 0); + assert(libsimple_strcaseeqnul(NULL, "") == 0); + assert(libsimple_strcaseeqnul(NULL, "1") == 0); + assert(libsimple_strcaseeqnul(NULL, NULL) == 1); + return 0; +} + +#endif diff --git a/strcasestarts.c b/strcasestarts.c new file mode 100644 index 0000000..df1fae3 --- /dev/null +++ b/strcasestarts.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcasestarts(const char *, const char *); /* TODO test */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/strcasestr.c b/strcasestr.c index 071b7df..7449e64 100644 --- a/strcasestr.c +++ b/strcasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strccpy.c b/strccpy.c new file mode 100644 index 0000000..613ffbe --- /dev/null +++ b/strccpy.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strccpy(char *restrict, const char *restrict, int); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", 'x') == NULL); + assert(!strcmp(buf, "hello")); + + return 0; +} + +#endif diff --git a/strchr_inv.c b/strchr_inv.c index 4c1e242..13843f5 100644 --- a/strchr_inv.c +++ b/strchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strchrnul.c b/strchrnul.c index e4ed5ab..d22e761 100644 --- a/strchrnul.c +++ b/strchrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strchrnul_inv.c b/strchrnul_inv.c index 1f79eb3..26ff63d 100644 --- a/strchrnul_inv.c +++ b/strchrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -40,64 +40,76 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], '\0') == &buf[5 + 6]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], 'o') == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], 'l') == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[5], &buf[5], 'x') == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], '\0') == &buf[3 + 6]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], 'o') == &buf[3 + 5]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], 'l') == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[3], &buf[5], 'x') == NULL); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], '\0') == &buf[8 + 6]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], 'o') == &buf[8 + 5]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], 'l') == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strcmove(&buf[8], &buf[5], 'x') == NULL); assert(!strcmp(buf, "-----helhello")); diff --git a/strcmpnul.c b/strcmpnul.c new file mode 100644 index 0000000..d3d57fa --- /dev/null +++ b/strcmpnul.c @@ -0,0 +1,35 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strcmpnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strcmpnul(NULL, NULL) == 0); + assert(libsimple_strcmpnul(NULL, "") < 0); + assert(libsimple_strcmpnul("", NULL) > 0); + assert(libsimple_strcmpnul("", "") == 0); + assert(libsimple_strcmpnul(NULL, "x") < 0); + assert(libsimple_strcmpnul("x", NULL) > 0); + assert(libsimple_strcmpnul("x", "x") == 0); + assert(libsimple_strcmpnul("a", "b") < 0); + assert(libsimple_strcmpnul("b", "a") > 0); + assert(libsimple_strcmpnul("aa", "ab") < 0); + assert(libsimple_strcmpnul("ab", "aa") > 0); + assert(libsimple_strcmpnul("aa", "aa") == 0); + assert(libsimple_strcmpnul("A", "a") < 0); + assert(libsimple_strcmpnul("a", "A") > 0); + assert(libsimple_strcmpnul("AA", "Aa") < 0); + assert(libsimple_strcmpnul("Aa", "AA") > 0); + assert(libsimple_strcmpnul("AA", "AA") == 0); + return 0; +} + +#endif diff --git a/strend.c b/strend.c new file mode 100644 index 0000000..ff5fa34 --- /dev/null +++ b/strend.c @@ -0,0 +1,19 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strend(const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz")); + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_streq(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_streq("abc", "abc") == 1); + assert(libsimple_streq("abc", "ab") == 0); + assert(libsimple_streq("ab", "abc") == 0); + assert(libsimple_streq("ab", "xy") == 0); + assert(libsimple_streq("xy", "ab") == 0); + assert(libsimple_streq("", "1") == 0); + assert(libsimple_streq("1", "") == 0); + assert(libsimple_streq("", "") == 1); + assert(libsimple_streq("abc", "ABC") == 0); + assert(libsimple_streq("ABC", "abc") == 0); + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/streqnul.c b/streqnul.c new file mode 100644 index 0000000..adee9f8 --- /dev/null +++ b/streqnul.c @@ -0,0 +1,33 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_streqnul(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_streqnul("abc", "abc") == 1); + assert(libsimple_streqnul("abc", "ab") == 0); + assert(libsimple_streqnul("ab", "abc") == 0); + assert(libsimple_streqnul("ab", "xy") == 0); + assert(libsimple_streqnul("xy", "ab") == 0); + assert(libsimple_streqnul("", "1") == 0); + assert(libsimple_streqnul("1", "") == 0); + assert(libsimple_streqnul("", "") == 1); + assert(libsimple_streqnul("abc", "ABC") == 0); + assert(libsimple_streqnul("ABC", "abc") == 0); + assert(libsimple_streqnul("", NULL) == 0); + assert(libsimple_streqnul("1", NULL) == 0); + assert(libsimple_streqnul(NULL, "") == 0); + assert(libsimple_streqnul(NULL, "1") == 0); + assert(libsimple_streqnul(NULL, NULL) == 1); + return 0; +} + +#endif diff --git a/strisutf8.c b/strisutf8.c new file mode 100644 index 0000000..c8244af --- /dev/null +++ b/strisutf8.c @@ -0,0 +1,74 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strisutf8(const char *, int); + + +#else +#include "test.h" + +int +main(void) +{ +#define ASSERT(STRING, GOOD)\ + assert(libsimple_strisutf8(STRING, i) == (GOOD)) + + int i; + for (i = 0; i < 2; i++) { + ASSERT("", 1); + ASSERT("a", 1); + ASSERT("abc", 1); + ASSERT("123", 1); + ASSERT("åäö", 1); + ASSERT("𝖆𝖇𝖈", 1); + ASSERT("\x1b", 1); + ASSERT("\n\r\t\f", 1); + ASSERT("\xFF", 0); + ASSERT("\x01", 1); + ASSERT("\x7F", 1); + ASSERT("\x80", 0); + ASSERT("\xC0", 0); + ASSERT("\xC0\x80", i); + ASSERT("\xC0\x81", 0); + ASSERT("\xCF", 0); + ASSERT("\xEF", 0); + ASSERT("\xEF\x8F", 0); + ASSERT("\xF7", 0); + ASSERT("\xF7\x8F", 0); + ASSERT("\xF7\x8F\x8F", 0); + ASSERT("\xFA", 0); + ASSERT("\xFA\x8F", 0); + ASSERT("\xFA\x8F\x8F", 0); + ASSERT("\xFA\x8F\x8F\x8F", 0); + ASSERT("\xFD", 0); + ASSERT("\xFD\x8F", 0); + ASSERT("\xFD\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE", 0); + ASSERT("\xFE\x8F", 0); + ASSERT("\xFE\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF", 0); + ASSERT("\xFF\x8F", 0); + ASSERT("\xFF\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xC1\x80", 0); + ASSERT("\xC2\x80", 1); + ASSERT("\xE1\x80\x80\x80", 0); + ASSERT("\xE1\x80\xC0\x80", 0); + ASSERT("\xE1\x80\x00\x80", 0); + ASSERT("\xF1\x80\x80\x80", 1); + ASSERT("\xFF\x80\x80\x80\x80\x80\x80\x80", 0); + } + return 0; +} + +#endif diff --git a/strmove.c b/strmove.c new file mode 100644 index 0000000..bdf3803 --- /dev/null +++ b/strmove.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strmove(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strmove(&buf[3], buf) == &buf[3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strmove(buf, &buf[3]) == buf); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strmove(buf, buf) == buf); + assert(!strcmp(buf, "hello world")); + + return 0; +} + +#endif diff --git a/strncasechr.c b/strncasechr.c index 9ba2b93..526acc0 100644 --- a/strncasechr.c +++ b/strncasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasechr_inv.c b/strncasechr_inv.c index cd30867..80bff5d 100644 --- a/strncasechr_inv.c +++ b/strncasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasechrnul.c b/strncasechrnul.c index 608f097..b49bf82 100644 --- a/strncasechrnul.c +++ b/strncasechrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasechrnul_inv.c b/strncasechrnul_inv.c index 6d6af35..0806195 100644 --- a/strncasechrnul_inv.c +++ b/strncasechrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasecmpnul.c b/strncasecmpnul.c new file mode 100644 index 0000000..5df9e7d --- /dev/null +++ b/strncasecmpnul.c @@ -0,0 +1,58 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strncasecmpnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strncasecmpnul(NULL, NULL, 5) == 0); + assert(libsimple_strncasecmpnul(NULL, "", 5) < 0); + assert(libsimple_strncasecmpnul("", NULL, 5) > 0); + assert(libsimple_strncasecmpnul("", "", 5) == 0); + assert(libsimple_strncasecmpnul(NULL, "x", 5) < 0); + assert(libsimple_strncasecmpnul("x", NULL, 5) > 0); + assert(libsimple_strncasecmpnul("x", "x", 5) == 0); + assert(libsimple_strncasecmpnul("a", "b", 5) < 0); + assert(libsimple_strncasecmpnul("b", "a", 5) > 0); + assert(libsimple_strncasecmpnul("aa", "ab", 5) < 0); + assert(libsimple_strncasecmpnul("ab", "aa", 5) > 0); + assert(libsimple_strncasecmpnul("aa", "aa", 5) == 0); + assert(libsimple_strncasecmpnul("A", "a", 5) == 0); + assert(libsimple_strncasecmpnul("a", "A", 5) == 0); + assert(libsimple_strncasecmpnul("AA", "Aa", 5) == 0); + assert(libsimple_strncasecmpnul("Aa", "AA", 5) == 0); + assert(libsimple_strncasecmpnul("AA", "AA", 5) == 0); + assert(libsimple_strncasecmpnul("aa", "ab", 1) == 0); + assert(libsimple_strncasecmpnul("ab", "aa", 1) == 0); + assert(libsimple_strncasecmpnul("aa", "aa", 1) == 0); + assert(libsimple_strncasecmpnul("AA", "Aa", 1) == 0); + assert(libsimple_strncasecmpnul("Aa", "AA", 1) == 0); + assert(libsimple_strncasecmpnul("AA", "AA", 1) == 0); + assert(libsimple_strncasecmpnul(NULL, NULL, 0) == 0); + assert(libsimple_strncasecmpnul(NULL, "", 0) < 0); + assert(libsimple_strncasecmpnul("", NULL, 0) > 0); + assert(libsimple_strncasecmpnul("", "", 0) == 0); + assert(libsimple_strncasecmpnul(NULL, "x", 0) < 0); + assert(libsimple_strncasecmpnul("x", NULL, 0) > 0); + assert(libsimple_strncasecmpnul("x", "x", 0) == 0); + assert(libsimple_strncasecmpnul("a", "b", 0) == 0); + assert(libsimple_strncasecmpnul("b", "a", 0) == 0); + assert(libsimple_strncasecmpnul("aa", "ab", 0) == 0); + assert(libsimple_strncasecmpnul("ab", "aa", 0) == 0); + assert(libsimple_strncasecmpnul("aa", "aa", 0) == 0); + assert(libsimple_strncasecmpnul("A", "a", 0) == 0); + assert(libsimple_strncasecmpnul("a", "A", 0) == 0); + assert(libsimple_strncasecmpnul("AA", "Aa", 0) == 0); + assert(libsimple_strncasecmpnul("Aa", "AA", 0) == 0); + assert(libsimple_strncasecmpnul("AA", "AA", 0) == 0); + return 0; +} + +#endif diff --git a/strncaseends.c b/strncaseends.c index 708c16a..6d69acc 100644 --- a/strncaseends.c +++ b/strncaseends.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncaseeq.c b/strncaseeq.c new file mode 100644 index 0000000..a0bfb02 --- /dev/null +++ b/strncaseeq.c @@ -0,0 +1,48 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strncaseeq(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strncaseeq("abc", "abc", 5) == 1); + assert(libsimple_strncaseeq("abc", "ab", 5) == 0); + assert(libsimple_strncaseeq("ab", "abc", 5) == 0); + assert(libsimple_strncaseeq("ab", "xy", 5) == 0); + assert(libsimple_strncaseeq("xy", "ab", 5) == 0); + assert(libsimple_strncaseeq("", "1", 5) == 0); + assert(libsimple_strncaseeq("1", "", 5) == 0); + assert(libsimple_strncaseeq("", "", 5) == 1); + assert(libsimple_strncaseeq("abc", "ABC", 5) == 1); + assert(libsimple_strncaseeq("ABC", "abc", 5) == 1); + assert(libsimple_strncaseeq("abc", "abc", 1) == 1); + assert(libsimple_strncaseeq("abc", "ab", 1) == 1); + assert(libsimple_strncaseeq("ab", "abc", 1) == 1); + assert(libsimple_strncaseeq("ab", "xy", 1) == 0); + assert(libsimple_strncaseeq("xy", "ab", 1) == 0); + assert(libsimple_strncaseeq("", "1", 1) == 0); + assert(libsimple_strncaseeq("1", "", 1) == 0); + assert(libsimple_strncaseeq("", "", 1) == 1); + assert(libsimple_strncaseeq("abc", "ABC", 1) == 1); + assert(libsimple_strncaseeq("ABC", "abc", 1) == 1); + assert(libsimple_strncaseeq("abc", "abc", 0) == 1); + assert(libsimple_strncaseeq("abc", "ab", 0) == 1); + assert(libsimple_strncaseeq("ab", "abc", 0) == 1); + assert(libsimple_strncaseeq("ab", "xy", 0) == 1); + assert(libsimple_strncaseeq("xy", "ab", 0) == 1); + assert(libsimple_strncaseeq("", "1", 0) == 1); + assert(libsimple_strncaseeq("1", "", 0) == 1); + assert(libsimple_strncaseeq("", "", 0) == 1); + assert(libsimple_strncaseeq("abc", "ABC", 0) == 1); + assert(libsimple_strncaseeq("ABC", "abc", 0) == 1); + return 0; +} + +#endif diff --git a/strncaseeqlen.c b/strncaseeqlen.c index 56ace80..c70f1e7 100644 --- a/strncaseeqlen.c +++ b/strncaseeqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncaseeqnul.c b/strncaseeqnul.c new file mode 100644 index 0000000..a8c5e01 --- /dev/null +++ b/strncaseeqnul.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strncaseeqnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strncaseeqnul("abc", "abc", 5) == 1); + assert(libsimple_strncaseeqnul("abc", "ab", 5) == 0); + assert(libsimple_strncaseeqnul("ab", "abc", 5) == 0); + assert(libsimple_strncaseeqnul("ab", "xy", 5) == 0); + assert(libsimple_strncaseeqnul("xy", "ab", 5) == 0); + assert(libsimple_strncaseeqnul("", "1", 5) == 0); + assert(libsimple_strncaseeqnul("1", "", 5) == 0); + assert(libsimple_strncaseeqnul("", "", 5) == 1); + assert(libsimple_strncaseeqnul("abc", "ABC", 5) == 1); + assert(libsimple_strncaseeqnul("ABC", "abc", 5) == 1); + assert(libsimple_strncaseeqnul("", NULL, 5) == 0); + assert(libsimple_strncaseeqnul("1", NULL, 5) == 0); + assert(libsimple_strncaseeqnul(NULL, "", 5) == 0); + assert(libsimple_strncaseeqnul(NULL, "1", 5) == 0); + assert(libsimple_strncaseeqnul(NULL, NULL, 5) == 1); + assert(libsimple_strncaseeqnul("abc", "abc", 1) == 1); + assert(libsimple_strncaseeqnul("abc", "ab", 1) == 1); + assert(libsimple_strncaseeqnul("ab", "abc", 1) == 1); + assert(libsimple_strncaseeqnul("ab", "xy", 1) == 0); + assert(libsimple_strncaseeqnul("xy", "ab", 1) == 0); + assert(libsimple_strncaseeqnul("", "1", 1) == 0); + assert(libsimple_strncaseeqnul("1", "", 1) == 0); + assert(libsimple_strncaseeqnul("", "", 1) == 1); + assert(libsimple_strncaseeqnul("abc", "ABC", 1) == 1); + assert(libsimple_strncaseeqnul("ABC", "abc", 1) == 1); + assert(libsimple_strncaseeqnul("", NULL, 1) == 0); + assert(libsimple_strncaseeqnul("1", NULL, 1) == 0); + assert(libsimple_strncaseeqnul(NULL, "", 1) == 0); + assert(libsimple_strncaseeqnul(NULL, "1", 1) == 0); + assert(libsimple_strncaseeqnul(NULL, NULL, 1) == 1); + assert(libsimple_strncaseeqnul("abc", "abc", 0) == 1); + assert(libsimple_strncaseeqnul("abc", "ab", 0) == 1); + assert(libsimple_strncaseeqnul("ab", "abc", 0) == 1); + assert(libsimple_strncaseeqnul("ab", "xy", 0) == 1); + assert(libsimple_strncaseeqnul("xy", "ab", 0) == 1); + assert(libsimple_strncaseeqnul("", "1", 0) == 1); + assert(libsimple_strncaseeqnul("1", "", 0) == 1); + assert(libsimple_strncaseeqnul("", "", 0) == 1); + assert(libsimple_strncaseeqnul("abc", "ABC", 0) == 1); + assert(libsimple_strncaseeqnul("ABC", "abc", 0) == 1); + assert(libsimple_strncaseeqnul("", NULL, 0) == 0); + assert(libsimple_strncaseeqnul("1", NULL, 0) == 0); + assert(libsimple_strncaseeqnul(NULL, "", 0) == 0); + assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0); + assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1); + return 0; +} + +#endif diff --git a/strncasestarts.c b/strncasestarts.c index d7c6350..f8646c9 100644 --- a/strncasestarts.c +++ b/strncasestarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncasestr.c b/strncasestr.c index 08adaf2..3543002 100644 --- a/strncasestr.c +++ b/strncasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnccpy.c b/strnccpy.c new file mode 100644 index 0000000..176c8a0 --- /dev/null +++ b/strnccpy.c @@ -0,0 +1,88 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strnccpy(char *restrict, const char *restrict, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL); + assert(!strcmp(buf, "hello")); + + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL); + assert(!strcmp(buf, "hello")); + + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL); + assert(!strncmp(buf, "hellox", 6)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]); + assert(!strncmp(buf, "hellox", 6)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL); + assert(!strncmp(buf, "hellox", 6)); + + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL); + assert(!strncmp(buf, "helx", 4)); + + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchr_inv.c b/strnchr_inv.c index 7854d13..66f5238 100644 --- a/strnchr_inv.c +++ b/strnchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchrnul.c b/strnchrnul.c index 4e7e1b8..b6b3a39 100644 --- a/strnchrnul.c +++ b/strnchrnul.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strnchrnul_inv.c b/strnchrnul_inv.c index a887221..8bbbdab 100644 --- a/strnchrnul_inv.c +++ b/strnchrnul_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strncmove.c b/strncmove.c index 1a03d2d..37b2bb4 100644 --- a/strncmove.c +++ b/strncmove.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -50,277 +50,329 @@ main(void) char buf[1024]; - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 1024) == &buf[5 + 6]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 1024) == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 1024) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 1024) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 1024) == &buf[3 + 6]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 1024) == &buf[3 + 5]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 1024) == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 1024) == NULL); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 1024) == &buf[8 + 6]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 1024) == &buf[8 + 5]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 1024) == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 1024) == NULL); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 6) == &buf[5 + 6]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 6) == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 6) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 6) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 6) == &buf[3 + 6]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 6) == &buf[3 + 5]); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 6) == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 6) == NULL); assert(!strcmp(buf, "---hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 6) == &buf[8 + 6]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 6) == &buf[8 + 5]); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 6) == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 6) == NULL); assert(!strcmp(buf, "-----helhello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 5) == &buf[5 + 5]); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----hello-", 11)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 5) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 5) == &buf[5 + 5]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 5) == &buf[5 + 3]); assert(!strcmp(buf, "-----hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 5) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 5) == NULL); assert(!strcmp(buf, "---hellolo")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 5) == &buf[3 + 5]); assert(!strcmp(buf, "---hellolo")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 5) == &buf[3 + 3]); assert(!strcmp(buf, "---hel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 5) == NULL); assert(!strcmp(buf, "---hellolo")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 5) == &buf[8 + 5]); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 5) == &buf[8 + 3]); assert(!strcmp(buf, "-----helhel")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 5) == NULL); assert(!strncmp(buf, "-----helhello-", 14)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], '\0', 3) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'o', 3) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'l', 3) == &buf[5 + 3]); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[5], &buf[5], 'x', 3) == NULL); assert(!strcmp(buf, "-----hello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], '\0', 3) == NULL); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'o', 3) == NULL); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'l', 3) == &buf[3 + 3]); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[3], &buf[5], 'x', 3) == NULL); assert(!strcmp(buf, "---helello")); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], '\0', 3) == NULL); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'o', 3) == NULL); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'l', 3) == &buf[8 + 3]); assert(!strncmp(buf, "-----helhel-", 12)); - memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; + memset(buf, '-', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; strcpy(&buf[5], "hello"); assert(libsimple_strncmove(&buf[8], &buf[5], 'x', 3) == NULL); assert(!strncmp(buf, "-----helhel-", 12)); diff --git a/strncmpnul.c b/strncmpnul.c new file mode 100644 index 0000000..25fd49b --- /dev/null +++ b/strncmpnul.c @@ -0,0 +1,58 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strncmpnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strncmpnul(NULL, NULL, 5) == 0); + assert(libsimple_strncmpnul(NULL, "", 5) < 0); + assert(libsimple_strncmpnul("", NULL, 5) > 0); + assert(libsimple_strncmpnul("", "", 5) == 0); + assert(libsimple_strncmpnul(NULL, "x", 5) < 0); + assert(libsimple_strncmpnul("x", NULL, 5) > 0); + assert(libsimple_strncmpnul("x", "x", 5) == 0); + assert(libsimple_strncmpnul("a", "b", 5) < 0); + assert(libsimple_strncmpnul("b", "a", 5) > 0); + assert(libsimple_strncmpnul("aa", "ab", 5) < 0); + assert(libsimple_strncmpnul("ab", "aa", 5) > 0); + assert(libsimple_strncmpnul("aa", "aa", 5) == 0); + assert(libsimple_strncmpnul("A", "a", 5) < 0); + assert(libsimple_strncmpnul("a", "A", 5) > 0); + assert(libsimple_strncmpnul("AA", "Aa", 5) < 0); + assert(libsimple_strncmpnul("Aa", "AA", 5) > 0); + assert(libsimple_strncmpnul("AA", "AA", 5) == 0); + assert(libsimple_strncmpnul("aa", "ab", 1) == 0); + assert(libsimple_strncmpnul("ab", "aa", 1) == 0); + assert(libsimple_strncmpnul("aa", "aa", 1) == 0); + assert(libsimple_strncmpnul("AA", "Aa", 1) == 0); + assert(libsimple_strncmpnul("Aa", "AA", 1) == 0); + assert(libsimple_strncmpnul("AA", "AA", 1) == 0); + assert(libsimple_strncmpnul(NULL, NULL, 0) == 0); + assert(libsimple_strncmpnul(NULL, "", 0) < 0); + assert(libsimple_strncmpnul("", NULL, 0) > 0); + assert(libsimple_strncmpnul("", "", 0) == 0); + assert(libsimple_strncmpnul(NULL, "x", 0) < 0); + assert(libsimple_strncmpnul("x", NULL, 0) > 0); + assert(libsimple_strncmpnul("x", "x", 0) == 0); + assert(libsimple_strncmpnul("a", "b", 0) == 0); + assert(libsimple_strncmpnul("b", "a", 0) == 0); + assert(libsimple_strncmpnul("aa", "ab", 0) == 0); + assert(libsimple_strncmpnul("ab", "aa", 0) == 0); + assert(libsimple_strncmpnul("aa", "aa", 0) == 0); + assert(libsimple_strncmpnul("A", "a", 0) == 0); + assert(libsimple_strncmpnul("a", "A", 0) == 0); + assert(libsimple_strncmpnul("AA", "Aa", 0) == 0); + assert(libsimple_strncmpnul("Aa", "AA", 0) == 0); + assert(libsimple_strncmpnul("AA", "AA", 0) == 0); + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strneq.c b/strneq.c new file mode 100644 index 0000000..f5ae440 --- /dev/null +++ b/strneq.c @@ -0,0 +1,48 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strneq(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strneq("abc", "abc", 5) == 1); + assert(libsimple_strneq("abc", "ab", 5) == 0); + assert(libsimple_strneq("ab", "abc", 5) == 0); + assert(libsimple_strneq("ab", "xy", 5) == 0); + assert(libsimple_strneq("xy", "ab", 5) == 0); + assert(libsimple_strneq("", "1", 5) == 0); + assert(libsimple_strneq("1", "", 5) == 0); + assert(libsimple_strneq("", "", 5) == 1); + assert(libsimple_strneq("abc", "ABC", 5) == 0); + assert(libsimple_strneq("ABC", "abc", 5) == 0); + assert(libsimple_strneq("abc", "abc", 1) == 1); + assert(libsimple_strneq("abc", "ab", 1) == 1); + assert(libsimple_strneq("ab", "abc", 1) == 1); + assert(libsimple_strneq("ab", "xy", 1) == 0); + assert(libsimple_strneq("xy", "ab", 1) == 0); + assert(libsimple_strneq("", "1", 1) == 0); + assert(libsimple_strneq("1", "", 1) == 0); + assert(libsimple_strneq("", "", 1) == 1); + assert(libsimple_strneq("abc", "ABC", 1) == 0); + assert(libsimple_strneq("ABC", "abc", 1) == 0); + assert(libsimple_strneq("abc", "abc", 0) == 1); + assert(libsimple_strneq("abc", "ab", 0) == 1); + assert(libsimple_strneq("ab", "abc", 0) == 1); + assert(libsimple_strneq("ab", "xy", 0) == 1); + assert(libsimple_strneq("xy", "ab", 0) == 1); + assert(libsimple_strneq("", "1", 0) == 1); + assert(libsimple_strneq("1", "", 0) == 1); + assert(libsimple_strneq("", "", 0) == 1); + assert(libsimple_strneq("abc", "ABC", 0) == 1); + assert(libsimple_strneq("ABC", "abc", 0) == 1); + return 0; +} + +#endif diff --git a/strneqlen.c b/strneqlen.c index 5ef50e3..09d3b8f 100644 --- a/strneqlen.c +++ b/strneqlen.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strneqnul.c b/strneqnul.c new file mode 100644 index 0000000..066d4e7 --- /dev/null +++ b/strneqnul.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strneqnul(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_strneqnul("abc", "abc", 5) == 1); + assert(libsimple_strneqnul("abc", "ab", 5) == 0); + assert(libsimple_strneqnul("ab", "abc", 5) == 0); + assert(libsimple_strneqnul("ab", "xy", 5) == 0); + assert(libsimple_strneqnul("xy", "ab", 5) == 0); + assert(libsimple_strneqnul("", "1", 5) == 0); + assert(libsimple_strneqnul("1", "", 5) == 0); + assert(libsimple_strneqnul("", "", 5) == 1); + assert(libsimple_strneqnul("abc", "ABC", 5) == 0); + assert(libsimple_strneqnul("ABC", "abc", 5) == 0); + assert(libsimple_strneqnul("", NULL, 5) == 0); + assert(libsimple_strneqnul("1", NULL, 5) == 0); + assert(libsimple_strneqnul(NULL, "", 5) == 0); + assert(libsimple_strneqnul(NULL, "1", 5) == 0); + assert(libsimple_strneqnul(NULL, NULL, 5) == 1); + assert(libsimple_strneqnul("abc", "abc", 1) == 1); + assert(libsimple_strneqnul("abc", "ab", 1) == 1); + assert(libsimple_strneqnul("ab", "abc", 1) == 1); + assert(libsimple_strneqnul("ab", "xy", 1) == 0); + assert(libsimple_strneqnul("xy", "ab", 1) == 0); + assert(libsimple_strneqnul("", "1", 1) == 0); + assert(libsimple_strneqnul("1", "", 1) == 0); + assert(libsimple_strneqnul("", "", 1) == 1); + assert(libsimple_strneqnul("abc", "ABC", 1) == 0); + assert(libsimple_strneqnul("ABC", "abc", 1) == 0); + assert(libsimple_strneqnul("", NULL, 1) == 0); + assert(libsimple_strneqnul("1", NULL, 1) == 0); + assert(libsimple_strneqnul(NULL, "", 1) == 0); + assert(libsimple_strneqnul(NULL, "1", 1) == 0); + assert(libsimple_strneqnul(NULL, NULL, 1) == 1); + assert(libsimple_strneqnul("abc", "abc", 0) == 1); + assert(libsimple_strneqnul("abc", "ab", 0) == 1); + assert(libsimple_strneqnul("ab", "abc", 0) == 1); + assert(libsimple_strneqnul("ab", "xy", 0) == 1); + assert(libsimple_strneqnul("xy", "ab", 0) == 1); + assert(libsimple_strneqnul("", "1", 0) == 1); + assert(libsimple_strneqnul("1", "", 0) == 1); + assert(libsimple_strneqnul("", "", 0) == 1); + assert(libsimple_strneqnul("abc", "ABC", 0) == 1); + assert(libsimple_strneqnul("ABC", "abc", 0) == 1); + assert(libsimple_strneqnul("", NULL, 0) == 0); + assert(libsimple_strneqnul("1", NULL, 0) == 0); + assert(libsimple_strneqnul(NULL, "", 0) == 0); + assert(libsimple_strneqnul(NULL, "1", 0) == 0); + assert(libsimple_strneqnul(NULL, NULL, 0) == 1); + return 0; +} + +#endif diff --git a/strnisutf8.c b/strnisutf8.c new file mode 100644 index 0000000..8c775ee --- /dev/null +++ b/strnisutf8.c @@ -0,0 +1,78 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline int libsimple_strnisutf8(const char *, size_t, int); + + +#else +#include "test.h" + +int +main(void) +{ +#define ASSERT(STRING, GOOD)\ + do {\ + assert(libsimple_strnisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\ + assert(libsimple_strnisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\ + assert(libsimple_strnisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\ + } while (0) + + int i; + for (i = 0; i < 2; i++) { + ASSERT("", 1); + ASSERT("a", 1); + ASSERT("abc", 1); + ASSERT("123", 1); + ASSERT("åäö", 1); + ASSERT("𝖆𝖇𝖈", 1); + ASSERT("\x1b", 1); + ASSERT("\n\r\t\f", 1); + ASSERT("\xFF", 0); + ASSERT("\x01", 1); + ASSERT("\x7F", 1); + ASSERT("\x80", 0); + ASSERT("\xC0", 0); + ASSERT("\xC0\x80", i); + ASSERT("\xC0\x81", 0); + ASSERT("\xCF", 0); + ASSERT("\xEF", 0); + ASSERT("\xEF\x8F", 0); + ASSERT("\xF7", 0); + ASSERT("\xF7\x8F", 0); + ASSERT("\xF7\x8F\x8F", 0); + ASSERT("\xFA", 0); + ASSERT("\xFA\x8F", 0); + ASSERT("\xFA\x8F\x8F", 0); + ASSERT("\xFA\x8F\x8F\x8F", 0); + ASSERT("\xFD", 0); + ASSERT("\xFD\x8F", 0); + ASSERT("\xFD\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE", 0); + ASSERT("\xFE\x8F", 0); + ASSERT("\xFE\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF", 0); + ASSERT("\xFF\x8F", 0); + ASSERT("\xFF\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xC1\x80", 0); + ASSERT("\xC2\x80", 1); + ASSERT("\xE1\x80\x80\x80", 0); + ASSERT("\xE1\x80\xC0\x80", 0); + ASSERT("\xE1\x80\x00\x80", 0); + ASSERT("\xF1\x80\x80\x80", 1); + ASSERT("\xFF\x80\x80\x80\x80\x80\x80\x80", 0); + } + return 0; +} + +#endif diff --git a/strnmove.c b/strnmove.c new file mode 100644 index 0000000..4bbcaa0 --- /dev/null +++ b/strnmove.c @@ -0,0 +1,92 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strnmove(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], 9) == buf); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, 12) == buf); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]); + assert(!strncmp(buf, "helhello worldx", 15)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], 8) == buf); + assert(!strcmp(buf, "lo worldrld")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, 11) == buf); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]); + assert(!strcmp(buf, "helhe world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], 2) == buf); + assert(!strcmp(buf, "lollo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, 2) == buf); + assert(!strcmp(buf, "hello world")); + + return 0; +} + +#endif diff --git a/strnreplace.c b/strnreplace.c new file mode 100644 index 0000000..eb26ec9 --- /dev/null +++ b/strnreplace.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strnreplace(char *, int, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', SIZE_MAX) == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 12) == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 11) == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 6) == &buf[6]); + assert(!memcmp(buf, "hellx world\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 5) == &buf[5]); + assert(!memcmp(buf, "hellx world\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 4) == &buf[4]); + assert(!memcmp(buf, "hello world\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/strnset.c b/strnset.c new file mode 100644 index 0000000..b2e1da4 --- /dev/null +++ b/strnset.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strnset(char *, int, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, 'x', SIZE_MAX) == buf); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, '\0', SIZE_MAX) == buf); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, 'x', 5) == buf); + assert(!strcmp(buf, "xxxxx world")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, '\0', 5) == buf); + assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/strnstarts.c b/strnstarts.c index 727cf3e..1fbeed3 100644 --- a/strnstarts.c +++ b/strnstarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strntolower.c b/strntolower.c new file mode 100644 index 0000000..33fdfa1 --- /dev/null +++ b/strntolower.c @@ -0,0 +1,57 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strntolower(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], SIZE_MAX), "abcdeabcde12345")); + assert(!strcmp(buf, "ABCabcdeabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], SIZE_MAX), "deabcde12345")); + assert(!strcmp(buf, "deabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], SIZE_MAX), "abcdeabcde12345")); + assert(!strcmp(buf, "abcdeabcde12345")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + buf[18] = 'X'; + assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 15), "abcdeabcde12345X")); + assert(!strcmp(buf, "ABCabcdeabcde12345X")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 12), "deabcde12345345")); + assert(!strcmp(buf, "deabcde12345345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345X"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 15), "abcdeabcde12345X")); + assert(!strcmp(buf, "abcdeabcde12345X")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 0), "DEabcde12345")); + assert(!strcmp(buf, "ABCDEabcde12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 0), "ABCDEabcde12345")); + assert(!strcmp(buf, "ABCDEabcde12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 0), "ABCDEabcde12345")); + assert(!strcmp(buf, "ABCDEabcde12345")); + + return 0; +} + +#endif diff --git a/strntoupper.c b/strntoupper.c new file mode 100644 index 0000000..2959af8 --- /dev/null +++ b/strntoupper.c @@ -0,0 +1,57 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strntoupper(char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); + assert(!strcmp(buf, "abcABCDEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], SIZE_MAX), "DEABCDE12345")); + assert(!strcmp(buf, "DEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); + assert(!strcmp(buf, "ABCDEABCDE12345")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + buf[18] = 'x'; + assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 15), "ABCDEABCDE12345x")); + assert(!strcmp(buf, "abcABCDEABCDE12345x")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 12), "DEABCDE12345345")); + assert(!strcmp(buf, "DEABCDE12345345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345x"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 15), "ABCDEABCDE12345x")); + assert(!strcmp(buf, "ABCDEABCDE12345x")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 0), "deABCDE12345")); + assert(!strcmp(buf, "abcdeABCDE12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 0), "abcdeABCDE12345")); + assert(!strcmp(buf, "abcdeABCDE12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 0), "abcdeABCDE12345")); + assert(!strcmp(buf, "abcdeABCDE12345")); + + return 0; +} + +#endif diff --git a/strrcasechr.c b/strrcasechr.c index 979e61b..26abb7e 100644 --- a/strrcasechr.c +++ b/strrcasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrcasechr_inv.c b/strrcasechr_inv.c index 5572a38..091779d 100644 --- a/strrcasechr_inv.c +++ b/strrcasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrcaseeqlen.c b/strrcaseeqlen.c new file mode 100644 index 0000000..351eaa6 --- /dev/null +++ b/strrcaseeqlen.c @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strrcaseeqlen(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + size_t i, j; + char a[] = "abcdefgh", b[] = "ABCDEFGH"; + + assert(libsimple_strrcaseeqlen("", "") == 0); + assert(libsimple_strrcaseeqlen("x", "") == 0); + assert(libsimple_strrcaseeqlen("x", "y") == 0); + assert(libsimple_strrcaseeqlen("", "y") == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + assert(libsimple_strrcaseeqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); + assert(libsimple_strrcaseeqlen(&b[i], &a[j]) == 8 - (i > j ? i : j)); + a[i] = b[j] = '\0'; + assert(libsimple_strrcaseeqlen(a, b) == (i == j ? i : 0)); + assert(libsimple_strrcaseeqlen(b, a) == (i == j ? i : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "ABCDEFGH"[j]; + } + } + assert(libsimple_strrcaseeqlen("abc", "abc") == 3); + assert(libsimple_strrcaseeqlen("123", "123") == 3); + + return 0; +} + +#endif diff --git a/strrcasestr.c b/strrcasestr.c index 3a3edce..7a17051 100644 --- a/strrcasestr.c +++ b/strrcasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrchr_inv.c b/strrchr_inv.c index 37b7e79..eb93c0e 100644 --- a/strrchr_inv.c +++ b/strrchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strreplace.c b/strreplace.c new file mode 100644 index 0000000..e427d7f --- /dev/null +++ b/strreplace.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strreplace(char *, int, int); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/strreqlen.c b/strreqlen.c new file mode 100644 index 0000000..5c7cece --- /dev/null +++ b/strreqlen.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strreqlen(const char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + size_t i, j; + char a[] = "abcdefgh", b[] = "abcdefgh"; + + assert(libsimple_strreqlen("", "") == 0); + assert(libsimple_strreqlen("x", "") == 0); + assert(libsimple_strreqlen("x", "y") == 0); + assert(libsimple_strreqlen("", "y") == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + assert(libsimple_strreqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); + a[i] = b[j] = '\0'; + assert(libsimple_strreqlen(a, b) == (i == j ? i : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "abcdefgh"[j]; + } + } + assert(libsimple_strreqlen("abc", "ABC") == 0); + assert(libsimple_strreqlen("123", "123") == 3); + + return 0; +} + +#endif diff --git a/strrncasechr.c b/strrncasechr.c index f4046d1..60ab4ac 100644 --- a/strrncasechr.c +++ b/strrncasechr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrncasechr_inv.c b/strrncasechr_inv.c index eb68b49..a471420 100644 --- a/strrncasechr_inv.c +++ b/strrncasechr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrncaseeqlen.c b/strrncaseeqlen.c new file mode 100644 index 0000000..d904577 --- /dev/null +++ b/strrncaseeqlen.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strrncaseeqlen(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + size_t i, j, n; + + for (n = 0; n < 10; n++) { + char a[] = "abcdefgh", b[] = "ABCDEFGH"; + size_t I, J; + assert(libsimple_strrncaseeqlen("", "", n) == 0); + assert(libsimple_strrncaseeqlen("x", "", n) == 0); + assert(libsimple_strrncaseeqlen("x", "y", n) == 0); + assert(libsimple_strrncaseeqlen("", "y", n) == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + I = 8 - i; + J = 8 - j; + assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + a[i] = b[j] = '\0'; + assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "ABCDEFGH"[j]; + } + } + assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n)); + assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); + } + + return 0; +} + +#endif diff --git a/strrncasestr.c b/strrncasestr.c index f1874c7..be57822 100644 --- a/strrncasestr.c +++ b/strrncasestr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrnchr_inv.c b/strrnchr_inv.c index fe657f9..060d3b0 100644 --- a/strrnchr_inv.c +++ b/strrnchr_inv.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strrneqlen.c b/strrneqlen.c new file mode 100644 index 0000000..f76cac8 --- /dev/null +++ b/strrneqlen.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strrneqlen(const char *, const char *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + size_t i, j, n; + + for (n = 0; n < 10; n++) { + char a[] = "abcdefgh", b[] = "abcdefgh"; + size_t I, J; + assert(libsimple_strrneqlen("", "", n) == 0); + assert(libsimple_strrneqlen("x", "", n) == 0); + assert(libsimple_strrneqlen("x", "y", n) == 0); + assert(libsimple_strrneqlen("", "y", n) == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + I = 8 - i; + J = 8 - j; + assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + a[i] = b[j] = '\0'; + assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "abcdefgh"[j]; + } + } + assert(libsimple_strrneqlen("abc", "ABC", n) == 0); + assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n)); + } + + return 0; +} + +#endif @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strset.c b/strset.c new file mode 100644 index 0000000..8d92f31 --- /dev/null +++ b/strset.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strset(char *, int); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strset(buf, 'x') == buf); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strset(buf, '\0') == buf); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + + return 0; +} + +#endif diff --git a/strstarts.c b/strstarts.c index b476222..321d3c5 100644 --- a/strstarts.c +++ b/strstarts.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtoh.c b/strtoh.c new file mode 100644 index 0000000..1c0181a --- /dev/null +++ b/strtoh.c @@ -0,0 +1,69 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +signed short int +libsimple_strtoh(const char *restrict nptr, char **restrict end, int base) +{ + signed long int r = strtol(nptr, end, base); + if (r < SHRT_MIN) { + r = SHRT_MIN; + errno = ERANGE; + } else if (r > SHRT_MAX) { + r = SHRT_MAX; + errno = ERANGE; + } + return (signed short int)r; +} + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%x", (unsigned int)SHRT_MAX); + errno = 0; + assert(strtoh(str, NULL, 0) == SHRT_MAX && !errno); + assert(strtoh(str, NULL, 16) == SHRT_MAX && !errno); + assert(strtoh(&str[2], NULL, 16) == SHRT_MAX && !errno); + assert(strtoh(str, NULL, 10) == 0 && !errno); + assert(strtoh(str, &e, 0) == SHRT_MAX && !*e && !errno); + assert(strtoh(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%x ", (unsigned int)SHRT_MAX); + assert(strtoh(str, &e, 16) == SHRT_MAX && *e == ' ' && !errno); + sprintf(str, "-%i", SHRT_MAX); + assert(strtoh(&str[1], &e, 10) == SHRT_MAX && !*e && !errno); + assert(strtoh(str, &e, 10) == -SHRT_MAX && !*e && !errno); + sprintf(str, "%i", SHRT_MIN); + assert(strtoh(str, &e, 10) == SHRT_MIN && !*e && !errno); + assert(strtoh("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtoh("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtoh("01234", &e, 0) == 01234 && !*e && !errno); + sprintf(str, "%i", SHRT_MAX); + add_one(str); + assert(strtoh(str, &e, 10) == SHRT_MAX && !*e && errno == ERANGE); + errno = 0; + sprintf(str, "%i", SHRT_MIN); + add_one(str); + assert(strtoh(str, &e, 10) == SHRT_MIN && !*e && errno == ERANGE); + errno = 0; + assert(!strtoh("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtohh.c b/strtohh.c new file mode 100644 index 0000000..3fb21b8 --- /dev/null +++ b/strtohh.c @@ -0,0 +1,69 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +signed char +libsimple_strtohh(const char *restrict nptr, char **restrict end, int base) +{ + signed long int r = strtol(nptr, end, base); + if (r < SCHAR_MIN) { + r = SCHAR_MIN; + errno = ERANGE; + } else if (r > SCHAR_MAX) { + r = SCHAR_MAX; + errno = ERANGE; + } + return (signed char)r; +} + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%x", (unsigned int)SCHAR_MAX); + errno = 0; + assert(strtohh(str, NULL, 0) == SCHAR_MAX && !errno); + assert(strtohh(str, NULL, 16) == SCHAR_MAX && !errno); + assert(strtohh(&str[2], NULL, 16) == SCHAR_MAX && !errno); + assert(strtohh(str, NULL, 10) == 0 && !errno); + assert(strtohh(str, &e, 0) == SCHAR_MAX && !*e && !errno); + assert(strtohh(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%x ", (unsigned int)SCHAR_MAX); + assert(strtohh(str, &e, 16) == SCHAR_MAX && *e == ' ' && !errno); + sprintf(str, "-%i", SCHAR_MAX); + assert(strtohh(&str[1], &e, 10) == SCHAR_MAX && !*e && !errno); + assert(strtohh(str, &e, 10) == -SCHAR_MAX && !*e && !errno); + sprintf(str, "%i", SCHAR_MIN); + assert(strtohh(str, &e, 10) == SCHAR_MIN && !*e && !errno); + assert(strtohh("12", &e, 10) == 12 && !*e && !errno); + assert(strtohh("12", &e, 8) == 012 && !*e && !errno); + assert(strtohh("012", &e, 0) == 012 && !*e && !errno); + sprintf(str, "%i", SCHAR_MAX); + add_one(str); + assert(strtohh(str, &e, 10) == SCHAR_MAX && !*e && errno == ERANGE); + errno = 0; + sprintf(str, "%i", SCHAR_MIN); + add_one(str); + assert(strtohh(str, &e, 10) == SCHAR_MIN && !*e && errno == ERANGE); + errno = 0; + assert(!strtohh("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoi.c b/strtoi.c new file mode 100644 index 0000000..946d647 --- /dev/null +++ b/strtoi.c @@ -0,0 +1,69 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +signed int +libsimple_strtoi(const char *restrict nptr, char **restrict end, int base) +{ + signed long int r = strtol(nptr, end, base); + if (r < INT_MIN) { + r = INT_MIN; + errno = ERANGE; + } else if (r > INT_MAX) { + r = INT_MAX; + errno = ERANGE; + } + return (signed int)r; +} + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%x", INT_MAX); + errno = 0; + assert(strtoi(str, NULL, 0) == INT_MAX && !errno); + assert(strtoi(str, NULL, 16) == INT_MAX && !errno); + assert(strtoi(&str[2], NULL, 16) == INT_MAX && !errno); + assert(strtoi(str, NULL, 10) == 0 && !errno); + assert(strtoi(str, &e, 0) == INT_MAX && !*e && !errno); + assert(strtoi(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%x ", INT_MAX); + assert(strtoi(str, &e, 16) == INT_MAX && *e == ' ' && !errno); + sprintf(str, "-%i", INT_MAX); + assert(strtoi(&str[1], &e, 10) == INT_MAX && !*e && !errno); + assert(strtoi(str, &e, 10) == -INT_MAX && !*e && !errno); + sprintf(str, "%i", INT_MIN); + assert(strtoi(str, &e, 10) == INT_MIN && !*e && !errno); + assert(strtoi("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtoi("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtoi("01234", &e, 0) == 01234 && !*e && !errno); + sprintf(str, "%i", INT_MAX); + add_one(str); + assert(strtoi(str, &e, 10) == INT_MAX && !*e && errno == ERANGE); + errno = 0; + sprintf(str, "%i", INT_MIN); + add_one(str); + assert(strtoi(str, &e, 10) == INT_MIN && !*e && errno == ERANGE); + errno = 0; + assert(!strtoi("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoi16.c b/strtoi16.c new file mode 100644 index 0000000..e247e19 --- /dev/null +++ b/strtoi16.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 32767LL +#define RET_MIN (-RET_MAX - 1LL) + + +int_least16_t +libsimple_strtoi16(const char *restrict nptr, char **restrict end, int base) +{ + intmax_t r = strtoimax(nptr, end, base); + if (r < RET_MIN) { + r = RET_MIN; + errno = ERANGE; + } else if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (int_least16_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtoi16("0x7FFF", NULL, 0) == INT16_C(0x7FFF) && !errno); + assert(strtoi16("0x7FFF", NULL, 16) == INT16_C(0x7FFF) && !errno); + assert(strtoi16("7FFF", NULL, 16) == INT16_C(0x7FFF) && !errno); + assert(strtoi16("0x7FFF", NULL, 10) == 0 && !errno); + assert(strtoi16("0x7FFF", &e, 0) == INT16_C(0x7FFF) && !*e && !errno); + assert(strtoi16("0x7FFF ", &e, 16) == INT16_C(0x7FFF) && *e == ' ' && !errno); + assert(strtoi16("0x7FFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtoi16("32767", &e, 10) == INT16_C(0x7FFF) && !*e && !errno); + assert(strtoi16("-32767", &e, 10) == INT16_C(-32767) && !*e && !errno); + assert(strtoi16("-32768", &e, 10) == INT16_C(-32768) && !*e && !errno); + assert(strtoi16("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtoi16("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtoi16("01234", &e, 0) == 01234 && !*e && !errno); + assert(strtoi16("32768", &e, 10) == INT16_C(32767) && !*e && errno == ERANGE); + errno = 0; + assert(strtoi16("-32769", &e, 10) == INT16_C(-32768) && !*e && errno == ERANGE); + errno = 0; + assert(!strtoi16("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoi32.c b/strtoi32.c new file mode 100644 index 0000000..4a768e8 --- /dev/null +++ b/strtoi32.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 2147483647LL +#define RET_MIN (-RET_MAX - 1LL) + + +int_least32_t +libsimple_strtoi32(const char *restrict nptr, char **restrict end, int base) +{ + intmax_t r = strtoimax(nptr, end, base); + if (r < RET_MIN) { + r = RET_MIN; + errno = ERANGE; + } else if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (int_least32_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtoi32("0x7FFFFFFF", NULL, 0) == INT32_C(0x7FFFFFFF) && !errno); + assert(strtoi32("0x7FFFFFFF", NULL, 16) == INT32_C(0x7FFFFFFF) && !errno); + assert(strtoi32("7FFFFFFF", NULL, 16) == INT32_C(0x7FFFFFFF) && !errno); + assert(strtoi32("0x7FFFFFFF", NULL, 10) == 0 && !errno); + assert(strtoi32("0x7FFFFFFF", &e, 0) == INT32_C(0x7FFFFFFF) && !*e && !errno); + assert(strtoi32("0x7FFFFFFF ", &e, 16) == INT32_C(0x7FFFFFFF) && *e == ' ' && !errno); + assert(strtoi32("0x7FFFFFFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtoi32("2147483647", &e, 10) == INT32_C(0x7FFFFFFF) && !*e && !errno); + assert(strtoi32("-2147483647", &e, 10) == INT32_C(-2147483647) && !*e && !errno); + assert(strtoi32("-2147483648", &e, 10) == INT32_C(-2147483648) && !*e && !errno); + assert(strtoi32("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtoi32("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtoi32("01234", &e, 0) == 01234 && !*e && !errno); + assert(strtoi32("2147483648", &e, 10) == INT32_C(2147483647) && !*e && errno == ERANGE); + errno = 0; + assert(strtoi32("-2147483649", &e, 10) == INT32_C(-2147483648) && !*e && errno == ERANGE); + errno = 0; + assert(!strtoi32("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoi64.c b/strtoi64.c new file mode 100644 index 0000000..a4c87bc --- /dev/null +++ b/strtoi64.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 9223372036854775807LL +#define RET_MIN (-RET_MAX - 1LL) + + +int_least64_t +libsimple_strtoi64(const char *restrict nptr, char **restrict end, int base) +{ + intmax_t r = strtoimax(nptr, end, base); + if (r < RET_MIN) { + r = RET_MIN; + errno = ERANGE; + } else if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (int_least64_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtoi64("0x7FFFFFFFFFFFFFFF", NULL, 0) == INT64_C(0x7FFFFFFFFFFFFFFF) && !errno); + assert(strtoi64("0x7FFFFFFFFFFFFFFF", NULL, 16) == INT64_C(0x7FFFFFFFFFFFFFFF) && !errno); + assert(strtoi64("7FFFFFFFFFFFFFFF", NULL, 16) == INT64_C(0x7FFFFFFFFFFFFFFF) && !errno); + assert(strtoi64("0x7FFFFFFFFFFFFFFF", NULL, 10) == 0 && !errno); + assert(strtoi64("0x7FFFFFFFFFFFFFFF", &e, 0) == INT64_C(0x7FFFFFFFFFFFFFFF) && !*e && !errno); + assert(strtoi64("0x7FFFFFFFFFFFFFFF ", &e, 16) == INT64_C(0x7FFFFFFFFFFFFFFF) && *e == ' ' && !errno); + assert(strtoi64("0x7FFFFFFFFFFFFFFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtoi64("9223372036854775807", &e, 10) == INT64_C(0x7FFFFFFFFFFFFFFF) && !*e && !errno); + assert(strtoi64("-9223372036854775807", &e, 10) == INT64_C(-9223372036854775807) && !*e && !errno); + assert(strtoi64("-9223372036854775808", &e, 10) == INT64_C(-9223372036854775808) && !*e && !errno); + assert(strtoi64("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtoi64("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtoi64("01234", &e, 0) == 01234 && !*e && !errno); + assert(strtoi64("9223372036854775808", &e, 10) == INT64_C(9223372036854775807) && !*e && errno == ERANGE); + errno = 0; + assert(strtoi64("-9223372036854775809", &e, 10) == INT64_C(-9223372036854775808) && !*e && errno == ERANGE); + errno = 0; + assert(!strtoi64("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoi8.c b/strtoi8.c new file mode 100644 index 0000000..01f783a --- /dev/null +++ b/strtoi8.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 127LL +#define RET_MIN (-RET_MAX - 1LL) + + +int_least8_t +libsimple_strtoi8(const char *restrict nptr, char **restrict end, int base) +{ + intmax_t r = strtoimax(nptr, end, base); + if (r < RET_MIN) { + r = RET_MIN; + errno = ERANGE; + } else if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (int_least8_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtoi8("0x7F", NULL, 0) == INT8_C(0x7F) && !errno); + assert(strtoi8("0x7F", NULL, 16) == INT8_C(0x7F) && !errno); + assert(strtoi8("7F", NULL, 16) == INT8_C(0x7F) && !errno); + assert(strtoi8("0x7F", NULL, 10) == 0 && !errno); + assert(strtoi8("0x7F", &e, 0) == INT8_C(0x7F) && !*e && !errno); + assert(strtoi8("0x7F ", &e, 16) == INT8_C(0x7F) && *e == ' ' && !errno); + assert(strtoi8("0x7F", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtoi8("127", &e, 10) == INT8_C(0x7F) && !*e && !errno); + assert(strtoi8("-127", &e, 10) == INT8_C(-127) && !*e && !errno); + assert(strtoi8("-128", &e, 10) == INT8_C(-128) && !*e && !errno); + assert(strtoi8("12", &e, 10) == 12 && !*e && !errno); + assert(strtoi8("12", &e, 8) == 012 && !*e && !errno); + assert(strtoi8("012", &e, 0) == 012 && !*e && !errno); + assert(strtoi8("128", &e, 10) == INT8_C(127) && !*e && errno == ERANGE); + errno = 0; + assert(strtoi8("-129", &e, 10) == INT8_C(-128) && !*e && errno == ERANGE); + errno = 0; + assert(!strtoi8("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtolower.c b/strtolower.c new file mode 100644 index 0000000..7f72eb0 --- /dev/null +++ b/strtolower.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strtolower(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strtolower(&buf[3], &buf[0]), "abcdeabcde12345")); + assert(!strcmp(buf, "ABCabcdeabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[3]), "deabcde12345")); + assert(!strcmp(buf, "deabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[0]), "abcdeabcde12345")); + assert(!strcmp(buf, "abcdeabcde12345")); + + return 0; +} + +#endif diff --git a/strtotimespec.c b/strtotimespec.c index d6bd64c..eb02112 100644 --- a/strtotimespec.c +++ b/strtotimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -11,9 +11,12 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch long int nsec = 0; long int mul = 100000000L; const char *p; + const char *end_s; - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } while (isspace(*s)) s++; @@ -58,8 +61,10 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch if (*s != '.') { ts->tv_sec = sec; ts->tv_nsec = 0; - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } return 0; } @@ -85,7 +90,7 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch } } if (end) - *end = (void *)p; + *end = REMOVE_CONST(p, char *); p = s; while (mul) { for (s = p; mul && isdigit(*s); s++) { @@ -118,8 +123,10 @@ libsimple_strtotimespec(struct timespec *restrict ts, const char *restrict s, ch while (isdigit(*s)) s++; } - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } } if (neg && nsec) { @@ -164,8 +171,10 @@ overflow_periodic: } overflow: - if (end) - *end = (void *)s; + if (end) { + end_s = s; + *end = REMOVE_CONST(end_s, char *); + } if (neg) { ts->tv_sec = TIME_MIN; ts->tv_nsec = 0; diff --git a/strtotimeval.c b/strtotimeval.c index 0305fb9..1e3dc9b 100644 --- a/strtotimeval.c +++ b/strtotimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/strtou.c b/strtou.c new file mode 100644 index 0000000..7fe836f --- /dev/null +++ b/strtou.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +unsigned int +libsimple_strtou(const char *restrict nptr, char **restrict end, int base) +{ + unsigned long int r = strtoul(nptr, end, base); + if (r > UINT_MAX) { + r = UINT_MAX; + errno = ERANGE; + } + return (unsigned int)r; +} + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%x", UINT_MAX); + errno = 0; + assert(strtou(str, NULL, 0) == UINT_MAX && !errno); + assert(strtou(str, NULL, 16) == UINT_MAX && !errno); + assert(strtou(&str[2], NULL, 16) == UINT_MAX && !errno); + assert(strtou(str, NULL, 10) == 0 && !errno); + assert(strtou(str, &e, 0) == UINT_MAX && !*e && !errno); + assert(strtou(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%x ", UINT_MAX); + assert(strtou(str, &e, 16) == UINT_MAX && *e == ' ' && !errno); + sprintf(str, "%u", UINT_MAX); + assert(strtou(str, &e, 10) == UINT_MAX && !*e && !errno); + assert(strtou("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtou("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtou("01234", &e, 0) == 01234 && !*e && !errno); + sprintf(str, "%u", UINT_MAX); + add_one(str); + assert(strtou(str, &e, 10) == UINT_MAX && !*e && errno == ERANGE); + errno = 0; + assert(!strtou("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtou16.c b/strtou16.c new file mode 100644 index 0000000..33fbffa --- /dev/null +++ b/strtou16.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 65535ULL + + +uint_least16_t +libsimple_strtou16(const char *restrict nptr, char **restrict end, int base) +{ + uintmax_t r = strtoumax(nptr, end, base); + if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (uint_least16_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtou16("0xFFFF", NULL, 0) == UINT16_C(0xFFFF) && !errno); + assert(strtou16("0xFFFF", NULL, 16) == UINT16_C(0xFFFF) && !errno); + assert(strtou16("FFFF", NULL, 16) == UINT16_C(0xFFFF) && !errno); + assert(strtou16("0xFFFF", NULL, 10) == 0 && !errno); + assert(strtou16("0xFFFF", &e, 0) == UINT16_C(0xFFFF) && !*e && !errno); + assert(strtou16("0xFFFF ", &e, 16) == UINT16_C(0xFFFF) && *e == ' ' && !errno); + assert(strtou16("0xFFFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtou16("65535", &e, 10) == UINT16_C(0xFFFF) && !*e && !errno); + assert(strtou16("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtou16("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtou16("01234", &e, 0) == 01234 && !*e && !errno); + assert(strtou16("65536", &e, 10) == UINT16_C(65535) && !*e && errno == ERANGE); + errno = 0; + assert(!strtou16("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtou32.c b/strtou32.c new file mode 100644 index 0000000..8e20bb1 --- /dev/null +++ b/strtou32.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 4294967295ULL + + +uint_least32_t +libsimple_strtou32(const char *restrict nptr, char **restrict end, int base) +{ + uintmax_t r = strtoumax(nptr, end, base); + if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (uint_least32_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtou32("0xFFFFFFFF", NULL, 0) == UINT32_C(0xFFFFFFFF) && !errno); + assert(strtou32("0xFFFFFFFF", NULL, 16) == UINT32_C(0xFFFFFFFF) && !errno); + assert(strtou32("FFFFFFFF", NULL, 16) == UINT32_C(0xFFFFFFFF) && !errno); + assert(strtou32("0xFFFFFFFF", NULL, 10) == 0 && !errno); + assert(strtou32("0xFFFFFFFF", &e, 0) == UINT32_C(0xFFFFFFFF) && !*e && !errno); + assert(strtou32("0xFFFFFFFF ", &e, 16) == UINT32_C(0xFFFFFFFF) && *e == ' ' && !errno); + assert(strtou32("0xFFFFFFFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtou32("4294967295", &e, 10) == UINT32_C(0xFFFFFFFF) && !*e && !errno); + assert(strtou32("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtou32("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtou32("01234", &e, 0) == 01234 && !*e && !errno); + assert(strtou32("4294967296", &e, 10) == UINT32_C(4294967295) && !*e && errno == ERANGE); + errno = 0; + assert(!strtou32("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtou64.c b/strtou64.c new file mode 100644 index 0000000..a9ce787 --- /dev/null +++ b/strtou64.c @@ -0,0 +1,48 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 18446744073709551615ULL + + +uint_least64_t +libsimple_strtou64(const char *restrict nptr, char **restrict end, int base) +{ + uintmax_t r = strtoumax(nptr, end, base); +#if UINTMAX_MAX > RET_MAX + if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } +#endif + return (uint_least64_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtou64("0xFFFFFFFFFFFFFFFF", NULL, 0) == UINT64_C(0xFFFFFFFFFFFFFFFF) && !errno); + assert(strtou64("0xFFFFFFFFFFFFFFFF", NULL, 16) == UINT64_C(0xFFFFFFFFFFFFFFFF) && !errno); + assert(strtou64("FFFFFFFFFFFFFFFF", NULL, 16) == UINT64_C(0xFFFFFFFFFFFFFFFF) && !errno); + assert(strtou64("0xFFFFFFFFFFFFFFFF", NULL, 10) == 0 && !errno); + assert(strtou64("0xFFFFFFFFFFFFFFFF", &e, 0) == UINT64_C(0xFFFFFFFFFFFFFFFF) && !*e && !errno); + assert(strtou64("0xFFFFFFFFFFFFFFFF ", &e, 16) == UINT64_C(0xFFFFFFFFFFFFFFFF) && *e == ' ' && !errno); + assert(strtou64("0xFFFFFFFFFFFFFFFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtou64("18446744073709551615", &e, 10) == UINT64_C(0xFFFFFFFFFFFFFFFF) && !*e && !errno); + assert(strtou64("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtou64("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtou64("01234", &e, 0) == 01234 && !*e && !errno); + assert(strtou64("18446744073709551616", &e, 10) == UINT64_C(18446744073709551615) && !*e && errno == ERANGE); + errno = 0; + assert(!strtou64("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtou8.c b/strtou8.c new file mode 100644 index 0000000..2f299b4 --- /dev/null +++ b/strtou8.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +#define RET_MAX 255ULL + + +uint_least8_t +libsimple_strtou8(const char *restrict nptr, char **restrict end, int base) +{ + uintmax_t r = strtoumax(nptr, end, base); + if (r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (uint_least8_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + char *e; + errno = 0; + assert(strtou8("0xFF", NULL, 0) == UINT8_C(0xFF) && !errno); + assert(strtou8("0xFF", NULL, 16) == UINT8_C(0xFF) && !errno); + assert(strtou8("FF", NULL, 16) == UINT8_C(0xFF) && !errno); + assert(strtou8("0xFF", NULL, 10) == 0 && !errno); + assert(strtou8("0xFF", &e, 0) == UINT8_C(0xFF) && !*e && !errno); + assert(strtou8("0xFF ", &e, 16) == UINT8_C(0xFF) && *e == ' ' && !errno); + assert(strtou8("0xFF", &e, 10) == 0 && *e == 'x' && !errno); + assert(strtou8("255", &e, 10) == UINT8_C(0xFF) && !*e && !errno); + assert(strtou8("12", &e, 10) == 12 && !*e && !errno); + assert(strtou8("12", &e, 8) == 012 && !*e && !errno); + assert(strtou8("012", &e, 0) == 012 && !*e && !errno); + assert(strtou8("256", &e, 10) == UINT8_C(255) && !*e && errno == ERANGE); + errno = 0; + assert(!strtou8("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtouh.c b/strtouh.c new file mode 100644 index 0000000..fb2f037 --- /dev/null +++ b/strtouh.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +unsigned short int +libsimple_strtouh(const char *restrict nptr, char **restrict end, int base) +{ + unsigned long int r = strtoul(nptr, end, base); + if (r > USHRT_MAX) { + r = USHRT_MAX; + errno = ERANGE; + } + return (unsigned short int)r; +} + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%x", (unsigned int)USHRT_MAX); + errno = 0; + assert(strtouh(str, NULL, 0) == USHRT_MAX && !errno); + assert(strtouh(str, NULL, 16) == USHRT_MAX && !errno); + assert(strtouh(&str[2], NULL, 16) == USHRT_MAX && !errno); + assert(strtouh(str, NULL, 10) == 0 && !errno); + assert(strtouh(str, &e, 0) == USHRT_MAX && !*e && !errno); + assert(strtouh(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%x ", (unsigned int)USHRT_MAX); + assert(strtouh(str, &e, 16) == USHRT_MAX && *e == ' ' && !errno); + sprintf(str, "%u", (unsigned int)USHRT_MAX); + assert(strtouh(str, &e, 10) == USHRT_MAX && !*e && !errno); + assert(strtouh("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtouh("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtouh("01234", &e, 0) == 01234 && !*e && !errno); + sprintf(str, "%u", (unsigned int)USHRT_MAX); + add_one(str); + assert(strtouh(str, &e, 10) == USHRT_MAX && !*e && errno == ERANGE); + errno = 0; + assert(!strtouh("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtouhh.c b/strtouhh.c new file mode 100644 index 0000000..b163b7f --- /dev/null +++ b/strtouhh.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +unsigned char +libsimple_strtouhh(const char *restrict nptr, char **restrict end, int base) +{ + unsigned long int r = strtoul(nptr, end, base); + if (r > UCHAR_MAX) { + r = UCHAR_MAX; + errno = ERANGE; + } + return (unsigned char)r; +} + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%x", (unsigned int)UCHAR_MAX); + errno = 0; + assert(strtouhh(str, NULL, 0) == UCHAR_MAX && !errno); + assert(strtouhh(str, NULL, 16) == UCHAR_MAX && !errno); + assert(strtouhh(&str[2], NULL, 16) == UCHAR_MAX && !errno); + assert(strtouhh(str, NULL, 10) == 0 && !errno); + assert(strtouhh(str, &e, 0) == UCHAR_MAX && !*e && !errno); + assert(strtouhh(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%x ", (unsigned int)UCHAR_MAX); + assert(strtouhh(str, &e, 16) == UCHAR_MAX && *e == ' ' && !errno); + sprintf(str, "%u", (unsigned int)UCHAR_MAX); + assert(strtouhh(str, &e, 10) == UCHAR_MAX && !*e && !errno); + assert(strtouhh("12", &e, 10) == 12 && !*e && !errno); + assert(strtouhh("12", &e, 8) == 012 && !*e && !errno); + assert(strtouhh("012", &e, 0) == 012 && !*e && !errno); + sprintf(str, "%u", (unsigned int)UCHAR_MAX); + add_one(str); + assert(strtouhh(str, &e, 10) == UCHAR_MAX && !*e && errno == ERANGE); + errno = 0; + assert(!strtouhh("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoupper.c b/strtoupper.c new file mode 100644 index 0000000..d22da79 --- /dev/null +++ b/strtoupper.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strtoupper(char *, const char *); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[100]; + + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strtoupper(&buf[3], &buf[0]), "ABCDEABCDE12345")); + assert(!strcmp(buf, "abcABCDEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[3]), "DEABCDE12345")); + assert(!strcmp(buf, "DEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[0]), "ABCDEABCDE12345")); + assert(!strcmp(buf, "ABCDEABCDE12345")); + + return 0; +} + +#endif diff --git a/strtouz.c b/strtouz.c new file mode 100644 index 0000000..7a92b6a --- /dev/null +++ b/strtouz.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline size_t libsimple_strtouz(const char *restrict, char **restrict, int); + + +#else +#include "test.h" + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%zx", SIZE_MAX); + errno = 0; + assert(strtouz(str, NULL, 0) == SIZE_MAX && !errno); + assert(strtouz(str, NULL, 16) == SIZE_MAX && !errno); + assert(strtouz(&str[2], NULL, 16) == SIZE_MAX && !errno); + assert(strtouz(str, NULL, 10) == 0 && !errno); + assert(strtouz(str, &e, 0) == SIZE_MAX && !*e && !errno); + assert(strtouz(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%zx ", SIZE_MAX); + assert(strtouz(str, &e, 16) == SIZE_MAX && *e == ' ' && !errno); + sprintf(str, "%zu", SIZE_MAX); + assert(strtouz(str, &e, 10) == SIZE_MAX && !*e && !errno); + assert(strtouz("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtouz("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtouz("01234", &e, 0) == 01234 && !*e && !errno); + sprintf(str, "%zu", SIZE_MAX); + add_one(str); + assert(strtouz(str, &e, 10) == SIZE_MAX && !*e && errno == ERANGE); + errno = 0; + assert(!strtouz("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/strtoz.c b/strtoz.c new file mode 100644 index 0000000..7826251 --- /dev/null +++ b/strtoz.c @@ -0,0 +1,61 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline ssize_t libsimple_strtoz(const char *restrict, char **restrict, int); + + +#else +#include "test.h" + +#ifndef SSIZE_MIN +#define SSIZE_MIN (-SSIZE_MAX - (-LONG_MAX != LONG_MIN)) +#endif + +static void +add_one(char *buf) +{ + char *p = strchr(buf, '\0'); + while (*--p == '9') + *p = '0'; + *p += 1; +} + +int +main(void) +{ + char str[128]; + char *e; + sprintf(str, "0x%zx", SSIZE_MAX); + errno = 0; + assert(strtoz(str, NULL, 0) == SSIZE_MAX && !errno); + assert(strtoz(str, NULL, 16) == SSIZE_MAX && !errno); + assert(strtoz(&str[2], NULL, 16) == SSIZE_MAX && !errno); + assert(strtoz(str, NULL, 10) == 0 && !errno); + assert(strtoz(str, &e, 0) == SSIZE_MAX && !*e && !errno); + assert(strtoz(str, &e, 10) == 0 && *e == 'x' && !errno); + sprintf(str, "0x%zx ", SSIZE_MAX); + assert(strtoz(str, &e, 16) == SSIZE_MAX && *e == ' ' && !errno); + sprintf(str, "-%zi", SSIZE_MAX); + assert(strtoz(&str[1], &e, 10) == SSIZE_MAX && !*e && !errno); + assert(strtoz(str, &e, 10) == -SSIZE_MAX && !*e && !errno); + sprintf(str, "%zi", SSIZE_MIN); + assert(strtoz(str, &e, 10) == SSIZE_MIN && !*e && !errno); + assert(strtoz("1234", &e, 10) == 1234 && !*e && !errno); + assert(strtoz("1234", &e, 8) == 01234 && !*e && !errno); + assert(strtoz("01234", &e, 0) == 01234 && !*e && !errno); + sprintf(str, "%zi", SSIZE_MAX); + add_one(str); + assert(strtoz(str, &e, 10) == SSIZE_MAX && !*e && errno == ERANGE); + errno = 0; + sprintf(str, "%zi", SSIZE_MIN); + add_one(str); + assert(strtoz(str, &e, 10) == SSIZE_MIN && !*e && errno == ERANGE); + errno = 0; + assert(!strtoz("1", &e, -10000) && errno == EINVAL); + errno = 0; + return 0; +} + +#endif diff --git a/sumtimespec.c b/sumtimespec.c index 2b2e935..b9dfdd6 100644 --- a/sumtimespec.c +++ b/sumtimespec.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -47,62 +47,82 @@ main(void) { struct timespec r, a, b; - a.tv_sec = 0, a.tv_nsec = 0; - b.tv_sec = 0, b.tv_nsec = 0; + a.tv_sec = 0; + a.tv_nsec = 0; + b.tv_sec = 0; + b.tv_nsec = 0; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 0); - a.tv_sec = 10, a.tv_nsec = 10000L; - b.tv_sec = 0, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10000L; + b.tv_sec = 0; + b.tv_nsec = 0L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 10); assert(r.tv_nsec == 10000L); - a.tv_sec = 10, a.tv_nsec = 10000L; - b.tv_sec = -10, b.tv_nsec = 0L; + a.tv_sec = 10; + a.tv_nsec = 10000L; + b.tv_sec = -10; + b.tv_nsec = 0L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 0); assert(r.tv_nsec == 10000L); - a.tv_sec = 10, a.tv_nsec = 10000L; - b.tv_sec = -20, b.tv_nsec = 20000L; + a.tv_sec = 10; + a.tv_nsec = 10000L; + b.tv_sec = -20; + b.tv_nsec = 20000L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == -10); assert(r.tv_nsec == 30000L); - a.tv_sec = 1, a.tv_nsec = 999999999L; - b.tv_sec = 1, b.tv_nsec = 1L; + a.tv_sec = 1; + a.tv_nsec = 999999999L; + b.tv_sec = 1; + b.tv_nsec = 1L; assert(!libsimple_sumtimespec(&r, &a, &b)); assert(r.tv_sec == 3); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MAX, a.tv_nsec = 0L; - b.tv_sec = TIME_MAX, b.tv_nsec = 0L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 0L; + b.tv_sec = TIME_MAX; + b.tv_nsec = 0L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 999999999L; - b.tv_sec = 0, b.tv_nsec = 1L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 999999999L; + b.tv_sec = 0; + b.tv_nsec = 1L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MAX, a.tv_nsec = 1L; - b.tv_sec = 0, b.tv_nsec = 999999999L; + a.tv_sec = TIME_MAX; + a.tv_nsec = 1L; + b.tv_sec = 0; + b.tv_nsec = 999999999L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MAX); assert(r.tv_nsec == 999999999L); - a.tv_sec = TIME_MIN, a.tv_nsec = 0L; - b.tv_sec = TIME_MIN, b.tv_nsec = 0L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 0L; + b.tv_sec = TIME_MIN; + b.tv_nsec = 0L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); - a.tv_sec = TIME_MIN, a.tv_nsec = 100L; - b.tv_sec = TIME_MIN, b.tv_nsec = 100L; + a.tv_sec = TIME_MIN; + a.tv_nsec = 100L; + b.tv_sec = TIME_MIN; + b.tv_nsec = 100L; assert(libsimple_sumtimespec(&r, &a, &b) == -1); assert(r.tv_sec == TIME_MIN); assert(r.tv_nsec == 0L); diff --git a/sumtimeval.c b/sumtimeval.c index e52d58f..5cc01ac 100644 --- a/sumtimeval.c +++ b/sumtimeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -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); @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include "test.h" #include <sys/syscall.h> @@ -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); @@ -330,6 +330,9 @@ vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } +#if defined(__GNUC__) +__attribute__((__format__(__printf__, 2, 0))) +#endif int test_vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) { @@ -337,7 +340,7 @@ test_vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) va_list ap2; int r; char *buf; - size_t n; + size_t i, n; va_copy(ap2, ap); r = vsnprintf(NULL, 0, format, ap2); @@ -347,13 +350,14 @@ 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 { assert(stderr_ok); assert(stderr_n + n <= sizeof(stderr_buf)); - memcpy((char *)(void *)(&stderr_buf[stderr_n]), buf, n); + for (i = 0; i < n; i++) + stderr_buf[stderr_n + i] = buf[i]; stderr_n += n; } free(buf); @@ -1,6 +1,18 @@ /* See LICENSE file for copyright and license details. */ +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +# pragma clang diagnostic ignored "-Walloca" +#endif + + #define assert(EXPR)\ do {\ if (EXPR)\ @@ -48,11 +60,15 @@ do {\ char buf__[1024];\ int len__;\ + size_t i__;\ + int not_same__ = 0;\ len__ = sprintf(buf__, __VA_ARGS__);\ assert(len__ >= 0);\ assert((size_t)len__ == stderr_n);\ - assert(!memcmp(buf__, (char **)(void *)(&stderr_buf), stderr_n)); \ - } while (0); + for (i__ = 0; i__ < stderr_n; i__++)\ + not_same__ |= buf__[i__] ^ stderr_buf[i__];\ + assert(!not_same__);\ + } while (0) struct allocinfo { @@ -66,7 +82,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 +116,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/timespec2timeval.c b/timespec2timeval.c index e71585a..c7ab175 100644 --- a/timespec2timeval.c +++ b/timespec2timeval.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timespectodouble.c b/timespectodouble.c new file mode 100644 index 0000000..325709b --- /dev/null +++ b/timespectodouble.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/timespectostr.c b/timespectostr.c index bd99fe1..9440620 100644 --- a/timespectostr.c +++ b/timespectostr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/timeval2timespec.c b/timeval2timespec.c new file mode 100644 index 0000000..4d2a71f --- /dev/null +++ b/timeval2timespec.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..d8bf8d9 --- /dev/null +++ b/timevaltodouble.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline double libsimple_timevaltodouble(const struct timeval *); /* TODO tested in libsimple.c */ + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/timevaltostr.c b/timevaltostr.c index 702b46b..daa2ff0 100644 --- a/timevaltostr.c +++ b/timevaltostr.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/unlist.c b/unlist.c new file mode 100644 index 0000000..edc69cf --- /dev/null +++ b/unlist.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void libsimple_unlist(void *, size_t, size_t *, size_t); + + +#else +#include "test.h" + +int +main(void) +{ + char buf[10]; + int intarray[10]; + size_t i, n; + + for (i = 0, n = 10; i < n; i++) + buf[i] = (char)i; + LIBSIMPLE_UNLIST(buf, 4, &n); + LIBSIMPLE_UNLIST(buf, 9 - 1, &n); + LIBSIMPLE_UNLIST(buf, 6 - 1, &n); + assert(n == 7); + assert(buf[0] == 0); + assert(buf[1] == 1); + assert(buf[2] == 2); + assert(buf[3] == 3); + assert(buf[4] == 5); + assert(buf[5] == 7); + assert(buf[6] == 8); + + for (i = 0, n = 10; i < n; i++) + intarray[i] = (int)i; + LIBSIMPLE_UNLIST(intarray, 4, &n); + LIBSIMPLE_UNLIST(intarray, 9 - 1, &n); + LIBSIMPLE_UNLIST(intarray, 6 - 1, &n); + assert(n == 7); + assert(intarray[0] == 0); + assert(intarray[1] == 1); + assert(intarray[2] == 2); + assert(intarray[3] == 3); + assert(intarray[4] == 5); + assert(intarray[5] == 7); + assert(intarray[6] == 8); + + return 0; +} + +#endif diff --git a/valigned_allocn.c b/valigned_allocn.c new file mode 100644 index 0000000..a3625b8 --- /dev/null +++ b/valigned_allocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_valigned_allocn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_aligned_allocn */ +} + +#endif diff --git a/valigned_reallocfn.c b/valigned_reallocfn.c new file mode 100644 index 0000000..f74b07d --- /dev/null +++ b/valigned_reallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_valigned_reallocfn(void *, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_aligned_reallocfn */ +} + +#endif diff --git a/valloc.c b/valloc.c new file mode 100644 index 0000000..eb9781f --- /dev/null +++ b/valloc.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_valloc(size_t); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vallocn.c b/vallocn.c new file mode 100644 index 0000000..73dc9ab --- /dev/null +++ b/vallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_vallocn(size_t, ...); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif diff --git a/vallocz.c b/vallocz.c new file mode 100644 index 0000000..2fbf4a4 --- /dev/null +++ b/vallocz.c @@ -0,0 +1,77 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..3016443 --- /dev/null +++ b/valloczn.c @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/vasprintf.c b/vasprintf.c index fd14650..65c494e 100644 --- a/vasprintf.c +++ b/vasprintf.c @@ -1,7 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif + int libsimple_vasprintf(char **strp, const char *fmt, va_list ap) diff --git a/vcallocn.c b/vcallocn.c new file mode 100644 index 0000000..ab3850c --- /dev/null +++ b/vcallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_vcallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_callocn */ +} + +#endif diff --git a/venprintf.c b/venprintf.c new file mode 100644 index 0000000..a8a39aa --- /dev/null +++ b/venprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..9082db2 --- /dev/null +++ b/veprintf.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/vmallocn.c b/vmallocn.c new file mode 100644 index 0000000..1cdb61b --- /dev/null +++ b/vmallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_vmallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_mallocn */ +} + +#endif diff --git a/vmemalignn.c b/vmemalignn.c new file mode 100644 index 0000000..1c75088 --- /dev/null +++ b/vmemalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_vmemalignn(size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_memalignn */ +} + +#endif diff --git a/vmemalignzn.c b/vmemalignzn.c new file mode 100644 index 0000000..46cfc25 --- /dev/null +++ b/vmemalignzn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_vmemalignzn(int, size_t, size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_memalignzn */ +} + +#endif diff --git a/vmemalloc.c b/vmemalloc.c index 8d92035..d725374 100644 --- a/vmemalloc.c +++ b/vmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include <stdalign.h> #ifndef TEST @@ -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,23 +158,35 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap) } } - return 0; inval: errno = EINVAL; return -1; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__const__))) 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/vposix_memalignn.c b/vposix_memalignn.c new file mode 100644 index 0000000..9179b09 --- /dev/null +++ b/vposix_memalignn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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 @@ -1,7 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif + int libsimple_vputenvf(const char *fmt, va_list ap) @@ -36,27 +40,7 @@ libsimple_vputenvf(const char *fmt, va_list ap) int main(void) { - unsetenv("X"); - assert(!getenv("X")); - unsetenv("Y"); - assert(!getenv("Y")); - - putenvf("X=xyz"); - assert(!strcmpnul(getenv("X"), "xyz")); - putenvf("Y=xyz"); - assert(!strcmpnul(getenv("Y"), "xyz")); - - putenvf("X=x%sz", "abc"); - assert(!strcmpnul(getenv("X"), "xabcz")); - putenvf("Y=x%sz", "abc"); - assert(!strcmpnul(getenv("Y"), "xabcz")); - - putenvf("X=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("X"), "10xabcz-11")); - putenvf("Y=%ix%sz%i", 10, "abc", -11); - assert(!strcmpnul(getenv("Y"), "10xabcz-11")); - - return 0; + return 0; /* Tested via libsimple_putenvf */ } #endif diff --git a/vpvallocn.c b/vpvallocn.c new file mode 100644 index 0000000..f90224c --- /dev/null +++ b/vpvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..3f3fbc1 --- /dev/null +++ b/vpvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..1aa770d --- /dev/null +++ b/vreallocfn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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/vvallocn.c b/vvallocn.c new file mode 100644 index 0000000..04b8d55 --- /dev/null +++ b/vvallocn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline void *libsimple_vvallocn(size_t, va_list); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; /* Tested via libsimple_vallocn */ +} + +#endif diff --git a/vvalloczn.c b/vvalloczn.c new file mode 100644 index 0000000..d3e1b55 --- /dev/null +++ b/vvalloczn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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..f684553 100644 --- a/vweprintf.c +++ b/vweprintf.c @@ -1,7 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif + extern char *argv0; @@ -32,8 +36,15 @@ libsimple_vweprintf(const char *fmt, va_list ap) va_copy(ap2, ap); r = vsnprintf(NULL, 0, fmt, ap1); if (0 <= r && r < 8096) { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Walloca" +#endif message = alloca((size_t)r + 1); vsprintf(message, fmt, ap2); +#if defined(__clang__) +# pragma clang diagnostic pop +#endif } va_end(ap2); va_end(ap1); @@ -69,111 +80,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 @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST diff --git a/weprintf.c b/weprintf.c new file mode 100644 index 0000000..df80abb --- /dev/null +++ b/weprintf.c @@ -0,0 +1,119 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.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 @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST |