]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Add mempcpy(3)
authorAlejandro Colomar <alx@kernel.org>
Fri, 10 Feb 2023 21:16:21 +0000 (22:16 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Thu, 16 Feb 2023 10:29:33 +0000 (11:29 +0100)
We'll use it for implementing stpecpy(), and may be interesting to have
it around.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
configure.ac
lib/mempcpy.h [new file with mode: 0644]
libmisc/Makefile.am
libmisc/mempcpy.c [new file with mode: 0644]

index 89fc1b26746de887c96e67b53aacc28518f75163..ecf9fb27941ada0a09f6dacda84002814099116f 100644 (file)
@@ -47,7 +47,7 @@ AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])
 
 AC_CHECK_FUNCS(arc4random_buf futimes \
        getentropy getrandom getspnam getusershell \
-       initgroups lckpwdf lutimes \
+       initgroups lckpwdf lutimes mempcpy \
        setgroups updwtmp updwtmpx innetgr \
        getspnam_r \
        memset_explicit explicit_bzero stpeprintf)
diff --git a/lib/mempcpy.h b/lib/mempcpy.h
new file mode 100644 (file)
index 0000000..528b976
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SPDX-FileCopyrightText:  2023, Alejandro Colomar <alx@kernel.org>
+ *
+ * SPDX-License-Identifier:  BSD-3-Clause
+ */
+
+
+#ifndef SHADOW_INCLUDE_LIB_MEMPCPY_H_
+#define SHADOW_INCLUDE_LIB_MEMPCPY_H_
+
+
+#include <config.h>
+
+#if !defined(HAVE_MEMPCPY)
+
+#include <stddef.h>
+#include <string.h>
+
+
+inline void *mempcpy(void *restrict dst, const void *restrict src, size_t n);
+
+
+inline void *
+mempcpy(void *restrict dst, const void *restrict src, size_t n)
+{
+       return memcpy(dst, src, n) + n;
+}
+
+
+#endif  // !HAVE_MEMPCPY
+#endif  // include guard
index a74de9755b6f4ccd8ee4140ae65f751fd140d777..870da0b8d2af210fa0166904859eafd79801f533 100644 (file)
@@ -44,6 +44,7 @@ libmisc_la_SOURCES = \
        list.c log.c \
        loginprompt.c \
        mail.c \
+       mempcpy.c \
        motd.c \
        myname.c \
        obscure.c \
diff --git a/libmisc/mempcpy.c b/libmisc/mempcpy.c
new file mode 100644 (file)
index 0000000..14a0961
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SPDX-FileCopyrightText:  2023, Alejandro Colomar <alx@kernel.org>
+ *
+ * SPDX-License-Identifier:  BSD-3-Clause
+ */
+
+
+#include <config.h>
+
+#if !defined(HAVE_MEMPCPY)
+
+#ident "$Id$"
+
+#include "mempcpy.h"
+
+#include <stddef.h>
+
+
+extern inline void *mempcpy(void *restrict dst, const void *restrict src,
+    size_t n);
+
+
+#endif