home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / unixtools / util / c / strdup < prev    next >
Text File  |  1992-07-21  |  355b  |  17 lines

  1. /*      > C.Strdup     - save a string on the heap; return pointer to it */
  2.  
  3. #include <string.h>
  4. #include <stddef.h>
  5. #include <stdlib.h>
  6. #include "utils.h"
  7.  
  8. char *strdup (const char *str)
  9. {
  10.         char *p = malloc(strlen(str)+1);
  11.  
  12.         if ( p == NULL )
  13.                 fatal(1,"Not enough memory to save string\n");
  14.  
  15.         return (strcpy(p,str));
  16. }
  17.