From e0e9e57a72e9f1bf2acb3156cc982d59b9ee4248 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 10 Feb 2023 22:16:21 +0100 Subject: [PATCH] Add mempcpy(3) We'll use it for implementing stpecpy(), and may be interesting to have it around. Signed-off-by: Alejandro Colomar --- configure.ac | 2 +- lib/mempcpy.h | 31 +++++++++++++++++++++++++++++++ libmisc/Makefile.am | 1 + libmisc/mempcpy.c | 23 +++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 lib/mempcpy.h create mode 100644 libmisc/mempcpy.c diff --git a/configure.ac b/configure.ac index 89fc1b26..ecf9fb27 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 00000000..528b976a --- /dev/null +++ b/lib/mempcpy.h @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2023, Alejandro Colomar + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +#ifndef SHADOW_INCLUDE_LIB_MEMPCPY_H_ +#define SHADOW_INCLUDE_LIB_MEMPCPY_H_ + + +#include + +#if !defined(HAVE_MEMPCPY) + +#include +#include + + +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 diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am index a74de975..870da0b8 100644 --- a/libmisc/Makefile.am +++ b/libmisc/Makefile.am @@ -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 index 00000000..14a09613 --- /dev/null +++ b/libmisc/mempcpy.c @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2023, Alejandro Colomar + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +#include + +#if !defined(HAVE_MEMPCPY) + +#ident "$Id$" + +#include "mempcpy.h" + +#include + + +extern inline void *mempcpy(void *restrict dst, const void *restrict src, + size_t n); + + +#endif