Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jan 2024 19:44:57 GMT
From:      Robert Clausecker <fuz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 667fa9c40483 - stable/14 - lib/libc/string: document restrict qualification of memccpy() arguments
Message-ID:  <202401241944.40OJivu6006022@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by fuz:

URL: https://cgit.FreeBSD.org/src/commit/?id=667fa9c40483f2c844a7960780e9567be4e581d5

commit 667fa9c40483f2c844a7960780e9567be4e581d5
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-12-05 14:03:28 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2024-01-24 19:39:30 +0000

    lib/libc/string: document restrict qualification of memccpy() arguments
    
    POSIX.1-2004 and the upcoming C23 agree that memccpy()'s arguments
    are restrict qualified and must not overlap.  In 2002, restrict
    qualifiers were added to <string.h>'s declaration of the function.
    Make things official and document that the arguments must not
    overlap.
    
    See also:       61b60edfd3fff20f884419f8097870c7045315c9
    Approved by:    kib
    MFC after:      1 month
    MFC to:         stable/14
    
    (cherry picked from commit e0d4f419ac41aa91b862f3ceadc32a86abf08572)
---
 lib/libc/string/bstring.3 | 10 ++++++++--
 lib/libc/string/memccpy.3 | 33 ++++++++++++++++++++++++++++++---
 lib/libc/string/memccpy.c |  2 +-
 3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/lib/libc/string/bstring.3 b/lib/libc/string/bstring.3
index cb29a6db6b14..bb1a0505fafd 100644
--- a/lib/libc/string/bstring.3
+++ b/lib/libc/string/bstring.3
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)bstring.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd June 4, 1993
+.Dd December 5, 2023
 .Dt BSTRING 3
 .Os
 .Sh NAME
@@ -58,7 +58,12 @@
 .Ft int
 .Fn memcmp "const void *b1" "const void *b2" "size_t len"
 .Ft void *
-.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
+.Fo memccpy
+.Fa "void * restrict dst"
+.Fa "const void * restrict src"
+.Fa "int c"
+.Fa "size_t len"
+.Fc
 .Ft void *
 .Fn memcpy "void *dst" "const void *src" "size_t len"
 .Ft void *
@@ -80,6 +85,7 @@ See the specific manual pages for more information.
 .Xr memccpy 3 ,
 .Xr memchr 3 ,
 .Xr memcmp 3 ,
+.Xr memccpy 3 ,
 .Xr memcpy 3 ,
 .Xr memmove 3 ,
 .Xr memset 3
diff --git a/lib/libc/string/memccpy.3 b/lib/libc/string/memccpy.3
index fb2409ada846..fe543d9172d3 100644
--- a/lib/libc/string/memccpy.3
+++ b/lib/libc/string/memccpy.3
@@ -27,7 +27,7 @@
 .\"
 .\"     @(#)memccpy.3	8.1 (Berkeley) 6/9/93
 .\"
-.Dd June 9, 1993
+.Dd December 5, 2023
 .Dt MEMCCPY 3
 .Os
 .Sh NAME
@@ -38,7 +38,12 @@
 .Sh SYNOPSIS
 .In string.h
 .Ft void *
-.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
+.Fo memccpy
+.Fa "void * restrict dst"
+.Fa "const void * restrict src"
+.Fa "int c"
+.Fa "size_t len"
+.Fc
 .Sh DESCRIPTION
 The
 .Fn memccpy
@@ -61,13 +66,35 @@ is returned.
 Otherwise,
 .Fa len
 bytes are copied, and a NULL pointer is returned.
+If
+.Fa src
+and
+.Fa dst
+overlap, behavior is undefined.
 .Sh SEE ALSO
 .Xr bcopy 3 ,
 .Xr memcpy 3 ,
 .Xr memmove 3 ,
 .Xr strcpy 3
+.Sh STANDARDS
+The
+.Fn memccpy
+function conforms to
+.St -p1003.1-2004
+and
+.\" St -isoC-2024 .
+ISO/IEC 9899:2024 (\(lqISO\~C23\(rq).
 .Sh HISTORY
 The
 .Fn memccpy
 function first appeared in
-.Bx 4.4 .
+.Bx 4.4
+and was first specified in the
+.\" St -svid1 .
+System\~V Interface Definition, First Edition (\(lqSVID1\(rq).
+The
+.Ft restrict
+keyword was added to the prototype in
+.Fx 5.0.0
+in accordance with the updated specification of
+.St -p1003.1-2004 .
diff --git a/lib/libc/string/memccpy.c b/lib/libc/string/memccpy.c
index fd080d4293f4..5ef2dd6567ca 100644
--- a/lib/libc/string/memccpy.c
+++ b/lib/libc/string/memccpy.c
@@ -35,7 +35,7 @@ static char sccsid[] = "@(#)memccpy.c	8.1 (Berkeley) 6/4/93";
 #include <string.h>
 
 void *
-memccpy(void *t, const void *f, int c, size_t n)
+memccpy(void * restrict t, const void * restrict f, int c, size_t n)
 {
 
 	if (n) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401241944.40OJivu6006022>