svn commit: r246766 - in head: include lib/libc/string

2013-02-13 Thread Niclas Zeising
Author: zeising (doc,ports committer)
Date: Wed Feb 13 15:46:33 2013
New Revision: 246766
URL: http://svnweb.freebsd.org/changeset/base/246766

Log:
  Add strchrnul(), a GNU function similar to strchr(), except that it returns
  a pointer to the end of the string, rather than NULL, if the character was
  not found.
  
  Approved by:  theraven

Added:
  head/lib/libc/string/strchrnul.c   (contents, props changed)
Modified:
  head/include/string.h
  head/lib/libc/string/Makefile.inc
  head/lib/libc/string/Symbol.map
  head/lib/libc/string/strchr.3

Modified: head/include/string.h
==
--- head/include/string.h   Wed Feb 13 15:43:15 2013(r246765)
+++ head/include/string.h   Wed Feb 13 15:46:33 2013(r246766)
@@ -74,6 +74,9 @@ char  *strcasestr(const char *, const cha
 #endif
 char   *strcat(char * __restrict, const char * __restrict);
 char   *strchr(const char *, int) __pure;
+#if defined(_GNU_SOURCE)
+char   *strchrnul(const char*, int) __pure;
+#endif
 int strcmp(const char *, const char *) __pure;
 int strcoll(const char *, const char *);
 char   *strcpy(char * __restrict, const char * __restrict);

Modified: head/lib/libc/string/Makefile.inc
==
--- head/lib/libc/string/Makefile.inc   Wed Feb 13 15:43:15 2013
(r246765)
+++ head/lib/libc/string/Makefile.inc   Wed Feb 13 15:46:33 2013
(r246766)
@@ -10,9 +10,9 @@ MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffs
memccpy.c memchr.c memrchr.c memcmp.c \
memcpy.c memmem.c memmove.c memset.c \
stpcpy.c stpncpy.c strcasecmp.c \
-   strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \
-   strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \
-   strncmp.c strncpy.c strndup.c strnlen.c strnstr.c \
+   strcat.c strcasestr.c strchr.c strchrnul.c strcmp.c strcoll.c strcpy.c\
+   strcspn.c strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c \
+   strncat.c strncmp.c strncpy.c strndup.c strnlen.c strnstr.c \
strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \
strxfrm.c swab.c wcpcpy.c wcpncpy.c wcscasecmp.c wcscat.c \
wcschr.c wcscmp.c wcscoll.c wcscpy.c wcscspn.c wcsdup.c \

Modified: head/lib/libc/string/Symbol.map
==
--- head/lib/libc/string/Symbol.map Wed Feb 13 15:43:15 2013
(r246765)
+++ head/lib/libc/string/Symbol.map Wed Feb 13 15:46:33 2013
(r246766)
@@ -94,6 +94,7 @@ FBSD_1.1 {
 FBSD_1.3 {
strcasecmp_l;
strcasestr_l;
+   strchrnul;
strncasecmp_l;
wcswidth_l;
wcwidth_l;

Modified: head/lib/libc/string/strchr.3
==
--- head/lib/libc/string/strchr.3   Wed Feb 13 15:43:15 2013
(r246765)
+++ head/lib/libc/string/strchr.3   Wed Feb 13 15:46:33 2013
(r246766)
@@ -32,11 +32,11 @@
 .\ @(#)strchr.3   8.2 (Berkeley) 4/19/94
 .\ $FreeBSD$
 .\
-.Dd April 19, 1994
+.Dd February 13, 2013
 .Dt STRCHR 3
 .Os
 .Sh NAME
-.Nm strchr , strrchr
+.Nm strchr , strrchr , strchrnul
 .Nd locate character in string
 .Sh LIBRARY
 .Lb libc
@@ -46,6 +46,8 @@
 .Fn strchr const char *s int c
 .Ft char *
 .Fn strrchr const char *s int c
+.Ft char *
+.Fn strchrnul const char *s int c
 .Sh DESCRIPTION
 The
 .Fn strchr
@@ -69,6 +71,18 @@ function is identical to
 .Fn strchr
 except it locates the last occurrence of
 .Fa c .
+.Pp
+The
+.Fn strchrnul
+function is identical to
+.Fn strchr
+except that if
+.Fa c
+is not found in
+.Fa s
+a pointer to the terminating
+.Ql \e0
+is returned.
 .Sh RETURN VALUES
 The functions
 .Fn strchr
@@ -77,6 +91,11 @@ and
 return a pointer to the located character, or
 .Dv NULL
 if the character does not appear in the string.
+.Pp
+.Fn strchrnul
+returns a pointer to the terminating
+.Ql \e0
+if the character does not appear in the string.
 .Sh SEE ALSO
 .Xr memchr 3 ,
 .Xr memmem 3 ,
@@ -94,3 +113,11 @@ and
 .Fn strrchr
 conform to
 .St -isoC .
+The
+.Fn strchrnul
+is a GNU extension .
+.Sh History
+The
+.Fn strchrnul
+function first appeared in glibc 2.1.1 and was added in
+.Fx 10.0 .

Added: head/lib/libc/string/strchrnul.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libc/string/strchrnul.cWed Feb 13 15:46:33 2013
(r246766)
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2013 Niclas Zeising
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the 

Re: svn commit: r246766 - in head: include lib/libc/string

2013-02-13 Thread Konstantin Belousov
On Wed, Feb 13, 2013 at 03:46:33PM +, Niclas Zeising wrote:
 Author: zeising (doc,ports committer)
 Date: Wed Feb 13 15:46:33 2013
 New Revision: 246766
 URL: http://svnweb.freebsd.org/changeset/base/246766
 
 Log:
   Add strchrnul(), a GNU function similar to strchr(), except that it returns
   a pointer to the end of the string, rather than NULL, if the character was
   not found.
   
   Approved by:theraven
 
 Added:
   head/lib/libc/string/strchrnul.c   (contents, props changed)
 Modified:
   head/include/string.h
   head/lib/libc/string/Makefile.inc
   head/lib/libc/string/Symbol.map
   head/lib/libc/string/strchr.3
 
 Modified: head/include/string.h
 ==
 --- head/include/string.h Wed Feb 13 15:43:15 2013(r246765)
 +++ head/include/string.h Wed Feb 13 15:46:33 2013(r246766)
 @@ -74,6 +74,9 @@ char*strcasestr(const char *, const cha
  #endif
  char *strcat(char * __restrict, const char * __restrict);
  char *strchr(const char *, int) __pure;
 +#if defined(_GNU_SOURCE)
 +char *strchrnul(const char*, int) __pure;
 +#endif
The GNU_SOURCE namespace is not present on the FreeBSD.  We use
#if __BSD_VISIBLE
namespace delineation for the extensions not covered by any standard
namespaces supported by the FreeBSD headers.

The only place in the system where system-native headers do check for
_GNU_SOURCE, the code also checks for _BSD_SOURCE.


pgpLmMHGUQMzE.pgp
Description: PGP signature