Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001633 [Issue 8 drafts] Base Definitions and Headers Comment Enhancement Request 2023-02-16 10:07 2024-09-05 16:10
Reporter nrk View Status public  
Assigned To
Priority normal Resolution Open  
Status New   Product Version
Name Nickolas Raymond Kaczynski
Organization
User Reference
Section <string.h>
Page Number n/a
Line Number n/a
Final Accepted Text
Summary 0001633: Add memrchr
Description memrchr is a simple and useful function that is similar to memchr, except it finds the last occurrence of a byte. It is provided by the following implementations already:

* glibc (https://www.man7.org/linux/man-pages/man3/memrchr.3.html) [^]
* musl
* openbsd (https://man.openbsd.org/memrchr.3) [^]
* freebsd (https://man.freebsd.org/cgi/man.cgi?query=memrchr&manpath=FreeBSD+13.1-RELEASE+and+Ports) [^]

(And probably many others).
Desired Action Under section <string.h> add:

void *memrchr(const void *s, int c, size_t n);

Under memchr, add memrchr to SEE ALSO.

Add a new memrchr page:

NAME

    memrchr - find last occurrence of a byte in memory

SYNOPSIS

    #include <string.h>

    void *memrchr(const void *s, int c, size_t n);

DESCRIPTION

    The memrchr() function shall locate the last occurrence of c (converted to an unsigned char) in the initial n bytes (each interpreted as unsigned char) pointed to by s.

RETURN VALUE

    The memrchr() function shall return a pointer to the located byte, or a null pointer if the byte is not found.

ERRORS

    No errors are defined.
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0006185)
Don Cragun (manager)
2023-03-02 16:56

In addition to memchr(), the standard also includes wmemchr(). Does this request also intend to add wmemrchr()?
(0006186)
nrk (reporter)
2023-03-02 17:10

The purpose of this defect report was to standardize a widely implemented interface.

I've quickly looked into glibc, musl, freebsd & openbsd and none of them seem to provide wmemrchr(). As such, I have no intention of adding wmemrchr().
(0006194)
shware_systems (reporter)
2023-03-06 16:36

Note 6186 was discussed in the 2023-03-06 teleconference and it was noted that because wcsrchr() is already present, it functionally serves as an equivalent for most situations to wmemrchr(), and this is a reason there hasn't been much call to implement wmemrchr(). However, for searching blocks that may have embedded wide null chars it is not sufficient; application code is necessary to find the last null before attempting the right scan.

As such, for symmetry and completeness the consensus is more the standard should contain the interface, unless some implementation has a compelling reason it can communicate here why it shouldn't be.
(0006867)
eblake (manager)
2024-08-22 15:24

Discussed on the 2024-08-22 call: At this point, we are unaware of any wmemrchr() implementations. While searching backwards for a byte can be done efficiently, searching backwards for the start of a multibyte character can be difficult depending on the encoding, at which point a loop over searching forward until reaching the end of the memory is just as efficient without needing a new specialized function. The consensus for now is that the Austin Group is willing to sponsor memrchr() with a rationale stating why there is no wmemrchr(), which could be amended at a later date if a wmemrchr() is no longer invention.
(0006875)
eblake (manager)
2024-09-05 16:10

Regarding Note: 0006867 - I have been reminded that wmemrchr() is about searching wchar_t not multibyte characters (searching backwards on multibyte characters is not trivial, but searching wchar_t can be efficient); but the point remains that the Austin Group is unaware of any implementations of wmemrchr() or applications that would benefit from having it.

- Issue History
Date Modified Username Field Change
2023-02-16 10:07 nrk New Issue
2023-02-16 10:07 nrk Name => Nickolas Raymond Kaczynski
2023-02-16 10:07 nrk Section => <string.h>
2023-02-16 10:07 nrk Page Number => n/a
2023-02-16 10:07 nrk Line Number => n/a
2023-02-16 10:16 nrk Issue Monitored: nrk
2023-03-02 16:56 Don Cragun Note Added: 0006185
2023-03-02 17:10 nrk Note Added: 0006186
2023-03-06 16:36 shware_systems Note Added: 0006194
2024-08-22 15:24 eblake Note Added: 0006867
2024-09-05 16:10 eblake Note Added: 0006875


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker