]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strcpy/zustr2stp.[ch], tests/: Remove ZUSTR2STP()
authorAlejandro Colomar <alx@kernel.org>
Tue, 14 May 2024 16:41:21 +0000 (18:41 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 2 Jul 2024 02:40:11 +0000 (21:40 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/strcpy/zustr2stp.c [deleted file]
lib/string/strcpy/zustr2stp.h [deleted file]
tests/unit/Makefile.am
tests/unit/test_zustr2stp.c [deleted file]

index 42ff20413d4bc0c80452e9a219e39f43dba47d80..a713f98cb5df2b72eceb7e26d4aec67c56c14c44 100644 (file)
@@ -158,8 +158,6 @@ libshadow_la_SOURCES = \
        string/strcpy/strncpy.h \
        string/strcpy/strtcpy.c \
        string/strcpy/strtcpy.h \
-       string/strcpy/zustr2stp.c \
-       string/strcpy/zustr2stp.h \
        string/strdup/strndupa.c \
        string/strdup/strndupa.h \
        string/strdup/xstrndup.c \
diff --git a/lib/string/strcpy/zustr2stp.c b/lib/string/strcpy/zustr2stp.c
deleted file mode 100644 (file)
index 9f4c789..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
-// SPDX-License-Identifier: BSD-3-Clause
-
-
-#include <config.h>
-
-#include "string/strcpy/zustr2stp.h"
diff --git a/lib/string/strcpy/zustr2stp.h b/lib/string/strcpy/zustr2stp.h
deleted file mode 100644 (file)
index 3064ce9..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
-// SPDX-License-Identifier: BSD-3-Clause
-
-
-#ifndef SHADOW_INCLUDE_LIB_STRING_STRCPY_ZUSTR2STP_H_
-#define SHADOW_INCLUDE_LIB_STRING_STRCPY_ZUSTR2STP_H_
-
-
-#include <config.h>
-
-#include <assert.h>
-#include <string.h>
-
-#include "must_be.h"
-#include "sizeof.h"
-
-
-/*
- * SYNOPSIS
- *     char *ZUSTR2STP(char *restrict dst, const char src[restrict]);
- *
- * ARGUMENTS
- *     dst     Destination buffer.
- *     src     Source null-padded character sequence.
- *
- * DESCRIPTION
- *     This macro copies at most NITEMS(src) non-null bytes from the
- *     array pointed to by src, followed by a null character, to the
- *     buffer pointed to by dst.
- *
- * RETURN VALUE
- *     dst + strlen(dst)
- *             This function returns a pointer to the terminating NUL
- *             byte.
- *
- * CAVEATS
- *     This function doesn't know the size of the destination buffer.
- *     It assumes it will always be large enough.  Since the size of
- *     the source buffer is known to the caller, it should make sure to
- *     allocate a destination buffer of at least `NITEMS(src) + 1`.
- *
- * EXAMPLES
- *     char  hostname[NITEMS(utmp->ut_host) + 1];
- *
- *     len = ZUSTR2STP(hostname, utmp->ut_host) - hostname;
- *     puts(hostname);
- */
-
-
-#define ZUSTR2STP(dst, src)                                                   \
-({                                                                            \
-       static_assert(!is_array(dst) || sizeof(dst) > SIZEOF_ARRAY(src), ""); \
-                                                                              \
-       stpcpy(mempcpy(dst, src, strnlen(src, NITEMS(src))), "");             \
-})
-
-
-#endif  // include guard
index b73d70368878d16e14d0e674653791001beb1c65..c854a15d076fb0e83b21ff19b3e06287d3ed5841 100644 (file)
@@ -11,8 +11,7 @@ check_PROGRAMS = \
     test_strncpy \
     test_strtcpy \
     test_typetraits \
-    test_xasprintf \
-    test_zustr2stp
+    test_xasprintf
 
 if ENABLE_LOGIND
 check_PROGRAMS += \
@@ -143,16 +142,4 @@ test_xasprintf_LDADD = \
     $(CMOCKA_LIBS) \
     $(NULL)
 
-test_zustr2stp_SOURCES = \
-    test_zustr2stp.c \
-    $(NULL)
-test_zustr2stp_CFLAGS = \
-    $(AM_CFLAGS) \
-    $(NULL)
-test_zustr2stp_LDFLAGS = \
-    $(NULL)
-test_zustr2stp_LDADD = \
-    $(CMOCKA_LIBS) \
-    $(NULL)
-
 endif # HAVE_CMOCKA
diff --git a/tests/unit/test_zustr2stp.c b/tests/unit/test_zustr2stp.c
deleted file mode 100644 (file)
index 3072ce4..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
-// SPDX-License-Identifier: BSD-3-Clause
-
-
-#include <config.h>
-
-#include <stddef.h>
-#include <string.h>
-
-#include <stdarg.h>  // Required by <cmocka.h>
-#include <stddef.h>  // Required by <cmocka.h>
-#include <setjmp.h>  // Required by <cmocka.h>
-#include <stdint.h>  // Required by <cmocka.h>
-#include <cmocka.h>
-
-#include "string/strcpy/zustr2stp.h"
-
-
-static void test_ZUSTR2STP(void **state);
-
-
-int
-main(void)
-{
-    const struct CMUnitTest  tests[] = {
-        cmocka_unit_test(test_ZUSTR2STP),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
-
-static void
-test_ZUSTR2STP(void **state)
-{
-       char  src[3] = {'1', '2', '3'};
-       char  dst[4];
-
-       assert_true(ZUSTR2STP(&dst, src) == dst + strlen("123"));
-       assert_true(strcmp("123", dst) == 0);
-
-       src[2] = '\0';
-       assert_true(ZUSTR2STP(&dst, src) == dst + strlen("12"));
-       assert_true(strcmp("12", dst) == 0);
-
-       src[1] = '\0';
-       assert_true(ZUSTR2STP(&dst, src) == dst + strlen("1"));
-       assert_true(strcmp("1", dst) == 0);
-
-       src[0] = '\0';
-       assert_true(ZUSTR2STP(&dst, src) == dst + strlen(""));
-       assert_true(strcmp("", dst) == 0);
-}