This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

Re: [patch/RFA] New functions wcpcpy/wcpncpy


Corinna Vinschen wrote:
Hi,

below is my implementation of wcpcpy and wcpncpy.  As their single
byte counterparts stpcpy and stpncpy, both functions are candidates
for inclusion into POSIX and SUSv4.  I tested the implementation
under Cygwin.

Ok to apply?



Yes, go ahead.

-- Jeff J.


Thanks, Corinna


* libc/include/wchar.h: Add prototypes for wcpcpy and wcpncpy. * libc/string/Makefile.am (ELIX_SOURCES): Add wcpcpy.c and wcpncpy.c. (CHEWOUT_FILES): Add wcpcpy.def and wcpncpy.def. * libc/string/Makefile.in: Regenerate. * libc/string/wcpcpy.c: New file. * libc/string/wcpncpy.c: New file. * libc/string/wcstrings.tex: Add wcpcpy and wcpncpy.

Index: libc/include/wchar.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v
retrieving revision 1.15
diff -u -p -r1.15 wchar.h
--- libc/include/wchar.h 6 Jul 2007 20:03:28 -0000 1.15
+++ libc/include/wchar.h 19 Dec 2007 17:14:43 -0000
@@ -58,6 +58,7 @@ wchar_t *_EXFUN(wcschr, (const wchar_t *
int _EXFUN(wcscmp, (const wchar_t *, const wchar_t *));
int _EXFUN(wcscoll, (const wchar_t *, const wchar_t *));
wchar_t *_EXFUN(wcscpy, (wchar_t * , const wchar_t *));
+wchar_t *_EXFUN(wcpcpy, (wchar_t * , const wchar_t *));
size_t _EXFUN(wcscspn, (const wchar_t *, const wchar_t *));
size_t _EXFUN(wcslcat, (wchar_t *, const wchar_t *, size_t));
size_t _EXFUN(wcslcpy, (wchar_t *, const wchar_t *, size_t));
@@ -65,6 +66,7 @@ size_t _EXFUN(wcslen, (const wchar_t *))
wchar_t *_EXFUN(wcsncat, (wchar_t * , const wchar_t * , size_t));
int _EXFUN(wcsncmp, (const wchar_t *, const wchar_t *, size_t));
wchar_t *_EXFUN(wcsncpy, (wchar_t * , const wchar_t * , size_t));
+wchar_t *_EXFUN(wcpncpy, (wchar_t * , const wchar_t * , size_t));
size_t _EXFUN(wcsnlen, (const wchar_t *, size_t));
wchar_t *_EXFUN(wcspbrk, (const wchar_t *, const wchar_t *));
wchar_t *_EXFUN(wcsrchr, (const wchar_t *, wchar_t));
Index: libc/string/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/Makefile.am,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.am
--- libc/string/Makefile.am 4 Jul 2007 16:18:34 -0000 1.18
+++ libc/string/Makefile.am 19 Dec 2007 17:14:43 -0000
@@ -82,7 +82,9 @@ ELIX_SOURCES = \
stpncpy.c \
strndup.c \
strcasestr.c \
- strndup_r.c
+ strndup_r.c \
+ wcpcpy.c \
+ wcpncpy.c \
endif
libstring_la_LDFLAGS = -Xcompiler -nostdlib
@@ -110,7 +112,7 @@ memcmp.def strchr.def strlen.def strnlen
strcasecmp.def strncasecmp.def strcasestr.def strlwr.def strupr.def \
memccpy.def mempcpy.def stpcpy.def stpncpy.def \
wcscat.def wcschr.def wcscmp.def wcscoll.def \
-wcscpy.def wcscspn.def \
+wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def \
wcslcat.def wcslcpy.def wcslen.def wcsncat.def \
wcsncmp.def wcsncpy.def wcsnlen.def wcspbrk.def \
wcsrchr.def wcsspn.def wcsstr.def \
Index: libc/string/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/Makefile.in,v
retrieving revision 1.30
diff -u -p -r1.30 Makefile.in
--- libc/string/Makefile.in 4 Jul 2007 16:18:34 -0000 1.30
+++ libc/string/Makefile.in 19 Dec 2007 17:14:44 -0000
@@ -95,7 +95,9 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) li
@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-strndup_r.$(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)
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
@USE_LIBTOOL_FALSE@ $(am__objects_2)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
@@ -116,7 +118,8 @@ am__objects_3 = bcopy.lo bzero.lo index.
wmemcpy.lo wmemmove.lo wmemset.lo
@ELIX_LEVEL_1_FALSE@am__objects_4 = 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
+@ELIX_LEVEL_1_FALSE@ strcasestr.lo strndup_r.lo wcpcpy.lo \
+@ELIX_LEVEL_1_FALSE@ wcpncpy.lo
@USE_LIBTOOL_TRUE@am_libstring_la_OBJECTS = $(am__objects_3) \
@USE_LIBTOOL_TRUE@ $(am__objects_4)
libstring_la_OBJECTS = $(am_libstring_la_OBJECTS)
@@ -371,7 +374,9 @@ GENERAL_SOURCES = \
@ELIX_LEVEL_1_FALSE@ mempcpy.c \
@ELIX_LEVEL_1_FALSE@ strndup.c \
@ELIX_LEVEL_1_FALSE@ strcasestr.c \
-@ELIX_LEVEL_1_FALSE@ strndup_r.c
+@ELIX_LEVEL_1_FALSE@ strndup_r.c \
+@ELIX_LEVEL_1_FALSE@ wcpcpy.c \
+@ELIX_LEVEL_1_FALSE@ wcpncpy.c
@ELIX_LEVEL_1_TRUE@ELIX_SOURCES = libstring_la_LDFLAGS = -Xcompiler -nostdlib
@@ -392,7 +397,7 @@ memcmp.def strchr.def strlen.def strnlen
strcasecmp.def strncasecmp.def strcasestr.def strlwr.def strupr.def \
memccpy.def mempcpy.def stpcpy.def stpncpy.def \
wcscat.def wcschr.def wcscmp.def wcscoll.def \
-wcscpy.def wcscspn.def \
+wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def \
wcslcat.def wcslcpy.def wcslen.def wcsncat.def \
wcsncmp.def wcsncpy.def wcsnlen.def wcspbrk.def \
wcsrchr.def wcsspn.def wcsstr.def \
@@ -908,6 +913,18 @@ lib_a-strndup_r.o: strndup_r.c
lib_a-strndup_r.obj: strndup_r.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strndup_r.obj `if test -f 'strndup_r.c'; then $(CYGPATH_W) 'strndup_r.c'; else $(CYGPATH_W) '$(srcdir)/strndup_r.c'; fi`
+lib_a-wcpcpy.o: wcpcpy.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcpcpy.o `test -f 'wcpcpy.c' || echo '$(srcdir)/'`wcpcpy.c
+
+lib_a-wcpcpy.obj: wcpcpy.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcpcpy.obj `if test -f 'wcpcpy.c'; then $(CYGPATH_W) 'wcpcpy.c'; else $(CYGPATH_W) '$(srcdir)/wcpcpy.c'; fi`
+
+lib_a-wcpncpy.o: wcpncpy.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcpncpy.o `test -f 'wcpncpy.c' || echo '$(srcdir)/'`wcpncpy.c
+
+lib_a-wcpncpy.obj: wcpncpy.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcpncpy.obj `if test -f 'wcpncpy.c'; then $(CYGPATH_W) 'wcpncpy.c'; else $(CYGPATH_W) '$(srcdir)/wcpncpy.c'; fi`
+
mostlyclean-libtool:
-rm -f *.lo
Index: libc/string/wcpcpy.c
===================================================================
RCS file: libc/string/wcpcpy.c
diff -N libc/string/wcpcpy.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libc/string/wcpcpy.c 19 Dec 2007 17:14:44 -0000
@@ -0,0 +1,41 @@
+/*
+FUNCTION
+ <<wcpcpy>>---copy a wide-character string returning a pointer to its end
+
+ANSI_SYNOPSIS
+ #include <wchar.h>
+ wchar_t *wcpcpy(wchar_t *<[s1]>, const wchar_t *,<[s2]>);
+
+TRAD_SYNOPSIS
+ wchar_t *wcpcpy(<[s1]>, <[s2]>
+ wchar_t *<[s1]>;
+ const wchar_t *<[s2]>;
+
+DESCRIPTION
+ The <<wcpcpy>> function copies the wide-character string pointed to by
+ <[s2]> (including the terminating null wide-character code) into the
+ array pointed to by <[s1]>. If copying takes place between objects that
+ overlap, the behaviour is undefined. +
+RETURNS
+ This function returns a pointer to the end of the destination string,
+ thus pointing to the trailing '\0'.
+
+PORTABILITY
+<<wcpcpy>> is a GNU extension.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <wchar.h>
+
+wchar_t *
+_DEFUN (wcpcpy, (s1, s2),
+ wchar_t * s1 _AND
+ _CONST wchar_t * s2)
+{
+ while ((*s1++ = *s2++))
+ ;
+ return --s1;
+}
Index: libc/string/wcpncpy.c
===================================================================
RCS file: libc/string/wcpncpy.c
diff -N libc/string/wcpncpy.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libc/string/wcpncpy.c 19 Dec 2007 17:14:44 -0000
@@ -0,0 +1,61 @@
+/*
+FUNCTION
+ <<wcpncpy>>---copy part of a wide-character string returning a pointer to its end
+
+ANSI_SYNOPSIS
+ #include <wchar.h>
+ wchar_t *wcpncpy(wchar_t *<[s1]>, const wchar_t *<[s2]>, size_t <[n]>);
+
+TRAD_SYNOPSIS
+ wchar_t *wcpncpy(<[s1]>, <[s2]>, <[n]>
+ wchar_t *<[s1]>;
+ const wchar_t *<[s2]>;
+ size_t <[n]>;
+
+DESCRIPTION
+ The <<wcpncpy>> function copies not more than n wide-character codes
+ (wide-character codes that follow a null wide-character code are not
+ copied) from the array pointed to by <[s2]> to the array pointed to
+ by <[s1]>. If copying takes place between objects that overlap, the
+ behaviour is undefined.
+
+ If the array pointed to by <[s2]> is a wide-character string that is
+ shorter than <[n]> wide-character codes, null wide-character codes are
+ appended to the copy in the array pointed to by <[s1]>, until <[n]>
+ wide-character codes in all are written. +
+RETURNS
+ The <<wcpncpy>> function returns <[s1]>; no return value is reserved to
+ indicate an error. +
+PORTABILITY
+<<wcpncpy>> is ISO/IEC 9899/AMD1:1995 (ISO C).
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <wchar.h>
+
+wchar_t *
+_DEFUN (wcpncpy, (dst, src, count),
+ wchar_t * dst _AND
+ _CONST wchar_t * src _AND
+ size_t count)
+{
+ wchar_t *ret = NULL;
+
+ while (count > 0)
+ {
+ --count;
+ if ((*dst++ = *src++) == L'\0')
+ {
+ ret = dst - 1;
+ break;
+ }
+ }
+ while (count-- > 0)
+ *dst++ = L'\0';
+
+ return ret ? ret : dst;
+}
Index: libc/string/wcstrings.tex
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/wcstrings.tex,v
retrieving revision 1.6
diff -u -p -r1.6 wcstrings.tex
--- libc/string/wcstrings.tex 4 Jul 2007 16:18:34 -0000 1.6
+++ libc/string/wcstrings.tex 19 Dec 2007 17:14:44 -0000
@@ -16,6 +16,7 @@ declarations are in @file{wchar.h}.
* wcscmp:: Wide-character string compare
* wcscoll:: Locale-specific wide-character string compare
* wcscpy:: Copy wide-character string
+* wcpcpy:: Copy a wide-character string returning a pointer to its end
* wcscspn:: Count wide characters not in string
* wcslcat:: Concatenate wide-character strings to specified length
* wcslcpy:: Copy wide-character string to specified length
@@ -23,6 +24,7 @@ declarations are in @file{wchar.h}.
* wcsncat:: Concatenate wide-character strings
* wcsncmp:: Wide-character string compare
* wcsncpy:: Counted copy wide-character string
+* wcpncpy:: Copy part of a wide-character string returning a pointer to its end
* wcsnlen:: Wide-character string length with maximum limit
* wcspbrk:: Find wide characters in string
* wcsrchr:: Reverse search for wide character in string
@@ -64,6 +66,9 @@ declarations are in @file{wchar.h}.
@include string/wcscpy.def
@page
+@include string/wcpcpy.def
+
+@page
@include string/wcscspn.def
@page
@@ -85,6 +90,9 @@ declarations are in @file{wchar.h}.
@include string/wcsncpy.def
@page
+@include string/wcpncpy.def
+
+@page
@include string/wcsnlen.def
@page




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