summaryrefslogtreecommitdiffstats
path: root/src/strscpy.c
diff options
context:
space:
mode:
authorlibuv upstream <libuv@googlegroups.com>2019-01-15 15:42:13 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-16 19:48:27 (GMT)
commit4fcb0d0213112bb2fdb04bb27e82543b93cfe41d (patch)
tree746a72d3795b562075d66fab8947dfd7527b6044 /src/strscpy.c
parentc8b67ea119c4000018238f6c3201a1364356d93a (diff)
downloadCMake-4fcb0d0213112bb2fdb04bb27e82543b93cfe41d.zip
CMake-4fcb0d0213112bb2fdb04bb27e82543b93cfe41d.tar.gz
CMake-4fcb0d0213112bb2fdb04bb27e82543b93cfe41d.tar.bz2
libuv 2019-01-15 (f84c5e69)
Code extracted from: https://github.com/libuv/libuv.git at commit f84c5e693b80cb0c62bcefba147e7a66e2b839c9 (v1.x).
Diffstat (limited to 'src/strscpy.c')
-rw-r--r--src/strscpy.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/strscpy.c b/src/strscpy.c
new file mode 100644
index 0000000..2a2bdce
--- /dev/null
+++ b/src/strscpy.c
@@ -0,0 +1,17 @@
+#include "strscpy.h"
+#include <limits.h> /* SSIZE_MAX */
+
+ssize_t uv__strscpy(char* d, const char* s, size_t n) {
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if ('\0' == (d[i] = s[i]))
+ return i > SSIZE_MAX ? UV_E2BIG : (ssize_t) i;
+
+ if (i == 0)
+ return 0;
+
+ d[--i] = '\0';
+
+ return UV_E2BIG;
+}