diff options
Diffstat (limited to 'Utilities/cmlibuv/src/strscpy.c')
-rw-r--r-- | Utilities/cmlibuv/src/strscpy.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Utilities/cmlibuv/src/strscpy.c b/Utilities/cmlibuv/src/strscpy.c new file mode 100644 index 0000000000..2a2bdce745 --- /dev/null +++ b/Utilities/cmlibuv/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; +} |