View Issue Details

IDProjectCategoryView StatusLast Update
00020171003.1(2024)/Issue8System Interfacespublic2026-12-02 15:30
Reporterromanzilka Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status NewResolutionOpen 
NameRoman Žilka
Organization
User Reference
Sectionstring.h
Page Number0
Line Number0
Interp Status
Final Accepted Text
Summary0002017: string.h: Add mempcpy(), analog of stpncpy()
DescriptionI propose adding the function mempcpy() into string.h, as known from the GNU C Library. See:
https://man7.org/linux/man-pages/man3/mempcpy.3.html

It will complement well the recently added stpcpy() and stpncpy() (or, rather, the other way around).

Desired Action doesn't include the obligatory function prototype in the section on string.h.
Desired ActionNAME
mempcpy — copy bytes in memory, returning a pointer just behind target area

SYNOPSIS
[CX]
#include <string.h>

void *mempcpy(void *restrict s1, const void *restrict s2, size_t n);
[/CX]

DESCRIPTION
The mempcpy() function shall copy n bytes from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined. The function shall behave as if the copying were performed by memcpy().

The mempcpy() function shall not change the setting of errno on valid input.

RETURN VALUE
The mempcpy() function shall return a pointer one past the last element of the array (unsigned char *)s1 of size n, i.e., (unsigned char *)s1 + n. No return value is reserved to indicate an error.

ERRORS
No errors are defined.
TagsNo tags attached.

Activities

alx

2026-12-02 11:03

reporter   bugnote:0007575

+1 to standardizing mempcpy(3).

I would simplify the RETURN VALUE wording:

> RETURN VALUE
> The mempcpy() function shall return a pointer one past the last element of the array (unsigned char *)s1 of size n, i.e., (unsigned char *)s1 + n. No return value is reserved to indicate an error.

diff:
 The mempcpy() function shall return
 a pointer one past the last
-element of the array (unsigned char *)s1 of size n,
+copied byte
 i.e., (unsigned char *)s1 + n.
 No return value is reserved to indicate an error.
it shall return &s1[n].

alx

2026-12-02 11:04

reporter   bugnote:0007576

Oops, the last line of my previous comment was a copy-paste error. The diff should have been:

diff:
 The mempcpy() function shall return
 a pointer one past the last
-element of the array (unsigned char *)s1 of size n,
+copied byte
 i.e., (unsigned char *)s1 + n.
 No return value is reserved to indicate an error.

hvd

2026-12-02 11:21

reporter   bugnote:0007577

Both the originally proposed wording and the simplified proposed wording are problematic if n is zero: the return value should be s1, and (unsigned char *)s1 + n captures that, but there is no such thing as an array of size 0, no last element of any array, and no last copied byte.

alx

2026-12-02 11:30

reporter   bugnote:0007578

Hmmmm, indeed. Perhaps:

diff:
 The mempcpy() function shall return
 a pointer one past the last
-element of the array (unsigned char *)s1 of size n,
+copied byte
+or s1 if no bytes were copied,
 i.e., (unsigned char *)s1 + n.
 No return value is reserved to indicate an error.

romanzilka

2026-12-02 15:13

reporter   bugnote:0007580

alx> The last copied byte is in s2 (that's the byte that the machine copied = made a copy of).
hvd> Good point.

Ok, how about we emphasize the purpose of the function?
"The mempcpy() function shall return (unsigned char *)s1 + n, or the address at which writing needs to continue in order to create at address s1 the concatenation of the data mempcpy() has placed at s1 and the continuation. No return value is reserved to indicate an error."

alx

2026-12-02 15:30

reporter   bugnote:0007581

> "The mempcpy() function shall return (unsigned char *)s1 + n, or the address at which writing needs to continue in order to create at address s1 the concatenation of the data mempcpy() has placed at s1 and the continuation. No return value is reserved to indicate an error."

That feels way too verbose.

> The last copied byte is in s2 (that's the byte that the machine copied = made a copy of).

Yeah, that's a bit ambiguous. Perhaps we can say 'byte written'.

diff:
 The mempcpy() function shall return
 a pointer one past the last
-element of the array (unsigned char *)s1 of size n,
+byte written
+or s1 if no bytes were written,
 i.e., (unsigned char *)s1 + n.
 No return value is reserved to indicate an error.

Issue History

Date Modified Username Field Change
2026-12-02 00:36 romanzilka New Issue
2026-12-02 11:03 alx Note Added: 0007575
2026-12-02 11:04 alx Note Added: 0007576
2026-12-02 11:21 hvd Note Added: 0007577
2026-12-02 11:30 alx Note Added: 0007578
2026-12-02 15:13 romanzilka Note Added: 0007580
2026-12-02 15:30 alx Note Added: 0007581