* @brief This function will duplicate a string. * * @param s is the string to be duplicated. * * @return The string address of the copy. */
| 542 | * @return The string address of the copy. |
| 543 | */ |
| 544 | char *rt_strdup(const char *s) |
| 545 | { |
| 546 | rt_size_t len = rt_strlen(s) + 1; |
| 547 | char *tmp = (char *)rt_malloc(len); |
| 548 | |
| 549 | if (!tmp) |
| 550 | { |
| 551 | return RT_NULL; |
| 552 | } |
| 553 | |
| 554 | rt_memcpy(tmp, s, len); |
| 555 | |
| 556 | return tmp; |
| 557 | } |
| 558 | RTM_EXPORT(rt_strdup); |
| 559 | #endif /* RT_USING_HEAP */ |
no test coverage detected