]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/xmemdup.c
pex-common.c: New file.
[thirdparty/gcc.git] / libiberty / xmemdup.c
CommitLineData
b10647f1
JG
1/* xmemdup.c -- Duplicate a memory buffer, using xcalloc.
2 This trivial function is in the public domain.
3 Jeff Garzik, September 1999. */
4
aaa5f039
DD
5/*
6
7@deftypefn Replacement void* xmemdup (void *@var{input}, size_t @var{copy_size}, size_t @var{alloc_size})
8
9Duplicates a region of memory without fail. First, @var{alloc_size} bytes
10are allocated, then @var{copy_size} bytes from @var{input} are copied into
11it, and the new memory is returned. If fewer bytes are copied than were
12allocated, the remaining memory is zeroed.
13
14@end deftypefn
15
16*/
17
b10647f1
JG
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21#include "ansidecl.h"
22#include "libiberty.h"
23
33c5ddcd 24#include <sys/types.h> /* For size_t. */
d11ec6f0
ZW
25#ifdef HAVE_STRING_H
26#include <string.h>
bb99744f
KG
27#else
28# ifdef HAVE_STRINGS_H
29# include <strings.h>
30# endif
d11ec6f0 31#endif
33c5ddcd 32
b10647f1 33PTR
7a17ef5e 34xmemdup (const PTR input, size_t copy_size, size_t alloc_size)
b10647f1
JG
35{
36 PTR output = xcalloc (1, alloc_size);
bb99744f 37 return (PTR) memcpy (output, input, copy_size);
b10647f1 38}