source: branches/libc-0.6/src/binutils/libiberty/xmemdup.c

Last change on this file was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 928 bytes
Line 
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
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
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21#include "ansidecl.h"
22#include "libiberty.h"
23
24#include <sys/types.h> /* For size_t. */
25#ifdef HAVE_STRING_H
26#include <string.h>
27#endif
28
29PTR
30xmemdup (input, copy_size, alloc_size)
31 const PTR input;
32 size_t copy_size;
33 size_t alloc_size;
34{
35 PTR output = xcalloc (1, alloc_size);
36 memcpy (output, input, copy_size);
37 return output;
38}
Note: See TracBrowser for help on using the repository browser.