| 1 | #include "strscpy.h" |
|---|---|
| 2 | #include <limits.h> /* SSIZE_MAX */ |
| 3 | |
| 4 | ssize_t uv__strscpy(char* d, const char* s, size_t n) { |
| 5 | size_t i; |
| 6 | |
| 7 | for (i = 0; i < n; i++) |
| 8 | if ('\0' == (d[i] = s[i])) |
| 9 | return i > SSIZE_MAX ? UV_E2BIG : (ssize_t) i; |
| 10 | |
| 11 | if (i == 0) |
| 12 | return 0; |
| 13 | |
| 14 | d[--i] = '\0'; |
| 15 | |
| 16 | return UV_E2BIG; |
| 17 | } |
| 18 |