Skip to content

Commit fa3462a

Browse files
JoeMattclaude
andcommitted
Update libretro-common to latest upstream (2025)
Update vendored libretro-common from ~Oct 2021 to current upstream. Brings 4+ years of bug fixes, new API support, platform compatibility improvements, and security fixes. Refs #105 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent e6d2400 commit fa3462a

33 files changed

Lines changed: 11175 additions & 5082 deletions

libretro-common/compat/compat_posix_string.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ int retro_strcasecmp__(const char *a, const char *b)
5656

5757
char *retro_strdup__(const char *orig)
5858
{
59-
size_t len = strlen(orig) + 1;
60-
char *ret = (char*)malloc(len);
59+
size_t _len = strlen(orig) + 1;
60+
char *ret = (char*)malloc(_len);
6161
if (!ret)
6262
return NULL;
63-
64-
strlcpy(ret, orig, len);
63+
memcpy(ret, orig, _len);
6564
return ret;
6665
}
6766

@@ -100,5 +99,4 @@ char *retro_strtok_r__(char *str, const char *delim, char **saveptr)
10099

101100
return first;
102101
}
103-
104102
#endif

libretro-common/compat/compat_snprintf.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,43 @@
3535

3636
static int c89_vscprintf_retro__(const char *fmt, va_list pargs)
3737
{
38-
int retval;
38+
int _len;
3939
va_list argcopy;
4040
va_copy(argcopy, pargs);
41-
retval = vsnprintf(NULL, 0, fmt, argcopy);
41+
_len = vsnprintf(NULL, 0, fmt, argcopy);
4242
va_end(argcopy);
43-
return retval;
43+
return _len;
4444
}
4545
#endif
4646

4747
/* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 */
4848

4949
int c99_vsnprintf_retro__(char *s, size_t len, const char *fmt, va_list ap)
5050
{
51-
int count = -1;
52-
51+
int _len = -1;
5352
if (len != 0)
5453
{
5554
#if (_MSC_VER <= 1310)
56-
count = _vsnprintf(s, len - 1, fmt, ap);
55+
_len = _vsnprintf(s, len - 1, fmt, ap);
5756
#else
58-
count = _vsnprintf_s(s, len, len - 1, fmt, ap);
57+
_len = _vsnprintf_s(s, len, len - 1, fmt, ap);
5958
#endif
6059
}
61-
62-
if (count == -1)
63-
count = _vscprintf(fmt, ap);
64-
60+
if (_len == -1)
61+
_len = _vscprintf(fmt, ap);
6562
/* there was no room for a NULL, so truncate the last character */
66-
if (count == len && len)
63+
if (_len == len && len)
6764
s[len - 1] = '\0';
68-
69-
return count;
65+
return _len;
7066
}
7167

7268
int c99_snprintf_retro__(char *s, size_t len, const char *fmt, ...)
7369
{
74-
int count;
70+
int _len;
7571
va_list ap;
76-
7772
va_start(ap, fmt);
78-
count = c99_vsnprintf_retro__(s, len, fmt, ap);
73+
_len = c99_vsnprintf_retro__(s, len, fmt, ap);
7974
va_end(ap);
80-
81-
return count;
75+
return _len;
8276
}
8377
#endif

libretro-common/compat/compat_strcasestr.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ static int casencmp(const char *a, const char *b, size_t n)
4242

4343
char *strcasestr_retro__(const char *haystack, const char *needle)
4444
{
45-
size_t i, search_off;
46-
size_t hay_len = strlen(haystack);
47-
size_t needle_len = strlen(needle);
48-
49-
if (needle_len > hay_len)
50-
return NULL;
51-
52-
search_off = hay_len - needle_len;
53-
for (i = 0; i <= search_off; i++)
54-
if (!casencmp(haystack + i, needle, needle_len))
55-
return (char*)haystack + i;
56-
45+
size_t _len = strlen(needle);
46+
size_t __len = strlen(haystack);
47+
if (_len <= __len)
48+
{
49+
size_t i;
50+
__len -= _len; /* offset */
51+
for (i = 0; i <= __len; i++)
52+
if (!casencmp(haystack + i, needle, _len))
53+
return (char*)haystack + i;
54+
}
5755
return NULL;
5856
}

libretro-common/compat/compat_strl.c

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,27 @@
2727

2828
/* Implementation of strlcpy()/strlcat() based on OpenBSD. */
2929

30-
#ifndef __MACH__
31-
32-
size_t strlcpy(char *dest, const char *source, size_t size)
30+
#if !(defined(__MACH__) && defined(__APPLE__))
31+
size_t strlcpy(char *s, const char *in, size_t len)
3332
{
34-
size_t src_size = 0;
35-
size_t n = size;
36-
37-
if (n)
38-
while (--n && (*dest++ = *source++)) src_size++;
39-
40-
if (!n)
41-
{
42-
if (size) *dest = '\0';
43-
while (*source++) src_size++;
44-
}
45-
46-
return src_size;
33+
size_t _len = strlen(in);
34+
if (len)
35+
{
36+
size_t __len = _len < len - 1 ? _len : len - 1;
37+
memcpy(s, in, __len);
38+
s[__len] = '\0';
39+
}
40+
return _len;
4741
}
4842

49-
size_t strlcat(char *dest, const char *source, size_t size)
43+
size_t strlcat(char *s, const char *source, size_t len)
5044
{
51-
size_t len = strlen(dest);
52-
53-
dest += len;
54-
55-
if (len > size)
56-
size = 0;
45+
size_t _len = strlen(s);
46+
s += _len;
47+
if (_len > len)
48+
len = 0;
5749
else
58-
size -= len;
59-
60-
return len + strlcpy(dest, source, size);
50+
len -= _len;
51+
return _len + strlcpy(s, source, len);
6152
}
6253
#endif
63-
64-
char *strldup(const char *s, size_t n)
65-
{
66-
char *dst = (char*)malloc(sizeof(char) * (n + 1));
67-
strlcpy(dst, s, n);
68-
return dst;
69-
}

libretro-common/compat/fopen_utf8.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,28 @@
3737
void *fopen_utf8(const char * filename, const char * mode)
3838
{
3939
#if defined(LEGACY_WIN32)
40-
FILE *ret = NULL;
4140
char * filename_local = utf8_to_local_string_alloc(filename);
42-
43-
if (!filename_local)
44-
return NULL;
45-
ret = fopen(filename_local, mode);
4641
if (filename_local)
42+
{
43+
FILE *ret = fopen(filename_local, mode);
4744
free(filename_local);
48-
return ret;
45+
return ret;
46+
}
4947
#else
50-
wchar_t * filename_w = utf8_to_utf16_string_alloc(filename);
51-
wchar_t * mode_w = utf8_to_utf16_string_alloc(mode);
52-
FILE* ret = NULL;
53-
54-
if (filename_w && mode_w)
55-
ret = _wfopen(filename_w, mode_w);
48+
wchar_t * filename_w = utf8_to_utf16_string_alloc(filename);
5649
if (filename_w)
50+
{
51+
FILE *ret = NULL;
52+
wchar_t *mode_w = utf8_to_utf16_string_alloc(mode);
53+
if (mode_w)
54+
{
55+
ret = _wfopen(filename_w, mode_w);
56+
free(mode_w);
57+
}
5758
free(filename_w);
58-
if (mode_w)
59-
free(mode_w);
60-
return ret;
59+
return ret;
60+
}
6161
#endif
62+
return NULL;
6263
}
6364
#endif

0 commit comments

Comments
 (0)