home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / STRDUP.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  566b  |  31 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Portable, public domain strdup() by Bob Stout
  5. */
  6.  
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "snip_str.h"
  10.  
  11. #if defined(__cplusplus) && __cplusplus
  12.  extern "C" {
  13. #endif
  14.  
  15. char *strdup(const char *string)
  16. {
  17.       char *newstring;
  18.  
  19.       if (string)
  20.       {
  21.             if (NULL != (newstring = malloc(strlen(string) + 1)))
  22.                   strcpy(newstring, string);
  23.             return newstring;
  24.       }
  25.       else  return NULL;
  26. }
  27.  
  28. #if defined(__cplusplus) && __cplusplus
  29.  }
  30. #endif
  31.