Patch to add mempcpy and stpcpy to libiberty

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Wed Apr 16 02:35:00 GMT 2003


 > From: DJ Delorie <dj@redhat.com>
 > 
 > > This patch adds two new functions, mempcpy and stpcpy to libiberty.
 > > Given the sizes of the function bodies, (one and two lines
 > > respectively) I wasn't sure whether they were copyrightable.  If they
 > > are, let me know and I'll use the LGPL.  (My disclaimer for LIBIBERTY
 > > is in place if that's an issue.)
 > 
 > A two-line change might not be, but a wholly new file would be.  It
 > certainly wouldn't hurt to add it.
 > 
 > > Ok for mainline?
 > 
 > Could you please add doc fragments too, and update the .texi files?
 > You'll have to configure with --enable-maintainer-mode, then just
 > "make" should do it.


Ok, here's the updated patch.  I randomly selected argv.c and copied
the LGPL in there to the new files.  I added doc fragments.  And for
completeness sake, I also added the stpncpy function.

Tested with "make libiberty.a", and the doc bits were tested with
"make libiberty.info" on sparc-sun-solaris2.7.

Ok for mainline?

		Thanks,
		--Kaveh



2003-04-15  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* mempcpy.c, stpcpy.c, stpncpy.c: New files.
	* configure.in (funcs, AC_CHECK_FUNCS): Add mempcpy, stpcpy
	and stpncpy.
	* Makefile.in (CFILES): Add mempcpy.c, stpcpy.c and stpncpy.c.
	(CONFIGURED_OFILES): Add mempcpy.o, stpcpy.o and stpncpy.o.
	Regenerate dependencies.

	* functions.texi, configure, config.in: Regenerated.

diff -rup orig/egcc-CVS20030415/libiberty/mempcpy.c egcc-CVS20030415/libiberty/mempcpy.c
--- orig/egcc-CVS20030415/libiberty/mempcpy.c	2003-04-15 16:19:05.497925000 -0400
+++ egcc-CVS20030415/libiberty/mempcpy.c	2003-04-15 16:26:08.965037000 -0400
@@ -0,0 +1,48 @@
+/* Implement the mempcpy function.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/*
+
+@deftypefn Supplemental void* mempcpy (void *@var{out}, const void *@var{in}, size_t @var{length})
+
+Copies @var{length} bytes from memory region @var{in} to region
+@var{out}.  Returns a pointer to @var{out} + @var{length}.
+
+@end deftypefn
+
+*/
+
+#include <ansidecl.h>
+#ifdef ANSI_PROTOTYPES
+#include <stddef.h>
+#else
+#define size_t unsigned long
+#endif
+
+extern PTR memcpy PARAMS ((PTR, const PTR, size_t));
+
+PTR
+mempcpy (dst, src, len)
+     PTR dst;
+     const PTR src;
+     size_t len;
+{
+  return (char *) memcpy (dst, src, len) + len;
+}
diff -rup orig/egcc-CVS20030415/libiberty/stpcpy.c egcc-CVS20030415/libiberty/stpcpy.c
--- orig/egcc-CVS20030415/libiberty/stpcpy.c	2003-04-15 16:19:13.947269000 -0400
+++ egcc-CVS20030415/libiberty/stpcpy.c	2003-04-15 16:40:22.759512000 -0400
@@ -0,0 +1,49 @@
+/* Implement the stpcpy function.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/*
+
+@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
+
+Copies the string @var{src} into @var{dst}.  Returns a pointer to
+@var{dst} + strlen(@var{src}).
+
+@end deftypefn
+
+*/
+
+#include <ansidecl.h>
+#ifdef ANSI_PROTOTYPES
+#include <stddef.h>
+#else
+#define size_t unsigned long
+#endif
+
+extern size_t strlen PARAMS ((const char *));
+extern PTR memcpy PARAMS ((PTR, const PTR, size_t));
+
+char *
+stpcpy (dst, src)
+     char *dst;
+     const char *src;
+{
+  const size_t len = strlen (src);
+  return (char *) memcpy (dst, src, len + 1) + len;
+}
diff -rup orig/egcc-CVS20030415/libiberty/stpncpy.c egcc-CVS20030415/libiberty/stpncpy.c
--- orig/egcc-CVS20030415/libiberty/stpncpy.c	2003-04-15 22:10:43.183053000 -0400
+++ egcc-CVS20030415/libiberty/stpncpy.c	2003-04-15 22:07:37.206655000 -0400
@@ -0,0 +1,54 @@
+/* Implement the stpncpy function.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/*
+
+@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, size_t @var{len})
+
+Copies the string @var{src} into @var{dst}, copying exactly @var{len}
+and padding with zeros if necessary.  If @var{len} < strlen(@var{src})
+then return @var{dst} + @var{len}, otherwise returns @var{dst} +
+strlen(@var{src}).
+
+@end deftypefn
+
+*/
+
+#include <ansidecl.h>
+#ifdef ANSI_PROTOTYPES
+#include <stddef.h>
+#else
+#define size_t unsigned long
+#endif
+
+extern size_t strlen PARAMS ((const char *));
+extern PTR strncpy PARAMS ((char *, const char *, size_t));
+
+char *
+stpncpy (dst, src, len)
+     char *dst;
+     const char *src;
+     size_t len;
+{
+  size_t n = strlen (src);
+  if (n > len)
+    n = len;
+  return strncpy (dst, src, len) + n;
+}
diff -rup orig/egcc-CVS20030415/libiberty/configure.in egcc-CVS20030415/libiberty/configure.in
--- orig/egcc-CVS20030415/libiberty/configure.in	2003-04-14 10:24:36.000000000 -0400
+++ egcc-CVS20030415/libiberty/configure.in	2003-04-15 22:09:29.659699000 -0400
@@ -177,6 +177,7 @@ funcs="$funcs memchr"
 funcs="$funcs memcmp"
 funcs="$funcs memcpy"
 funcs="$funcs memmove"
