133965Sjdp/* xstrdup.c -- Duplicate a string in memory, using xmalloc. 233965Sjdp This trivial function is in the public domain. 333965Sjdp Ian Lance Taylor, Cygnus Support, December 1995. */ 433965Sjdp 589857Sobrien/* 689857Sobrien 789857Sobrien@deftypefn Replacement char* xstrdup (const char *@var{s}) 889857Sobrien 989857SobrienDuplicates a character string without fail, using @code{xmalloc} to 1089857Sobrienobtain memory. 1189857Sobrien 1289857Sobrien@end deftypefn 1389857Sobrien 1489857Sobrien*/ 1589857Sobrien 1660484Sobrien#include <sys/types.h> 1760484Sobrien#ifdef HAVE_CONFIG_H 1860484Sobrien#include "config.h" 1960484Sobrien#endif 2060484Sobrien#ifdef HAVE_STRING_H 2160484Sobrien#include <string.h> 22218822Sdim#else 23218822Sdim# ifdef HAVE_STRINGS_H 24218822Sdim# include <strings.h> 25218822Sdim# endif 2660484Sobrien#endif 2733965Sjdp#include "ansidecl.h" 2833965Sjdp#include "libiberty.h" 2933965Sjdp 3033965Sjdpchar * 31218822Sdimxstrdup (const char *s) 3233965Sjdp{ 3360484Sobrien register size_t len = strlen (s) + 1; 34218822Sdim register char *ret = XNEWVEC (char, len); 35218822Sdim return (char *) memcpy (ret, s, len); 3633965Sjdp} 37