1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/***
6*tcscpy_s.inl - general implementation of _tcscpy_s
7*
8
9*
10*Purpose:
11* This file contains the general algorithm for strcpy_s and its variants.
12*
13****/
14
15_FUNC_PROLOGUE
16errno_t __cdecl _FUNC_NAME(_CHAR *_DEST, size_t _SIZE, const _CHAR *_SRC)
17{
18 _CHAR *p;
19 size_t available;
20
21 /* validation section */
22 _VALIDATE_STRING(_DEST, _SIZE);
23 _VALIDATE_POINTER_RESET_STRING(_SRC, _DEST, _SIZE);
24
25 p = _DEST;
26 available = _SIZE;
27 while ((*p++ = *_SRC++) != 0 && --available > 0)
28 {
29 }
30
31 if (available == 0)
32 {
33 _RESET_STRING(_DEST, _SIZE);
34 _RETURN_BUFFER_TOO_SMALL(_DEST, _SIZE);
35 }
36 _FILL_STRING(_DEST, _SIZE, _SIZE - available + 1);
37 _RETURN_NO_ERROR;
38}
39
40