mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-09 09:24:24 +02:00
Added SDL_strnlen() and SDL_wcsnlen()
This commit is contained in:
@@ -875,6 +875,8 @@ SDL3_0.0.0 {
|
||||
SDL_GetGamepadStringForType;
|
||||
SDL_GetRealGamepadInstanceType;
|
||||
SDL_GetRealGamepadType;
|
||||
SDL_wcsnlen;
|
||||
SDL_strnlen;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -901,3 +901,5 @@
|
||||
#define SDL_GetGamepadStringForType SDL_GetGamepadStringForType_REAL
|
||||
#define SDL_GetRealGamepadInstanceType SDL_GetRealGamepadInstanceType_REAL
|
||||
#define SDL_GetRealGamepadType SDL_GetRealGamepadType_REAL
|
||||
#define SDL_wcsnlen SDL_wcsnlen_REAL
|
||||
#define SDL_strnlen SDL_strnlen_REAL
|
||||
|
||||
@@ -946,3 +946,5 @@ SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForType,(SDL_GamepadType a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetRealGamepadInstanceType,(SDL_JoystickID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetRealGamepadType,(SDL_Gamepad *a),(a),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_wcsnlen,(const wchar_t *a, size_t b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_strnlen,(const char *a, size_t b),(a,b),return)
|
||||
|
||||
@@ -390,6 +390,19 @@ size_t SDL_strlen(const char *string)
|
||||
#endif /* HAVE_STRLEN */
|
||||
}
|
||||
|
||||
size_t SDL_strnlen(const char *string, size_t maxlen)
|
||||
{
|
||||
#ifdef HAVE_STRNLEN
|
||||
return strnlen(string, maxlen);
|
||||
#else
|
||||
size_t len = 0;
|
||||
while (len < maxlen && *string++) {
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
#endif /* HAVE_STRNLEN */
|
||||
}
|
||||
|
||||
size_t SDL_wcslen(const wchar_t *string)
|
||||
{
|
||||
#ifdef HAVE_WCSLEN
|
||||
@@ -403,6 +416,19 @@ size_t SDL_wcslen(const wchar_t *string)
|
||||
#endif /* HAVE_WCSLEN */
|
||||
}
|
||||
|
||||
size_t SDL_wcsnlen(const wchar_t *string, size_t maxlen)
|
||||
{
|
||||
#ifdef HAVE_WCSNLEN
|
||||
return wcsnlen(string, maxlen);
|
||||
#else
|
||||
size_t len = 0;
|
||||
while (len < maxlen && *string++) {
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
#endif /* HAVE_WCSNLEN */
|
||||
}
|
||||
|
||||
size_t SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
|
||||
{
|
||||
#ifdef HAVE_WCSLCPY
|
||||
@@ -702,11 +728,11 @@ char *SDL_strdup(const char *string)
|
||||
|
||||
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);
|
||||
size_t len = SDL_strnlen(string, maxlen);
|
||||
char *newstr = (char *)SDL_malloc(len + 1);
|
||||
if (newstr) {
|
||||
SDL_memcpy(newstr, string, len);
|
||||
newstr[len - 1] = '\0';
|
||||
newstr[len] = '\0';
|
||||
}
|
||||
return newstr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user