~ubuntu-branches/ubuntu/hoary/binutils/hoary

« back to all changes in this revision

Viewing changes to libiberty/xstrdup.c

  • Committer: Bazaar Package Importer
  • Author(s): James Troup
  • Date: 2004-05-19 10:35:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040519103544-17h3o6e8pwndydrg
Tags: 2.14.90.0.7-8
debian/rules: don't use gcc-2.95 on m68k.  Thanks to Adam Conrad for
pointing this out.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* xstrdup.c -- Duplicate a string in memory, using xmalloc.
 
2
   This trivial function is in the public domain.
 
3
   Ian Lance Taylor, Cygnus Support, December 1995.  */
 
4
 
 
5
/*
 
6
 
 
7
@deftypefn Replacement char* xstrdup (const char *@var{s})
 
8
 
 
9
Duplicates a character string without fail, using @code{xmalloc} to
 
10
obtain memory.
 
11
 
 
12
@end deftypefn
 
13
 
 
14
*/
 
15
 
 
16
#include <sys/types.h>
 
17
#ifdef HAVE_CONFIG_H
 
18
#include "config.h"
 
19
#endif
 
20
#ifdef HAVE_STRING_H
 
21
#include <string.h>
 
22
#endif
 
23
#include "ansidecl.h"
 
24
#include "libiberty.h"
 
25
 
 
26
char *
 
27
xstrdup (s)
 
28
  const char *s;
 
29
{
 
30
  register size_t len = strlen (s) + 1;
 
31
  register char *ret = xmalloc (len);
 
32
  memcpy (ret, s, len);
 
33
  return ret;
 
34
}