Source code of Windows XP (NT5)
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. *wcsncpy.c - copy at most n characters of wide-character string
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines wcsncpy() - copy at most n characters of wchar_t string
  8. *
  9. *Revision History:
  10. * 09-09-91 ETC Created from strncpy.c.
  11. * 04-07-92 KRS Updated and ripped out _INTL switches.
  12. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  13. * 02-07-94 CFW POSIXify.
  14. *
  15. *******************************************************************************/
  16. #ifndef _POSIX_
  17. #include <cruntime.h>
  18. #include <string.h>
  19. /***
  20. *wchar_t *wcsncpy(dest, source, count) - copy at most n wide characters
  21. *
  22. *Purpose:
  23. * Copies count characters from the source string to the
  24. * destination. If count is less than the length of source,
  25. * NO NULL CHARACTER is put onto the end of the copied string.
  26. * If count is greater than the length of sources, dest is padded
  27. * with null characters to length count (wide-characters).
  28. *
  29. *
  30. *Entry:
  31. * wchar_t *dest - pointer to destination
  32. * wchar_t *source - source string for copy
  33. * size_t count - max number of characters to copy
  34. *
  35. *Exit:
  36. * returns dest
  37. *
  38. *Exceptions:
  39. *
  40. *******************************************************************************/
  41. wchar_t * __cdecl wcsncpy (
  42. wchar_t * dest,
  43. const wchar_t * source,
  44. size_t count
  45. )
  46. {
  47. wchar_t *start = dest;
  48. while (count && (*dest++ = *source++)) /* copy string */
  49. count--;
  50. if (count) /* pad out with zeroes */
  51. while (--count)
  52. *dest++ = L'\0';
  53. return(start);
  54. }
  55. #endif /* _POSIX_ */