This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] Add strchrnul
- From: "Yaakov (Cygwin/X)" <yselkowitz at users dot sourceforge dot net>
- To: newlib <newlib at sources dot redhat dot com>
- Date: Sun, 27 Mar 2011 22:37:47 -0500
- Subject: [PATCH] Add strchrnul
I'm attaching a patch and new C file to implement strchrnul, a GNU
extension.
Corinna: patch for winsup being posted to cygwin-patches.
Yaakov
Cygwin Ports
2011-03-27 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* libc/include/string.h (strchrnul): Declare.
* libc/string/strchrnul.c: New file.
* libc/string/Makefile.am (ELIX_2_SOURCES): Add strchrnul.c.
* libc/string/Makefile.in: Regenerate.
Index: libc/include/string.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/string.h,v
retrieving revision 1.26
diff -u -r1.26 string.h
--- libc/include/string.h 3 Mar 2011 11:11:41 -0000 1.26
+++ libc/include/string.h 28 Mar 2011 03:05:09 -0000
@@ -63,6 +63,7 @@
char *_EXFUN(stpncpy,(char *, const char *, size_t));
int _EXFUN(strcasecmp,(const char *, const char *));
char *_EXFUN(strcasestr,(const char *, const char *));
+char *_EXFUN(strchrnul,(const char *, int));
char *_EXFUN(strdup,(const char *));
char *_EXFUN(_strdup_r,(struct _reent *, const char *));
char *_EXFUN(strndup,(const char *, size_t));
Index: libc/string/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/Makefile.am,v
retrieving revision 1.27
diff -u -r1.27 Makefile.am
--- libc/string/Makefile.am 10 Feb 2011 16:48:18 -0000 1.27
+++ libc/string/Makefile.am 28 Mar 2011 03:05:09 -0000
@@ -85,6 +85,7 @@
stpncpy.c \
strndup.c \
strcasestr.c \
+ strchrnul.c \
strndup_r.c \
wcpcpy.c \
wcpncpy.c \
Index: libc/string/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/Makefile.in,v
retrieving revision 1.44
diff -u -r1.44 Makefile.in
--- libc/string/Makefile.in 10 Feb 2011 16:48:18 -0000 1.44
+++ libc/string/Makefile.in 28 Mar 2011 03:05:10 -0000
@@ -96,6 +96,7 @@
@ELIX_LEVEL_1_FALSE@ lib_a-stpncpy.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-strndup.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-strcasestr.$(OBJEXT) \
+@ELIX_LEVEL_1_FALSE@ lib_a-strchrnul.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-strndup_r.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-wcpcpy.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-wcpncpy.$(OBJEXT) \
@@ -123,8 +124,8 @@
wmemcpy.lo wmemmove.lo wmemset.lo xpg_strerror_r.lo
@ELIX_LEVEL_1_FALSE@am__objects_5 = bcmp.lo memccpy.lo mempcpy.lo \
@ELIX_LEVEL_1_FALSE@ stpcpy.lo stpncpy.lo strndup.lo \
-@ELIX_LEVEL_1_FALSE@ strcasestr.lo strndup_r.lo wcpcpy.lo \
-@ELIX_LEVEL_1_FALSE@ wcpncpy.lo wcsdup.lo
+@ELIX_LEVEL_1_FALSE@ strcasestr.lo strchrnul.lo strndup_r.lo \
+@ELIX_LEVEL_1_FALSE@ wcpcpy.lo wcpncpy.lo wcsdup.lo
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_6 = memmem.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wcscasecmp.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wcsncasecmp.lo
@@ -375,6 +376,7 @@
@ELIX_LEVEL_1_FALSE@ stpncpy.c \
@ELIX_LEVEL_1_FALSE@ strndup.c \
@ELIX_LEVEL_1_FALSE@ strcasestr.c \
+@ELIX_LEVEL_1_FALSE@ strchrnul.c \
@ELIX_LEVEL_1_FALSE@ strndup_r.c \
@ELIX_LEVEL_1_FALSE@ wcpcpy.c \
@ELIX_LEVEL_1_FALSE@ wcpncpy.c \
@@ -937,6 +939,12 @@
lib_a-strcasestr.obj: strcasestr.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strcasestr.obj `if test -f 'strcasestr.c'; then $(CYGPATH_W) 'strcasestr.c'; else $(CYGPATH_W) '$(srcdir)/strcasestr.c'; fi`
+lib_a-strchrnul.o: strchrnul.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strchrnul.o `test -f 'strchrnul.c' || echo '$(srcdir)/'`strchrnul.c
+
+lib_a-strchrnul.obj: strchrnul.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strchrnul.obj `if test -f 'strchrnul.c'; then $(CYGPATH_W) 'strchrnul.c'; else $(CYGPATH_W) '$(srcdir)/strchrnul.c'; fi`
+
lib_a-strndup_r.o: strndup_r.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strndup_r.o `test -f 'strndup_r.c' || echo '$(srcdir)/'`strndup_r.c
/*
FUNCTION
<<strchrnul>>---search for character in string
INDEX
strchrnul
ANSI_SYNOPSIS
#include <string.h>
char * strchrnul(const char *<[string]>, int <[c]>);
TRAD_SYNOPSIS
#include <string.h>
char * strchrnul(<[string]>, <[c]>);
const char *<[string]>;
int <[c]>;
DESCRIPTION
This function finds the first occurence of <[c]> (converted to
a char) in the string pointed to by <[string]> (including the
terminating null character).
RETURNS
Returns a pointer to the located character, or a pointer
to the concluding null byte if <[c]> does not occur in <[string]>.
PORTABILITY
<<strchrnul>> is a GNU extension.
<<strchrnul>> requires no supporting OS subroutines. It uses
strchr() and strlen() from elsewhere in this library.
QUICKREF
strchrnul
*/
#include <string.h>
char *
_DEFUN (strchrnul, (s1, i),
_CONST char *s1 _AND
int i)
{
char *s = strchr(s1, i);
if (*s != NULL)
return s;
return (char *)s1 + strlen(s1);
}