Added SDL_strndup()

This commit is contained in:
Sam Lantinga
2023-07-15 09:12:39 -07:00
parent 8cc3783e75
commit f3d6320bac
5 changed files with 15 additions and 0 deletions

View File

@@ -700,6 +700,17 @@ char *SDL_strdup(const char *string)
return newstr;
}
char *SDL_strndup(const char *string, size_t maxlen)
{
size_t len = SDL_min(SDL_strlen(string), maxlen) + 1;
char *newstr = (char *)SDL_malloc(len);
if (newstr) {
SDL_memcpy(newstr, string, len);
newstr[len - 1] = '\0';
}
return newstr;
}
char *SDL_strrev(char *string)
{
#ifdef HAVE__STRREV