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