]> sourceware.org Git - newlib-cygwin.git/commitdiff
* libc/include/string.h: Add prototypes for stpcpy and stpncpy.
authorCorinna Vinschen <corinna@vinschen.de>
Thu, 28 Jun 2007 17:07:23 +0000 (17:07 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 28 Jun 2007 17:07:23 +0000 (17:07 +0000)
* libc/string/Makefile.am (ELIX_SOURCES): Add stpcpy.c and
stpncpy.c.
(CHEWOUT_FILES): Add stpcpy.def and stpncpy.def.
* libc/string/Makefile.in: Regenerate.
* libc/string/stpcpy.c: New file.
* libc/string/stpncpy.c: New file.
* libc/string/strings.tex: Add stpcpy and stpncpy.

newlib/ChangeLog
newlib/libc/include/string.h
newlib/libc/string/Makefile.am
newlib/libc/string/Makefile.in
newlib/libc/string/stpcpy.c [new file with mode: 0644]
newlib/libc/string/stpncpy.c [new file with mode: 0644]
newlib/libc/string/strings.tex

index 7822a6edf58ba4e9628eb4d384931bbde9cf2faa..bd610389ac56652bdd355baaf3a87d8d155b33f1 100644 (file)
@@ -1,3 +1,14 @@
+2007-06-28  Corinna Vinschen  <corinna@vinschen.de>
+
+       * libc/include/string.h: Add prototypes for stpcpy and stpncpy.
+       * libc/string/Makefile.am (ELIX_SOURCES): Add stpcpy.c and
+       stpncpy.c.
+       (CHEWOUT_FILES): Add stpcpy.def and stpncpy.def.
+       * libc/string/Makefile.in: Regenerate.
+       * libc/string/stpcpy.c: New file.
+       * libc/string/stpncpy.c: New file.
+       * libc/string/strings.tex: Add stpcpy and stpncpy.
+
 2007-06-27  Eric Blake  <ebb9@byu.net>
 
        Support __func__ in assert, as required by C99.
index c677f6f7be2422046b0f50eaf4e2db3324e3ae7f..27c314620adf183f0928327dc070dd5dea964321 100644 (file)
@@ -60,6 +60,8 @@ _PTR   _EXFUN(mempcpy,(_PTR, const _PTR, size_t));
 extern void *memmem (__const void *, size_t,  __const void *, size_t);
 #endif
 char   *_EXFUN(rindex,(const char *, int));
+char   *_EXFUN(stpcpy,(char *, const char *));
+char   *_EXFUN(stpncpy,(char *, const char *, size_t));
 int     _EXFUN(strcasecmp,(const char *, const char *));
 char   *_EXFUN(strcasestr,(const char *, const char *));
 char   *_EXFUN(strdup,(const char *));
index e0482d82e6bb7d6da91bd5fc231ff0a01ee740ec..94d1868fa7c9bc57966386403dcb4dfd0991262c 100644 (file)
@@ -77,6 +77,8 @@ ELIX_SOURCES = \
        bcmp.c \
        memccpy.c \
        mempcpy.c \
+       stpcpy.c \
+       stpncpy.c \
        strndup.c \
        strcasestr.c \
        strndup_r.c
@@ -105,7 +107,7 @@ index.def   rindex.def      strcspn.def     strpbrk.def swab.def \
 memchr.def     strcat.def      strerror.def    strerror_r.def strrchr.def \
 memcmp.def     strchr.def      strlen.def      strnlen.def strspn.def \
 strcasecmp.def strncasecmp.def strcasestr.def  strlwr.def  strupr.def \
-memccpy.def    mempcpy.def \
+memccpy.def    mempcpy.def     stpcpy.def      stpncpy.def \
 wcscat.def     wcschr.def      wcscmp.def      wcscoll.def \
 wcscpy.def     wcscspn.def \
 wcslcat.def    wcslcpy.def     wcslen.def      wcsncat.def \
index f5c5bdbe6ade8b5dd326bc7ba5dc4c3c54545180..8c5406cf0ae7a9bed2e4a655b1a3061946588eda 100644 (file)
@@ -90,6 +90,8 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@   lib_a-memccpy.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@   lib_a-mempcpy.$(OBJEXT) \
+@ELIX_LEVEL_1_FALSE@   lib_a-stpcpy.$(OBJEXT) \
+@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)
@@ -100,19 +102,20 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
 libstring_la_LIBADD =
 am__objects_3 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \
        memcpy.lo memmove.lo memset.lo rindex.lo strcasecmp.lo \
