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:	61b60edfd3
Approved by:	kib
MFC after:	1 month
MFC to:		stable/14
This commit is contained in:
Robert Clausecker 2023-12-05 09:03:28 -05:00
parent ea7b13771c
commit e0d4f419ac
3 changed files with 39 additions and 6 deletions

View File

@ -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

View File

@ -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 .

View File

@ -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) {