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.

63 lines
1.5 KiB

  1. /***
  2. *wcsdup.c - duplicate a wide-character string in malloc'd memory
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _wcsdup() - grab new memory, and duplicate the string into it
  8. * (wide-character).
  9. *
  10. *Revision History:
  11. * 09-09-91 ETC Created from strdup.c.
  12. * 04-07-92 KRS Updated and ripped out _INTL switches.
  13. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  14. * 02-07-94 CFW POSIXify.
  15. *
  16. *******************************************************************************/
  17. #ifndef _POSIX_
  18. #include <cruntime.h>
  19. #include <malloc.h>
  20. #include <string.h>
  21. /***
  22. *wchar_t *_wcsdup(string) - duplicate string into malloc'd memory
  23. *
  24. *Purpose:
  25. * Allocates enough storage via malloc() for a copy of the
  26. * string, copies the string into the new memory, and returns
  27. * a pointer to it (wide-character).
  28. *
  29. *Entry:
  30. * wchar_t *string - string to copy into new memory
  31. *
  32. *Exit:
  33. * returns a pointer to the newly allocated storage with the
  34. * string in it.
  35. *
  36. * returns NULL if enough memory could not be allocated, or
  37. * string was NULL.
  38. *
  39. *Uses:
  40. *
  41. *Exceptions:
  42. *
  43. *******************************************************************************/
  44. wchar_t * __cdecl _wcsdup (
  45. const wchar_t * string
  46. )
  47. {
  48. wchar_t *memory;
  49. if (!string)
  50. return(NULL);
  51. if (memory = (wchar_t *) malloc((wcslen(string)+1) * sizeof(wchar_t)))
  52. return(wcscpy(memory,string));
  53. return(NULL);
  54. }
  55. #endif /* _POSIX_ */