Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

  1. /***
  2. *strdup.c - duplicate a string in malloc'd memory
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _strdup() - grab new memory, and duplicate the string into it.
  8. *
  9. *Revision History:
  10. * 05-31-89 JCR C version created.
  11. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  12. * copyright.
  13. * 08-14-90 SBM Removed now redundant #include <stddef.h>
  14. * 10-02-90 GJF New-style function declarator.
  15. * 01-18-91 GJF ANSI naming.
  16. * 09-02-93 GJF Replaced _CALLTYPE1 with __cdecl.
  17. *
  18. *******************************************************************************/
  19. #include <cruntime.h>
  20. #include <malloc.h>
  21. #include <string.h>
  22. /***
  23. *char *_strdup(string) - duplicate string into malloc'd memory
  24. *
  25. *Purpose:
  26. * Allocates enough storage via malloc() for a copy of the
  27. * string, copies the string into the new memory, and returns
  28. * a pointer to it.
  29. *
  30. *Entry:
  31. * char *string - string to copy into new memory
  32. *
  33. *Exit:
  34. * returns a pointer to the newly allocated storage with the
  35. * string in it.
  36. *
  37. * returns NULL if enough memory could not be allocated, or
  38. * string was NULL.
  39. *
  40. *Uses:
  41. *
  42. *Exceptions:
  43. *
  44. *******************************************************************************/
  45. char * __cdecl _strdup (
  46. const char * string
  47. )
  48. {
  49. char *memory;
  50. if (!string)
  51. return(NULL);
  52. if (memory = malloc(strlen(string) + 1))
  53. return(strcpy(memory,string));
  54. return(NULL);
  55. }