/** * Create a duplicate of the given string. * @param s The string to duplicate. * @param last The last character that is safe to duplicate. If NULL, the whole string is duplicated. * @note The maximum length of the resulting string might therefore be last - s + 1. * @return The duplicate of the string. */ char *stredup(const char *s, const char *last) { size_t len = last == NULL ? strlen(s) : ttd_strnlen(s, last - s + 1); char *tmp = CallocT<char>(len + 1); memcpy(tmp, s, len); return tmp; }
char *strndup(const char *s, size_t len) { len = ttd_strnlen(s, len); char *tmp = CallocT<char>(len + 1); memcpy(tmp, s, len); return tmp; }