summaryrefslogtreecommitdiff
path: root/src/pal/src/safecrt/tcscat_s.inl
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/src/safecrt/tcscat_s.inl')
-rw-r--r--src/pal/src/safecrt/tcscat_s.inl51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/pal/src/safecrt/tcscat_s.inl b/src/pal/src/safecrt/tcscat_s.inl
new file mode 100644
index 0000000000..b6fefdc0ae
--- /dev/null
+++ b/src/pal/src/safecrt/tcscat_s.inl
@@ -0,0 +1,51 @@
+// 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.
+
+/***
+*tcscat_s.inl - general implementation of _tcscpy_s
+*
+
+*
+*Purpose:
+* This file contains the general algorithm for strcat_s and its variants.
+*
+****/
+
+_FUNC_PROLOGUE
+errno_t __cdecl _FUNC_NAME(_CHAR *_DEST, size_t _SIZE, const _CHAR *_SRC)
+{
+ _CHAR *p;
+ size_t available;
+
+ /* validation section */
+ _VALIDATE_STRING(_DEST, _SIZE);
+ _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);
+ }
+
+ while ((*p++ = *_SRC++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ _RESET_STRING(_DEST, _SIZE);
+ _RETURN_BUFFER_TOO_SMALL(_DEST, _SIZE);
+ }
+ _FILL_STRING(_DEST, _SIZE, _SIZE - available + 1);
+ _RETURN_NO_ERROR;
+}
+