home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / wcsdup.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  56 lines

  1. /***
  2. *wcsdup.c - duplicate a wide-character string in malloc'd memory
  3. *
  4. *       Copyright (c) 1985-1997, 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. *******************************************************************************/
  11.  
  12.  
  13. #include <cruntime.h>
  14. #include <malloc.h>
  15. #include <string.h>
  16.  
  17. /***
  18. *wchar_t *_wcsdup(string) - duplicate string into malloc'd memory
  19. *
  20. *Purpose:
  21. *       Allocates enough storage via malloc() for a copy of the
  22. *       string, copies the string into the new memory, and returns
  23. *       a pointer to it (wide-character).
  24. *
  25. *Entry:
  26. *       wchar_t *string - string to copy into new memory
  27. *
  28. *Exit:
  29. *       returns a pointer to the newly allocated storage with the
  30. *       string in it.
  31. *
  32. *       returns NULL if enough memory could not be allocated, or
  33. *       string was NULL.
  34. *
  35. *Uses:
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40.  
  41. wchar_t * __cdecl _wcsdup (
  42.         const wchar_t * string
  43.         )
  44. {
  45.         wchar_t *memory;
  46.  
  47.         if (!string)
  48.                 return(NULL);
  49.  
  50.         if (memory = (wchar_t *) malloc((wcslen(string)+1) * sizeof(wchar_t)))
  51.                 return(wcscpy(memory,string));
  52.  
  53.         return(NULL);
  54. }
  55.  
  56.