home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / utilslib / c / Strdup < prev    next >
Encoding:
Text File  |  1992-12-23  |  412 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.