tomato/external/sdl/SDL/src/stdlib/SDL_string.c

2154 lines
58 KiB
C
Raw Normal View History

/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
/* This file contains portable string manipulation functions for SDL */
#include "SDL_vacopy.h"
#ifdef __vita__
#include <psp2/kernel/clib.h>
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_WCSTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
#endif
#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
static size_t UTF8_GetTrailingBytes(unsigned char c)
{
if (c >= 0xC0 && c <= 0xDF) {
return 1;
} else if (c >= 0xE0 && c <= 0xEF) {
return 2;
} else if (c >= 0xF0 && c <= 0xF4) {
return 3;
}
return 0;
}
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
static size_t SDL_ScanLong(const char *text, int count, int radix, long *valuep)
{
const char *textstart = text;
long value = 0;
SDL_bool negative = SDL_FALSE;
if (*text == '-') {
negative = SDL_TRUE;
++text;
}
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
text += 2;
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
} else if (radix == 16 && SDL_islowerhex(*text)) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
if (count > 0 && (text - textstart) == count) {
break;
}
}
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
*valuep = value;
}
}
return text - textstart;
}
#endif
#if !defined(HAVE_WCSTOL)
static size_t SDL_ScanLongW(const wchar_t *text, int count, int radix, long *valuep)
{
const wchar_t *textstart = text;
long value = 0;
SDL_bool negative = SDL_FALSE;
if (*text == '-') {
negative = SDL_TRUE;
++text;
}
if (radix == 16 && SDL_wcsncmp(text, L"0x", 2) == 0) {
text += 2;
}
for (;;) {
int v;
if (*text >= '0' && *text <= '9') {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
} else if (radix == 16 && SDL_islowerhex(*text)) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
if (count > 0 && (text - textstart) == count) {
break;
}
}
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
*valuep = value;
}
}
return text - textstart;
}
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
static size_t SDL_ScanUnsignedLong(const char *text, int count, int radix, unsigned long *valuep)
{
const char *textstart = text;
unsigned long value = 0;
if (*text == '-') {
return SDL_ScanLong(text, count, radix, (long *)valuep);
}
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
text += 2;
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
} else if (radix == 16 && SDL_islowerhex(*text)) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
if (count > 0 && (text - textstart) == count) {
break;
}
}
if (valuep && text > textstart) {
*valuep = value;
}
return text - textstart;
}
#endif
#ifndef HAVE_VSSCANF
static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
{
const char *textstart = text;
uintptr_t value = 0;
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
text += 2;
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
} else if (radix == 16 && SDL_islowerhex(*text)) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
}
if (valuep && text > textstart) {
*valuep = value;
}
return text - textstart;
}
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
static size_t SDL_ScanLongLong(const char *text, int count, int radix, Sint64 *valuep)
{
const char *textstart = text;
Sint64 value = 0;
SDL_bool negative = SDL_FALSE;
if (*text == '-') {
negative = SDL_TRUE;
++text;
}
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
text += 2;
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
} else if (radix == 16 && SDL_islowerhex(*text)) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
if (count > 0 && (text - textstart) == count) {
break;
}
}
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
*valuep = value;
}
}
return text - textstart;
}
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL)
static size_t SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 *valuep)
{
const char *textstart = text;
Uint64 value = 0;
if (*text == '-') {
return SDL_ScanLongLong(text, count, radix, (Sint64 *)valuep);
}
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
text += 2;
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
} else if (radix == 16 && SDL_islowerhex(*text)) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
if (count > 0 && (text - textstart) == count) {
break;
}
}
if (valuep && text > textstart) {
*valuep = value;
}
return text - textstart;
}
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOD)
static size_t SDL_ScanFloat(const char *text, double *valuep)
{
const char *textstart = text;
unsigned long lvalue = 0;
double value = 0.0;
SDL_bool negative = SDL_FALSE;
if (*text == '-') {
negative = SDL_TRUE;
++text;
}
text += SDL_ScanUnsignedLong(text, 0, 10, &lvalue);
value += lvalue;
if (*text == '.') {
int mult = 10;
++text;
while (SDL_isdigit((unsigned char)*text)) {
lvalue = *text - '0';
value += (double)lvalue / mult;
mult *= 10;
++text;
}
}
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
*valuep = value;
}
}
return text - textstart;
}
#endif
void *SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{
#ifdef HAVE_MEMMOVE
return memmove(dst, src, len);
#else
char *srcp = (char *)src;
char *dstp = (char *)dst;
if (src < dst) {
srcp += len - 1;
dstp += len - 1;
while (len--) {
*dstp-- = *srcp--;
}
} else {
while (len--) {
*dstp++ = *srcp++;
}
}
return dst;
#endif /* HAVE_MEMMOVE */
}
int SDL_memcmp(const void *s1, const void *s2, size_t len)
{
#ifdef __vita__
/*
Using memcmp on NULL is UB per POSIX / C99 7.21.1/2.
But, both linux and bsd allow that, with an exception:
zero length strings are always identical, so NULLs are never dereferenced.
sceClibMemcmp on PSVita doesn't allow that, so we check ourselves.
*/
if (len == 0) {
return 0;
}
return sceClibMemcmp(s1, s2, len);
#elif defined(HAVE_MEMCMP)
return memcmp(s1, s2, len);
#else
char *s1p = (char *)s1;
char *s2p = (char *)s2;
while (len--) {
if (*s1p != *s2p) {
return *s1p - *s2p;
}
++s1p;
++s2p;
}
return 0;
#endif /* HAVE_MEMCMP */
}
size_t SDL_strlen(const char *string)
{
#ifdef HAVE_STRLEN
return strlen(string);
#else
size_t len = 0;
while (*string++) {
++len;
}
return len;
#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
return wcslen(string);
#else
size_t len = 0;
while (*string++) {
++len;
}
return len;
#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
return wcslcpy(dst, src, maxlen);
#else
size_t srclen = SDL_wcslen(src);
if (maxlen > 0) {
size_t len = SDL_min(srclen, maxlen - 1);
SDL_memcpy(dst, src, len * sizeof(wchar_t));
dst[len] = '\0';
}
return srclen;
#endif /* HAVE_WCSLCPY */
}
size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
{
#ifdef HAVE_WCSLCAT
return wcslcat(dst, src, maxlen);
#else
size_t dstlen = SDL_wcslen(dst);
size_t srclen = SDL_wcslen(src);
if (dstlen < maxlen) {
SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
}
return dstlen + srclen;
#endif /* HAVE_WCSLCAT */
}
wchar_t *SDL_wcsdup(const wchar_t *string)
{
size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t));
wchar_t *newstr = (wchar_t *)SDL_malloc(len);
if (newstr) {
SDL_memcpy(newstr, string, len);
}
return newstr;
}
wchar_t *SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
{
#ifdef HAVE_WCSSTR
return SDL_const_cast(wchar_t *, wcsstr(haystack, needle));
#else
size_t length = SDL_wcslen(needle);
while (*haystack) {
if (SDL_wcsncmp(haystack, needle, length) == 0) {
return (wchar_t *)haystack;
}
++haystack;
}
return NULL;
#endif /* HAVE_WCSSTR */
}
int SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
{
#ifdef HAVE_WCSCMP
return wcscmp(str1, str2);
#else
while (*str1 && *str2) {
if (*str1 != *str2) {
break;
}
++str1;
++str2;
}
return *str1 - *str2;
#endif /* HAVE_WCSCMP */
}
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
{
#ifdef HAVE_WCSNCMP
return wcsncmp(str1, str2, maxlen);
#else
while (*str1 && *str2 && maxlen) {
if (*str1 != *str2) {
break;
}
++str1;
++str2;
--maxlen;
}
if (!maxlen) {
return 0;
}
return *str1 - *str2;
#endif /* HAVE_WCSNCMP */
}
int SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
{
#ifdef HAVE_WCSCASECMP
return wcscasecmp(str1, str2);
#elif defined(HAVE__WCSICMP)
return _wcsicmp(str1, str2);
#else
wchar_t a = 0;
wchar_t b = 0;
while (*str1 && *str2) {
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = (wchar_t)SDL_toupper((unsigned char)*str1);
b = (wchar_t)SDL_toupper((unsigned char)*str2);
}
if (a != b) {
break;
}
++str1;
++str2;
}
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = (wchar_t)SDL_toupper((unsigned char)*str1);
b = (wchar_t)SDL_toupper((unsigned char)*str2);
}
return (int)((unsigned int)a - (unsigned int)b);
#endif /* HAVE__WCSICMP */
}
int SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
{
#ifdef HAVE_WCSNCASECMP
return wcsncasecmp(str1, str2, maxlen);
#elif defined(HAVE__WCSNICMP)
return _wcsnicmp(str1, str2, maxlen);
#else
wchar_t a = 0;
wchar_t b = 0;
while (*str1 && *str2 && maxlen) {
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = (wchar_t)SDL_toupper((unsigned char)*str1);
b = (wchar_t)SDL_toupper((unsigned char)*str2);
}
if (a != b) {
break;
}
++str1;
++str2;
--maxlen;
}
if (maxlen == 0) {
return 0;
} else {
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = (wchar_t)SDL_toupper((unsigned char)*str1);
b = (wchar_t)SDL_toupper((unsigned char)*str2);
}
return (int)((unsigned int)a - (unsigned int)b);
}
#endif /* HAVE__WCSNICMP */
}
long SDL_wcstol(const wchar_t *string, wchar_t **endp, int base)
{
#ifdef HAVE_WCSTOL
return wcstol(string, endp, base);
#else
size_t len;
long value = 0;
if (!base) {
if ((SDL_wcslen(string) > 2) && (SDL_wcsncmp(string, L"0x", 2) == 0)) {
base = 16;
} else {
base = 10;
}
}
len = SDL_ScanLongW(string, 0, base, &value);
if (endp) {
*endp = (wchar_t *)string + len;
}
return value;
#endif /* HAVE_WCSTOL */
}
size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
#ifdef HAVE_STRLCPY
return strlcpy(dst, src, maxlen);
#else
size_t srclen = SDL_strlen(src);
if (maxlen > 0) {
size_t len = SDL_min(srclen, maxlen - 1);
SDL_memcpy(dst, src, len);
dst[len] = '\0';
}
return srclen;
#endif /* HAVE_STRLCPY */
}
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
{
size_t src_bytes = SDL_strlen(src);
size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
size_t i = 0;
size_t trailing_bytes = 0;
if (bytes) {
unsigned char c = (unsigned char)src[bytes - 1];
if (UTF8_IsLeadByte(c)) {
--bytes;
} else if (UTF8_IsTrailingByte(c)) {
for (i = bytes - 1; i != 0; --i) {
c = (unsigned char)src[i];
trailing_bytes = UTF8_GetTrailingBytes(c);
if (trailing_bytes) {
if ((bytes - i) != (trailing_bytes + 1)) {
bytes = i;
}
break;
}
}
}
SDL_memcpy(dst, src, bytes);
}
dst[bytes] = '\0';
return bytes;
}
size_t SDL_utf8strlen(const char *str)
{
size_t retval = 0;
const char *p = str;
unsigned char ch;
while ((ch = *(p++)) != 0) {
/* if top two bits are 1 and 0, it's a continuation byte. */
if ((ch & 0xc0) != 0x80) {
retval++;
}
}
return retval;
}
size_t SDL_utf8strnlen(const char *str, size_t bytes)
{
size_t retval = 0;
const char *p = str;
unsigned char ch;
while ((ch = *(p++)) != 0 && bytes-- > 0) {
/* if top two bits are 1 and 0, it's a continuation byte. */
if ((ch & 0xc0) != 0x80) {
retval++;
}
}
return retval;
}
size_t SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
#ifdef HAVE_STRLCAT
return strlcat(dst, src, maxlen);
#else
size_t dstlen = SDL_strlen(dst);
size_t srclen = SDL_strlen(src);
if (dstlen < maxlen) {
SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
}
return dstlen + srclen;
#endif /* HAVE_STRLCAT */
}
char *SDL_strdup(const char *string)
{
size_t len = SDL_strlen(string) + 1;
char *newstr = (char *)SDL_malloc(len);
if (newstr) {
SDL_memcpy(newstr, string, len);
}
return newstr;
}
char *SDL_strndup(const char *string, size_t maxlen)
{
size_t len = SDL_strnlen(string, maxlen);
char *newstr = (char *)SDL_malloc(len + 1);
if (newstr) {
SDL_memcpy(newstr, string, len);
newstr[len] = '\0';
}
return newstr;
}
char *SDL_strrev(char *string)
{
#ifdef HAVE__STRREV
return _strrev(string);
#else
size_t len = SDL_strlen(string);
char *a = &string[0];
char *b = &string[len - 1];
len /= 2;
while (len--) {
char c = *a; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */
*a++ = *b;
*b-- = c;
}
return string;
#endif /* HAVE__STRREV */
}
char *SDL_strupr(char *string)
{
#ifdef HAVE__STRUPR
return _strupr(string);
#else
char *bufp = string;
while (*bufp) {
*bufp = (char)SDL_toupper((unsigned char)*bufp);
++bufp;
}
return string;
#endif /* HAVE__STRUPR */
}
char *SDL_strlwr(char *string)
{
#ifdef HAVE__STRLWR
return _strlwr(string);
#else
char *bufp = string;
while (*bufp) {
*bufp = (char)SDL_tolower((unsigned char)*bufp);
++bufp;
}
return string;
#endif /* HAVE__STRLWR */
}
char *SDL_strchr(const char *string, int c)
{
#ifdef HAVE_STRCHR
return SDL_const_cast(char *, strchr(string, c));
#elif defined(HAVE_INDEX)
return SDL_const_cast(char *, index(string, c));
#else
while (*string) {
if (*string == c) {
return (char *)string;
}
++string;
}
if (c == '\0') {
return (char *)string;
}
return NULL;
#endif /* HAVE_STRCHR */
}
char *SDL_strrchr(const char *string, int c)
{
#ifdef HAVE_STRRCHR
return SDL_const_cast(char *, strrchr(string, c));
#elif defined(HAVE_RINDEX)
return SDL_const_cast(char *, rindex(string, c));
#else
const char *bufp = string + SDL_strlen(string);
while (bufp >= string) {
if (*bufp == c) {
return (char *)bufp;
}
--bufp;
}
return NULL;
#endif /* HAVE_STRRCHR */
}
char *SDL_strstr(const char *haystack, const char *needle)
{
#ifdef HAVE_STRSTR
return SDL_const_cast(char *, strstr(haystack, needle));
#else
size_t length = SDL_strlen(needle);
while (*haystack) {
if (SDL_strncmp(haystack, needle, length) == 0) {
return (char *)haystack;
}
++haystack;
}
return NULL;
#endif /* HAVE_STRSTR */
}
char *SDL_strcasestr(const char *haystack, const char *needle)
{
#ifdef HAVE_STRCASESTR
return SDL_const_cast(char *, strcasestr(haystack, needle));
#else
size_t length = SDL_strlen(needle);
while (*haystack) {
if (SDL_strncasecmp(haystack, needle, length) == 0) {
return (char *)haystack;
}
++haystack;
}
return NULL;
#endif /* HAVE_STRCASESTR */
}
#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
!defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
static const char ntoa_table[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z'
};
#endif /* ntoa() conversion table */
char *SDL_itoa(int value, char *string, int radix)
{
#ifdef HAVE_ITOA
return itoa(value, string, radix);
#else
return SDL_ltoa((long)value, string, radix);
#endif /* HAVE_ITOA */
}
char *SDL_uitoa(unsigned int value, char *string, int radix)
{
#ifdef HAVE__UITOA
return _uitoa(value, string, radix);
#else
return SDL_ultoa((unsigned long)value, string, radix);
#endif /* HAVE__UITOA */
}
char *SDL_ltoa(long value, char *string, int radix)
{
#ifdef HAVE__LTOA
return _ltoa(value, string, radix);
#else
char *bufp = string;
if (value < 0) {
*bufp++ = '-';
SDL_ultoa(-value, bufp, radix);
} else {
SDL_ultoa(value, bufp, radix);
}
return string;
#endif /* HAVE__LTOA */
}
char *SDL_ultoa(unsigned long value, char *string, int radix)
{
#ifdef HAVE__ULTOA
return _ultoa(value, string, radix);
#else
char *bufp = string;
if (value) {
while (value > 0) {
*bufp++ = ntoa_table[value % radix];
value /= radix;
}
} else {
*bufp++ = '0';
}
*bufp = '\0';
/* The numbers went into the string backwards. :) */
SDL_strrev(string);
return string;
#endif /* HAVE__ULTOA */
}
char *SDL_lltoa(Sint64 value, char *string, int radix)
{
#ifdef HAVE__I64TOA
return _i64toa(value, string, radix);
#else
char *bufp = string;
if (value < 0) {
*bufp++ = '-';
SDL_ulltoa(-value, bufp, radix);
} else {
SDL_ulltoa(value, bufp, radix);
}
return string;
#endif /* HAVE__I64TOA */
}
char *SDL_ulltoa(Uint64 value, char *string, int radix)
{
#ifdef HAVE__UI64TOA
return _ui64toa(value, string, radix);
#else
char *bufp = string;
if (value) {
while (value > 0) {
*bufp++ = ntoa_table[value % radix];
value /= radix;
}
} else {
*bufp++ = '0';
}
*bufp = '\0';
/* The numbers went into the string backwards. :) */
SDL_strrev(string);
return string;
#endif /* HAVE__UI64TOA */
}
int SDL_atoi(const char *string)
{
#ifdef HAVE_ATOI
return atoi(string);
#else
return SDL_strtol(string, NULL, 10);
#endif /* HAVE_ATOI */
}
double SDL_atof(const char *string)
{
#ifdef HAVE_ATOF
return atof(string);
#else
return SDL_strtod(string, NULL);
#endif /* HAVE_ATOF */
}
long SDL_strtol(const char *string, char **endp, int base)
{
#ifdef HAVE_STRTOL
return strtol(string, endp, base);
#else
size_t len;
long value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
base = 16;
} else {
base = 10;
}
}
len = SDL_ScanLong(string, 0, base, &value);
if (endp) {
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOL */
}
unsigned long
SDL_strtoul(const char *string, char **endp, int base)
{
#ifdef HAVE_STRTOUL
return strtoul(string, endp, base);
#else
size_t len;
unsigned long value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
base = 16;
} else {
base = 10;
}
}
len = SDL_ScanUnsignedLong(string, 0, base, &value);
if (endp) {
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOUL */
}
Sint64 SDL_strtoll(const char *string, char **endp, int base)
{
#ifdef HAVE_STRTOLL
return strtoll(string, endp, base);
#else
size_t len;
Sint64 value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
base = 16;
} else {
base = 10;
}
}
len = SDL_ScanLongLong(string, 0, base, &value);
if (endp) {
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOLL */
}
Uint64 SDL_strtoull(const char *string, char **endp, int base)
{
#ifdef HAVE_STRTOULL
return strtoull(string, endp, base);
#else
size_t len;
Uint64 value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
base = 16;
} else {
base = 10;
}
}
len = SDL_ScanUnsignedLongLong(string, 0, base, &value);
if (endp) {
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOULL */
}
double
SDL_strtod(const char *string, char **endp)
{
#ifdef HAVE_STRTOD
return strtod(string, endp);
#else
size_t len;
double value = 0.0;
len = SDL_ScanFloat(string, &value);
if (endp) {
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOD */
}
int SDL_strcmp(const char *str1, const char *str2)
{
#ifdef HAVE_STRCMP
return strcmp(str1, str2);
#else
int result;
while (1) {
result = ((unsigned char)*str1 - (unsigned char)*str2);
if (result != 0 || (*str1 == '\0' /* && *str2 == '\0'*/)) {
break;
}
++str1;
++str2;
}
return result;
#endif /* HAVE_STRCMP */
}
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
{
#ifdef HAVE_STRNCMP
return strncmp(str1, str2, maxlen);
#else
int result = 0;
while (maxlen) {
result = (int)(unsigned char)*str1 - (unsigned char)*str2;
if (result != 0 || *str1 == '\0' /* && *str2 == '\0'*/) {
break;
}
++str1;
++str2;
--maxlen;
}
return result;
#endif /* HAVE_STRNCMP */
}
int SDL_strcasecmp(const char *str1, const char *str2)
{
#ifdef HAVE_STRCASECMP
return strcasecmp(str1, str2);
#elif defined(HAVE__STRICMP)
return _stricmp(str1, str2);
#else
int a, b, result;
while (1) {
a = SDL_toupper((unsigned char)*str1);
b = SDL_toupper((unsigned char)*str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/) {
break;
}
++str1;
++str2;
}
return result;
#endif /* HAVE_STRCASECMP */
}
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
{
#ifdef HAVE_STRNCASECMP
return strncasecmp(str1, str2, maxlen);
#elif defined(HAVE__STRNICMP)
return _strnicmp(str1, str2, maxlen);
#else
int a, b, result = 0;
while (maxlen) {
a = SDL_tolower((unsigned char)*str1);
b = SDL_tolower((unsigned char)*str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/) {
break;
}
++str1;
++str2;
--maxlen;
}
return result;
#endif /* HAVE_STRNCASECMP */
}
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
{
int rc;
va_list ap;
va_start(ap, fmt);
rc = SDL_vsscanf(text, fmt, ap);
va_end(ap);
return rc;
}
#ifdef HAVE_VSSCANF
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
return vsscanf(text, fmt, ap);
}
#else
/* NOLINTNEXTLINE(readability-non-const-parameter) */
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
int retval = 0;
if (text == NULL || !*text) {
return -1;
}
while (*fmt) {
if (*fmt == ' ') {
while (SDL_isspace((unsigned char)*text)) {
++text;
}
++fmt;
continue;
}
if (*fmt == '%') {
SDL_bool done = SDL_FALSE;
long count = 0;
int radix = 10;
enum
{
DO_SHORT,
DO_INT,
DO_LONG,
DO_LONGLONG,
DO_SIZE_T
} inttype = DO_INT;
size_t advance;
SDL_bool suppress = SDL_FALSE;
++fmt;
if (*fmt == '%') {
if (*text == '%') {
++text;
++fmt;
continue;
}
break;
}
if (*fmt == '*') {
suppress = SDL_TRUE;
++fmt;
}
fmt += SDL_ScanLong(fmt, 0, 10, &count);
if (*fmt == 'c') {
if (!count) {
count = 1;
}
if (suppress) {
while (count--) {
++text;
}
} else {
char *valuep = va_arg(ap, char *);
while (count--) {
*valuep++ = *text++;
}
++retval;
}
continue;
}
while (SDL_isspace((unsigned char)*text)) {
++text;
}
/* FIXME: implement more of the format specifiers */
while (!done) {
switch (*fmt) {
case '*':
suppress = SDL_TRUE;
break;
case 'h':
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
if (inttype == DO_INT) {
inttype = DO_SHORT;
} else if (inttype > DO_SHORT) {
++inttype;
}
break;
case 'l':
if (inttype < DO_LONGLONG) {
++inttype;
}
break;
case 'I':
if (SDL_strncmp(fmt, "I64", 3) == 0) {
fmt += 2;
inttype = DO_LONGLONG;
}
break;
case 'z':
inttype = DO_SIZE_T;
break;
case 'i':
{
int index = 0;
if (text[index] == '-') {
++index;
}
if (text[index] == '0') {
if (SDL_tolower((unsigned char)text[index + 1]) == 'x') {
radix = 16;
} else {
radix = 8;
}
}
}
SDL_FALLTHROUGH;
case 'd':
if (inttype == DO_LONGLONG) {
Sint64 value = 0;
advance = SDL_ScanLongLong(text, count, radix, &value);
text += advance;
if (advance && !suppress) {
Sint64 *valuep = va_arg(ap, Sint64 *);
*valuep = value;
++retval;
}
} else if (inttype == DO_SIZE_T) {
Sint64 value = 0;
advance = SDL_ScanLongLong(text, count, radix, &value);
text += advance;
if (advance && !suppress) {
size_t *valuep = va_arg(ap, size_t *);
*valuep = (size_t)value;
++retval;
}
} else {
long value = 0;
advance = SDL_ScanLong(text, count, radix, &value);
text += advance;
if (advance && !suppress) {
switch (inttype) {
case DO_SHORT:
{
short *valuep = va_arg(ap, short *);
*valuep = (short)value;
} break;
case DO_INT:
{
int *valuep = va_arg(ap, int *);
*valuep = (int)value;
} break;
case DO_LONG:
{
long *valuep = va_arg(ap, long *);
*valuep = value;
} break;
case DO_LONGLONG:
case DO_SIZE_T:
/* Handled above */
break;
}
++retval;
}
}
done = SDL_TRUE;
break;
case 'o':
if (radix == 10) {
radix = 8;
}
SDL_FALLTHROUGH;
case 'x':
case 'X':
if (radix == 10) {
radix = 16;
}
SDL_FALLTHROUGH;
case 'u':
if (inttype == DO_LONGLONG) {
Uint64 value = 0;
advance = SDL_ScanUnsignedLongLong(text, count, radix, &value);
text += advance;
if (advance && !suppress) {
Uint64 *valuep = va_arg(ap, Uint64 *);
*valuep = value;
++retval;
}
} else if (inttype == DO_SIZE_T) {
Uint64 value = 0;
advance = SDL_ScanUnsignedLongLong(text, count, radix, &value);
text += advance;
if (advance && !suppress) {
size_t *valuep = va_arg(ap, size_t *);
*valuep = (size_t)value;
++retval;
}
} else {
unsigned long value = 0;
advance = SDL_ScanUnsignedLong(text, count, radix, &value);
text += advance;
if (advance && !suppress) {
switch (inttype) {
case DO_SHORT:
{
short *valuep = va_arg(ap, short *);
*valuep = (short)value;
} break;
case DO_INT:
{
int *valuep = va_arg(ap, int *);
*valuep = (int)value;
} break;
case DO_LONG:
{
long *valuep = va_arg(ap, long *);
*valuep = value;
} break;
case DO_LONGLONG:
case DO_SIZE_T:
/* Handled above */
break;
}
++retval;
}
}
done = SDL_TRUE;
break;
case 'p':
{
uintptr_t value = 0;
advance = SDL_ScanUintPtrT(text, 16, &value);
text += advance;
if (advance && !suppress) {
void **valuep = va_arg(ap, void **);
*valuep = (void *)value;
++retval;
}
}
done = SDL_TRUE;
break;
case 'f':
{
double value = 0.0;
advance = SDL_ScanFloat(text, &value);
text += advance;
if (advance && !suppress) {
float *valuep = va_arg(ap, float *);
*valuep = (float)value;
++retval;
}
}
done = SDL_TRUE;
break;
case 's':
if (suppress) {
while (!SDL_isspace((unsigned char)*text)) {
++text;
if (count) {
if (--count == 0) {
break;
}
}
}
} else {
char *valuep = va_arg(ap, char *);
while (!SDL_isspace((unsigned char)*text)) {
*valuep++ = *text++;
if (count) {
if (--count == 0) {
break;
}
}
}
*valuep = '\0';
++retval;
}
done = SDL_TRUE;
break;
default:
done = SDL_TRUE;
break;
}
++fmt;
}
continue;
}
if (*text == *fmt) {
++text;
++fmt;
continue;
}
/* Text didn't match format specifier */
break;
}
return retval;
}
#endif /* HAVE_VSSCANF */
int SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int retval;
va_start(ap, fmt);
retval = SDL_vsnprintf(text, maxlen, fmt, ap);
va_end(ap);
return retval;
}
int SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...)
{
va_list ap;
int retval;
va_start(ap, fmt);
retval = SDL_vswprintf(text, maxlen, fmt, ap);
va_end(ap);
return retval;
}
#if defined(HAVE_LIBC) && defined(__WATCOMC__)
/* _vsnprintf() doesn't ensure nul termination */
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
int retval;
if (!fmt) {
fmt = "";
}
retval = _vsnprintf(text, maxlen, fmt, ap);
if (maxlen > 0) {
text[maxlen - 1] = '\0';
}
if (retval < 0) {
retval = (int)maxlen;
}
return retval;
}
#elif defined(HAVE_VSNPRINTF)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
if (!fmt) {
fmt = "";
}
return vsnprintf(text, maxlen, fmt, ap);
}
#else
#define TEXT_AND_LEN_ARGS (length < maxlen) ? &text[length] : NULL, (length < maxlen) ? (maxlen - length) : 0
/* FIXME: implement more of the format specifiers */
typedef enum
{
SDL_CASE_NOCHANGE,
SDL_CASE_LOWER,
SDL_CASE_UPPER
} SDL_letter_case;
typedef struct
{
SDL_bool left_justify; /* for now: ignored. */
SDL_bool force_sign;
SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */
SDL_bool pad_zeroes;
SDL_letter_case force_case;
int width;
int radix;
int precision;
} SDL_FormatInfo;
static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
{
size_t length = 0;
size_t slen, sz;
if (string == NULL) {
string = "(null)";
}
sz = SDL_strlen(string);
if (info && info->width > 0 && (size_t)info->width > sz) {
const char fill = info->pad_zeroes ? '0' : ' ';
size_t width = info->width - sz;
size_t filllen;
if (info->precision >= 0 && (size_t)info->precision < sz) {
width += sz - (size_t)info->precision;
}
filllen = SDL_min(width, maxlen);
SDL_memset(text, fill, filllen);
text += filllen;
maxlen -= filllen;
length += width;
}
SDL_strlcpy(text, string, maxlen);
length += sz;
if (info) {
if (info->precision >= 0 && (size_t)info->precision < sz) {
slen = (size_t)info->precision;
if (slen < maxlen) {
text[slen] = '\0';
}
length -= (sz - slen);
}
if (maxlen > 1) {
if (info->force_case == SDL_CASE_LOWER) {
SDL_strlwr(text);
} else if (info->force_case == SDL_CASE_UPPER) {
SDL_strupr(text);
}
}
}
return length;
}
static size_t SDL_PrintStringW(char *text, size_t maxlen, SDL_FormatInfo *info, const wchar_t *wide_string)
{
size_t length = 0;
if (wide_string) {
char *string = SDL_iconv_string("UTF-8", "WCHAR_T", (char *)(wide_string), (SDL_wcslen(wide_string) + 1) * sizeof(*wide_string));
length = SDL_PrintString(TEXT_AND_LEN_ARGS, info, string);
SDL_free(string);
} else {
length = SDL_PrintString(TEXT_AND_LEN_ARGS, info, NULL);
}
return length;
}
static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
{ /* left-pad num with zeroes. */
size_t sz, pad, have_sign;
if (info == NULL) {
return;
}
have_sign = 0;
if (*num == '-' || *num == '+') {
have_sign = 1;
++num;
--maxlen;
}
sz = SDL_strlen(num);
if (info->precision > 0 && sz < (size_t)info->precision) {
pad = (size_t)info->precision - sz;
if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */
SDL_memmove(num + pad, num, sz + 1);
SDL_memset(num, '0', pad);
}
}
info->precision = -1; /* so that SDL_PrintString() doesn't make a mess. */
if (info->pad_zeroes && info->width > 0 && (size_t)info->width > sz + have_sign) {
/* handle here: spaces are added before the sign
but zeroes must be placed _after_ the sign. */
/* sz hasn't changed: we ignore pad_zeroes if a precision is given. */
pad = (size_t)info->width - sz - have_sign;
if (pad + sz + 1 <= maxlen) {
SDL_memmove(num + pad, num, sz + 1);
SDL_memset(num, '0', pad);
}
info->width = 0; /* so that SDL_PrintString() doesn't make a mess. */
}
}
static size_t SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
{
char num[130], *p = num;
if (info->force_sign && value >= 0L) {
*p++ = '+';
}
SDL_ltoa(value, p, info ? info->radix : 10);
SDL_IntPrecisionAdjust(num, sizeof(num), info);
return SDL_PrintString(text, maxlen, info, num);
}
static size_t SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
{
char num[130];
SDL_ultoa(value, num, info ? info->radix : 10);
SDL_IntPrecisionAdjust(num, sizeof(num), info);
return SDL_PrintString(text, maxlen, info, num);
}
static size_t SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
{
char num[130], *p = num;
if (info->force_sign && value >= (Sint64)0) {
*p++ = '+';
}
SDL_lltoa(value, p, info ? info->radix : 10);
SDL_IntPrecisionAdjust(num, sizeof(num), info);
return SDL_PrintString(text, maxlen, info, num);
}
static size_t SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value)
{
char num[130];
SDL_ulltoa(value, num, info ? info->radix : 10);
SDL_IntPrecisionAdjust(num, sizeof(num), info);
return SDL_PrintString(text, maxlen, info, num);
}
static size_t SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg, SDL_bool g)
{
char num[327];
size_t length = 0;
size_t integer_length;
int precision = info->precision;
/* This isn't especially accurate, but hey, it's easy. :) */
Uint64 value;
if (arg < 0) {
num[length++] = '-';
arg = -arg;
} else if (info->force_sign) {
num[length++] = '+';
}
value = (Uint64)arg;
integer_length = SDL_PrintUnsignedLongLong(&num[length], sizeof(num) - length, NULL, value);
length += integer_length;
arg -= value;
if (precision < 0) {
precision = 6;
}
if (g) {
/* The precision includes the integer portion */
precision -= SDL_min((int)integer_length, precision);
}
if (info->force_type || precision > 0) {
const char decimal_separator = '.';
double integer_value;
SDL_assert(length < sizeof(num));
num[length++] = decimal_separator;
while (precision > 1) {
arg *= 10.0;
arg = SDL_modf(arg, &integer_value);
SDL_assert(length < sizeof(num));
num[length++] = '0' + (char)integer_value;
--precision;
}
if (precision == 1) {
arg *= 10.0;
integer_value = SDL_round(arg);
if (integer_value == 10.0) {
/* Carry the one... */
size_t i;
for (i = length; i--; ) {
if (num[i] == decimal_separator) {
continue;
}
if (num[i] == '9') {
num[i] = '0';
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
if (i == 0 || num[i - 1] == '-' || num[i - 1] == '+') {
SDL_memmove(&num[i+1], &num[i], length - i);
num[i] = '1';
++length;
break;
}
} else {
++num[i];
break;
}
}
SDL_assert(length < sizeof(num));
num[length++] = '0';
} else {
SDL_assert(length < sizeof(num));
num[length++] = '0' + (char)integer_value;
}
}
if (g) {
/* Trim trailing zeroes and decimal separator */
size_t i;
for (i = length - 1; num[i] != decimal_separator; --i) {
if (num[i] == '0') {
--length;
} else {
break;
}
}
if (num[i] == decimal_separator) {
--length;
}
}
}
num[length] = '\0';
info->precision = -1;
length = SDL_PrintString(text, maxlen, info, num);
if (info->width > 0 && (size_t)info->width > length) {
const char fill = info->pad_zeroes ? '0' : ' ';
size_t width = info->width - length;
size_t filllen, movelen;
filllen = SDL_min(width, maxlen);
movelen = SDL_min(length, (maxlen - filllen));
SDL_memmove(&text[filllen], text, movelen);
SDL_memset(text, fill, filllen);
length += width;
}
return length;
}
static size_t SDL_PrintPointer(char *text, size_t maxlen, SDL_FormatInfo *info, const void *value)
{
char num[130];
size_t length;
if (!value) {
return SDL_PrintString(text, maxlen, info, NULL);
}
SDL_ulltoa((unsigned long long)(uintptr_t)value, num, 16);
length = SDL_PrintString(text, maxlen, info, "0x");
return length + SDL_PrintString(TEXT_AND_LEN_ARGS, info, num);
}
/* NOLINTNEXTLINE(readability-non-const-parameter) */
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
size_t length = 0;
if (!text) {
maxlen = 0;
}
if (!fmt) {
fmt = "";
}
while (*fmt) {
if (*fmt == '%') {
SDL_bool done = SDL_FALSE;
SDL_bool check_flag;
SDL_FormatInfo info;
enum
{
DO_INT,
DO_LONG,
DO_LONGLONG,
DO_SIZE_T
} inttype = DO_INT;
SDL_zero(info);
info.radix = 10;
info.precision = -1;
check_flag = SDL_TRUE;
while (check_flag) {
++fmt;
switch (*fmt) {
case '-':
info.left_justify = SDL_TRUE;
break;
case '+':
info.force_sign = SDL_TRUE;
break;
case '#':
info.force_type = SDL_TRUE;
break;
case '0':
info.pad_zeroes = SDL_TRUE;
break;
default:
check_flag = SDL_FALSE;
break;
}
}
if (*fmt >= '0' && *fmt <= '9') {
info.width = SDL_strtol(fmt, (char **)&fmt, 0);
} else if (*fmt == '*') {
++fmt;
info.width = va_arg(ap, int);
}
if (*fmt == '.') {
++fmt;
if (*fmt >= '0' && *fmt <= '9') {
info.precision = SDL_strtol(fmt, (char **)&fmt, 0);
} else if (*fmt == '*') {
++fmt;
info.precision = va_arg(ap, int);
} else {
info.precision = 0;
}
if (info.precision < 0) {
info.precision = 0;
}
}
while (!done) {
switch (*fmt) {
case '%':
if (length < maxlen) {
text[length] = '%';
}
++length;
done = SDL_TRUE;
break;
case 'c':
/* char is promoted to int when passed through (...) */
if (length < maxlen) {
text[length] = (char)va_arg(ap, int);
}
++length;
done = SDL_TRUE;
break;
case 'h':
/* short is promoted to int when passed through (...) */
break;
case 'l':
if (inttype < DO_LONGLONG) {
++inttype;
}
break;
case 'I':
if (SDL_strncmp(fmt, "I64", 3) == 0) {
fmt += 2;
inttype = DO_LONGLONG;
}
break;
case 'z':
inttype = DO_SIZE_T;
break;
case 'i':
case 'd':
if (info.precision >= 0) {
info.pad_zeroes = SDL_FALSE;
}
switch (inttype) {
case DO_INT:
length += SDL_PrintLong(TEXT_AND_LEN_ARGS, &info,
(long)va_arg(ap, int));
break;
case DO_LONG:
length += SDL_PrintLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, long));
break;
case DO_LONGLONG:
length += SDL_PrintLongLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, Sint64));
break;
case DO_SIZE_T:
length += SDL_PrintLongLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, size_t));
break;
}
done = SDL_TRUE;
break;
case 'p':
info.force_case = SDL_CASE_LOWER;
length += SDL_PrintPointer(TEXT_AND_LEN_ARGS, &info, va_arg(ap, void *));
done = SDL_TRUE;
break;
case 'x':
info.force_case = SDL_CASE_LOWER;
SDL_FALLTHROUGH;
case 'X':
if (info.force_case == SDL_CASE_NOCHANGE) {
info.force_case = SDL_CASE_UPPER;
}
if (info.radix == 10) {
info.radix = 16;
}
SDL_FALLTHROUGH;
case 'o':
if (info.radix == 10) {
info.radix = 8;
}
SDL_FALLTHROUGH;
case 'u':
info.force_sign = SDL_FALSE;
if (info.precision >= 0) {
info.pad_zeroes = SDL_FALSE;
}
switch (inttype) {
case DO_INT:
length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, &info,
(unsigned long)
va_arg(ap, unsigned int));
break;
case DO_LONG:
length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, unsigned long));
break;
case DO_LONGLONG:
length += SDL_PrintUnsignedLongLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, Uint64));
break;
case DO_SIZE_T:
length += SDL_PrintUnsignedLongLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, size_t));
break;
}
done = SDL_TRUE;
break;
case 'f':
length += SDL_PrintFloat(TEXT_AND_LEN_ARGS, &info, va_arg(ap, double), SDL_FALSE);
done = SDL_TRUE;
break;
case 'g':
length += SDL_PrintFloat(TEXT_AND_LEN_ARGS, &info, va_arg(ap, double), SDL_TRUE);
done = SDL_TRUE;
break;
case 'S':
info.pad_zeroes = SDL_FALSE;
length += SDL_PrintStringW(TEXT_AND_LEN_ARGS, &info, va_arg(ap, wchar_t *));
done = SDL_TRUE;
break;
case 's':
info.pad_zeroes = SDL_FALSE;
if (inttype > DO_INT) {
length += SDL_PrintStringW(TEXT_AND_LEN_ARGS, &info, va_arg(ap, wchar_t *));
} else {
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, va_arg(ap, char *));
}
done = SDL_TRUE;
break;
default:
done = SDL_TRUE;
break;
}
++fmt;
}
} else {
if (length < maxlen) {
text[length] = *fmt;
}
++fmt;
++length;
}
}
if (length < maxlen) {
text[length] = '\0';
} else if (maxlen > 0) {
text[maxlen - 1] = '\0';
}
return (int)length;
}
#undef TEXT_AND_LEN_ARGS
#endif /* HAVE_VSNPRINTF */
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap)
{
char *text_utf8 = NULL, *fmt_utf8 = NULL;
int retval;
if (fmt) {
fmt_utf8 = SDL_iconv_string("UTF-8", "WCHAR_T", (const char *)fmt, (SDL_wcslen(fmt) + 1) * sizeof(wchar_t));
if (!fmt_utf8) {
return -1;
}
}
if (!maxlen) {
/* We still need to generate the text to find the final text length */
maxlen = 1024;
}
text_utf8 = (char *)SDL_malloc(maxlen * 4);
if (!text_utf8) {
SDL_free(fmt_utf8);
return -1;
}
retval = SDL_vsnprintf(text_utf8, maxlen * 4, fmt_utf8, ap);
if (retval >= 0) {
wchar_t *text_wchar = (wchar_t *)SDL_iconv_string("WCHAR_T", "UTF-8", text_utf8, SDL_strlen(text_utf8) + 1);
if (text_wchar) {
if (text) {
SDL_wcslcpy(text, text_wchar, maxlen);
}
retval = (int)SDL_wcslen(text_wchar);
SDL_free(text_wchar);
} else {
retval = -1;
}
}
SDL_free(text_utf8);
SDL_free(fmt_utf8);
return retval;
}
int SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int retval;
va_start(ap, fmt);
retval = SDL_vasprintf(strp, fmt, ap);
va_end(ap);
return retval;
}
int SDL_vasprintf(char **strp, const char *fmt, va_list ap)
{
int retval;
int size = 100; /* Guess we need no more than 100 bytes */
char *p, *np;
va_list aq;
*strp = NULL;
p = (char *)SDL_malloc(size);
if (p == NULL) {
return -1;
}
while (1) {
/* Try to print in the allocated space */
va_copy(aq, ap);
retval = SDL_vsnprintf(p, size, fmt, aq);
va_end(aq);
/* Check error code */
if (retval < 0) {
return retval;
}
/* If that worked, return the string */
if (retval < size) {
*strp = p;
return retval;
}
/* Else try again with more space */
size = retval + 1; /* Precisely what is needed */
np = (char *)SDL_realloc(p, size);
if (np == NULL) {
SDL_free(p);
return -1;
} else {
p = np;
}
}
}