git: e0d4f419ac41 - main - lib/libc/string: document restrict qualification of memccpy() arguments
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 25 Dec 2023 14:26:04 UTC
The branch main has been updated by fuz:
URL: https://cgit.FreeBSD.org/src/commit/?id=e0d4f419ac41aa91b862f3ceadc32a86abf08572
commit e0d4f419ac41aa91b862f3ceadc32a86abf08572
Author: Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-12-05 14:03:28 +0000
Commit: Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-12-25 13:59:50 +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
---
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 fd976c7676b7..91603fe6dbac 100644
--- a/lib/libc/string/bstring.3
+++ b/lib/libc/string/bstring.3
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 4, 1993
+.Dd December 5, 2023
.Dt BSTRING 3
.Os
.Sh NAME
@@ -56,7 +56,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 *
@@ -78,6 +83,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 ce8d5f65ac93..3bdae24354c1 100644
--- a/lib/libc/string/memccpy.3
+++ b/lib/libc/string/memccpy.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 9, 1993
+.Dd December 5, 2023
.Dt MEMCCPY 3
.Os
.Sh NAME
@@ -36,7 +36,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
@@ -59,13 +64,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 174824ba2393..d6a446503eb6 100644
--- a/lib/libc/string/memccpy.c
+++ b/lib/libc/string/memccpy.c
@@ -32,7 +32,7 @@
#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) {