diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/src/safecrt/tcsncat_s.inl | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/src/safecrt/tcsncat_s.inl')
-rw-r--r-- | src/pal/src/safecrt/tcsncat_s.inl | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/pal/src/safecrt/tcsncat_s.inl b/src/pal/src/safecrt/tcsncat_s.inl new file mode 100644 index 0000000000..6de501767d --- /dev/null +++ b/src/pal/src/safecrt/tcsncat_s.inl @@ -0,0 +1,81 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*** +*tcsncat_s.inl - general implementation of _tcscpy_s +* + +* +*Purpose: +* This file contains the general algorithm for strncat_s and its variants. +* +****/ + +_FUNC_PROLOGUE +errno_t __cdecl _FUNC_NAME(_CHAR *_DEST, size_t _SIZE, const _CHAR *_SRC, size_t _COUNT) +{ + _CHAR *p; + size_t available; + + if (_COUNT == 0 && _DEST == NULL && _SIZE == 0) + { + /* this case is allowed; nothing to do */ + _RETURN_NO_ERROR; + } + + /* validation section */ + _VALIDATE_STRING(_DEST, _SIZE); + if (_COUNT != 0) + { + _VALIDATE_POINTER_RESET_STRING(_SRC, _DEST, _SIZE); + } + + p = _DEST; + available = _SIZE; + while (available > 0 && *p != 0) + { + p++; + available--; + } + + if (available == 0) + { + _RESET_STRING(_DEST, _SIZE); + _RETURN_DEST_NOT_NULL_TERMINATED(_DEST, _SIZE); + } + + if (_COUNT == _TRUNCATE) + { + while ((*p++ = *_SRC++) != 0 && --available > 0) + { + } + } + else + { + _ASSERT_EXPR((!_CrtGetCheckCount() || _COUNT < available), "Buffer is too small"); + + while (_COUNT > 0 && (*p++ = *_SRC++) != 0 && --available > 0) + { + _COUNT--; + } + if (_COUNT == 0) + { + *p = 0; + } + } + + if (available == 0) + { + if (_COUNT == _TRUNCATE) + { + _DEST[_SIZE - 1] = 0; + _RETURN_TRUNCATE; + } + _RESET_STRING(_DEST, _SIZE); + _RETURN_BUFFER_TOO_SMALL(_DEST, _SIZE); + } + _FILL_STRING(_DEST, _SIZE, _SIZE - available + 1); + _RETURN_NO_ERROR; +} + |