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