Added SDL_strndup()

main
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

@ -549,6 +549,7 @@ extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, cons
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strdup(const char *str);
extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strndup(const char *str, size_t maxlen);
extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);

View File

@ -870,6 +870,7 @@ SDL3_0.0.0 {
SDL_GetGamepadInstanceID;
SDL_GetGamepadPowerLevel;
SDL_SetGamepadMapping;
SDL_strndup;
# extra symbols go here (don't modify this line)
local: *;
};

View File

@ -896,3 +896,4 @@
#define SDL_GetGamepadInstanceID SDL_GetGamepadInstanceID_REAL
#define SDL_GetGamepadPowerLevel SDL_GetGamepadPowerLevel_REAL
#define SDL_SetGamepadMapping SDL_SetGamepadMapping_REAL
#define SDL_strndup SDL_strndup_REAL

View File

@ -941,3 +941,4 @@ SDL_DYNAPI_PROC(int,SDL_ClearClipboardData,(void),(),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadInstanceID,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickPowerLevel,SDL_GetGamepadPowerLevel,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetGamepadMapping,(SDL_JoystickID a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(char*,SDL_strndup,(const char *a, size_t b),(a,b),return)

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