/* estrdup.c -- duplicate a string, die if error * * char *string; * char *newstring; * newstring = estrdup(string); * * estrdup returns a copy of its argument, located in memory * allocated from the heap. If it is unable to allocate the * necessary memory, estrdup executes error("no memory"). * (Generally, the routine error is not expected to return, * but if it does, estrdup will return NULL.) */ #include char *malloc(); int strlen(); char * estrdup(s) char *s; { register char *t; if (NULL == (t = malloc(strlen(s)+1))) { error("no memory"); return(NULL); } strcpy(t, s); return(t); }