1
0
Fork 0

(svn r26498) -Add: method for duplicating strings with similar behaviours as strecpy and strecat; give end pointer instead of a size

release/1.5
rubidium 2014-04-24 18:21:32 +00:00
parent 389d61f2fa
commit 382ca0941f
2 changed files with 16 additions and 0 deletions

View File

@ -113,6 +113,21 @@ char *strecpy(char *dst, const char *src, const char *last)
return dst;
}
/**
* 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;
}
/**
* Format, "printf", into a newly allocated string.
* @param str The formatting string.

View File

@ -31,6 +31,7 @@
char *strecat(char *dst, const char *src, const char *last);
char *strecpy(char *dst, const char *src, const char *last);
char *stredup(const char *src, const char *last = NULL);
int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FORMAT(3, 4);