-       strcat.lo strchr.lo strcmp.lo strcoll.lo strcpy.lo strcspn.lo \
-       strdup.lo strdup_r.lo strerror.lo strerror_r.lo strlcat.lo \
-       strlcpy.lo strlen.lo strlwr.lo strncasecmp.lo strncat.lo \
-       strncmp.lo strncpy.lo strnlen.lo strpbrk.lo strrchr.lo \
-       strsep.lo strspn.lo strtok.lo strtok_r.lo strupr.lo strxfrm.lo \
-       strstr.lo swab.lo u_strerr.lo wcscat.lo wcschr.lo wcscmp.lo \
-       wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo wcslcpy.lo \
-       wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo wcsnlen.lo \
-       wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcswidth.lo \
-       wcwidth.lo wmemchr.lo wmemcmp.lo wmemcpy.lo wmemmove.lo \
-       wmemset.lo
+       strcat.lo strchr.lo strcmp.lo strcoll.lo strcpy.lo \
+       strcspn.lo strdup.lo strdup_r.lo strerror.lo strerror_r.lo \
+       strlcat.lo strlcpy.lo strlen.lo strlwr.lo strncasecmp.lo \
+       strncat.lo strncmp.lo strncpy.lo strnlen.lo strpbrk.lo \
+       strrchr.lo strsep.lo strspn.lo strtok.lo strtok_r.lo \
+       strupr.lo strxfrm.lo strstr.lo swab.lo u_strerr.lo wcscat.lo \
+       wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo wcscspn.lo \
+       wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo wcsncmp.lo \
+       wcsncpy.lo wcsnlen.lo wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo \
+       wcswidth.lo wcwidth.lo wmemchr.lo wmemcmp.lo wmemcpy.lo \
+       wmemmove.lo wmemset.lo
 @ELIX_LEVEL_1_FALSE@am__objects_4 = bcmp.lo memccpy.lo mempcpy.lo \
-@ELIX_LEVEL_1_FALSE@   strndup.lo strcasestr.lo strndup_r.lo
+@ELIX_LEVEL_1_FALSE@   stpcpy.lo stpncpy.lo strndup.lo \
+@ELIX_LEVEL_1_FALSE@   strcasestr.lo strndup_r.lo
 @USE_LIBTOOL_TRUE@am_libstring_la_OBJECTS = $(am__objects_3) \
 @USE_LIBTOOL_TRUE@     $(am__objects_4)
 libstring_la_OBJECTS = $(am_libstring_la_OBJECTS)
@@ -360,6 +363,8 @@ GENERAL_SOURCES = \
 
 @ELIX_LEVEL_1_FALSE@ELIX_SOURCES = \
 @ELIX_LEVEL_1_FALSE@   bcmp.c \
+@ELIX_LEVEL_1_FALSE@   stpcpy.c \
+@ELIX_LEVEL_1_FALSE@   stpncpy.c \
 @ELIX_LEVEL_1_FALSE@   memccpy.c \
 @ELIX_LEVEL_1_FALSE@   mempcpy.c \
 @ELIX_LEVEL_1_FALSE@   strndup.c \
@@ -383,7 +388,7 @@ index.def   rindex.def      strcspn.def     strpbrk.def swab.def \
 memchr.def     strcat.def      strerror.def    strerror_r.def strrchr.def \
 memcmp.def     strchr.def      strlen.def      strnlen.def strspn.def \
 strcasecmp.def strncasecmp.def strcasestr.def  strlwr.def  strupr.def \
-memccpy.def    mempcpy.def \
+memccpy.def    mempcpy.def     stpcpy.def      stpncpy.def \
 wcscat.def     wcschr.def      wcscmp.def      wcscoll.def \
 wcscpy.def     wcscspn.def \
 wcslcat.def    wcslcpy.def     wcslen.def      wcsncat.def \
