This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] strchr, strchrnul


Hello,

I could not register to Bugzilla.  I never receive the confirmation
e-mail, even though I have tried several of my addresses (@orange.fr,
@wanadoo.fr, @me.com...).  So, well, here it is.

I think that the documentation for strchr is not very clear in its
last paragraph:

 -- Function: char * strchr (const char *STRING, int C)
     The `strchr' function finds the first occurrence of the character
     C (converted to a `char') in the null-terminated string beginning
     at STRING.  The return value is a pointer to the located
     character, or a null pointer if no match was found.

     For example,
          strchr ("hello, world", 'l')
              => "llo, world"
          strchr ("hello, world", '?')
              => NULL

     The terminating null character is considered to be part of the
     string, so you can use this function get a pointer to the end of a
     string by specifying a null character as the value of the C
     argument.  It would be better (but less portable) to use
     `strchrnul' in this case, though.

As a reminder, here is the documentation for strchrnul:

 -- Function: char * strchrnul (const char *STRING, int C)
     `strchrnul' is the same as `strchr' except that if it does not
     find the character, it returns a pointer to string's terminating
     null character rather than a null pointer.

     This function is a GNU extension.

I have made the below patch for string.texi.  Could you please have a
look at it?

diff -c /home/noon/prog/glibc-cvs/libc/manual/string.texi.orig /home/noon/prog/glibc-cvs/libc/manual/string.texi
*** /home/noon/prog/glibc-cvs/libc/manual/string.texi.orig	Sat Sep  6 12:47:36 2008
--- /home/noon/prog/glibc-cvs/libc/manual/string.texi	Sat Sep  6 13:01:57 2008
***************
*** 1647,1655 ****
  
  The terminating null character is considered to be part of the string,
  so you can use this function get a pointer to the end of a string by
! specifying a null character as the value of the @var{c} argument.  It
! would be better (but less portable) to use @code{strchrnul} in this
! case, though.
  @end deftypefun
  
  @comment wchar.h
--- 1647,1658 ----
  
  The terminating null character is considered to be part of the string,
  so you can use this function get a pointer to the end of a string by
! specifying a null character as the value of the @var{c} argument.
! 
! When @code{strchr} returns a null pointer, it does not let you know
! the position of the terminating null character it has found.  If you
! need that information, it is better (but less portable) to use
! @code{strchrnul} than to search for it a second time.
  @end deftypefun
  
  @comment wchar.h

Thanks.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]