* Duplicate a string. * * @param s The string to duplicate. * @return A pointer to the copy of the original string. */
| 226 | * @return A pointer to the copy of the original string. |
| 227 | */ |
| 228 | char *strdup(const char *s) |
| 229 | { |
| 230 | size_t n = strlen(s); |
| 231 | char *p = malloc(n + 1); |
| 232 | |
| 233 | if (p != NULL) { |
| 234 | strncpy(p, s, n); |
| 235 | p[n] = 0; |
| 236 | } |
| 237 | return p; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Duplicate a string with a max length of size |
no test coverage detected