[PATCH] strchr, strchrnul

Fabrice Bauzac fabrice.bauzac@mac.com
Mon Sep 15 18:46:00 GMT 2008


Le 15 sept. 08 à 15:31, Carlos O'Donell a écrit :

>
> On Sun, Sep 14, 2008 at 2:46 AM, Fabrice Bauzac  
> <fabrice.bauzac@mac.com> wrote:
>> I could not register to Bugzilla [...].
>
> That is very odd. Have you contacted sourcemaster@sourcware.org to
> determine is there is a problem?

Good idea, I've sent a mail.

>> ! When @code{strchr} returns a null pointer, it does not let you know
>> ! the position of the terminating null character it has found.
>
> What are you trying to say here? Could you please expand this  
> sentence.

Sorry, my English is not very good. I'll try to explain more:

strchr ("my very long string containing no dashes...", '-') reads the  
whole string until its terminating NUL character, then returns the  
NULL pointer once it has found the said NUL character.

I have a program that does not know in advance the length of the  
string, and it is annoying that strchr does not provide that  
information even though it has found it. My program has to perform a  
strlen() which means a second full-length read of the string.

strchrnul, if I understand correctly, has the functionality of strchr  
while providing that information, since it provides a pointer to the  
ending NUL character. The string length can be computed with the  
difference between pointers.

Thanks.


More information about the Libc-help mailing list