home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / cutils / C / Strdup < prev    next >
Encoding:
Text File  |  1990-07-15  |  349 b   |  21 lines

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