Back to index

cell-binutils  2.17cvs20070401
xstrdup.c
Go to the documentation of this file.
00001 /* xstrdup.c -- Duplicate a string in memory, using xmalloc.
00002    This trivial function is in the public domain.
00003    Ian Lance Taylor, Cygnus Support, December 1995.  */
00004 
00005 /*
00006 
00007 @deftypefn Replacement char* xstrdup (const char *@var{s})
00008 
00009 Duplicates a character string without fail, using @code{xmalloc} to
00010 obtain memory.
00011 
00012 @end deftypefn
00013 
00014 */
00015 
00016 #include <sys/types.h>
00017 #ifdef HAVE_CONFIG_H
00018 #include "config.h"
00019 #endif
00020 #ifdef HAVE_STRING_H
00021 #include <string.h>
00022 #else
00023 # ifdef HAVE_STRINGS_H
00024 #  include <strings.h>
00025 # endif
00026 #endif
00027 #include "ansidecl.h"
00028 #include "libiberty.h"
00029 
00030 char *
00031 xstrdup (const char *s)
00032 {
00033   register size_t len = strlen (s) + 1;
00034   register char *ret = XNEWVEC (char, len);
00035   return (char *) memcpy (ret, s, len);
00036 }