Mercurial > hg > CbC > CbC_gcc
annotate libiberty/xmemdup.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | a06113de4d67 |
children | 04ced10e8804 |
rev | line source |
---|---|
0 | 1 /* xmemdup.c -- Duplicate a memory buffer, using xcalloc. |
2 This trivial function is in the public domain. | |
3 Jeff Garzik, September 1999. */ | |
4 | |
5 /* | |
6 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
7 @deftypefn Replacement void* xmemdup (void *@var{input}, @ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
8 size_t @var{copy_size}, size_t @var{alloc_size}) |
0 | 9 |
10 Duplicates a region of memory without fail. First, @var{alloc_size} bytes | |
11 are allocated, then @var{copy_size} bytes from @var{input} are copied into | |
12 it, and the new memory is returned. If fewer bytes are copied than were | |
13 allocated, the remaining memory is zeroed. | |
14 | |
15 @end deftypefn | |
16 | |
17 */ | |
18 | |
19 #ifdef HAVE_CONFIG_H | |
20 #include "config.h" | |
21 #endif | |
22 #include "ansidecl.h" | |
23 #include "libiberty.h" | |
24 | |
25 #include <sys/types.h> /* For size_t. */ | |
26 #ifdef HAVE_STRING_H | |
27 #include <string.h> | |
28 #else | |
29 # ifdef HAVE_STRINGS_H | |
30 # include <strings.h> | |
31 # endif | |
32 #endif | |
33 | |
34 PTR | |
35 xmemdup (const PTR input, size_t copy_size, size_t alloc_size) | |
36 { | |
37 PTR output = xcalloc (1, alloc_size); | |
38 return (PTR) memcpy (output, input, copy_size); | |
39 } |