* Copy a string with a maximum length. * * @param d The destination memory. * @param s The source string. * @param n Copy at most n characters as length of the string. * @return A pointer to the destination memory. */
| 130 | * @return A pointer to the destination memory. |
| 131 | */ |
| 132 | char *strncpy(char *d, const char *s, size_t n) |
| 133 | { |
| 134 | /* Use +1 to get the NUL terminator. */ |
| 135 | size_t max = n > strlen(s) + 1 ? strlen(s) + 1 : n; |
| 136 | |
| 137 | for (size_t i = 0; i < max; i++) |
| 138 | d[i] = (char)s[i]; |
| 139 | |
| 140 | return d; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Copy a string. |
no test coverage detected