12a6b7db3Sskrll /* xstrdup.c -- Duplicate a string in memory, using xmalloc.
22a6b7db3Sskrll    This trivial function is in the public domain.
32a6b7db3Sskrll    Ian Lance Taylor, Cygnus Support, December 1995.  */
42a6b7db3Sskrll 
52a6b7db3Sskrll /*
62a6b7db3Sskrll 
72a6b7db3Sskrll @deftypefn Replacement char* xstrdup (const char *@var{s})
82a6b7db3Sskrll 
92a6b7db3Sskrll Duplicates a character string without fail, using @code{xmalloc} to
102a6b7db3Sskrll obtain memory.
112a6b7db3Sskrll 
122a6b7db3Sskrll @end deftypefn
132a6b7db3Sskrll 
142a6b7db3Sskrll */
152a6b7db3Sskrll 
162a6b7db3Sskrll #ifdef HAVE_CONFIG_H
172a6b7db3Sskrll #include "config.h"
182a6b7db3Sskrll #endif
19*b3ac4aedSchristos #include <sys/types.h>
202a6b7db3Sskrll #ifdef HAVE_STRING_H
212a6b7db3Sskrll #include <string.h>
222a6b7db3Sskrll #else
232a6b7db3Sskrll # ifdef HAVE_STRINGS_H
242a6b7db3Sskrll #  include <strings.h>
252a6b7db3Sskrll # endif
262a6b7db3Sskrll #endif
272a6b7db3Sskrll #include "ansidecl.h"
282a6b7db3Sskrll #include "libiberty.h"
292a6b7db3Sskrll 
302a6b7db3Sskrll char *
xstrdup(const char * s)312a6b7db3Sskrll xstrdup (const char *s)
322a6b7db3Sskrll {
332a6b7db3Sskrll   register size_t len = strlen (s) + 1;
342a6b7db3Sskrll   register char *ret = XNEWVEC (char, len);
352a6b7db3Sskrll   return (char *) memcpy (ret, s, len);
362a6b7db3Sskrll }
37