Skip to contentSkip to conversation

should strstr return const char* ?

DISCUSSION Jon 3 participants 3 messages Feb 28, 2010 – Jun 19, 2010 1 message not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore

Jon

author
#0 lore raw

Hi there,

A couple of queries. I hope could be considered.

I see this function on Ubuntu 9.10:

     char *strstr(const char *haystack, const char *needle);

Should it not return as const char * though?

Also could the description be clarified:

DESCRIPTION
The strstr() function finds the first occurrence of the
substring needle in the string haystack. The terminating
'\0' characters are not compared.

Can this be added: "If needle is longer than haystack it will never match. When the search reaches a character position in haystack which does not leave enough characters left to compare, searching will end, the haystack buffer will not be overrun.

Thanks again for considering this.
Cheers, Jon
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 5 lines · On Sunday 28 February 2010 16:29:59 Jon wrote:

I see this function on Ubuntu 9.10:

      char *strstr(const char *haystack, const char *needle);

Should it not return as const char * though?

man pages document the API only. if you want to propose changing a function, you'd have to ask the glibc mainling lists and/or more likely the POSIX mailing lists.
-mike

#3 lore raw
In reply to a message not in the archive

Hello Jon,

Quoted 9 lines · Jon

Hi there,

A couple of queries. I hope could be considered.

I see this function on Ubuntu 9.10:

    char *strstr(const char *haystack, const char *needle);

Should it not return as const char * though?

As Mike Frysinger pointed out, man-pages here is documenting things as they are in glibc. (Also, POSIX does not document a "const" here in the spec.)

Quoted 11 lines

Also could the description be clarified:
DESCRIPTION
      The strstr() function finds the first occurrence of the substring needle in the string haystack.  The terminating
      '\0' characters are not compared.

Can this be added: "If needle is longer than haystack it will never match. When the search reaches a character position in haystack which does not leave enough characters left to compare, searching will end, the haystack buffer will not be overrun.

I regard these points as reasonably self-evident, so I don't think they really need to be specifically mentioned. (What else could one reasonably expect to happen in these cases?)

Thanks,

Michael

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface" http://blog.man7.org/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html