From owner-dev-commits-src-branches@freebsd.org Thu Jul 22 10:33:27 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EC216657B5D; Thu, 22 Jul 2021 10:33:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GVph74Jj6z3pT9; Thu, 22 Jul 2021 10:33:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7701C10453; Thu, 22 Jul 2021 10:33:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16MAXRmm055714; Thu, 22 Jul 2021 10:33:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16MAXRbD055713; Thu, 22 Jul 2021 10:33:27 GMT (envelope-from git) Date: Thu, 22 Jul 2021 10:33:27 GMT Message-Id: <202107221033.16MAXRbD055713@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: dba677d13b26 - stable/13 - libc: add mempcpy(3) and wmempcpy(3) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: dba677d13b26ad5422133b2ab76486b74d63ade4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2021 10:33:28 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=dba677d13b26ad5422133b2ab76486b74d63ade4 commit dba677d13b26ad5422133b2ab76486b74d63ade4 Author: Konstantin Belousov AuthorDate: 2021-07-14 15:41:36 +0000 Commit: Konstantin Belousov CommitDate: 2021-07-22 10:33:10 +0000 libc: add mempcpy(3) and wmempcpy(3) (cherry picked from commit ee37f64cf875255338f917a9da76c643cf59786c) --- include/string.h | 3 +++ include/wchar.h | 3 +++ lib/libc/string/Makefile.inc | 6 ++++-- lib/libc/string/Symbol.map | 5 +++++ lib/libc/string/memcpy.3 | 19 +++++++++++++++---- lib/libc/string/mempcpy.c | 41 +++++++++++++++++++++++++++++++++++++++++ lib/libc/string/wmemchr.3 | 10 +++++++--- lib/libc/string/wmempcpy.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 9 deletions(-) diff --git a/include/string.h b/include/string.h index 774cf5fe9756..afa90c3f2536 100644 --- a/include/string.h +++ b/include/string.h @@ -66,6 +66,9 @@ void *memcpy(void * __restrict, const void * __restrict, size_t); void *memmem(const void *, size_t, const void *, size_t) __pure; #endif void *memmove(void *, const void *, size_t); +#if __BSD_VISIBLE +void *mempcpy(void * __restrict, const void * __restrict, size_t); +#endif void *memset(void *, int, size_t); #if __POSIX_VISIBLE >= 200809 char *stpcpy(char * __restrict, const char * __restrict); diff --git a/include/wchar.h b/include/wchar.h index 1c9d232d47e3..78f2f010048f 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -172,6 +172,9 @@ wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) __pure; int wmemcmp(const wchar_t *, const wchar_t *, size_t) __pure; wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); +#if __BSD_VISIBLE +wchar_t *wmempcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); +#endif wchar_t *wmemset(wchar_t *, wchar_t, size_t); int wprintf(const wchar_t * __restrict, ...); int wscanf(const wchar_t * __restrict, ...); diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 6e6a3f42f723..6945155812af 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -10,7 +10,7 @@ CFLAGS+= -I${LIBC_SRCTOP}/locale MISRCS+=bcmp.c bcopy.c bzero.c explicit_bzero.c \ ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \ memccpy.c memchr.c memrchr.c memcmp.c \ - memcpy.c memmem.c memmove.c memset.c memset_s.c \ + memcpy.c memmem.c memmove.c mempcpy.c memset.c memset_s.c \ stpcpy.c stpncpy.c strcasecmp.c \ strcat.c strcasestr.c strchr.c strchrnul.c strcmp.c strcoll.c strcpy.c\ strcspn.c strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c \ @@ -25,7 +25,7 @@ MISRCS+=bcmp.c bcopy.c bzero.c explicit_bzero.c \ wcsncpy.c wcsnlen.c wcspbrk.c \ wcsrchr.c wcsspn.c wcsstr.c wcstok.c wcswidth.c wcsxfrm.c wmemchr.c \ wmemcmp.c \ - wmemcpy.c wmemmove.c wmemset.c + wmemcpy.c wmemmove.c wmempcpy.c wmemset.c SYM_MAPS+= ${LIBC_SRCTOP}/string/Symbol.map @@ -50,6 +50,7 @@ MLINKS+=ffs.3 ffsl.3 \ ffs.3 flsll.3 MLINKS+=index.3 rindex.3 MLINKS+=memchr.3 memrchr.3 +MLINKS+=memcpy.3 mempcpy.3 MLINKS+=memset.3 memset_s.3 MLINKS+=strcasecmp.3 strncasecmp.3 \ strcasecmp.3 strcasecmp_l.3 \ @@ -101,4 +102,5 @@ MLINKS+=wmemchr.3 wcpcpy.3 \ wmemchr.3 wmemcmp.3 \ wmemchr.3 wmemcpy.3 \ wmemchr.3 wmemmove.3 \ + wmemchr.3 wmempcpy.3 \ wmemchr.3 wmemset.3 diff --git a/lib/libc/string/Symbol.map b/lib/libc/string/Symbol.map index 450b745c7e0a..ec45d7fd7ddb 100644 --- a/lib/libc/string/Symbol.map +++ b/lib/libc/string/Symbol.map @@ -114,6 +114,11 @@ FBSD_1.6 { strerror_l; }; +FBSD_1.7 { + mempcpy; + wmempcpy; +}; + FBSDprivate_1.0 { __strtok_r; }; diff --git a/lib/libc/string/memcpy.3 b/lib/libc/string/memcpy.3 index febc0fa34dd9..c65e4145264a 100644 --- a/lib/libc/string/memcpy.3 +++ b/lib/libc/string/memcpy.3 @@ -32,7 +32,7 @@ .\" @(#)memcpy.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd July 14, 2021 .Dt MEMCPY 3 .Os .Sh NAME @@ -44,11 +44,15 @@ .In string.h .Ft void * .Fn memcpy "void *dst" "const void *src" "size_t len" +.Ft void * +.Fn mempcpy "void *dst" "const void *src" "size_t len" .Sh DESCRIPTION The .Fn memcpy -function -copies +and +.Fn mempcpy +functions +copy .Fa len bytes from string .Fa src @@ -65,12 +69,17 @@ The function returns the original value of .Fa dst . +.Pp +The +.Fn mempcpy +function returns a pointer to the byte after the last written byte. .Sh SEE ALSO .Xr bcopy 3 , .Xr memccpy 3 , .Xr memmove 3 , .Xr strcpy 3 , .Xr wmemcpy 3 +.Xr wmempcpy 3 .Sh STANDARDS The .Fn memcpy @@ -80,7 +89,9 @@ conforms to .Sh BUGS In this implementation .Fn memcpy -is implemented using +and +.Fn mempcpy +are implemented using .Xr bcopy 3 , and therefore the strings may overlap. On other systems, copying overlapping strings may produce surprises. diff --git a/lib/libc/string/mempcpy.c b/lib/libc/string/mempcpy.c new file mode 100644 index 000000000000..12c0d791e9d3 --- /dev/null +++ b/lib/libc/string/mempcpy.c @@ -0,0 +1,41 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +void * +mempcpy(void *__restrict dst, const void *__restrict src, size_t len) +{ + return ((char *)memcpy(dst, src, len) + len); +} diff --git a/lib/libc/string/wmemchr.3 b/lib/libc/string/wmemchr.3 index 37ba05031ca9..8a926eef456a 100644 --- a/lib/libc/string/wmemchr.3 +++ b/lib/libc/string/wmemchr.3 @@ -35,7 +35,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 4, 2009 +.Dd July 14, 2021 .Dt WMEMCHR 3 .Os .Sh NAME @@ -43,6 +43,7 @@ .Nm wmemcmp , .Nm wmemcpy , .Nm wmemmove , +.Nm wmempcpy , .Nm wmemset , .Nm wcpcpy , .Nm wcpncpy , @@ -79,6 +80,8 @@ .Ft wchar_t * .Fn wmemmove "wchar_t *s1" "const wchar_t *s2" "size_t n" .Ft wchar_t * +.Fn wmempcpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" +.Ft wchar_t * .Fn wmemset "wchar_t *s" "wchar_t c" "size_t n" .Ft wchar_t * .Fn wcpcpy "wchar_t *s1" "wchar_t *s2" @@ -168,7 +171,8 @@ and which conform to .St -p1003.1-2008 ; and -.Fn wcslcat -and +.Fn wcslcat , .Fn wcslcpy , +and +.Fn wmempcpy , which are extensions. diff --git a/lib/libc/string/wmempcpy.c b/lib/libc/string/wmempcpy.c new file mode 100644 index 000000000000..208d62a26849 --- /dev/null +++ b/lib/libc/string/wmempcpy.c @@ -0,0 +1,42 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +wchar_t * +wmempcpy(wchar_t *__restrict dst, const wchar_t *__restrict src, size_t len) +{ + return (wmemcpy(dst, src, len) + len); +}