diff options
author | Alejandro Colomar <alx@kernel.org> | 2022-12-29 14:43:12 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2022-12-29 19:21:25 +0100 |
commit | f6f7e9ac99582b856102f7c0e9ec9c67763fec3b (patch) | |
tree | c3d9563e8aba64099c813319c90b1fa09b24e932 | |
parent | 5d5bbeb5cb4e384c947493a0175daabd913a1d5e (diff) |
Make this library part of a modular libc
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | .gitignore | 2 | ||||
l--------- | CONTRIBUTING | 2 | ||||
l--------- | INSTALL | 2 | ||||
l--------- | README | 2 | ||||
-rw-r--r-- | include/c/stp/_compiler.h | 35 | ||||
-rw-r--r-- | include/c/stp/stp/ustr2stp.h | 33 | ||||
-rw-r--r-- | include/c/stp/stp/zustr2stp.h | 33 | ||||
-rw-r--r-- | include/c/stp/stpe/stpecpy.h (renamed from include/stp/stpe/stpecpy.h) | 16 | ||||
-rw-r--r-- | include/c/stp/stpe/stpeprintf.h (renamed from include/stp/stpe/stpeprintf.h) | 30 | ||||
-rw-r--r-- | include/c/stp/ustp/ustpcpy.h (renamed from include/stp/ustp/ustpcpy.h) | 11 | ||||
-rw-r--r-- | include/c/stp/ustp/zustr2ustp.h | 29 | ||||
-rw-r--r-- | include/stp/_compiler.h | 35 | ||||
-rw-r--r-- | include/stp/stp/ustr2stp.h | 32 | ||||
-rw-r--r-- | include/stp/stp/zustr2stp.h | 32 | ||||
-rw-r--r-- | include/stp/ustp/zustr2ustp.h | 29 | ||||
-rw-r--r-- | lib/build-deps.mk | 1 | ||||
-rw-r--r-- | lib/build-lib.mk | 2 | ||||
-rw-r--r-- | lib/lint-c.mk | 4 | ||||
-rw-r--r-- | lib/version.mk | 2 | ||||
-rw-r--r-- | share/doc/libc-stp/contributing (renamed from share/doc/libstp/contributing) | 4 | ||||
-rw-r--r-- | share/doc/libc-stp/install (renamed from share/doc/libstp/install) | 10 | ||||
-rw-r--r-- | share/doc/libc-stp/readme (renamed from share/doc/libstp/readme) | 8 | ||||
-rw-r--r-- | share/man/man3/c_stpecpy.3 (renamed from share/man/man3/stpecpy.3) | 59 | ||||
-rw-r--r-- | share/man/man3/c_stpeprintf.3 (renamed from share/man/man3/stpeprintf.3) | 28 | ||||
-rw-r--r-- | share/man/man3/c_ustpcpy.3 (renamed from share/man/man3/ustpcpy.3) | 42 | ||||
-rw-r--r-- | share/man/man3/c_ustr2stp.3 (renamed from share/man/man3/ustr2stp.3) | 41 | ||||
-rw-r--r-- | share/man/man3/c_vstpeprintf.3 | 1 | ||||
-rw-r--r-- | share/man/man3/c_zustr2stp.3 (renamed from share/man/man3/zustr2stp.3) | 45 | ||||
-rw-r--r-- | share/man/man3/c_zustr2ustp.3 (renamed from share/man/man3/zustr2ustp.3) | 38 | ||||
-rw-r--r-- | share/man/man3/vstpeprintf.3 | 1 | ||||
-rw-r--r-- | share/pkgconfig/libc-stp-uninstalled.pc (renamed from share/pkgconfig/libstp-uninstalled.pc) | 6 | ||||
-rwxr-xr-x | share/tests/libc-stp/Makefile (renamed from share/tests/libstp/Makefile) | 12 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/001/test.c (renamed from share/tests/libstp/stpe/001/test.c) | 8 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/001/test.sh (renamed from share/tests/libstp/stpe/001/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/002/test.c (renamed from share/tests/libstp/stpe/002/test.c) | 8 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/002/test.sh (renamed from share/tests/libstp/stpe/002/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/003/test.c (renamed from share/tests/libstp/stpe/003/test.c) | 8 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/003/test.sh (renamed from share/tests/libstp/stpe/003/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/004/test.c (renamed from share/tests/libstp/stpe/004/test.c) | 8 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/004/test.sh (renamed from share/tests/libstp/stpe/004/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/005/test.c (renamed from share/tests/libstp/stpe/005/test.c) | 8 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/005/test.sh (renamed from share/tests/libstp/stpe/005/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/006/test.c (renamed from share/tests/libstp/stpe/006/test.c) | 10 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/006/test.sh (renamed from share/tests/libstp/stpe/006/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/007/test.c (renamed from share/tests/libstp/stpe/007/test.c) | 10 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/007/test.sh (renamed from share/tests/libstp/stpe/007/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/008/test.c (renamed from share/tests/libstp/stpe/008/test.c) | 10 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/008/test.sh (renamed from share/tests/libstp/stpe/008/test.sh) | 0 | ||||
-rw-r--r-- | share/tests/libc-stp/stpe/009/test.c (renamed from share/tests/libstp/stpe/009/test.c) | 10 | ||||
-rwxr-xr-x | share/tests/libc-stp/stpe/009/test.sh (renamed from share/tests/libstp/stpe/009/test.sh) | 0 | ||||
-rw-r--r-- | src/c/stp/_compiler.c (renamed from src/stp/_compiler.c) | 2 | ||||
-rw-r--r-- | src/c/stp/stp/ustr2stp.c (renamed from src/stp/stp/ustr2stp.c) | 4 | ||||
-rw-r--r-- | src/c/stp/stp/zustr2stp.c (renamed from src/stp/stp/zustr2stp.c) | 4 | ||||
-rw-r--r-- | src/c/stp/stpe/stpecpy.c (renamed from src/stp/stpe/stpecpy.c) | 6 | ||||
-rw-r--r-- | src/c/stp/stpe/stpeprintf.c | 17 | ||||
-rw-r--r-- | src/c/stp/ustp/ustpcpy.c (renamed from src/stp/ustp/ustpcpy.c) | 4 | ||||
-rw-r--r-- | src/c/stp/ustp/zustr2ustp.c (renamed from src/stp/ustp/zustr2ustp.c) | 4 | ||||
-rw-r--r-- | src/stp/stpe/stpeprintf.c | 17 |
58 files changed, 340 insertions, 425 deletions
@@ -5,4 +5,4 @@ /.checkpatch-camelcase* # 'make check' binaries -/share/tests/libstp/**/test +/share/tests/libc-stp/**/test diff --git a/CONTRIBUTING b/CONTRIBUTING index 31a8c66..bb8d59c 120000 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -1 +1 @@ -share/doc/libstp/contributing
\ No newline at end of file +share/doc/libc-stp/contributing
\ No newline at end of file @@ -1 +1 @@ -share/doc/libstp/install
\ No newline at end of file +share/doc/libc-stp/install
\ No newline at end of file @@ -1 +1 @@ -share/doc/libstp/readme
\ No newline at end of file +share/doc/libc-stp/readme
\ No newline at end of file diff --git a/include/c/stp/_compiler.h b/include/c/stp/_compiler.h new file mode 100644 index 0000000..85c20a0 --- /dev/null +++ b/include/c/stp/_compiler.h @@ -0,0 +1,35 @@ +// Copyright 2022 Alejandro Colomar <alx@kernel.org> +// 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 new file mode 100644 index 0000000..9933193 --- /dev/null +++ b/include/c/stp/stp/ustr2stp.h @@ -0,0 +1,33 @@ +// Copyright 2022 Alejandro Colomar <alx@kernel.org> +// 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 <stddef.h> + +#include <c/stp/_compiler.h> // IWYU pragma: keep +#include <c/stp/ustp/ustpcpy.h> + + +#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 new file mode 100644 index 0000000..53c2305 --- /dev/null +++ b/include/c/stp/stp/zustr2stp.h @@ -0,0 +1,33 @@ +// Copyright 2022 Alejandro Colomar <alx@kernel.org> +// 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 <stddef.h> + +#include <c/stp/_compiler.h> // IWYU pragma: keep +#include <c/stp/ustp/zustr2ustp.h> + + +#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/stp/stpe/stpecpy.h b/include/c/stp/stpe/stpecpy.h index 59d81e9..eb84587 100644 --- a/include/stp/stpe/stpecpy.h +++ b/include/c/stp/stpe/stpecpy.h @@ -2,33 +2,33 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#ifndef INCLUDE_STP_STPE_STPECPY_H_ -#define INCLUDE_STP_STPE_STPECPY_H_ +#ifndef INCLUDE_C_STP_STPE_STPECPY_H_ +#define INCLUDE_C_STP_STPE_STPECPY_H_ #include <stdbool.h> #include <stddef.h> #include <string.h> -#include <stp/_compiler.h> +#include <c/stp/_compiler.h> #pragma clang assume_nonnull begin -inline char *stp_nullable stpecpy(char *stp_nullable dst, char *end, +inline char *c_nullable c_stpecpy(char *c_nullable dst, char *end, const char *restrict src); -inline char *stp_nullable -stpecpy(char *stp_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 (stp_unlikely(dst == NULL)) // Allow chaining with stpeprintf(). + if (c_unlikely(dst == NULL)) // Allow chaining with stpeprintf(). return NULL; - stp_impossible(dst > end); + c_impossible(dst > end); dsize = end - dst; slen = strnlen(src, dsize); diff --git a/include/stp/stpe/stpeprintf.h b/include/c/stp/stpe/stpeprintf.h index c7508e2..32dc0fe 100644 --- a/include/stp/stpe/stpeprintf.h +++ b/include/c/stp/stpe/stpeprintf.h @@ -2,53 +2,53 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#ifndef INCLUDE_STP_STPE_STPEPRINTF_H_ -#define INCLUDE_STP_STPE_STPEPRINTF_H_ +#ifndef INCLUDE_C_STP_STPE_STPEPRINTF_H_ +#define INCLUDE_C_STP_STPE_STPEPRINTF_H_ #include <stdarg.h> #include <stdio.h> -#include <stp/_compiler.h> +#include <c/stp/_compiler.h> #pragma clang assume_nonnull begin -inline char *stp_nullable stpeprintf(char *stp_nullable dst, char *end, +inline char *c_nullable c_stpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, ...); -inline char *stp_nullable vstpeprintf(char *stp_nullable dst, char *end, +inline char *c_nullable c_vstpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, va_list ap); -inline char *stp_nullable -stpeprintf(char *stp_nullable dst, char *end, const char *restrict fmt, ...) +inline char *c_nullable +c_stpeprintf(char *c_nullable dst, char *end, const char *restrict fmt, ...) { - char *stp_nullable p; + char *c_nullable p; va_list ap; va_start(ap, fmt); - p = vstpeprintf(dst, end, fmt, ap); + p = c_vstpeprintf(dst, end, fmt, ap); va_end(ap); return p; } -inline char *stp_nullable -vstpeprintf(char *stp_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) { int len; if (dst == end) return end; - if (stp_unlikely(dst == NULL)) + if (c_unlikely(dst == NULL)) return NULL; - stp_impossible(dst > end); + c_impossible(dst > end); len = vsnprintf(dst, end - dst, fmt, ap); - stp_impossible(len < -1); - if (stp_unlikely(len == -1)) + c_impossible(len < -1); + if (c_unlikely(len == -1)) return NULL; if (len >= end - dst) return end; diff --git a/include/stp/ustp/ustpcpy.h b/include/c/stp/ustp/ustpcpy.h index 578eb7d..0045f0e 100644 --- a/include/stp/ustp/ustpcpy.h +++ b/include/c/stp/ustp/ustpcpy.h @@ -2,22 +2,23 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#ifndef INCLUDE_STP_USTP_USTPCPY_H_ -#define INCLUDE_STP_USTP_USTPCPY_H_ +#ifndef INCLUDE_C_STP_USTP_USTPCPY_H_ +#define INCLUDE_C_STP_USTP_USTPCPY_H_ #include <stddef.h> #include <string.h> -#include <stp/_compiler.h> // IWYU pragma: keep +#include <c/stp/_compiler.h> // IWYU pragma: keep #pragma clang assume_nonnull begin -inline char *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); inline char * -ustpcpy(char *restrict dst, const char *restrict src, size_t len) +c_ustpcpy(char *restrict dst, const char *restrict src, size_t len) { #if defined(_GNU_SOURCE) return mempcpy(dst, src, len); diff --git a/include/c/stp/ustp/zustr2ustp.h b/include/c/stp/ustp/zustr2ustp.h new file mode 100644 index 0000000..e8428cf --- /dev/null +++ b/include/c/stp/ustp/zustr2ustp.h @@ -0,0 +1,29 @@ +// Copyright 2022 Alejandro Colomar <alx@kernel.org> +// 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 <stddef.h> +#include <string.h> + +#include <c/stp/_compiler.h> // IWYU pragma: keep +#include <c/stp/ustp/ustpcpy.h> + + +#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/stp/_compiler.h b/include/stp/_compiler.h deleted file mode 100644 index 001ddcf..0000000 --- a/include/stp/_compiler.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2022 Alejandro Colomar <alx@kernel.org> -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_STP__COMPILER_H_ -#define INCLUDE_STP__COMPILER_H_ - - -#if (__STDC_VERSION__ < 199901L) -# error "Minimum C version is C99" -#endif - - -#define stp_impossible(e) do \ -{ \ - if (e) \ - stp_unreachable(); \ -} while (0) - -#if defined(__clang__) -# define stp_nullable _Nullable -#else -# define stp_nullable -#endif - -#define stp_unlikely(e) __builtin_expect(!!(e), 0) - -#if defined(unreachable) -# define stp_unreachable() unreachable() -#else -# define stp_unreachable() __builtin_unreachable() -#endif - - -#endif // Header guard diff --git a/include/stp/stp/ustr2stp.h b/include/stp/stp/ustr2stp.h deleted file mode 100644 index 10350cf..0000000 --- a/include/stp/stp/ustr2stp.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2022 Alejandro Colomar <alx@kernel.org> -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_STP_STP_USTR2STP_H_ -#define INCLUDE_STP_STP_USTR2STP_H_ - - -#include <stddef.h> - -#include <stp/_compiler.h> // IWYU pragma: keep -#include <stp/ustp/ustpcpy.h> - - -#pragma clang assume_nonnull begin -inline char *ustr2stp(char *restrict dst, const char *restrict src, size_t len); - - -inline char * -ustr2stp(char *restrict dst, const char *restrict src, size_t len) -{ - char *p; - - p = ustpcpy(dst, src, len); - *p = '\0'; - - return p; -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/stp/stp/zustr2stp.h b/include/stp/stp/zustr2stp.h deleted file mode 100644 index 2b87ab4..0000000 --- a/include/stp/stp/zustr2stp.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2022 Alejandro Colomar <alx@kernel.org> -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_STP_STP_ZUSTR2STP_H_ -#define INCLUDE_STP_STP_ZUSTR2STP_H_ - - -#include <stddef.h> - -#include <stp/_compiler.h> // IWYU pragma: keep -#include <stp/ustp/zustr2ustp.h> - - -#pragma clang assume_nonnull begin -inline char *zustr2stp(char *restrict dst, const char *restrict src, size_t sz); - - -inline char * -zustr2stp(char *restrict dst, const char *restrict src, size_t sz) -{ - char *p; - - p = zustr2ustp(dst, src, sz); - *p = '\0'; - - return p; -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/include/stp/ustp/zustr2ustp.h b/include/stp/ustp/zustr2ustp.h deleted file mode 100644 index 6348720..0000000 --- a/include/stp/ustp/zustr2ustp.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2022 Alejandro Colomar <alx@kernel.org> -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#ifndef INCLUDE_STP_USTP_ZUSTR2USTP_H_ -#define INCLUDE_STP_USTP_ZUSTR2USTP_H_ - - -#include <stddef.h> -#include <string.h> - -#include <stp/_compiler.h> // IWYU pragma: keep -#include <stp/ustp/ustpcpy.h> - - -#pragma clang assume_nonnull begin -inline char *zustr2ustp(char *restrict dst, const char *restrict src, - size_t sz); - - -inline char * -zustr2ustp(char *restrict dst, const char *restrict src, size_t sz) -{ - return ustpcpy(dst, src, strnlen(src, sz)); -} -#pragma clang assume_nonnull end - - -#endif // Header guard diff --git a/lib/build-deps.mk b/lib/build-deps.mk index 8a1507d..38c1251 100644 --- a/lib/build-deps.mk +++ b/lib/build-deps.mk @@ -34,6 +34,7 @@ EXTRA_CPPFLAGS := CPPFLAGS := $(DEFAULT_CPPFLAGS) $(EXTRA_CPPFLAGS) DEFAULT_CFLAGS := -O3 +DEFAULT_CFLAGS += -std=gnu2x DEFAULT_CFLAGS += -Wall DEFAULT_CFLAGS += -Wextra DEFAULT_CFLAGS += -Wstrict-prototypes diff --git a/lib/build-lib.mk b/lib/build-lib.mk index 2288fae..3d23c70 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 -lstp,$(shell $(PKGCONF_CMD) --libs-only-l $(pc_reqs) $(HIDE_ERR))) +DEFAULT_LDLIBS := $(filter-out -lc-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/lint-c.mk b/lib/lint-c.mk index 30e7da3..d8ab103 100644 --- a/lib/lint-c.mk +++ b/lib/lint-c.mk @@ -50,8 +50,8 @@ DEFAULT_CPPCHECKFLAGS += --error-exitcode=2 DEFAULT_CPPCHECKFLAGS += --inconclusive DEFAULT_CPPCHECKFLAGS += --quiet DEFAULT_CPPCHECKFLAGS += --suppressions-list=$(CPPCHECK_CONF) -DEFAULT_CPPCHECKFLAGS += -Ustp_unlikely -DEFAULT_CPPCHECKFLAGS += -Ustp_unreachable +DEFAULT_CPPCHECKFLAGS += -Uc_unlikely +DEFAULT_CPPCHECKFLAGS += -Uc_unreachable EXTRA_CPPCHECKFLAGS := CPPCHECKFLAGS := $(DEFAULT_CPPCHECKFLAGS) $(EXTRA_CPPCHECKFLAGS) CPPCHECK := cppcheck diff --git a/lib/version.mk b/lib/version.mk index a9389b7..b961bfa 100644 --- a/lib/version.mk +++ b/lib/version.mk @@ -10,7 +10,7 @@ include $(srcdir)/lib/cmd.mk include $(srcdir)/lib/verbose.mk -libname := libstp +libname := libc-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/doc/libstp/contributing b/share/doc/libc-stp/contributing index 7cc4d0b..fdba378 100644 --- a/share/doc/libstp/contributing +++ b/share/doc/libc-stp/contributing @@ -54,7 +54,7 @@ Description which warnings you'll still see from that file that are not your fault. - $ touch src/stp/stpecpy.c # replace by the file you'll modify + $ touch src/c/stp/stpecpy.c # replace by the file you'll modify $ make -k lint (3) Apply your changes, and then run make(1) again. You can ignore @@ -62,7 +62,7 @@ Description please fix them if you know how, or at least note them in your patch email. - $ vi src/stp/stpecpy.c # do your work + $ vi src/c/stp/stpecpy.c # do your work $ make -k lint See <INSTALL> for a list of dependencies that this feature requires. diff --git a/share/doc/libstp/install b/share/doc/libc-stp/install index c90aa0a..a329e55 100644 --- a/share/doc/libstp/install +++ b/share/doc/libc-stp/install @@ -115,7 +115,7 @@ Files lib/*.mk Other makefiles. - include/stp/* + include/c/stp/* Header files. src/* @@ -124,16 +124,16 @@ Files share/pkgconfig/*.pc pc(5) file. - /usr/local/include/stp/*.h + /usr/local/include/c/stp/*.h Installed header files. - /usr/local/lib/libstp.a + /usr/local/lib/libc-stp.a Static library file. - /usr/local/lib/libstp.so* + /usr/local/lib/libc-stp.so* Shared library. - /usr/local/share/pkgconfig/libstp.pc + /usr/local/share/pkgconfig/libc-stp.pc Installed pc(5) file. Standards diff --git a/share/doc/libstp/readme b/share/doc/libc-stp/readme index 548ff60..b615895 100644 --- a/share/doc/libstp/readme +++ b/share/doc/libc-stp/readme @@ -1,5 +1,5 @@ Name - libstp - stp string library + libc-stp - stp string library Synopsis Simple and high-performance string library that allows chain-copying. @@ -36,7 +36,7 @@ Files include/* Header files. - share/doc/libstp/* + share/doc/libc-stp/* Project documentation. share/man/* @@ -58,7 +58,7 @@ Copyright See also Cgit - <http://www.alejandro-colomar.es/src/alx/alx/libstp.git> + <http://www.alejandro-colomar.es/src/alx/alx/libc-stp.git> Git - <git://www.alejandro-colomar.es/src/alx/alx/libstp.git> + <git://www.alejandro-colomar.es/src/alx/alx/libc-stp.git> diff --git a/share/man/man3/stpecpy.3 b/share/man/man3/c_stpecpy.3 index 03cce57..628e53e 100644 --- a/share/man/man3/stpecpy.3 +++ b/share/man/man3/c_stpecpy.3 @@ -2,18 +2,18 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception .\" -.TH stpecpy 3 (date) "libstp (unreleased)" +.TH c_stpecpy 3 (date) "libc\-stp (unreleased)" .SH NAME -stpecpy \- copy a string with truncation +c_stpecpy \- copy a string with truncation .SH LIBRARY stp string library -.RI ( libstp ", " "pkgconf --cflags --libs libstp" ) +.RI ( libc\-stp ", " "pkgconf \-\-cflags \-\-libs libc\-stp" ) .SH SYNOPSIS .nf -.B #include <stp/stpe/stpecpy.h> +.B #include <c/stp/stpe/stpecpy.h> .PP -.BI "char *_Nullable stpecpy(char *_Nullable " dst ", char " end [0], -.BI " const char *restrict " src ); +.BI "char *_Nullable c_stpecpy(char *_Nullable " dst ", char " end [0], +.BI " const char *restrict " src ); .fi .SH DESCRIPTION This function copies the string pointed to by @@ -28,34 +28,9 @@ isn't large enough to hold the copy, the resulting string is truncated. .PP This function can be chained with calls to -.MR stpeprintf 3 +.MR c_stpeprintf 3 and -.MR vstpeprintf 3 . -.PP -An implementation of this function might be -.PP -.in +4n -.EX -/* This code is in the public domain. */ - -char * -.IR stpecpy "(char *dst, char end[0], const char *restrict src)" -{ - char *p; - - if (dst == end || dst == NULL) - return dst; - - p = memccpy(dst, src, \(aq\e0\(aq, end \- dst); - if (p != NULL) - return p \- 1; - - /* truncation detected */ - end[\-1] = \(aq\e0\(aq; - return end; -} -.EE -.in +.MR c_vstpeprintf 3 . .SH RETURN VALUE .TP .B NULL @@ -91,7 +66,7 @@ lbx lb lb l l l. Interface Attribute Value T{ -.MR stpecpy 3 +.MR c_stpecpy 3 T} Thread safety MT-Safe .TE .hy @@ -101,7 +76,7 @@ T} Thread safety MT-Safe None. .SH EXAMPLES .nf -.RB "$ " "cc ./stpecpy.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libstp)" +.RB "$ " "cc ./stpecpy.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libc\-stp)" .RB "$ " "./a.out" [len = 12]: Hello world! $ @@ -114,8 +89,8 @@ $ #include <stdio.h> #include <stdlib.h> -#include <stp/stpe/stpecpy.h> -#include <stp/stpe/stpeprintf.h> +#include <c/stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpeprintf.h> int main(void) @@ -126,11 +101,11 @@ main(void) end = buf + BUFSIZ; p = buf; - p = stpecpy(p, end, "Hello, "); - p = stpeprintf(p, end, "%d worlds", 22); - p = stpecpy(p, end, "!"); + p = c_stpecpy(p, end, "Hello, "); + p = c_stpeprintf(p, end, "%d worlds", 22); + p = c_stpecpy(p, end, "!"); if (p == NULL) - err(EXIT_FAILURE, "stpeprintf()"); + err(EXIT_FAILURE, "c_stpeprintf()"); if (p == end) { p\-\-; warnx("Truncated"); @@ -144,5 +119,5 @@ main(void) .EE .\" SRC END .SH SEE ALSO -.MR stpeprintf 3 , +.MR c_stpeprintf 3 , .MR string_copying 7 diff --git a/share/man/man3/stpeprintf.3 b/share/man/man3/c_stpeprintf.3 index 5edacc9..47a2a81 100644 --- a/share/man/man3/stpeprintf.3 +++ b/share/man/man3/c_stpeprintf.3 @@ -2,20 +2,20 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception .\" -.TH stpeprintf 3 (date) "libstp (unreleased)" +.TH c_stpeprintf 3 (date) "libc\-stp (unreleased)" .SH NAME -stpeprintf, vstpeprintf \- create a formatted string with truncation +c_stpeprintf, c_vstpeprintf \- create a formatted string with truncation .SH LIBRARY stp string library -.RI ( libstp ", " "pkgconf --cflags --libs libstp" ) +.RI ( libc\-stp ", " "pkgconf \-\-cflags \-\-libs libc\-stp" ) .SH SYNOPSIS .nf -.B #include <stp/stpe/stpeprintf.h> +.B #include <c/stp/stpe/stpeprintf.h> .PP -.BI "char *_Nullable stpeprintf(char *_Nullable " dst ", char " end [0], -.BI " const char *restrict " fmt ", ...);" -.BI "char *_Nullable vstpeprintf(char *_Nullable " dst ", char " end [0], -.BI " const char *restrict " fmt ", va_list " ap ); +.BI "char *_Nullable c_stpeprintf(char *_Nullable " dst ", char " end [0], +.BI " const char *restrict " fmt ", ...);" +.BI "char *_Nullable c_vstpeprintf(char *_Nullable " dst ", char " end [0], +.BI " const char *restrict " fmt ", va_list " ap ); .fi .SH DESCRIPTION These functions are almost identical to @@ -29,9 +29,7 @@ The destination buffer is limited by a pointer to its instead of a size. .PP These functions can be chained with calls to -.MR stpeprintf 3 -and -.MR vstpeprintf 3 . +.MR c_stpecpy 3 . .SH RETURN VALUE .TP .B NULL @@ -77,8 +75,8 @@ lbx lb lb l l l. Interface Attribute Value T{ -.MR stpeprintf 3 , -.MR vstpeprintf 3 +.MR c_stpeprintf 3 , +.MR c_vstpeprintf 3 T} Thread safety MT-Safe .TE .hy @@ -88,7 +86,7 @@ T} Thread safety MT-Safe None. .SH EXAMPLES See -.MR stpecpy 3 . +.MR c_stpecpy 3 . .SH SEE ALSO -.MR stpecpy 3 , +.MR c_stpecpy 3 , .MR string_copying 7 diff --git a/share/man/man3/ustpcpy.3 b/share/man/man3/c_ustpcpy.3 index cf3874f..e5e3751 100644 --- a/share/man/man3/ustpcpy.3 +++ b/share/man/man3/c_ustpcpy.3 @@ -2,17 +2,17 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception .\" -.TH ustpcpy 3 (date) "libstp (unreleased)" +.TH c_ustpcpy 3 (date) "libc\-stp (unreleased)" .SH NAME -ustpcpy \- copy a character sequence +c_ustpcpy \- copy a character sequence .SH LIBRARY stp string library -.RI ( libstp ", " "pkgconf --cflags --libs libstp" ) +.RI ( libc\-stp ", " "pkgconf \-\-cflags \-\-libs libc\-stp" ) .SH SYNOPSIS .nf -.B #include <stp/ustp/ustpcpy.h> +.B #include <c/stp/ustp/ustpcpy.h> .PP -.BI "char *ustpcpy(char *restrict " dst ", const char " src "[restrict ." len ], +.BI "char *c_ustpcpy(char *restrict " dst ", const char " src "[restrict ." len ], .BI " size_t " len ); .fi .SH DESCRIPTION @@ -29,21 +29,7 @@ that is, bytes. .PP This function can be chained with calls to -.MR zustr2ustp 3 . -.PP -An implementation of this function might be: -.PP -.in +4n -.EX -/* This code is in the public domain. */ - -char * -.IR ustpcpy "(char *restrict dst, const char *restrict src, size_t len)" -{ - return mempcpy(dst, src, len); -} -.EE -.in +.MR c_zustr2ustp 3 . .SH RETURN VALUE This function returns .IR "dst + len" ; @@ -60,7 +46,7 @@ lbx lb lb l l l. Interface Attribute Value T{ -.MR ustpcpy 3 +.MR c_ustpcpy 3 T} Thread safety MT-Safe .TE .hy @@ -72,7 +58,7 @@ None. The character sequences .I src and -,I dst +.I dst may not overlap. .PP If the destination buffer is not large enough, @@ -83,7 +69,7 @@ in .MR feature_test_macros 7 . .SH EXAMPLES .nf -.RB "$ " "cc ./ustpcpy.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libstp)" +.RB "$ " "cc ./ustpcpy.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libc\-stp)" .RB "$ " "./a.out" [len = 12]: Hello world! $ @@ -96,7 +82,7 @@ $ #include <stdio.h> #include <stdlib.h> -#include <stp/ustp/ustpcpy.h> +#include <c/stp/ustp/ustpcpy.h> int main(void) @@ -110,9 +96,9 @@ main(void) err(EXIT_FAILURE, "malloc()"); p = buf; - p = ustpcpy(p, "Hello ", 6); - p = ustpcpy(p, "world", 5); - p = ustpcpy(p, "!", 1); + p = c_ustpcpy(p, "Hello ", 6); + p = c_ustpcpy(p, "world", 5); + p = c_ustpcpy(p, "!", 1); len = p \- buf; printf("[len = %zu]: %.*s\en", len, (int) len, buf); @@ -122,5 +108,5 @@ main(void) .EE .\" SRC END .SH SEE ALSO -.MR zustr2ustp 3 , +.MR c_zustr2ustp 3 , .MR string_copying 7 diff --git a/share/man/man3/ustr2stp.3 b/share/man/man3/c_ustr2stp.3 index 98768d5..2633f6d 100644 --- a/share/man/man3/ustr2stp.3 +++ b/share/man/man3/c_ustr2stp.3 @@ -2,17 +2,17 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception .\" -.TH ustr2stp 3 (date) "libstp (unreleased)" +.TH c_ustr2stp 3 (date) "libc\-stp (unreleased)" .SH NAME ustr2stp \- copy a character sequence into a string .SH LIBRARY stp string library -.RI ( libstp ", " "pkgconf --cflags --libs libstp" ) +.RI ( libc\-stp ", " "pkgconf \-\-cflags \-\-libs libc\-stp" ) .SH SYNOPSIS .nf -.B #include <stp/stp/ustr2stp.h> +.B #include <c/stp/stp/ustr2stp.h> .PP -.BI "char *ustr2stp(char *restrict " dst ", const char " src "[restrict ." len ], +.BI "char *c_ustr2stp(char *restrict " dst ", const char " src "[restrict ." len ], .BI " size_t " len ); .fi .SH DESCRIPTION @@ -29,26 +29,7 @@ that is, bytes. .PP This function can be chained with calls to -.MR ustr2stp 3 . -.PP -An implementation of this function might be: -.PP -.in +4n -.EX -/* This code is in the public domain. */ - -char * -.IR ustr2stp "(char *restrict dst, const char *restrict src, size_t len)" -{ - char *p; - - p = ustpcpy(dst, src, len); - *p = \(aq\e0\(aq; - - return p; -} -.EE -.in +.MR c_ustr2stp 3 . .SH RETURN VALUE This function returns .IR "dst + len" ; @@ -66,7 +47,7 @@ lbx lb lb l l l. Interface Attribute Value T{ -.MR ustr2stp 3 +.MR c_ustr2stp 3 T} Thread safety MT-Safe .TE .hy @@ -83,7 +64,7 @@ in .MR feature_test_macros 7 . .SH EXAMPLES .nf -.RB "$ " "cc ./ustr2stp.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libstp)" +.RB "$ " "cc ./ustr2stp.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libc\-stp)" .RB "$ " "./a.out" [len = 12]: Hello world! $ @@ -96,7 +77,7 @@ $ #include <stdio.h> #include <stdlib.h> -#include <stp/stp/ustr2stp.h> +#include <c/stp/stp/ustr2stp.h> int main(void) @@ -110,9 +91,9 @@ main(void) err(EXIT_FAILURE, "malloc()"); p = buf; - p = ustr2stp(p, "Hello ", 6); - p = ustr2stp(p, "world", 5); - p = ustr2stp(p, "!", 1); + p = c_ustr2stp(p, "Hello ", 6); + p = c_ustr2stp(p, "world", 5); + p = c_ustr2stp(p, "!", 1); len = p \- buf; printf("[len = %zu]: %s\en", len, buf); diff --git a/share/man/man3/c_vstpeprintf.3 b/share/man/man3/c_vstpeprintf.3 new file mode 100644 index 0000000..74512b6 --- /dev/null +++ b/share/man/man3/c_vstpeprintf.3 @@ -0,0 +1 @@ +.so man3/c_stpeprintf.3 diff --git a/share/man/man3/zustr2stp.3 b/share/man/man3/c_zustr2stp.3 index 6cae10c..503ecfc 100644 --- a/share/man/man3/zustr2stp.3 +++ b/share/man/man3/c_zustr2stp.3 @@ -2,17 +2,17 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception .\" -.TH zustr2stp 3 (date) "libstp (unreleased)" +.TH c_zustr2stp 3 (date) "libc\-stp (unreleased)" .SH NAME -zustr2stp \- copy a null-padded character sequence into a string +c_zustr2stp \- copy a null-padded character sequence into a string .SH LIBRARY stp string library -.RI ( libstp ", " "pkgconf --cflags --libs libstp" ) +.RI ( libc\-stp ", " "pkgconf \-\-cflags \-\-libs libc\-stp" ) .SH SYNOPSIS .nf -.B #include <stp/stp/zustr2stp.h> +.B #include <c/stp/stp/zustr2stp.h> .PP -.BI "char *zustr2stp(char *restrict " dst ", const char " src "[restrict ." sz ], +.BI "char *c_zustr2stp(char *restrict " dst ", const char " src "[restrict ." sz ], .BI " size_t " sz ); .fi .SH DESCRIPTION @@ -28,26 +28,7 @@ that is, .IR "strnlen(len, sz) + 1" . .PP This function can be chained with calls to -.MR ustr2stp 3 . -.PP -An implementation of this function might be: -.PP -.in +4n -.EX -/* This code is in the public domain. */ - -char * -.IR zustr2stp "(char *restrict dst, const char *restrict src, size_t sz)" -{ - char *p; - - p = zustr2ustp(dst, src, sz); - *p = \(aq\e0\(aq; - - return p; -} -.EE -.in +.MR c_ustr2stp 3 . .SH RETURN VALUE This function returns .IR "dst + strnlen(src, sz)" ; @@ -65,7 +46,7 @@ lbx lb lb l l l. Interface Attribute Value T{ -.MR zustr2stp 3 +.MR c_zustr2stp 3 T} Thread safety MT-Safe .TE .hy @@ -82,7 +63,7 @@ in .MR feature_test_macros 7 . .SH EXAMPLES .nf -.RB "$ " "cc ./zustr2stp.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libstp)" +.RB "$ " "cc ./zustr2stp.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libc\-stp)" .RB "$ " "./a.out" [len = 12]: pre.some_long_body.foo.bar $ @@ -95,7 +76,7 @@ $ #include <stdio.h> #include <stdlib.h> -#include <stp/stp/zustr2stp.h> +#include <c/stp/stp/zustr2stp.h> int main(void) @@ -118,9 +99,9 @@ main(void) err(EXIT_FAILURE, "malloc()"); p = buf; - p = zustr2ustp(p, pre, nitems(pre)); - p = ustr2stp(p, src, strlen(src) \- strlen(post)); - p = zustr2stp(p, new_post, nitems(new_post)); + p = c_zustr2ustp(p, pre, nitems(pre)); + p = c_ustr2stp(p, src, strlen(src) \- strlen(post)); + p = c_zustr2stp(p, new_post, nitems(new_post)); len = p \- buf; printf("[len = %zu]: %s\en", len, buf); @@ -130,5 +111,5 @@ main(void) .EE .\" SRC END .SH SEE ALSO -.MR ustr2stp 3 , +.MR c_ustr2stp 3 , .MR string_copying 7 diff --git a/share/man/man3/zustr2ustp.3 b/share/man/man3/c_zustr2ustp.3 index 00356d0..698218a 100644 --- a/share/man/man3/zustr2ustp.3 +++ b/share/man/man3/c_zustr2ustp.3 @@ -2,17 +2,17 @@ .\" Copyright 2022 Alejandro Colomar <alx@kernel.org> .\" SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception .\" -.TH zustr2ustp 3 (date) "libstp (unreleased)" +.TH c_zustr2ustp 3 (date) "libc\-stp (unreleased)" .SH NAME zustr2ustp \- copy a null-padded character sequence into a character sequence .SH LIBRARY stp string library -.RI ( libstp ", " "pkgconf --cflags --libs libstp" ) +.RI ( libc\-stp ", " "pkgconf \-\-cflags \-\-libs libc\-stp" ) .SH SYNOPSIS .nf -.B #include <stp/ustp/zustr2ustp.h> +.B #include <c/stp/ustp/zustr2ustp.h> .PP -.BI "char *zustr2ustp(char *restrict " dst ", const char " src "[restrict ." sz ], +.BI "char *c_zustr2ustp(char *restrict " dst ", const char " src "[restrict ." sz ], .BI " size_t " sz ); .fi .SH DESCRIPTION @@ -28,21 +28,7 @@ that is, .IR "strnlen(len, sz)" . .PP This function can be chained with calls to -.MR ustpcpy 3 . -.PP -An implementation of this function might be: -.PP -.in +4n -.EX -/* This code is in the public domain. */ - -char * -.IR zustr2ustp "(char *restrict dst, const char *restrict src, size_t sz)" -{ - return ustpcpy(dst, src, strnlen(src, sz)); -} -.EE -.in +.MR c_ustpcpy 3 . .SH RETURN VALUE This function returns .IR "dst + strnlen(src, sz)" ; @@ -59,7 +45,7 @@ lbx lb lb l l l. Interface Attribute Value T{ -.MR zustr2ustp 3 +.MR c_zustr2ustp 3 T} Thread safety MT-Safe .TE .hy @@ -76,7 +62,7 @@ in .MR feature_test_macros 7 . .SH EXAMPLES .nf -.RB "$ " "cc ./zustr2ustp.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libstp)" +.RB "$ " "cc ./zustr2ustp.c $(pkgconf \-\-cflags \-\-libs libbsd\-overlay libc\-stp)" .RB "$ " "./a.out" [len = 12]: pre.some_long_body.foo.bar $ @@ -89,7 +75,7 @@ $ #include <stdio.h> #include <stdlib.h> -#include <stp/ustp/zustr2ustp.h> +#include <c/stp/ustp/zustr2ustp.h> int main(void) @@ -112,9 +98,9 @@ main(void) err(EXIT_FAILURE, "malloc()"); p = buf; - p = zustr2ustp(p, pre, nitems(pre)); - p = ustpcpy(p, src, strlen(src) \- strlen(post)); - p = zustr2ustp(p, new_post, nitems(new_post)); + p = c_zustr2ustp(p, pre, nitems(pre)); + p = c_ustpcpy(p, src, strlen(src) \- strlen(post)); + p = c_zustr2ustp(p, new_post, nitems(new_post)); len = p \- buf; printf("[len = %zu]: %.*s\en", len, (int) len, buf); @@ -124,5 +110,5 @@ main(void) .EE .\" SRC END .SH SEE ALSO -.MR ustpcpy 3 , +.MR c_ustpcpy 3 , .MR string_copying 7 diff --git a/share/man/man3/vstpeprintf.3 b/share/man/man3/vstpeprintf.3 deleted file mode 100644 index 123004b..0000000 --- a/share/man/man3/vstpeprintf.3 +++ /dev/null @@ -1 +0,0 @@ -.so man3/stpeprintf.3 diff --git a/share/pkgconfig/libstp-uninstalled.pc b/share/pkgconfig/libc-stp-uninstalled.pc index d865b81..c5dbd80 100644 --- a/share/pkgconfig/libstp-uninstalled.pc +++ b/share/pkgconfig/libc-stp-uninstalled.pc @@ -1,6 +1,6 @@ -Name: libstp +Name: libc-stp Description: stp string library -URL: http://www.alejandro-colomar.es/src/alx/alx/libstp.git +URL: http://www.alejandro-colomar.es/src/alx/alx/libc-stp.git Version: <version> Requires: Requires.private: @@ -11,5 +11,5 @@ exec_prefix=${prefix} libdir=${exec_prefix}/lib Cflags: -isystem${includedir} -Libs: -L${libdir} -lstp -lc +Libs: -L${libdir} -lc-stp -lc Libs.private: diff --git a/share/tests/libstp/Makefile b/share/tests/libc-stp/Makefile index 6dda814..00d7e53 100755 --- a/share/tests/libstp/Makefile +++ b/share/tests/libc-stp/Makefile @@ -18,21 +18,25 @@ PKGCONF := pkgconf SORT := sort +libname := libc-stp + + PKGCONFFLAGS := CPPFLAGS := CFLAGS := -Wall -Wextra -Werror -CFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --cflags libstp) +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 libstp) -LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-other libstp) +LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-L $(libname)) +LDFLAGS += $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-other $(libname)) -LDLIBS := $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-l libstp) +LDLIBS := $(shell $(PKGCONF) $(PKGCONFFLAGS) --libs-only-l $(libname)) TESTDIR := . diff --git a/share/tests/libstp/stpe/001/test.c b/share/tests/libc-stp/stpe/001/test.c index d7c8e51..f040c32 100644 --- a/share/tests/libstp/stpe/001/test.c +++ b/share/tests/libc-stp/stpe/001/test.c @@ -1,4 +1,4 @@ -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> #include <stddef.h> #include <stdio.h> @@ -12,9 +12,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello "); - p = stpecpy(p, end, "world"); - p = stpecpy(p, end, "!"); + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); if (p == end) { p--; puts("Truncated:"); diff --git a/share/tests/libstp/stpe/001/test.sh b/share/tests/libc-stp/stpe/001/test.sh index 8f0870d..8f0870d 100755 --- a/share/tests/libstp/stpe/001/test.sh +++ b/share/tests/libc-stp/stpe/001/test.sh diff --git a/share/tests/libstp/stpe/002/test.c b/share/tests/libc-stp/stpe/002/test.c index e584c6c..d9d7a3d 100644 --- a/share/tests/libstp/stpe/002/test.c +++ b/share/tests/libc-stp/stpe/002/test.c @@ -1,4 +1,4 @@ -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> #include <stddef.h> #include <stdio.h> @@ -12,9 +12,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello "); - p = stpecpy(p, end, "world"); - p = stpecpy(p, end, "!"); + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); if (p == end) { p--; puts("Truncated:"); diff --git a/share/tests/libstp/stpe/002/test.sh b/share/tests/libc-stp/stpe/002/test.sh index e5eadd2..e5eadd2 100755 --- a/share/tests/libstp/stpe/002/test.sh +++ b/share/tests/libc-stp/stpe/002/test.sh diff --git a/share/tests/libstp/stpe/003/test.c b/share/tests/libc-stp/stpe/003/test.c index 3ce821e..9df9f7b 100644 --- a/share/tests/libstp/stpe/003/test.c +++ b/share/tests/libc-stp/stpe/003/test.c @@ -1,4 +1,4 @@ -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> #include <stddef.h> #include <stdio.h> @@ -12,9 +12,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello "); - p = stpecpy(p, end, "world"); - p = stpecpy(p, end, "!"); + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); if (p == end) { p--; puts("Truncated:"); diff --git a/share/tests/libstp/stpe/003/test.sh b/share/tests/libc-stp/stpe/003/test.sh index ee952ea..ee952ea 100755 --- a/share/tests/libstp/stpe/003/test.sh +++ b/share/tests/libc-stp/stpe/003/test.sh diff --git a/share/tests/libstp/stpe/004/test.c b/share/tests/libc-stp/stpe/004/test.c index 22e3677..48cbb53 100644 --- a/share/tests/libstp/stpe/004/test.c +++ b/share/tests/libc-stp/stpe/004/test.c @@ -1,4 +1,4 @@ -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> #include <stddef.h> #include <stdio.h> @@ -12,9 +12,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello "); - p = stpecpy(p, end, "world"); - p = stpecpy(p, end, "!"); + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); if (p == end) { p--; puts("Truncated:"); diff --git a/share/tests/libstp/stpe/004/test.sh b/share/tests/libc-stp/stpe/004/test.sh index 7eccc45..7eccc45 100755 --- a/share/tests/libstp/stpe/004/test.sh +++ b/share/tests/libc-stp/stpe/004/test.sh diff --git a/share/tests/libstp/stpe/005/test.c b/share/tests/libc-stp/stpe/005/test.c index 808d701..e1fa59b 100644 --- a/share/tests/libstp/stpe/005/test.c +++ b/share/tests/libc-stp/stpe/005/test.c @@ -1,4 +1,4 @@ -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> #include <stddef.h> #include <stdio.h> @@ -12,9 +12,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello "); - p = stpecpy(p, end, "world"); - p = stpecpy(p, end, "!"); + p = c_stpecpy(p, end, "Hello "); + p = c_stpecpy(p, end, "world"); + p = c_stpecpy(p, end, "!"); if (p == end) { p--; puts("Truncated:"); diff --git a/share/tests/libstp/stpe/005/test.sh b/share/tests/libc-stp/stpe/005/test.sh index 1cadf3a..1cadf3a 100755 --- a/share/tests/libstp/stpe/005/test.sh +++ b/share/tests/libc-stp/stpe/005/test.sh diff --git a/share/tests/libstp/stpe/006/test.c b/share/tests/libc-stp/stpe/006/test.c index a7f959f..875915c 100644 --- a/share/tests/libstp/stpe/006/test.c +++ b/share/tests/libc-stp/stpe/006/test.c @@ -1,4 +1,4 @@ -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> #include <stddef.h> #include <stdio.h> @@ -12,10 +12,10 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello "); - p = stpecpy(p, end, "world"); - p = stpecpy(p, end, "!"); - p = stpecpy(p, end, ""); + 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:"); diff --git a/share/tests/libstp/stpe/006/test.sh b/share/tests/libc-stp/stpe/006/test.sh index 7eccc45..7eccc45 100755 --- a/share/tests/libstp/stpe/006/test.sh +++ b/share/tests/libc-stp/stpe/006/test.sh diff --git a/share/tests/libstp/stpe/007/test.c b/share/tests/libc-stp/stpe/007/test.c index 856f523..c27d1a5 100644 --- a/share/tests/libstp/stpe/007/test.c +++ b/share/tests/libc-stp/stpe/007/test.c @@ -1,5 +1,5 @@ -#include <stp/stpe/stpecpy.h> -#include <stp/stpe/stpeprintf.h> +#include <c/stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpeprintf.h> #include <stddef.h> #include <stdio.h> @@ -13,9 +13,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello, "); - p = stpeprintf(p, end, "%d worlds", 22); - p = stpecpy(p, end, "!"); + 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:"); diff --git a/share/tests/libstp/stpe/007/test.sh b/share/tests/libc-stp/stpe/007/test.sh index e532969..e532969 100755 --- a/share/tests/libstp/stpe/007/test.sh +++ b/share/tests/libc-stp/stpe/007/test.sh diff --git a/share/tests/libstp/stpe/008/test.c b/share/tests/libc-stp/stpe/008/test.c index dc0c5aa..9ed7eff 100644 --- a/share/tests/libstp/stpe/008/test.c +++ b/share/tests/libc-stp/stpe/008/test.c @@ -1,5 +1,5 @@ -#include <stp/stpe/stpecpy.h> -#include <stp/stpe/stpeprintf.h> +#include <c/stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpeprintf.h> #include <stddef.h> #include <stdio.h> @@ -13,9 +13,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello, "); - p = stpeprintf(p, end, "%d worlds", 22); - p = stpecpy(p, end, "!"); + 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:"); diff --git a/share/tests/libstp/stpe/008/test.sh b/share/tests/libc-stp/stpe/008/test.sh index 52043f7..52043f7 100755 --- a/share/tests/libstp/stpe/008/test.sh +++ b/share/tests/libc-stp/stpe/008/test.sh diff --git a/share/tests/libstp/stpe/009/test.c b/share/tests/libc-stp/stpe/009/test.c index 53bb187..45b1ae3 100644 --- a/share/tests/libstp/stpe/009/test.c +++ b/share/tests/libc-stp/stpe/009/test.c @@ -1,5 +1,5 @@ -#include <stp/stpe/stpecpy.h> -#include <stp/stpe/stpeprintf.h> +#include <c/stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpeprintf.h> #include <stddef.h> #include <stdio.h> @@ -13,9 +13,9 @@ main(void) end = buf + sizeof(buf); p = buf; - p = stpecpy(p, end, "Hello, "); - p = stpeprintf(p, end, "%d worlds", 22); - p = stpecpy(p, end, "!"); + 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:"); diff --git a/share/tests/libstp/stpe/009/test.sh b/share/tests/libc-stp/stpe/009/test.sh index 555d657..555d657 100755 --- a/share/tests/libstp/stpe/009/test.sh +++ b/share/tests/libc-stp/stpe/009/test.sh diff --git a/src/stp/_compiler.c b/src/c/stp/_compiler.c index c7ce8d1..5798531 100644 --- a/src/stp/_compiler.c +++ b/src/c/stp/_compiler.c @@ -2,4 +2,4 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#include <stp/_compiler.h> +#include <c/stp/_compiler.h> diff --git a/src/stp/stp/ustr2stp.c b/src/c/stp/stp/ustr2stp.c index 00da1aa..695b401 100644 --- a/src/stp/stp/ustr2stp.c +++ b/src/c/stp/stp/ustr2stp.c @@ -2,12 +2,12 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#include <stp/stp/ustr2stp.h> +#include <c/stp/stp/ustr2stp.h> #include <stddef.h> #pragma clang assume_nonnull begin -extern inline char *ustr2stp(char *restrict dst, const char *restrict src, +extern inline char *c_ustr2stp(char *restrict dst, const char *restrict src, size_t len); #pragma clang assume_nonnull end diff --git a/src/stp/stp/zustr2stp.c b/src/c/stp/stp/zustr2stp.c index a838b62..bb804b0 100644 --- a/src/stp/stp/zustr2stp.c +++ b/src/c/stp/stp/zustr2stp.c @@ -2,12 +2,12 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#include <stp/stp/zustr2stp.h> +#include <c/stp/stp/zustr2stp.h> #include <stddef.h> #pragma clang assume_nonnull begin -extern inline char *zustr2stp(char *restrict dst, const char *restrict src, +extern inline char *c_zustr2stp(char *restrict dst, const char *restrict src, size_t sz); #pragma clang assume_nonnull end diff --git a/src/stp/stpe/stpecpy.c b/src/c/stp/stpe/stpecpy.c index 3c61da0..a0a21cd 100644 --- a/src/stp/stpe/stpecpy.c +++ b/src/c/stp/stpe/stpecpy.c @@ -2,12 +2,12 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#include <stp/stpe/stpecpy.h> +#include <c/stp/stpe/stpecpy.h> -#include <stp/_compiler.h> +#include <c/stp/_compiler.h> #pragma clang assume_nonnull begin -extern inline char *stp_nullable stpecpy(char *stp_nullable dst, char end[0], +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 new file mode 100644 index 0000000..bf7ad39 --- /dev/null +++ b/src/c/stp/stpe/stpeprintf.c @@ -0,0 +1,17 @@ +// Copyright 2022 Alejandro Colomar <alx@kernel.org> +// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception + + +#include <c/stp/stpe/stpeprintf.h> + +#include <stdarg.h> + +#include <c/stp/_compiler.h> + + +#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/stp/ustp/ustpcpy.c b/src/c/stp/ustp/ustpcpy.c index 7aa1108..22e8768 100644 --- a/src/stp/ustp/ustpcpy.c +++ b/src/c/stp/ustp/ustpcpy.c @@ -2,12 +2,12 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#include <stp/ustp/ustpcpy.h> +#include <c/stp/ustp/ustpcpy.h> #include <stddef.h> #pragma clang assume_nonnull begin -extern inline char *ustpcpy(char *restrict dst, const char *restrict src, +extern inline char *c_ustpcpy(char *restrict dst, const char *restrict src, size_t len); #pragma clang assume_nonnull end diff --git a/src/stp/ustp/zustr2ustp.c b/src/c/stp/ustp/zustr2ustp.c index d4ab033..4ba3b57 100644 --- a/src/stp/ustp/zustr2ustp.c +++ b/src/c/stp/ustp/zustr2ustp.c @@ -2,12 +2,12 @@ // SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception -#include <stp/ustp/zustr2ustp.h> +#include <c/stp/ustp/zustr2ustp.h> #include <stddef.h> #pragma clang assume_nonnull begin -extern inline char *zustr2ustp(char *restrict dst, const char *restrict src, +extern inline char *c_zustr2ustp(char *restrict dst, const char *restrict src, size_t sz); #pragma clang assume_nonnull end diff --git a/src/stp/stpe/stpeprintf.c b/src/stp/stpe/stpeprintf.c deleted file mode 100644 index adbd8d2..0000000 --- a/src/stp/stpe/stpeprintf.c +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022 Alejandro Colomar <alx@kernel.org> -// SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception - - -#include <stp/stpe/stpeprintf.h> - -#include <stdarg.h> - -#include <stp/_compiler.h> - - -#pragma clang assume_nonnull begin -extern inline char *stp_nullable stpeprintf(char *stp_nullable dst, - char end[0], const char *restrict fmt, ...); -extern inline char *stp_nullable vstpeprintf(char *stp_nullable dst, - char end[0], const char *restrict fmt, va_list ap); -#pragma clang assume_nonnull end |