Skip to content

Commit 746dc04

Browse files
committed
Update to libretro-common VFS - use VFS now instead of straight file I/O
1 parent 4dade20 commit 746dc04

45 files changed

Lines changed: 10459 additions & 62 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile.common

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,20 @@ SOURCES_C := \
4747
$(CORE_DIR)/src/vjag_memory.c \
4848
$(CORE_DIR)/src/universalhdr.c \
4949
$(CORE_DIR)/src/wavetable.c
50+
51+
ifneq ($(STATIC_LINKING), 1)
52+
SOURCES_C += \
53+
$(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \
54+
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \
55+
$(LIBRETRO_COMM_DIR)/compat/compat_snprintf.c \
56+
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
57+
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \
58+
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.c \
59+
$(LIBRETRO_COMM_DIR)/streams/file_stream.c \
60+
$(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.c \
61+
$(LIBRETRO_COMM_DIR)/string/stdstring.c \
62+
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c \
63+
$(LIBRETRO_COMM_DIR)/file/file_path.c \
64+
$(LIBRETRO_COMM_DIR)/file/file_path_io.c \
65+
$(LIBRETRO_COMM_DIR)/time/rtime.c
66+
endif
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* Copyright (C) 2010-2020 The RetroArch team
2+
*
3+
* ---------------------------------------------------------------------------------------
4+
* The following license statement only applies to this file (compat_posix_string.c).
5+
* ---------------------------------------------------------------------------------------
6+
*
7+
* Permission is hereby granted, free of charge,
8+
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
9+
* to deal in the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include <ctype.h>
24+
25+
#include <compat/posix_string.h>
26+
27+
#ifdef _WIN32
28+
29+
#undef strcasecmp
30+
#undef strdup
31+
#undef isblank
32+
#undef strtok_r
33+
#include <ctype.h>
34+
#include <stdlib.h>
35+
#include <stddef.h>
36+
#include <compat/strl.h>
37+
38+
#include <string.h>
39+
40+
int retro_strcasecmp__(const char *a, const char *b)
41+
{
42+
while (*a && *b)
43+
{
44+
int a_ = tolower(*a);
45+
int b_ = tolower(*b);
46+
47+
if (a_ != b_)
48+
return a_ - b_;
49+
50+
a++;
51+
b++;
52+
}
53+
54+
return tolower(*a) - tolower(*b);
55+
}
56+
57+
char *retro_strdup__(const char *orig)
58+
{
59+
size_t len = strlen(orig) + 1;
60+
char *ret = (char*)malloc(len);
61+
if (!ret)
62+
return NULL;
63+
64+
strlcpy(ret, orig, len);
65+
return ret;
66+
}
67+
68+
int retro_isblank__(int c)
69+
{
70+
return (c == ' ') || (c == '\t');
71+
}
72+
73+
char *retro_strtok_r__(char *str, const char *delim, char **saveptr)
74+
{
75+
char *first = NULL;
76+
if (!saveptr || !delim)
77+
return NULL;
78+
79+
if (str)
80+
*saveptr = str;
81+
82+
do
83+
{
84+
char *ptr = NULL;
85+
first = *saveptr;
86+
while (*first && strchr(delim, *first))
87+
*first++ = '\0';
88+
89+
if (*first == '\0')
90+
return NULL;
91+
92+
ptr = first + 1;
93+
94+
while (*ptr && !strchr(delim, *ptr))
95+
ptr++;
96+
97+
*saveptr = ptr + (*ptr ? 1 : 0);
98+
*ptr = '\0';
99+
} while (strlen(first) == 0);
100+
101+
return first;
102+
}
103+
104+
#endif
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* Copyright (C) 2010-2020 The RetroArch team
2+
*
3+
* ---------------------------------------------------------------------------------------
4+
* The following license statement only applies to this file (compat_snprintf.c).
5+
* ---------------------------------------------------------------------------------------
6+
*
7+
* Permission is hereby granted, free of charge,
8+
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
9+
* to deal in the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
/* THIS FILE HAS NOT BEEN VALIDATED ON PLATFORMS BESIDES MSVC */
24+
#ifdef _MSC_VER
25+
26+
#include <stdio.h>
27+
#include <stdarg.h>
28+
29+
#if _MSC_VER < 1800
30+
#define va_copy(dst, src) ((dst) = (src))
31+
#endif
32+
33+
#if _MSC_VER < 1300
34+
#define _vscprintf c89_vscprintf_retro__
35+
36+
static int c89_vscprintf_retro__(const char *fmt, va_list pargs)
37+
{
38+
int retval;
39+
va_list argcopy;
40+
va_copy(argcopy, pargs);
41+
retval = vsnprintf(NULL, 0, fmt, argcopy);
42+
va_end(argcopy);
43+
return retval;
44+
}
45+
#endif
46+
47+
/* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 */
48+
49+
int c99_vsnprintf_retro__(char *s, size_t len, const char *fmt, va_list ap)
50+
{
51+
int count = -1;
52+
53+
if (len != 0)
54+
{
55+
#if (_MSC_VER <= 1310)
56+
count = _vsnprintf(s, len - 1, fmt, ap);
57+
#else
58+
count = _vsnprintf_s(s, len, len - 1, fmt, ap);
59+
#endif
60+
}
61+
62+
if (count == -1)
63+
count = _vscprintf(fmt, ap);
64+
65+
/* there was no room for a NULL, so truncate the last character */
66+
if (count == len && len)
67+
s[len - 1] = '\0';
68+
69+
return count;
70+
}
71+
72+
int c99_snprintf_retro__(char *s, size_t len, const char *fmt, ...)
73+
{
74+
int count;
75+
va_list ap;
76+
77+
va_start(ap, fmt);
78+
count = c99_vsnprintf_retro__(s, len, fmt, ap);
79+
va_end(ap);
80+
81+
return count;
82+
}
83+
#endif
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Copyright (C) 2010-2020 The RetroArch team
2+
*
3+
* ---------------------------------------------------------------------------------------
4+
* The following license statement only applies to this file (compat_strcasestr.c).
5+
* ---------------------------------------------------------------------------------------
6+
*
7+
* Permission is hereby granted, free of charge,
8+
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
9+
* to deal in the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include <ctype.h>
24+
25+
#include <compat/strcasestr.h>
26+
27+
/* Pretty much strncasecmp. */
28+
static int casencmp(const char *a, const char *b, size_t n)
29+
{
30+
size_t i;
31+
32+
for (i = 0; i < n; i++)
33+
{
34+
int a_lower = tolower(a[i]);
35+
int b_lower = tolower(b[i]);
36+
if (a_lower != b_lower)
37+
return a_lower - b_lower;
38+
}
39+
40+
return 0;
41+
}
42+
43+
char *strcasestr_retro__(const char *haystack, const char *needle)
44+
{
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+
57+
return NULL;
58+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Copyright (C) 2010-2020 The RetroArch team
2+
*
3+
* ---------------------------------------------------------------------------------------
4+
* The following license statement only applies to this file (compat_strl.c).
5+
* ---------------------------------------------------------------------------------------
6+
*
7+
* Permission is hereby granted, free of charge,
8+
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
9+
* to deal in the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include <stdlib.h>
24+
#include <ctype.h>
25+
26+
#include <compat/strl.h>
27+
28+
/* Implementation of strlcpy()/strlcat() based on OpenBSD. */
29+
30+
#ifndef __MACH__
31+
32+
size_t strlcpy(char *dest, const char *source, size_t size)
33+
{
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;
47+
}
48+
49+
size_t strlcat(char *dest, const char *source, size_t size)
50+
{
51+
size_t len = strlen(dest);
52+
53+
dest += len;
54+
55+
if (len > size)
56+
size = 0;
57+
else
58+
size -= len;
59+
60+
return len + strlcpy(dest, source, size);
61+
}
62+
#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+
}

0 commit comments

Comments
 (0)