Skip to content

Commit 5a0ef73

Browse files
authored
Merge pull request libretro#89 from jdgleaver/vfs-support
Replace direct direct file access with VFS routines
2 parents f53deef + 7d871ab commit 5a0ef73

36 files changed

+10743
-45
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ else
562562
-Wno-sign-compare \
563563
-Wno-unused-variable \
564564
-Wno-unused-function \
565+
-Wno-unused-parameter \
565566
-Wno-uninitialized \
566567
-Wno-strict-aliasing \
567568
-Wno-overflow \

Makefile.common

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ endif
5050

5151
ifeq ($(LOAD_FROM_MEMORY),1)
5252
FLAGS += -DLOAD_FROM_MEMORY
53+
else ifneq ($(STATIC_LINKING), 1)
54+
SOURCES_C += \
55+
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \
56+
$(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \
57+
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
58+
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.c \
59+
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \
60+
$(LIBRETRO_COMM_DIR)/file/file_path.c \
61+
$(LIBRETRO_COMM_DIR)/file/file_path_io.c \
62+
$(LIBRETRO_COMM_DIR)/streams/file_stream.c \
63+
$(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.c \
64+
$(LIBRETRO_COMM_DIR)/string/stdstring.c \
65+
$(LIBRETRO_COMM_DIR)/time/rtime.c \
66+
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c
5367
endif
5468

5569
ifeq ($(USE_OLD_COLOUR_OPS),1)
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: 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+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Copyright (C) 2010-2020 The RetroArch team
2+
*
3+
* ---------------------------------------------------------------------------------------
4+
* The following license statement only applies to this file (fopen_utf8.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 <compat/fopen_utf8.h>
24+
#include <encodings/utf.h>
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
28+
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
29+
#ifndef LEGACY_WIN32
30+
#define LEGACY_WIN32
31+
#endif
32+
#endif
33+
34+
#ifdef _WIN32
35+
#undef fopen
36+
37+
void *fopen_utf8(const char * filename, const char * mode)
38+
{
39+
#if defined(LEGACY_WIN32)
40+
FILE *ret = NULL;
41+
char * filename_local = utf8_to_local_string_alloc(filename);
42+
43+
if (!filename_local)
44+
return NULL;
45+
ret = fopen(filename_local, mode);
46+
if (filename_local)
47+
free(filename_local);
48+
return ret;
49+
#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);
56+
if (filename_w)
57+
free(filename_w);
58+
if (mode_w)
59+
free(mode_w);
60+
return ret;
61+
#endif
62+
}
63+
#endif

0 commit comments

Comments
 (0)