PATCH to add xmemdup to libiberty

Jeff Garzik garzik@havoc.gtf.org
Tue Sep 7 13:40:00 GMT 1999


The changes below add 'xmemdup' to libiberty.  Four attachments:
o include/ChangeLog entry
o libiberty/ChangeLog entry
o libiberty/xmemdup.c file
o patch to egcs/include and egcs/libiberty



1999-09-07  Jeff Garzik  <jgarzik@pobox.com>

	* libiberty.h (xmemdup): Add prototype for new function.




1999-09-07  Jeff Garzik  <jgarzik@pobox.com>

	* xmemdup.c:  New xmemdup function.
	* Makefile.in, makefile.vms, vmsbuild.com:  Use xmemdup.[co].








/* xmemdup.c -- Duplicate a memory buffer, using xcalloc.
   This trivial function is in the public domain.
   Jeff Garzik, September 1999.  */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ansidecl.h"
#include "libiberty.h"

PTR
xmemdup (input, copy_size, alloc_size)
  const PTR input;
  size_t copy_size;
  size_t alloc_size;
{
  PTR output = xcalloc (1, alloc_size);
  memcpy (output, input, copy_size);
  return output;
}









Index: include/libiberty.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/include/libiberty.h,v
retrieving revision 1.6
diff -u -r1.6 libiberty.h
--- libiberty.h	1999/08/31 00:52:57	1.6
+++ libiberty.h	1999/09/07 20:35:47
@@ -149,6 +149,10 @@
 
 extern char *xstrdup PARAMS ((const char *));
 
+/* Copy an existing memory buffer to a new memory buffer without fail.  */
+
+extern PTR xmemdup PARAMS ((const PTR, size_t, size_t));
+
 /* hex character manipulation routines */
 
 #define _hex_array_size 256
Index: libiberty/Makefile.in
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/libiberty/Makefile.in,v
retrieving revision 1.29
diff -u -r1.29 Makefile.in
--- Makefile.in	1999/08/31 00:50:36	1.29
+++ Makefile.in	1999/09/07 20:35:47
@@ -129,14 +129,14 @@
 	spaces.c splay-tree.c strcasecmp.c strncasecmp.c strchr.c strdup.c \
 	strerror.c strrchr.c strsignal.c strstr.c strtod.c strtol.c strtoul.c \
 	tmpnam.c vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c \
-	waitpid.c xatexit.c xexit.c xmalloc.c xstrdup.c xstrerror.c
+	waitpid.c xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
 
 # These are always included in the library.
 REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o \
   fdmatch.o fnmatch.o getopt.o getopt1.o getpwd.o getruntime.o hex.o \
   floatformat.o objalloc.o obstack.o pexecute.o spaces.o \
   splay-tree.o strerror.o strsignal.o xatexit.o xexit.o xmalloc.o \
-  xstrdup.o xstrerror.o
+  xmemdup.o xstrdup.o xstrerror.o
 
 $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) $(ALLOCA)
 	rm -f $(TARGETLIB)
@@ -270,5 +270,6 @@
 xatexit.o: $(INCDIR)/libiberty.h
 xexit.o: $(INCDIR)/libiberty.h
 xmalloc.o: $(INCDIR)/libiberty.h
+xmemdup.o: config.h $(INCDIR)/libiberty.h
 xstrdup.o: config.h $(INCDIR)/libiberty.h
 xstrerror.o: config.h $(INCDIR)/libiberty.h
Index: libiberty/makefile.vms
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/libiberty/makefile.vms,v
retrieving revision 1.3
diff -u -r1.3 makefile.vms
--- makefile.vms	1998/05/15 23:42:39	1.3
+++ makefile.vms	1999/09/07 20:35:47
@@ -10,7 +10,7 @@
 OBJS=bcopy.obj,bcmp.obj,getopt.obj,obstack.obj,xexit.obj,xmalloc.obj,hex.obj,\
    getopt1.obj,cplus-dem.obj,strncasecmp.obj,strcasecmp.obj,strdup.obj,\
    concat.obj,getruntime.obj,getpagesize.obj,alloca.obj,xstrerror.obj,\
-   xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,objalloc.obj
+   xmemdup.obj,xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,objalloc.obj
 
 ifeq ($(CC),gcc)
 CFLAGS=/include=([],[-.include])
Index: libiberty/vmsbuild.com
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/libiberty/vmsbuild.com,v
retrieving revision 1.4
diff -u -r1.4 vmsbuild.com
--- vmsbuild.com	1998/05/15 23:42:43	1.4
+++ vmsbuild.com	1999/09/07 20:35:48
@@ -15,7 +15,7 @@
 $ REQUIRED_OFILES = "argv.o basename.o choose-temp.o concat.o cplus-dem.o "-
 	+ "fdmatch.o fnmatch.o getopt.o getopt1.o getruntime.o hex.o "-
 	+ "floatformat.o objalloc.o obstack.o spaces.o strerror.o strsignal.o "-
-	+ "xatexit.o xexit.o xmalloc.o xstrdup.o xstrerror.o"
+	+ "xatexit.o xexit.o xmalloc.o xmemdup.o xstrdup.o xstrerror.o"
 $! anything not caught by link+search of dummy.* should be added here
 $ EXTRA_OFILES = ""
 $!


More information about the Gcc-patches mailing list