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 2023-03-06 16:36
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.

- 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


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