View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002017 | 1003.1(2024)/Issue8 | System Interfaces | public | 2026-12-02 00:36 | 2026-12-02 15:30 |
| Reporter | romanzilka | Assigned To | |||
| Priority | normal | Severity | Editorial | Type | Enhancement Request |
| Status | New | Resolution | Open | ||
| Name | Roman Žilka | ||||
| Organization | |||||
| User Reference | |||||
| Section | string.h | ||||
| Page Number | 0 | ||||
| Line Number | 0 | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0002017: string.h: Add mempcpy(), analog of stpncpy() | ||||
| Description | I 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 Action | NAME 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. | ||||
| Tags | No tags attached. | ||||
|
|
+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]. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
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." |
|
|
> "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. |
| 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 |