| 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 | *tcscat_s.inl - general implementation of _tcscpy_s |
| 7 | * |
| 8 | |
| 9 | * |
| 10 | *Purpose: |
| 11 | * This file contains the general algorithm for strcat_s and its variants. |
| 12 | * |
| 13 | ****/ |
| 14 | |
| 15 | _FUNC_PROLOGUE |
| 16 | errno_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 (available > 0 && *p != 0) |
| 28 | { |
| 29 | p++; |
| 30 | available--; |
| 31 | } |
| 32 | |
| 33 | if (available == 0) |
| 34 | { |
| 35 | _RESET_STRING(_DEST, _SIZE); |
| 36 | _RETURN_DEST_NOT_NULL_TERMINATED(_DEST, _SIZE); |
| 37 | } |
| 38 | |
| 39 | while ((*p++ = *_SRC++) != 0 && --available > 0) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | if (available == 0) |
| 44 | { |
| 45 | _RESET_STRING(_DEST, _SIZE); |
| 46 | _RETURN_BUFFER_TOO_SMALL(_DEST, _SIZE); |
| 47 | } |
| 48 | _FILL_STRING(_DEST, _SIZE, _SIZE - available + 1); |
| 49 | _RETURN_NO_ERROR; |
| 50 | } |
| 51 | |
| 52 | |