@@ -865,6 +870,18 @@ lib_a-mempcpy.o: mempcpy.c
 lib_a-mempcpy.obj: mempcpy.c
        $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mempcpy.obj `if test -f 'mempcpy.c'; then $(CYGPATH_W) 'mempcpy.c'; else $(CYGPATH_W) '$(srcdir)/mempcpy.c'; fi`
 
+lib_a-stpcpy.o: stpcpy.c
+       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpcpy.o `test -f 'stpcpy.c' || echo '$(srcdir)/'`stpcpy.c
+
+lib_a-stpcpy.obj: stpcpy.c
+       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpcpy.obj `if test -f 'stpcpy.c'; then $(CYGPATH_W) 'stpcpy.c'; else $(CYGPATH_W) '$(srcdir)/stpcpy.c'; fi`
+
+lib_a-stpncpy.o: stpncpy.c
+       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpncpy.o `test -f 'stpncpy.c' || echo '$(srcdir)/'`stpncpy.c
+
+lib_a-stpncpy.obj: stpncpy.c
+       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpncpy.obj `if test -f 'stpncpy.c'; then $(CYGPATH_W) 'stpncpy.c'; else $(CYGPATH_W) '$(srcdir)/stpncpy.c'; fi`
+
 lib_a-strndup.o: strndup.c
        $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strndup.o `test -f 'strndup.c' || echo '$(srcdir)/'`strndup.c
 
