Bug 42042
Summary: | strchr(3) and memchr(3) should explain behaviour when character 'c' is '\0'. | ||
---|---|---|---|
Product: | Documentation | Reporter: | James Hunt (jamesodhunt) |
Component: | man-pages | Assignee: | documentation_man-pages (documentation_man-pages) |
Status: | RESOLVED CODE_FIX | ||
Severity: | normal | CC: | akpm, mtk.manpages |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | Subsystem: | ||
Regression: | No | Bisected commit-id: | |
Attachments: |
update to strchr.3 and memchr.3
test program showing behaviour of strchr, strrchr, memchr, strchrnul, and strstr. |
Description
James Hunt
2011-08-30 13:17:37 UTC
Send us a patch ;) Documentation/SubmittingPatches has some guidelines. Created attachment 70952 [details]
update to strchr.3 and memchr.3
Created attachment 70962 [details]
test program showing behaviour of strchr, strrchr, memchr, strchrnul, and strstr.
Test program run on: - Ubuntu Natty (11.04) system with libc6 version 2.13-0ubuntu13 (egcs). - Fedora 15 system with glibc version 2.13.90-9. The BSD folk already have this behaviour documented in their man pages: http://www.freebsd.org/cgi/man.cgi?query=strchr&apropos=0&sektion=0&manpath=FreeBSD+8.2-RELEASE&arch=default&format=html James, Thanks for the detailed report, and sorry I've been slow to respond. For strchr(3), I applied a variation of what you proposed: --- a/man3/strchr.3 +++ b/man3/strchr.3 @@ -28,7 +28,7 @@ .\" 2006-05-19, Justin Pryzby <pryzbyj@justinpryzby.com> .\" Document strchrnul(3). .\" -.TH STRCHR 3 2010-09-20 "GNU" "Linux Programmer's Manual" +.TH STRCHR 3 2012-04-24 "GNU" "Linux Programmer's Manual" .SH NAME strchr, strrchr, strchrnul \- locate character in string .SH SYNOPSIS @@ -72,6 +72,11 @@ and .BR strrchr () functions return a pointer to the matched character or NULL if the character is not found. +The terminating null byte is considered part of the string, +so that if +.I c +is specified as \(aq\\0\(aq, +these functions return a pointer to the terminator. The .BR strchrnul () James, Regarding memchr(), I'm not sure a change is warranted. memchr() is defined in terms of 'bytes' and 'memory areas', rather than strings, so I'd have said it would take an obtuse reading to consider that '\0' is interpreted specially (whereas, as you say, one could be left doubtful about what strchr() does when c is '\0'). I'd guess that this is also why POSIX and the FreeBSD man page make no statement on this pont. So, I'm inclined not to make a change. Thanks, Michael One further note about memchr(3) though. It does talk about the argument c as a *character*, and rawmemchr() also talks about strings, which clouds the issue somewhat. I'll do some rewrites there to refer rather to "bytes" and "memory areas". James, all changes are pushed to kernel.org git now. I'll close this now. Please reopen if you thing there's more to be said about memchr(). |