+funcs="$funcs mempcpy"
 funcs="$funcs memset"
 funcs="$funcs mkstemps"
 funcs="$funcs putenv"
@@ -185,6 +186,8 @@ funcs="$funcs rename"
 funcs="$funcs rindex"
 funcs="$funcs setenv"
 funcs="$funcs sigsetmask"
+funcs="$funcs stpcpy"
+funcs="$funcs stpncpy"
 funcs="$funcs strcasecmp"
 funcs="$funcs strchr"
 funcs="$funcs strdup"
@@ -214,8 +217,8 @@ checkfuncs="$checkfuncs getsysinfo table
 if test "x" = "y"; then
   AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bsearch bzero calloc clock)
   AC_CHECK_FUNCS(getcwd getpagesize index insque mkstemps memchr memcmp memcpy)
-  AC_CHECK_FUNCS(memmove memset putenv random rename rindex sigsetmask)
-  AC_CHECK_FUNCS(strcasecmp setenv strchr strdup strncasecmp strrchr strstr)
+  AC_CHECK_FUNCS(memmove mempcpy memset putenv random rename rindex sigsetmask)
+  AC_CHECK_FUNCS(strcasecmp setenv stpcpy stpncpy strchr strdup strncasecmp strrchr strstr)
   AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
   AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
   AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
diff -rup orig/egcc-CVS20030415/libiberty/Makefile.in egcc-CVS20030415/libiberty/Makefile.in
--- orig/egcc-CVS20030415/libiberty/Makefile.in	2003-04-15 16:18:21.911446000 -0400
+++ egcc-CVS20030415/libiberty/Makefile.in	2003-04-15 22:11:54.987793000 -0400
@@ -140,7 +140,7 @@ CFILES = alloca.c argv.c asprintf.c atex
 	lrealpath.c							\
 	make-relative-prefix.c						\
 	make-temp-file.c md5.c memchr.c memcmp.c memcpy.c memmove.c	\
-	 memset.c mkstemps.c						\
+	 mempcpy.c memset.c mkstemps.c					\
 	objalloc.c obstack.c						\
 	partition.c							\
 	 pex-djgpp.c pex-mpw.c pex-msdos.c pex-os2.c			\
@@ -148,9 +148,9 @@ CFILES = alloca.c argv.c asprintf.c atex
          physmem.c putenv.c						\
 	random.c regex.c rename.c rindex.c				\
 	safe-ctype.c setenv.c sigsetmask.c sort.c spaces.c		\
-	 splay-tree.c strcasecmp.c strchr.c strdup.c strerror.c		\
-	 strncasecmp.c strncmp.c strrchr.c strsignal.c strstr.c		\
-	 strtod.c strtol.c strtoul.c					\
+	 splay-tree.c stpcpy.c stpncpy.c strcasecmp.c strchr.c strdup.c	\
+	 strerror.c strncasecmp.c strncmp.c strrchr.c strsignal.c	\
+	 strstr.c strtod.c strtol.c strtoul.c				\
 	ternary.c tmpnam.c						\
 	vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c		\
 	waitpid.c							\
@@ -186,14 +186,14 @@ CONFIGURED_OFILES = asprintf.o atexit.o	
 	ffs.o								\
 	getcwd.o getpagesize.o						\
 	index.o insque.o						\
-	memchr.o memcmp.o memcpy.o memmove.o memset.o mkstemps.o	\
+	memchr.o memcmp.o memcpy.o memmove.o mempcpy.o memset.o mkstemps.o \
 	pex-djgpp.o pex-mpw.o pex-msdos.o pex-os2.o			\
 	 pex-unix.o pex-win32.o						\
 	 putenv.o							\
 	random.o rename.o rindex.o					\
-	setenv.o sigsetmask.o strcasecmp.o strchr.o strdup.o		\
-	 strncasecmp.o strncmp.o strrchr.o strstr.o strtod.o strtol.o	\
-	 strtoul.o							\
+	setenv.o sigsetmask.o stpcpy.o stpncpy.o strcasecmp.o strchr.o	\
+	 strdup.o strncasecmp.o strncmp.o strrchr.o strstr.o strtod.o	\
+	 strtol.o strtoul.o						\
 	tmpnam.o							\
 	vasprintf.o vfork.o vfprintf.o vprintf.o vsprintf.o		\
 	waitpid.o
@@ -459,6 +459,7 @@ memchr.o: $(INCDIR)/ansidecl.h
 memcmp.o: $(INCDIR)/ansidecl.h
 memcpy.o: $(INCDIR)/ansidecl.h
 memmove.o: $(INCDIR)/ansidecl.h
+mempcpy.o: $(INCDIR)/ansidecl.h
 memset.o: $(INCDIR)/ansidecl.h
 mkstemps.o: config.h $(INCDIR)/ansidecl.h
 objalloc.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/objalloc.h
@@ -490,6 +491,8 @@ sort.o: config.h $(INCDIR)/ansidecl.h $(
 spaces.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
 splay-tree.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
 	$(INCDIR)/splay-tree.h
+stpcpy.o: $(INCDIR)/ansidecl.h
+stpncpy.o: $(INCDIR)/ansidecl.h
 strcasecmp.o: $(INCDIR)/ansidecl.h
 strchr.o: $(INCDIR)/ansidecl.h
 strdup.o: $(INCDIR)/ansidecl.h



More information about the Gcc-patches mailing list