diff --git a/newlib/libc/string/stpcpy.c b/newlib/libc/string/stpcpy.c
new file mode 100644 (file)
index 0000000..62fe799
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+FUNCTION
+       <<stpcpy>>---copy string returning a pointer to its end
+
+INDEX
+       stpcpy
+
+ANSI_SYNOPSIS
+       #include <string.h>
+       char *stpcpy(char *<[dst]>, const char *<[src]>);
+
+TRAD_SYNOPSIS
+       #include <string.h>
+       char *stpcpy(<[dst]>, <[src]>)
+       char *<[dst]>;
+       char *<[src]>;
+
+DESCRIPTION
+       <<stpcpy>> copies the string pointed to by <[src]>
+       (including the terminating null character) to the array
+       pointed to by <[dst]>.
+
+RETURNS
+       This function returns a pointer to the end of the destination string,
+       thus pointing to the trailing '\0'.
+
+PORTABILITY
+<<stpcpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4.
+
+<<stpcpy>> requires no supporting OS subroutines.
+
+QUICKREF
+       stpcpy gnu
+*/
+
+#include <string.h>
+#include <limits.h>
+
+/*SUPPRESS 560*/
+/*SUPPRESS 530*/
+
+/* Nonzero if either X or Y is not aligned on a "long" boundary.  */
+#define UNALIGNED(X, Y) \
+  (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
+
+#if LONG_MAX == 2147483647L
+#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
+#else
+#if LONG_MAX == 9223372036854775807L
+/* Nonzero if X (a long int) contains a NULL byte. */
+#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
+#else
+#error long int is not a 32bit or 64bit type.
+#endif
+#endif
+
+#ifndef DETECTNULL
+#error long int is not a 32bit or 64bit byte
+#endif
+
+char*
+_DEFUN (stpcpy, (dst, src),
+       char *dst _AND
+       _CONST char *src)
+{
+#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
+  long *aligned_dst;
+  _CONST long *aligned_src;
+
+  /* If SRC or DEST is unaligned, then copy bytes.  */
+  if (!UNALIGNED (src, dst))
+    {
+      aligned_dst = (long*)dst;
+      aligned_src = (long*)src;
+
+      /* SRC and DEST are both "long int" aligned, try to do "long int"
+         sized copies.  */
+      while (!DETECTNULL(*aligned_src))
+        {
+          *aligned_dst++ = *aligned_src++;
+        }
+
+      dst = (char*)aligned_dst;
+      src = (char*)aligned_src;
+    }
+#endif /* not PREFER_SIZE_OVER_SPEED */
+
+  while ((*dst++ = *src++))
+    ;
+  return --dst;
+}
diff --git a/newlib/libc/string/stpncpy.c b/newlib/libc/string/stpncpy.c
new file mode 100644 (file)
index 0000000..fca10d3
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+FUNCTION
+       <<stpncpy>>---counted copy string returning a pointer to its end
+
+INDEX
+       stpncpy
+
+ANSI_SYNOPSIS
+       #include <string.h>
+       char *stpncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>);
+
+TRAD_SYNOPSIS
+       #include <string.h>
+       char *stpncpy(<[dst]>, <[src]>, <[length]>)
+       char *<[dst]>;
+       char *<[src]>;
+       size_t <[length]>;
+
+DESCRIPTION
+       <<stpncpy>> copies not more than <[length]> characters from the
+       the string pointed to by <[src]> (including the terminating
+       null character) to the array pointed to by <[dst]>.  If the
+       string pointed to by <[src]> is shorter than <[length]>
+       characters, null characters are appended to the destination
+       array until a total of <[length]> characters have been
+       written.
+
+RETURNS
+       This function returns a pointer to the end of the destination string,
+       thus pointing to the trailing '\0', or, if the destination string is
+       not null-terminated, pointing to dst + n.
+
+PORTABILITY
+<<stpncpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4.
+
+<<stpncpy>> requires no supporting OS subroutines.
+
+QUICKREF
+       stpncpy gnu
+*/
+
+#include <string.h>
+#include <limits.h>
+
+/*SUPPRESS 560*/
+/*SUPPRESS 530*/
+
+/* Nonzero if either X or Y is not aligned on a "long" boundary.  */
+#define UNALIGNED(X, Y) \
+  (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
+
+#if LONG_MAX == 2147483647L
+#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
+#else
+#if LONG_MAX == 9223372036854775807L
+/* Nonzero if X (a long int) contains a NULL byte. */
+#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
+#else
+#error long int is not a 32bit or 64bit type.
+#endif
+#endif
+
+#ifndef DETECTNULL
+#error long int is not a 32bit or 64bit byte
+#endif
+
+#define TOO_SMALL(LEN) ((LEN) < sizeof (long))
+
+char *
+_DEFUN (stpncpy, (dst, src),
+       char *dst _AND
+       _CONST char *src _AND
+       size_t count)
+{
+  char *ret = NULL;
+
+#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
+  long *aligned_dst;
+  _CONST long *aligned_src;
+
+  /* If SRC and DEST is aligned and count large enough, then copy words.  */
+  if (!UNALIGNED (src, dst) && !TOO_SMALL (count))
+    {
+      aligned_dst = (long*)dst;
+      aligned_src = (long*)src;
+
+      /* SRC and DEST are both "long int" aligned, try to do "long int"
+        sized copies.  */
+      while (count >= sizeof (long int) && !DETECTNULL(*aligned_src))
+       {
+         count -= sizeof (long int);
+         *aligned_dst++ = *aligned_src++;
+       }
+
+      dst = (char*)aligned_dst;
+      src = (char*)aligned_src;
+    }
+#endif /* not PREFER_SIZE_OVER_SPEED */
+
+  while (count > 0)
+    {
+      --count;
+      if ((*dst++ = *src++) == '\0')
+       {
+         ret = dst - 1;
+         break;
+       }
+    }
+
+  while (count-- > 0)
+    *dst++ = '\0';
+
+  return ret ? ret : dst;
+}
index 5d43fd56b790107dd5f7f4c4c048dac20f07ea71..5ba6e0fe5dd09ef2efe7d805d319e3388283af59 100644 (file)
@@ -18,6 +18,8 @@ managing areas of memory.  The corresponding declarations are in
 * mempcpy::    Copy memory regions and locate end
 * memset::      Set an area of memory
 * rindex::      Reverse search for character in string
+* stpcpy::      Copy string returning a pointer to its end
+* stpncpy::     Counted copy string returning a pointer to its end
 * strcasecmp:: Compare strings ignoring case
 * strcasestr:: Find string segment ignoring case
 * strcat::      Concatenate strings
@@ -81,6 +83,12 @@ managing areas of memory.  The corresponding declarations are in
 @page
 @include string/rindex.def
 
+@page
+@include string/stpcpy.def
+
+@page
+@include string/stpncpy.def
+
 @page
 @include string/strcasecmp.def
 
This page took 0.055917 seconds and 5 git commands to generate.