tcscpy_s.inl 875 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  4. //
  5. /***
  6. *tcscpy_s.inl - general implementation of _tcscpy_s
  7. *
  8. *
  9. *Purpose:
  10. * This file contains the general algorithm for strcpy_s and its variants.
  11. *
  12. ****/
  13. _FUNC_PROLOGUE
  14. errno_t __cdecl _FUNC_NAME(_CHAR *_DEST, size_t _SIZE, const _CHAR *_SRC)
  15. {
  16. _CHAR *p;
  17. size_t available;
  18. /* validation section */
  19. _VALIDATE_STRING(_DEST, _SIZE);
  20. _VALIDATE_POINTER_RESET_STRING(_SRC, _DEST, _SIZE);
  21. p = _DEST;
  22. available = _SIZE;
  23. while ((*p++ = *_SRC++) != 0 && --available > 0)
  24. {
  25. }
  26. if (available == 0)
  27. {
  28. _RESET_STRING(_DEST, _SIZE);
  29. _RETURN_BUFFER_TOO_SMALL(_DEST, _SIZE);
  30. }
  31. _FILL_STRING(_DEST, _SIZE, _SIZE - available + 1);
  32. _RETURN_NO_ERROR;
  33. }