From 994e2ede81e2735fa7a9483442c34d8b7379e21e Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Thu, 29 Dec 2022 19:22:10 +0100 Subject: Add dependency on libc-mem Signed-off-by: Alejandro Colomar --- .gitignore | 2 +- include/c/stp/_compiler.h | 35 -------------- include/c/stp/stp/ustr2stp.h | 33 ------------- include/c/stp/stp/zustr2stp.h | 33 ------------- include/c/stp/stpe/stpecpy.h | 44 ----------------- include/c/stp/stpe/stpeprintf.h | 61 ------------------------ include/c/stp/ustp/ustpcpy.h | 32 ------------- include/c/stp/ustp/zustr2ustp.h | 29 ------------ include/c/str/cpy/stp/_compiler.h | 35 ++++++++++++++ include/c/str/cpy/stp/stp/ustr2stp.h | 33 +++++++++++++ include/c/str/cpy/stp/stp/zustr2stp.h | 33 +++++++++++++ include/c/str/cpy/stp/stpe/stpecpy.h | 45 ++++++++++++++++++ include/c/str/cpy/stp/stpe/stpeprintf.h | 61 ++++++++++++++++++++++++ include/c/str/cpy/stp/ustp/ustpcpy.h | 28 +++++++++++ include/c/str/cpy/stp/ustp/zustr2ustp.h | 29 ++++++++++++ lib/build-lib.mk | 2 +- lib/version.mk | 2 +- share/pkgconfig/libc-stp-uninstalled.pc | 15 ------ share/pkgconfig/libc-str-cpy-stp-uninstalled.pc | 15 ++++++ share/tests/libc-stp/Makefile | 63 ------------------------- share/tests/libc-stp/stpe/001/test.c | 25 ---------- share/tests/libc-stp/stpe/001/test.sh | 22 --------- share/tests/libc-stp/stpe/002/test.c | 25 ---------- share/tests/libc-stp/stpe/002/test.sh | 22 --------- share/tests/libc-stp/stpe/003/test.c | 25 ---------- share/tests/libc-stp/stpe/003/test.sh | 19 -------- share/tests/libc-stp/stpe/004/test.c | 25 ---------- share/tests/libc-stp/stpe/004/test.sh | 19 -------- share/tests/libc-stp/stpe/005/test.c | 25 ---------- share/tests/libc-stp/stpe/005/test.sh | 19 -------- share/tests/libc-stp/stpe/006/test.c | 26 ---------- share/tests/libc-stp/stpe/006/test.sh | 19 -------- share/tests/libc-stp/stpe/007/test.c | 26 ---------- share/tests/libc-stp/stpe/007/test.sh | 22 --------- share/tests/libc-stp/stpe/008/test.c | 26 ---------- share/tests/libc-stp/stpe/008/test.sh | 19 -------- share/tests/libc-stp/stpe/009/test.c | 26 ---------- share/tests/libc-stp/stpe/009/test.sh | 19 -------- share/tests/libc-str-cpy-stp/Makefile | 63 +++++++++++++++++++++++++ share/tests/libc-str-cpy-stp/stpe/001/test.c | 25 ++++++++++ share/tests/libc-str-cpy-stp/stpe/001/test.sh | 22 +++++++++ share/tests/libc-str-cpy-stp/stpe/002/test.c | 25 ++++++++++ share/tests/libc-str-cpy-stp/stpe/002/test.sh | 22 +++++++++ share/tests/libc-str-cpy-stp/stpe/003/test.c | 25 ++++++++++ share/tests/libc-str-cpy-stp/stpe/003/test.sh | 19 ++++++++ share/tests/libc-str-cpy-stp/stpe/004/test.c | 25 ++++++++++ share/tests/libc-str-cpy-stp/stpe/004/test.sh | 19 ++++++++ share/tests/libc-str-cpy-stp/stpe/005/test.c | 25 ++++++++++ share/tests/libc-str-cpy-stp/stpe/005/test.sh | 19 ++++++++ share/tests/libc-str-cpy-stp/stpe/006/test.c | 26 ++++++++++ share/tests/libc-str-cpy-stp/stpe/006/test.sh | 19 ++++++++ share/tests/libc-str-cpy-stp/stpe/007/test.c | 26 ++++++++++ share/tests/libc-str-cpy-stp/stpe/007/test.sh | 22 +++++++++ share/tests/libc-str-cpy-stp/stpe/008/test.c | 26 ++++++++++ share/tests/libc-str-cpy-stp/stpe/008/test.sh | 19 ++++++++ share/tests/libc-str-cpy-stp/stpe/009/test.c | 26 ++++++++++ share/tests/libc-str-cpy-stp/stpe/009/test.sh | 19 ++++++++ src/c/stp/_compiler.c | 5 -- src/c/stp/stp/ustr2stp.c | 13 ----- src/c/stp/stp/zustr2stp.c | 13 ----- src/c/stp/stpe/stpecpy.c | 13 ----- src/c/stp/stpe/stpeprintf.c | 17 ------- src/c/stp/ustp/ustpcpy.c | 13 ----- src/c/stp/ustp/zustr2ustp.c | 13 ----- src/c/str/cpy/stp/_compiler.c | 5 ++ src/c/str/cpy/stp/stp/ustr2stp.c | 13 +++++ src/c/str/cpy/stp/stp/zustr2stp.c | 13 +++++ src/c/str/cpy/stp/stpe/stpecpy.c | 13 +++++ src/c/str/cpy/stp/stpe/stpeprintf.c | 17 +++++++ src/c/str/cpy/stp/ustp/ustpcpy.c | 13 +++++ src/c/str/cpy/stp/ustp/zustr2ustp.c | 13 +++++ 71 files changed, 841 insertions(+), 844 deletions(-) delete mode 100644 include/c/stp/_compiler.h delete mode 100644 include/c/stp/stp/ustr2stp.h delete mode 100644 include/c/stp/stp/zustr2stp.h delete mode 100644 include/c/stp/stpe/stpecpy.h delete mode 100644 include/c/stp/stpe/stpeprintf.h delete mode 100644 include/c/stp/ustp/ustpcpy.h delete mode 100644 include/c/stp/ustp/zustr2ustp.h create mode 100644 include/c/str/cpy/stp/_compiler.h create mode 100644 include/c/str/cpy/stp/stp/ustr2stp.h create mode 100644 include/c/str/cpy/stp/stp/zustr2stp.h create mode 100644 include/c/str/cpy/stp/stpe/stpecpy.h create mode 100644 include/c/str/cpy/stp/stpe/stpeprintf.h create mode 100644 include/c/str/cpy/stp/ustp/ustpcpy.h create mode 100644 include/c/str/cpy/stp/ustp/zustr2ustp.h delete mode 100644 share/pkgconfig/libc-stp-uninstalled.pc create mode 100644 share/pkgconfig/libc-str-cpy-stp-uninstalled.pc delete mode 100755 share/tests/libc-stp/Makefile delete mode 100644 share/tests/libc-stp/stpe/001/test.c delete mode 100755 share/tests/libc-stp/stpe/001/test.sh delete mode 100644 share/tests/libc-stp/stpe/002/test.c delete mode 100755 share/tests/libc-stp/stpe/002/test.sh delete mode 100644 share/tests/libc-stp/stpe/003/test.c delete mode 100755 share/tests/libc-stp/stpe/003/test.sh delete mode 100644 share/tests/libc-stp/stpe/004/test.c delete mode 100755 share/tests/libc-stp/stpe/004/test.sh delete mode 100644 share/tests/libc-stp/stpe/005/test.c delete mode 100755 share/tests/libc-stp/stpe/005/test.sh delete mode 100644 share/tests/libc-stp/stpe/006/test.c delete mode 100755 share/tests/libc-stp/stpe/006/test.sh delete mode 100644 share/tests/libc-stp/stpe/007/test.c delete mode 100755 share/tests/libc-stp/stpe/007/test.sh delete mode 100644 share/tests/libc-stp/stpe/008/test.c delete mode 100755 share/tests/libc-stp/stpe/008/test.sh delete mode 100644 share/tests/libc-stp/stpe/009/test.c delete mode 100755 share/tests/libc-stp/stpe/009/test.sh create mode 100755 share/tests/libc-str-cpy-stp/Makefile create mode 100644 share/tests/libc-str-cpy-stp/stpe/001/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/001/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/002/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/002/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/003/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/003/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/004/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/004/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/005/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/005/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/006/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/006/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/007/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/007/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/008/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/008/test.sh create mode 100644 share/tests/libc-str-cpy-stp/stpe/009/test.c create mode 100755 share/tests/libc-str-cpy-stp/stpe/009/test.sh delete mode 100644 src/c/stp/_compiler.c delete mode 100644 src/c/stp/stp/ustr2stp.c delete mode 100644 src/c/stp/stp/zustr2stp.c delete mode 100644 src/c/stp/stpe/stpecpy.c delete mode 100644 src/c/stp/stpe/stpeprintf.c delete mode 100644 src/c/stp/ustp/ustpcpy.c delete mode 100644 src/c/stp/ustp/zustr2ustp.c create mode 100644 src/c/str/cpy/stp/_compiler.c create mode 100644 src/c/str/cpy/stp/stp/ustr2stp.c create mode 100644 src/c/str/cpy/stp/stp/zustr2stp.c create mode 100644 src/c/str/cpy/stp/stpe/stpecpy.c create mode 100644 src/c/str/cpy/stp/stpe/stpeprintf.c create mode 100644 src/c/str/cpy/stp/ustp/ustpcpy.c create mode 100644 src/c/str/cpy/stp/ustp/zustr2ustp.c diff --git a/.gitignore b/.gitignore index 04d0d85..97c467c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ /.checkpatch-camelcase* # 'make check' binaries -/share/tests/libc-stp/**/test +/share/tests/libc-str-cpy-stp/**/test diff --git a/include/c/stp/_compiler.h b/include/c/stp/_compiler.h deleted file mode 100644 index 85c20a0..0000000 --- a/include/c/stp/_compiler.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP__COMPILER_H_ -#define INCLUDE_C_STP__COMPILER_H_ - - -#if (__STDC_VERSION__ < 202000L) -# warn "Minimum C version is C23" -#endif - - -#define c_impossible(e) do \ -{ \ - if (e) \ - c_unreachable(); \ -} while (0) - -#if defined(__clang__) -# define c_nullable _Nullable -#else -# define c_nullable -#endif - -#define c_unlikely(e) __builtin_expect(!!(e), 0) - -#if defined(unreachable) -# define c_unreachable() unreachable() -#else -# define c_unreachable() __builtin_unreachable() -#endif - - -#endif // Header guard diff --git a/include/c/stp/stp/ustr2stp.h b/include/c/stp/stp/ustr2stp.h deleted file mode 100644 index 9933193..0000000 --- a/include/c/stp/stp/ustr2stp.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP_STP_USTR2STP_H_ -#define INCLUDE_C_STP_STP_USTR2STP_H_ - - -#include - -#include // IWYU pragma: keep -#include - - -#pragma clang assume_nonnull begin -inline char *c_ustr2stp(char *restrict dst, const char *restrict src, - size_t len); - - -inline char * -c_ustr2stp(char *restrict dst, const char *restrict src, size_t len) -{ - char *p; - - p = c_ustpcpy(dst, src, len); - *p = '\0'; - - return p; -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/c/stp/stp/zustr2stp.h b/include/c/stp/stp/zustr2stp.h deleted file mode 100644 index 53c2305..0000000 --- a/include/c/stp/stp/zustr2stp.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP_STP_ZUSTR2STP_H_ -#define INCLUDE_C_STP_STP_ZUSTR2STP_H_ - - -#include - -#include // IWYU pragma: keep -#include - - -#pragma clang assume_nonnull begin -inline char *c_zustr2stp(char *restrict dst, const char *restrict src, - size_t sz); - - -inline char * -c_zustr2stp(char *restrict dst, const char *restrict src, size_t sz) -{ - char *p; - - p = c_zustr2ustp(dst, src, sz); - *p = '\0'; - - return p; -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/c/stp/stpe/stpecpy.h b/include/c/stp/stpe/stpecpy.h deleted file mode 100644 index eb84587..0000000 --- a/include/c/stp/stpe/stpecpy.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP_STPE_STPECPY_H_ -#define INCLUDE_C_STP_STPE_STPECPY_H_ - - -#include -#include -#include - -#include - - -#pragma clang assume_nonnull begin -inline char *c_nullable c_stpecpy(char *c_nullable dst, char *end, - const char *restrict src); - - -inline char *c_nullable -c_stpecpy(char *c_nullable dst, char *end, const char *restrict src) -{ - bool trunc; - size_t dsize, dlen, slen; - - if (dst == end) - return end; - if (c_unlikely(dst == NULL)) // Allow chaining with stpeprintf(). - return NULL; - c_impossible(dst > end); - - dsize = end - dst; - slen = strnlen(src, dsize); - trunc = (slen == dsize); - dlen = slen - trunc; - dst[dlen] = '\0'; - - return mempcpy(dst, src, dlen) + trunc; -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/c/stp/stpe/stpeprintf.h b/include/c/stp/stpe/stpeprintf.h deleted file mode 100644 index 32dc0fe..0000000 --- a/include/c/stp/stpe/stpeprintf.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP_STPE_STPEPRINTF_H_ -#define INCLUDE_C_STP_STPE_STPEPRINTF_H_ - - -#include -#include - -#include - - -#pragma clang assume_nonnull begin -inline char *c_nullable c_stpeprintf(char *c_nullable dst, char *end, - const char *restrict fmt, ...); -inline char *c_nullable c_vstpeprintf(char *c_nullable dst, char *end, - const char *restrict fmt, va_list ap); - - -inline char *c_nullable -c_stpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, ...) -{ - char *c_nullable p; - va_list ap; - - va_start(ap, fmt); - p = c_vstpeprintf(dst, end, fmt, ap); - va_end(ap); - - return p; -} - - -inline char *c_nullable -c_vstpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, - va_list ap) -{ - int len; - - if (dst == end) - return end; - if (c_unlikely(dst == NULL)) - return NULL; - c_impossible(dst > end); - - len = vsnprintf(dst, end - dst, fmt, ap); - - c_impossible(len < -1); - if (c_unlikely(len == -1)) - return NULL; - if (len >= end - dst) - return end; - - return dst + len; -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/c/stp/ustp/ustpcpy.h b/include/c/stp/ustp/ustpcpy.h deleted file mode 100644 index 0045f0e..0000000 --- a/include/c/stp/ustp/ustpcpy.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP_USTP_USTPCPY_H_ -#define INCLUDE_C_STP_USTP_USTPCPY_H_ - - -#include -#include - -#include // IWYU pragma: keep - - -#pragma clang assume_nonnull begin -inline char *c_ustpcpy(char *restrict dst, const char *restrict src, - size_t len); - - -inline char * -c_ustpcpy(char *restrict dst, const char *restrict src, size_t len) -{ -#if defined(_GNU_SOURCE) - return mempcpy(dst, src, len); -#else - return memcpy(dst, src, len) + len; -#endif -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/c/stp/ustp/zustr2ustp.h b/include/c/stp/ustp/zustr2ustp.h deleted file mode 100644 index e8428cf..0000000 --- a/include/c/stp/ustp/zustr2ustp.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_C_STP_USTP_ZUSTR2USTP_H_ -#define INCLUDE_C_STP_USTP_ZUSTR2USTP_H_ - - -#include -#include - -#include // IWYU pragma: keep -#include - - -#pragma clang assume_nonnull begin -inline char *c_zustr2ustp(char *restrict dst, const char *restrict src, - size_t sz); - - -inline char * -c_zustr2ustp(char *restrict dst, const char *restrict src, size_t sz) -{ - return c_ustpcpy(dst, src, strnlen(src, sz)); -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/c/str/cpy/stp/_compiler.h b/include/c/str/cpy/stp/_compiler.h new file mode 100644 index 0000000..7b76f5f --- /dev/null +++ b/include/c/str/cpy/stp/_compiler.h @@ -0,0 +1,35 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP__COMPILER_H_ +#define INCLUDE_C_STR_CPY_STP__COMPILER_H_ + + +#if (__STDC_VERSION__ < 202000L) +# warn "Minimum C version is C23" +#endif + + +#define c_impossible(e) do \ +{ \ + if (e) \ + c_unreachable(); \ +} while (0) + +#if defined(__clang__) +# define c_nullable _Nullable +#else +# define c_nullable +#endif + +#define c_unlikely(e) __builtin_expect(!!(e), 0) + +#if defined(unreachable) +# define c_unreachable() unreachable() +#else +# define c_unreachable() __builtin_unreachable() +#endif + + +#endif // Header guard diff --git a/include/c/str/cpy/stp/stp/ustr2stp.h b/include/c/str/cpy/stp/stp/ustr2stp.h new file mode 100644 index 0000000..9c8b21f --- /dev/null +++ b/include/c/str/cpy/stp/stp/ustr2stp.h @@ -0,0 +1,33 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP_STP_USTR2STP_H_ +#define INCLUDE_C_STR_CPY_STP_STP_USTR2STP_H_ + + +#include + +#include // IWYU pragma: keep +#include + + +#pragma clang assume_nonnull begin +inline char *c_ustr2stp(char *restrict dst, const char *restrict src, + size_t len); + + +inline char * +c_ustr2stp(char *restrict dst, const char *restrict src, size_t len) +{ + char *p; + + p = c_ustpcpy(dst, src, len); + *p = '\0'; + + return p; +} +#pragma clang assume_nonnull end + + +#endif // Header guard diff --git a/include/c/str/cpy/stp/stp/zustr2stp.h b/include/c/str/cpy/stp/stp/zustr2stp.h new file mode 100644 index 0000000..f055dd6 --- /dev/null +++ b/include/c/str/cpy/stp/stp/zustr2stp.h @@ -0,0 +1,33 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP_STP_ZUSTR2STP_H_ +#define INCLUDE_C_STR_CPY_STP_STP_ZUSTR2STP_H_ + + +#include + +#include // IWYU pragma: keep +#include + + +#pragma clang assume_nonnull begin +inline char *c_zustr2stp(char *restrict dst, const char *restrict src, + size_t sz); + + +inline char * +c_zustr2stp(char *restrict dst, const char *restrict src, size_t sz) +{ + char *p; + + p = c_zustr2ustp(dst, src, sz); + *p = '\0'; + + return p; +} +#pragma clang assume_nonnull end + + +#endif // Header guard diff --git a/include/c/str/cpy/stp/stpe/stpecpy.h b/include/c/str/cpy/stp/stpe/stpecpy.h new file mode 100644 index 0000000..94750a7 --- /dev/null +++ b/include/c/str/cpy/stp/stpe/stpecpy.h @@ -0,0 +1,45 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP_STPE_STPECPY_H_ +#define INCLUDE_C_STR_CPY_STP_STPE_STPECPY_H_ + + +#include +#include +#include + +#include +#include + + +#pragma clang assume_nonnull begin +inline char *c_nullable c_stpecpy(char *c_nullable dst, char *end, + const char *restrict src); + + +inline char *c_nullable +c_stpecpy(char *c_nullable dst, char *end, const char *restrict src) +{ + bool trunc; + size_t dsize, dlen, slen; + + if (dst == end) + return end; + if (c_unlikely(dst == NULL)) // Allow chaining with stpeprintf(). + return NULL; + c_impossible(dst > end); + + dsize = end - dst; + slen = strnlen(src, dsize); + trunc = (slen == dsize); + dlen = slen - trunc; + dst[dlen] = '\0'; + + return c_mempcpy(dst, src, dlen) + trunc; +} +#pragma clang assume_nonnull end + + +#endif // Header guard diff --git a/include/c/str/cpy/stp/stpe/stpeprintf.h b/include/c/str/cpy/stp/stpe/stpeprintf.h new file mode 100644 index 0000000..1a74dd8 --- /dev/null +++ b/include/c/str/cpy/stp/stpe/stpeprintf.h @@ -0,0 +1,61 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP_STPE_STPEPRINTF_H_ +#define INCLUDE_C_STR_CPY_STP_STPE_STPEPRINTF_H_ + + +#include +#include + +#include + + +#pragma clang assume_nonnull begin +inline char *c_nullable c_stpeprintf(char *c_nullable dst, char *end, + const char *restrict fmt, ...); +inline char *c_nullable c_vstpeprintf(char *c_nullable dst, char *end, + const char *restrict fmt, va_list ap); + + +inline char *c_nullable +c_stpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, ...) +{ + char *c_nullable p; + va_list ap; + + va_start(ap, fmt); + p = c_vstpeprintf(dst, end, fmt, ap); + va_end(ap); + + return p; +} + + +inline char *c_nullable +c_vstpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, + va_list ap) +{ + int len; + + if (dst == end) + return end; + if (c_unlikely(dst == NULL)) + return NULL; + c_impossible(dst > end); + + len = vsnprintf(dst, end - dst, fmt, ap); + + c_impossible(len < -1); + if (c_unlikely(len == -1)) + return NULL; + if (len >= end - dst) + return end; + + return dst + len; +} +#pragma clang assume_nonnull end + + +#endif // Header guard diff --git a/include/c/str/cpy/stp/ustp/ustpcpy.h b/include/c/str/cpy/stp/ustp/ustpcpy.h new file mode 100644 index 0000000..610b36e --- /dev/null +++ b/include/c/str/cpy/stp/ustp/ustpcpy.h @@ -0,0 +1,28 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP_USTP_USTPCPY_H_ +#define INCLUDE_C_STR_CPY_STP_USTP_USTPCPY_H_ + + +#include + +#include +#include // IWYU pragma: keep + + +#pragma clang assume_nonnull begin +inline char *c_ustpcpy(char *restrict dst, const char *restrict src, + size_t len); + + +inline char * +c_ustpcpy(char *restrict dst, const char *restrict src, size_t len) +{ + return c_mempcpy(dst, src, len); +} +#pragma clang assume_nonnull end + + +#endif // Header guard diff --git a/include/c/str/cpy/stp/ustp/zustr2ustp.h b/include/c/str/cpy/stp/ustp/zustr2ustp.h new file mode 100644 index 0000000..28aefd8 --- /dev/null +++ b/include/c/str/cpy/stp/ustp/zustr2ustp.h @@ -0,0 +1,29 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#ifndef INCLUDE_C_STR_CPY_STP_USTP_ZUSTR2USTP_H_ +#define INCLUDE_C_STR_CPY_STP_USTP_ZUSTR2USTP_H_ + + +#include +#include + +#include // IWYU pragma: keep +#include + + +#pragma clang assume_nonnull begin +inline char *c_zustr2ustp(char *restrict dst, const char *restrict src, + size_t sz); + + +inline char * +c_zustr2ustp(char *restrict dst, const char *restrict src, size_t sz) +{ + return c_ustpcpy(dst, src, strnlen(src, sz)); +} +#pragma clang assume_nonnull end + + +#endif // Header guard diff --git a/lib/build-lib.mk b/lib/build-lib.mk index 3d23c70..4ce3d98 100644 --- a/lib/build-lib.mk +++ b/lib/build-lib.mk @@ -27,7 +27,7 @@ DEFAULT_LDFLAGS += $(shell $(PKGCONF_CMD) --libs-only-other $(pc_reqs) $(HIDE_ER EXTRA_LDFLAGS := LDFLAGS := $(DEFAULT_LDFLAGS) $(EXTRA_LDFLAGS) -DEFAULT_LDLIBS := $(filter-out -lc-stp,$(shell $(PKGCONF_CMD) --libs-only-l $(pc_reqs) $(HIDE_ERR))) +DEFAULT_LDLIBS := $(filter-out -lc-str-cpy-stp,$(shell $(PKGCONF_CMD) --libs-only-l $(pc_reqs) $(HIDE_ERR))) DEFAULT_LDLIBS += $(shell $(SED) -n '/^Libs.private: /s///p' $(LIB_pc_u)) EXTRA_LDLIBS := LDLIBS := $(DEFAULT_LDLIBS) $(EXTRA_LDLIBS) diff --git a/lib/version.mk b/lib/version.mk index b961bfa..47a5519 100644 --- a/lib/version.mk +++ b/lib/version.mk @@ -10,7 +10,7 @@ include $(srcdir)/lib/cmd.mk include $(srcdir)/lib/verbose.mk -libname := libc-stp +libname := libc-str-cpy-stp DISTVERSION := $(patsubst v%,%,$(shell $(GIT) describe $(HIDE_ERR) || $(ECHO) unreleased)) DISTNAME := $(libname)-$(DISTVERSION) MAJOR_VERSION := $(shell $(ECHO) $(DISTVERSION) | $(CUT) -f1 -d. ) diff --git a/share/pkgconfig/libc-stp-uninstalled.pc b/share/pkgconfig/libc-stp-uninstalled.pc deleted file mode 100644 index c5dbd80..0000000 --- a/share/pkgconfig/libc-stp-uninstalled.pc +++ /dev/null @@ -1,15 +0,0 @@ -Name: libc-stp -Description: stp string library -URL: http://www.alejandro-colomar.es/src/alx/alx/libc-stp.git -Version: -Requires: -Requires.private: - -prefix=/usr/local -includedir=${prefix}/include -exec_prefix=${prefix} -libdir=${exec_prefix}/lib - -Cflags: -isystem${includedir} -Libs: -L${libdir} -lc-stp -lc -Libs.private: diff --git a/share/pkgconfig/libc-str-cpy-stp-uninstalled.pc b/share/pkgconfig/libc-str-cpy-stp-uninstalled.pc new file mode 100644 index 0000000..29c036c --- /dev/null +++ b/share/pkgconfig/libc-str-cpy-stp-uninstalled.pc @@ -0,0 +1,15 @@ +Name: libc-str-cpy-stp +Description: stp string library +URL: http://www.alejandro-colomar.es/src/alx/alx/libc-stp.git +Version: +Requires: libc-mem +Requires.private: + +prefix=/usr/local +includedir=${prefix}/include +exec_prefix=${prefix} +libdir=${exec_prefix}/lib + +Cflags: -isystem${includedir} +Libs: -L${libdir} -lc-str-cpy-stp -lc +Libs.private: diff --git a/share/tests/libc-stp/Makefile b/share/tests/libc-stp/Makefile deleted file mode 100755 index 00d7e53..0000000 --- a/share/tests/libc-stp/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2022 Alejandro Colomar -# SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -SHELL := /usr/bin/env bash -Eeuo pipefail - - -MAKEFLAGS += --warn-undefined-variables -MAKEFLAGS += --no-builtin-rules -MAKEFLAGS += --no-builtin-variables -MAKEFLAGS += --no-print-directory - - -CC := cc -FIND := find -GREP := grep -PKGCONF := pkgconf -SORT := sort - - -libname := libc-stp - - -PKGCONFFLAGS := - -CPPFLAGS := - -CFLAGS := -Wall -Wextra -Werror -CFLAGS += -std=gnu2x -CFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --cflags $(libname)) - -LDFLAGS := -Wl,--as-needed -LDFLAGS += -Wl,--no-allow-shlib-undefined -LDFLAGS += -Wl,--no-copy-dt-needed-entries -LDFLAGS += -Wl,--no-undefined -LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-L $(libname)) -LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-other $(libname)) - -LDLIBS := $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-l $(libname)) - - -TESTDIR := . - - -TESTS_c := $(shell $(FIND) $(TESTDIR) -type f | $(GREP) '\.c$$' | $(SORT)) -TESTS := $(patsubst %.c,%,$(TESTS_c)) - - -.PHONY: all -all: $(TESTS) - - -$(TESTS): %: %.c FORCE - $(info TEST $(dir $@)) - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@ - cd $(dir $@) && ./test.sh - - -V := -$(V).SILENT: - - -FORCE: diff --git a/share/tests/libc-stp/stpe/001/test.c b/share/tests/libc-stp/stpe/001/test.c deleted file mode 100644 index f040c32..0000000 --- a/share/tests/libc-stp/stpe/001/test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include -#include - -int -main(void) -{ - char buf[BUFSIZ]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello "); - p = c_stpecpy(p, end, "world"); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/001/test.sh b/share/tests/libc-stp/stpe/001/test.sh deleted file mode 100755 index 8f0870d..0000000 --- a/share/tests/libc-stp/stpe/001/test.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| while read out; do - if echo $out | grep -q '^Truncated:$'; then - >&2 echo "$out"; - exit 2; - fi; - - echo $out; -done \ -| while read out; do - if echo $out | grep -q -v '^12: Hello world!$'; then - >&2 echo "$out"; - exit 3; - fi; -done; diff --git a/share/tests/libc-stp/stpe/002/test.c b/share/tests/libc-stp/stpe/002/test.c deleted file mode 100644 index d9d7a3d..0000000 --- a/share/tests/libc-stp/stpe/002/test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include -#include - -int -main(void) -{ - char buf[13]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello "); - p = c_stpecpy(p, end, "world"); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/002/test.sh b/share/tests/libc-stp/stpe/002/test.sh deleted file mode 100755 index e5eadd2..0000000 --- a/share/tests/libc-stp/stpe/002/test.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| while read out; do - if echo $out | grep -q 'Truncated'; then - >&2 echo "$out"; - exit 2; - fi; - - echo $out; -done \ -| while read out; do - if echo $out | grep -q -v '^12: Hello world!$'; then - >&2 echo "$out"; - exit 3; - fi; -done; diff --git a/share/tests/libc-stp/stpe/003/test.c b/share/tests/libc-stp/stpe/003/test.c deleted file mode 100644 index 9df9f7b..0000000 --- a/share/tests/libc-stp/stpe/003/test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include -#include - -int -main(void) -{ - char buf[12]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello "); - p = c_stpecpy(p, end, "world"); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/003/test.sh b/share/tests/libc-stp/stpe/003/test.sh deleted file mode 100755 index ee952ea..0000000 --- a/share/tests/libc-stp/stpe/003/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| if ! grep -q '^Truncated:$'; then - >&2 ./test; - exit 2; -fi; - - -./test \ -| if ! grep -q '^11: Hello world$'; then - >&2 ./test; - exit 3; -fi; diff --git a/share/tests/libc-stp/stpe/004/test.c b/share/tests/libc-stp/stpe/004/test.c deleted file mode 100644 index 48cbb53..0000000 --- a/share/tests/libc-stp/stpe/004/test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include -#include - -int -main(void) -{ - char buf[11]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello "); - p = c_stpecpy(p, end, "world"); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/004/test.sh b/share/tests/libc-stp/stpe/004/test.sh deleted file mode 100755 index 7eccc45..0000000 --- a/share/tests/libc-stp/stpe/004/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| if ! grep -q '^Truncated:$'; then - >&2 ./test; - exit 2; -fi; - - -./test \ -| if ! grep -q '^10: Hello worl$'; then - >&2 ./test; - exit 3; -fi; diff --git a/share/tests/libc-stp/stpe/005/test.c b/share/tests/libc-stp/stpe/005/test.c deleted file mode 100644 index e1fa59b..0000000 --- a/share/tests/libc-stp/stpe/005/test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include -#include - -int -main(void) -{ - char buf[1]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello "); - p = c_stpecpy(p, end, "world"); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/005/test.sh b/share/tests/libc-stp/stpe/005/test.sh deleted file mode 100755 index 1cadf3a..0000000 --- a/share/tests/libc-stp/stpe/005/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| if ! grep -q '^Truncated:$'; then - >&2 ./test; - exit 2; -fi; - - -./test \ -| if ! grep -q '^0: $'; then - >&2 ./test; - exit 3; -fi; diff --git a/share/tests/libc-stp/stpe/006/test.c b/share/tests/libc-stp/stpe/006/test.c deleted file mode 100644 index 875915c..0000000 --- a/share/tests/libc-stp/stpe/006/test.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include -#include - -int -main(void) -{ - char buf[11]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello "); - p = c_stpecpy(p, end, "world"); - p = c_stpecpy(p, end, "!"); - p = c_stpecpy(p, end, ""); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/006/test.sh b/share/tests/libc-stp/stpe/006/test.sh deleted file mode 100755 index 7eccc45..0000000 --- a/share/tests/libc-stp/stpe/006/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| if ! grep -q '^Truncated:$'; then - >&2 ./test; - exit 2; -fi; - - -./test \ -| if ! grep -q '^10: Hello worl$'; then - >&2 ./test; - exit 3; -fi; diff --git a/share/tests/libc-stp/stpe/007/test.c b/share/tests/libc-stp/stpe/007/test.c deleted file mode 100644 index c27d1a5..0000000 --- a/share/tests/libc-stp/stpe/007/test.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#include -#include - -int -main(void) -{ - char buf[BUFSIZ]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello, "); - p = c_stpeprintf(p, end, "%d worlds", 22); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/007/test.sh b/share/tests/libc-stp/stpe/007/test.sh deleted file mode 100755 index e532969..0000000 --- a/share/tests/libc-stp/stpe/007/test.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| while read out; do - if echo $out | grep -q '^Truncated:$'; then - >&2 echo "$out"; - exit 2; - fi; - - echo $out; -done \ -| while read out; do - if echo $out | grep -q -v '^17: Hello, 22 worlds!$'; then - >&2 echo "$out"; - exit 3; - fi; -done; diff --git a/share/tests/libc-stp/stpe/008/test.c b/share/tests/libc-stp/stpe/008/test.c deleted file mode 100644 index 9ed7eff..0000000 --- a/share/tests/libc-stp/stpe/008/test.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#include -#include - -int -main(void) -{ - char buf[17]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello, "); - p = c_stpeprintf(p, end, "%d worlds", 22); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/008/test.sh b/share/tests/libc-stp/stpe/008/test.sh deleted file mode 100755 index 52043f7..0000000 --- a/share/tests/libc-stp/stpe/008/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| if ! grep -q '^Truncated:$'; then - >&2 ./test; - exit 2; -fi; - - -./test \ -| if ! grep -q '^16: Hello, 22 worlds$'; then - >&2 ./test; - exit 3; -fi; diff --git a/share/tests/libc-stp/stpe/009/test.c b/share/tests/libc-stp/stpe/009/test.c deleted file mode 100644 index 45b1ae3..0000000 --- a/share/tests/libc-stp/stpe/009/test.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#include -#include - -int -main(void) -{ - char buf[10]; - char *p, *end; - size_t len; - - end = buf + sizeof(buf); - p = buf; - p = c_stpecpy(p, end, "Hello, "); - p = c_stpeprintf(p, end, "%d worlds", 22); - p = c_stpecpy(p, end, "!"); - if (p == end) { - p--; - puts("Truncated:"); - } - len = p - buf; - printf("%zu: ", len); - puts(buf); -} diff --git a/share/tests/libc-stp/stpe/009/test.sh b/share/tests/libc-stp/stpe/009/test.sh deleted file mode 100755 index 555d657..0000000 --- a/share/tests/libc-stp/stpe/009/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - - -set -Eefuo pipefail; -shopt -s lastpipe; - - -./test \ -| if ! grep -q '^Truncated:$'; then - >&2 ./test; - exit 2; -fi; - - -./test \ -| if ! grep -q '^9: Hello, 22'; then - >&2 ./test; - exit 3; -fi; diff --git a/share/tests/libc-str-cpy-stp/Makefile b/share/tests/libc-str-cpy-stp/Makefile new file mode 100755 index 0000000..466770e --- /dev/null +++ b/share/tests/libc-str-cpy-stp/Makefile @@ -0,0 +1,63 @@ +# Copyright 2022 Alejandro Colomar +# SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +SHELL := /usr/bin/env bash -Eeuo pipefail + + +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --no-builtin-variables +MAKEFLAGS += --no-print-directory + + +CC := cc +FIND := find +GREP := grep +PKGCONF := pkgconf +SORT := sort + + +libname := libc-str-cpy-stp + + +PKGCONFFLAGS := + +CPPFLAGS := + +CFLAGS := -Wall -Wextra -Werror +CFLAGS += -std=gnu2x +CFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --cflags $(libname)) + +LDFLAGS := -Wl,--as-needed +LDFLAGS += -Wl,--no-allow-shlib-undefined +LDFLAGS += -Wl,--no-copy-dt-needed-entries +LDFLAGS += -Wl,--no-undefined +LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-L $(libname)) +LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-other $(libname)) + +LDLIBS := $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-l $(libname)) + + +TESTDIR := . + + +TESTS_c := $(shell $(FIND) $(TESTDIR) -type f | $(GREP) '\.c$$' | $(SORT)) +TESTS := $(patsubst %.c,%,$(TESTS_c)) + + +.PHONY: all +all: $(TESTS) + + +$(TESTS): %: %.c FORCE + $(info TEST $(dir $@)) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@ + cd $(dir $@) && ./test.sh + + +V := +$(V).SILENT: + + +FORCE: diff --git a/share/tests/libc-str-cpy-stp/stpe/001/test.c b/share/tests/libc-str-cpy-stp/stpe/001/test.c new file mode 100644 index 0000000..02b4896 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/001/test.c @@ -0,0 +1,25 @@ +#include + +#include +#include + +int +main(void) +{ + char buf[BUFSIZ]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/001/test.sh b/share/tests/libc-str-cpy-stp/stpe/001/test.sh new file mode 100755 index 0000000..8f0870d --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/001/test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| while read out; do + if echo $out | grep -q '^Truncated:$'; then + >&2 echo "$out"; + exit 2; + fi; + + echo $out; +done \ +| while read out; do + if echo $out | grep -q -v '^12: Hello world!$'; then + >&2 echo "$out"; + exit 3; + fi; +done; diff --git a/share/tests/libc-str-cpy-stp/stpe/002/test.c b/share/tests/libc-str-cpy-stp/stpe/002/test.c new file mode 100644 index 0000000..3aa8fe1 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/002/test.c @@ -0,0 +1,25 @@ +#include + +#include +#include + +int +main(void) +{ + char buf[13]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/002/test.sh b/share/tests/libc-str-cpy-stp/stpe/002/test.sh new file mode 100755 index 0000000..e5eadd2 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/002/test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| while read out; do + if echo $out | grep -q 'Truncated'; then + >&2 echo "$out"; + exit 2; + fi; + + echo $out; +done \ +| while read out; do + if echo $out | grep -q -v '^12: Hello world!$'; then + >&2 echo "$out"; + exit 3; + fi; +done; diff --git a/share/tests/libc-str-cpy-stp/stpe/003/test.c b/share/tests/libc-str-cpy-stp/stpe/003/test.c new file mode 100644 index 0000000..5f216ff --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/003/test.c @@ -0,0 +1,25 @@ +#include + +#include +#include + +int +main(void) +{ + char buf[12]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/003/test.sh b/share/tests/libc-str-cpy-stp/stpe/003/test.sh new file mode 100755 index 0000000..ee952ea --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/003/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| if ! grep -q '^Truncated:$'; then + >&2 ./test; + exit 2; +fi; + + +./test \ +| if ! grep -q '^11: Hello world$'; then + >&2 ./test; + exit 3; +fi; diff --git a/share/tests/libc-str-cpy-stp/stpe/004/test.c b/share/tests/libc-str-cpy-stp/stpe/004/test.c new file mode 100644 index 0000000..c3645ad --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/004/test.c @@ -0,0 +1,25 @@ +#include + +#include +#include + +int +main(void) +{ + char buf[11]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/004/test.sh b/share/tests/libc-str-cpy-stp/stpe/004/test.sh new file mode 100755 index 0000000..7eccc45 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/004/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| if ! grep -q '^Truncated:$'; then + >&2 ./test; + exit 2; +fi; + + +./test \ +| if ! grep -q '^10: Hello worl$'; then + >&2 ./test; + exit 3; +fi; diff --git a/share/tests/libc-str-cpy-stp/stpe/005/test.c b/share/tests/libc-str-cpy-stp/stpe/005/test.c new file mode 100644 index 0000000..9c4a585 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/005/test.c @@ -0,0 +1,25 @@ +#include + +#include +#include + +int +main(void) +{ + char buf[1]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/005/test.sh b/share/tests/libc-str-cpy-stp/stpe/005/test.sh new file mode 100755 index 0000000..1cadf3a --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/005/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| if ! grep -q '^Truncated:$'; then + >&2 ./test; + exit 2; +fi; + + +./test \ +| if ! grep -q '^0: $'; then + >&2 ./test; + exit 3; +fi; diff --git a/share/tests/libc-str-cpy-stp/stpe/006/test.c b/share/tests/libc-str-cpy-stp/stpe/006/test.c new file mode 100644 index 0000000..58f390f --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/006/test.c @@ -0,0 +1,26 @@ +#include + +#include +#include + +int +main(void) +{ + char buf[11]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); + p = c_stpecpy(p, end, ""); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/006/test.sh b/share/tests/libc-str-cpy-stp/stpe/006/test.sh new file mode 100755 index 0000000..7eccc45 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/006/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| if ! grep -q '^Truncated:$'; then + >&2 ./test; + exit 2; +fi; + + +./test \ +| if ! grep -q '^10: Hello worl$'; then + >&2 ./test; + exit 3; +fi; diff --git a/share/tests/libc-str-cpy-stp/stpe/007/test.c b/share/tests/libc-str-cpy-stp/stpe/007/test.c new file mode 100644 index 0000000..baf7df6 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/007/test.c @@ -0,0 +1,26 @@ +#include +#include + +#include +#include + +int +main(void) +{ + char buf[BUFSIZ]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello, "); + p = c_stpeprintf(p, end, "%d worlds", 22); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/007/test.sh b/share/tests/libc-str-cpy-stp/stpe/007/test.sh new file mode 100755 index 0000000..e532969 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/007/test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| while read out; do + if echo $out | grep -q '^Truncated:$'; then + >&2 echo "$out"; + exit 2; + fi; + + echo $out; +done \ +| while read out; do + if echo $out | grep -q -v '^17: Hello, 22 worlds!$'; then + >&2 echo "$out"; + exit 3; + fi; +done; diff --git a/share/tests/libc-str-cpy-stp/stpe/008/test.c b/share/tests/libc-str-cpy-stp/stpe/008/test.c new file mode 100644 index 0000000..5f8c2cf --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/008/test.c @@ -0,0 +1,26 @@ +#include +#include + +#include +#include + +int +main(void) +{ + char buf[17]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello, "); + p = c_stpeprintf(p, end, "%d worlds", 22); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/008/test.sh b/share/tests/libc-str-cpy-stp/stpe/008/test.sh new file mode 100755 index 0000000..52043f7 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/008/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| if ! grep -q '^Truncated:$'; then + >&2 ./test; + exit 2; +fi; + + +./test \ +| if ! grep -q '^16: Hello, 22 worlds$'; then + >&2 ./test; + exit 3; +fi; diff --git a/share/tests/libc-str-cpy-stp/stpe/009/test.c b/share/tests/libc-str-cpy-stp/stpe/009/test.c new file mode 100644 index 0000000..bb181f8 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/009/test.c @@ -0,0 +1,26 @@ +#include +#include + +#include +#include + +int +main(void) +{ + char buf[10]; + char *p, *end; + size_t len; + + end = buf + sizeof(buf); + p = buf; + p = c_stpecpy(p, end, "Hello, "); + p = c_stpeprintf(p, end, "%d worlds", 22); + p = c_stpecpy(p, end, "!"); + if (p == end) { + p--; + puts("Truncated:"); + } + len = p - buf; + printf("%zu: ", len); + puts(buf); +} diff --git a/share/tests/libc-str-cpy-stp/stpe/009/test.sh b/share/tests/libc-str-cpy-stp/stpe/009/test.sh new file mode 100755 index 0000000..555d657 --- /dev/null +++ b/share/tests/libc-str-cpy-stp/stpe/009/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +set -Eefuo pipefail; +shopt -s lastpipe; + + +./test \ +| if ! grep -q '^Truncated:$'; then + >&2 ./test; + exit 2; +fi; + + +./test \ +| if ! grep -q '^9: Hello, 22'; then + >&2 ./test; + exit 3; +fi; diff --git a/src/c/stp/_compiler.c b/src/c/stp/_compiler.c deleted file mode 100644 index 5798531..0000000 --- a/src/c/stp/_compiler.c +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include diff --git a/src/c/stp/stp/ustr2stp.c b/src/c/stp/stp/ustr2stp.c deleted file mode 100644 index 695b401..0000000 --- a/src/c/stp/stp/ustr2stp.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include - -#include - - -#pragma clang assume_nonnull begin -extern inline char *c_ustr2stp(char *restrict dst, const char *restrict src, - size_t len); -#pragma clang assume_nonnull end diff --git a/src/c/stp/stp/zustr2stp.c b/src/c/stp/stp/zustr2stp.c deleted file mode 100644 index bb804b0..0000000 --- a/src/c/stp/stp/zustr2stp.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include - -#include - - -#pragma clang assume_nonnull begin -extern inline char *c_zustr2stp(char *restrict dst, const char *restrict src, - size_t sz); -#pragma clang assume_nonnull end diff --git a/src/c/stp/stpe/stpecpy.c b/src/c/stp/stpe/stpecpy.c deleted file mode 100644 index a0a21cd..0000000 --- a/src/c/stp/stpe/stpecpy.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include - -#include - - -#pragma clang assume_nonnull begin -extern inline char *c_nullable c_stpecpy(char *c_nullable dst, char end[0], - const char *restrict src); -#pragma clang assume_nonnull end diff --git a/src/c/stp/stpe/stpeprintf.c b/src/c/stp/stpe/stpeprintf.c deleted file mode 100644 index bf7ad39..0000000 --- a/src/c/stp/stpe/stpeprintf.c +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include - -#include - -#include - - -#pragma clang assume_nonnull begin -extern inline char *c_nullable c_stpeprintf(char *c_nullable dst, char end[0], - const char *restrict fmt, ...); -extern inline char *c_nullable c_vstpeprintf(char *c_nullable dst, char end[0], - const char *restrict fmt, va_list ap); -#pragma clang assume_nonnull end diff --git a/src/c/stp/ustp/ustpcpy.c b/src/c/stp/ustp/ustpcpy.c deleted file mode 100644 index 22e8768..0000000 --- a/src/c/stp/ustp/ustpcpy.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include - -#include - - -#pragma clang assume_nonnull begin -extern inline char *c_ustpcpy(char *restrict dst, const char *restrict src, - size_t len); -#pragma clang assume_nonnull end diff --git a/src/c/stp/ustp/zustr2ustp.c b/src/c/stp/ustp/zustr2ustp.c deleted file mode 100644 index 4ba3b57..0000000 --- a/src/c/stp/ustp/zustr2ustp.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022 Alejandro Colomar -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include - -#include - - -#pragma clang assume_nonnull begin -extern inline char *c_zustr2ustp(char *restrict dst, const char *restrict src, - size_t sz); -#pragma clang assume_nonnull end diff --git a/src/c/str/cpy/stp/_compiler.c b/src/c/str/cpy/stp/_compiler.c new file mode 100644 index 0000000..5ede2f4 --- /dev/null +++ b/src/c/str/cpy/stp/_compiler.c @@ -0,0 +1,5 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include diff --git a/src/c/str/cpy/stp/stp/ustr2stp.c b/src/c/str/cpy/stp/stp/ustr2stp.c new file mode 100644 index 0000000..8b4e683 --- /dev/null +++ b/src/c/str/cpy/stp/stp/ustr2stp.c @@ -0,0 +1,13 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include + +#include + + +#pragma clang assume_nonnull begin +extern inline char *c_ustr2stp(char *restrict dst, const char *restrict src, + size_t len); +#pragma clang assume_nonnull end diff --git a/src/c/str/cpy/stp/stp/zustr2stp.c b/src/c/str/cpy/stp/stp/zustr2stp.c new file mode 100644 index 0000000..45ea57f --- /dev/null +++ b/src/c/str/cpy/stp/stp/zustr2stp.c @@ -0,0 +1,13 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include + +#include + + +#pragma clang assume_nonnull begin +extern inline char *c_zustr2stp(char *restrict dst, const char *restrict src, + size_t sz); +#pragma clang assume_nonnull end diff --git a/src/c/str/cpy/stp/stpe/stpecpy.c b/src/c/str/cpy/stp/stpe/stpecpy.c new file mode 100644 index 0000000..5dc3154 --- /dev/null +++ b/src/c/str/cpy/stp/stpe/stpecpy.c @@ -0,0 +1,13 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include + +#include + + +#pragma clang assume_nonnull begin +extern inline char *c_nullable c_stpecpy(char *c_nullable dst, char end[0], + const char *restrict src); +#pragma clang assume_nonnull end diff --git a/src/c/str/cpy/stp/stpe/stpeprintf.c b/src/c/str/cpy/stp/stpe/stpeprintf.c new file mode 100644 index 0000000..32d18f8 --- /dev/null +++ b/src/c/str/cpy/stp/stpe/stpeprintf.c @@ -0,0 +1,17 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include + +#include + +#include + + +#pragma clang assume_nonnull begin +extern inline char *c_nullable c_stpeprintf(char *c_nullable dst, char end[0], + const char *restrict fmt, ...); +extern inline char *c_nullable c_vstpeprintf(char *c_nullable dst, char end[0], + const char *restrict fmt, va_list ap); +#pragma clang assume_nonnull end diff --git a/src/c/str/cpy/stp/ustp/ustpcpy.c b/src/c/str/cpy/stp/ustp/ustpcpy.c new file mode 100644 index 0000000..a838769 --- /dev/null +++ b/src/c/str/cpy/stp/ustp/ustpcpy.c @@ -0,0 +1,13 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include + +#include + + +#pragma clang assume_nonnull begin +extern inline char *c_ustpcpy(char *restrict dst, const char *restrict src, + size_t len); +#pragma clang assume_nonnull end diff --git a/src/c/str/cpy/stp/ustp/zustr2ustp.c b/src/c/str/cpy/stp/ustp/zustr2ustp.c new file mode 100644 index 0000000..932af12 --- /dev/null +++ b/src/c/str/cpy/stp/ustp/zustr2ustp.c @@ -0,0 +1,13 @@ +// Copyright 2022 Alejandro Colomar +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include + +#include + + +#pragma clang assume_nonnull begin +extern inline char *c_zustr2ustp(char *restrict dst, const char *restrict src, + size_t sz); +#pragma clang assume_nonnull end -- cgit v1.2.3