From 7d871ab87d45e535d1512a5834b627cbbce2e66c Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Fri, 17 Sep 2021 10:37:49 +0100 Subject: Replace direct direct file access with VFS routines --- libretro-common/include/compat/fopen_utf8.h | 34 +++++++++++++++ libretro-common/include/compat/msvc.h | 24 ++++------- libretro-common/include/compat/msvc/stdint.h | 3 -- libretro-common/include/compat/posix_string.h | 60 +++++++++++++++++++++++++++ libretro-common/include/compat/strcasestr.h | 48 +++++++++++++++++++++ libretro-common/include/compat/strl.h | 59 ++++++++++++++++++++++++++ 6 files changed, 210 insertions(+), 18 deletions(-) create mode 100644 libretro-common/include/compat/fopen_utf8.h create mode 100644 libretro-common/include/compat/posix_string.h create mode 100644 libretro-common/include/compat/strcasestr.h create mode 100644 libretro-common/include/compat/strl.h (limited to 'libretro-common/include/compat') diff --git a/libretro-common/include/compat/fopen_utf8.h b/libretro-common/include/compat/fopen_utf8.h new file mode 100644 index 0000000..97d4404 --- /dev/null +++ b/libretro-common/include/compat/fopen_utf8.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (fopen_utf8.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_SDK_COMPAT_FOPEN_UTF8_H +#define __LIBRETRO_SDK_COMPAT_FOPEN_UTF8_H + +#ifdef _WIN32 +/* Defined to error rather than fopen_utf8, to make it clear to everyone reading the code that not worrying about utf16 is fine */ +/* TODO: enable */ +/* #define fopen (use fopen_utf8 instead) */ +void *fopen_utf8(const char * filename, const char * mode); +#else +#define fopen_utf8 fopen +#endif +#endif diff --git a/libretro-common/include/compat/msvc.h b/libretro-common/include/compat/msvc.h index 5175214..a4c93a5 100644 --- a/libretro-common/include/compat/msvc.h +++ b/libretro-common/include/compat/msvc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2017 The RetroArch team +/* Copyright (C) 2010-2020 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (msvc.h). @@ -29,20 +29,17 @@ extern "C" { #endif -/* Pre-MSVC 2015 compilers don't implement snprintf in a cross-platform manner. */ +/* Pre-MSVC 2015 compilers don't implement snprintf, vsnprintf in a cross-platform manner. */ #if _MSC_VER < 1900 + #include + #include #include + #ifndef snprintf #define snprintf c99_snprintf_retro__ #endif - int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...); -#endif -/* Pre-MSVC 2010 compilers don't implement vsnprintf in a cross-platform manner? Not sure about this one. */ -#if _MSC_VER < 1600 - #include - #include #ifndef vsnprintf #define vsnprintf c99_vsnprintf_retro__ #endif @@ -56,6 +53,8 @@ extern "C" { #undef UNICODE /* Do not bother with UNICODE at this time. */ #include #include + +#define _USE_MATH_DEFINES #include /* Python headers defines ssize_t and sets HAVE_SSIZE_T. @@ -92,7 +91,7 @@ typedef int ssize_t; #define va_copy(x, y) ((x) = (y)) #endif -#if _MSC_VER <= 1200 +#if _MSC_VER <= 1310 #ifndef __cplusplus /* VC6 math.h doesn't define some functions when in C mode. * Trying to define a prototype gives "undefined reference". @@ -106,11 +105,7 @@ typedef int ssize_t; #define ceilf(x) ((float)ceil((double)x)) #define floorf(x) ((float)floor((double)x)) #define sqrtf(x) ((float)sqrt((double)x)) - #endif - - #ifndef _vscprintf - #define _vscprintf c89_vscprintf_retro__ - int c89_vscprintf_retro__(const char *format, va_list pargs); + #define fabsf(x) ((float)fabs((double)(x))) #endif #ifndef _strtoui64 @@ -129,4 +124,3 @@ typedef int ssize_t; #endif #endif - diff --git a/libretro-common/include/compat/msvc/stdint.h b/libretro-common/include/compat/msvc/stdint.h index c791176..7c91a68 100644 --- a/libretro-common/include/compat/msvc/stdint.h +++ b/libretro-common/include/compat/msvc/stdint.h @@ -67,7 +67,6 @@ extern "C" { # endif #endif - /* 7.18.1 Integer types. */ /* 7.18.1.1 Exact-width integer types. */ @@ -94,7 +93,6 @@ extern "C" { typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; - /* 7.18.1.2 Minimum-width integer types. */ typedef int8_t int_least8_t; typedef int16_t int_least16_t; @@ -255,4 +253,3 @@ typedef uint64_t uintmax_t; #endif #endif - diff --git a/libretro-common/include/compat/posix_string.h b/libretro-common/include/compat/posix_string.h new file mode 100644 index 0000000..47964b2 --- /dev/null +++ b/libretro-common/include/compat/posix_string.h @@ -0,0 +1,60 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (posix_string.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_SDK_COMPAT_POSIX_STRING_H +#define __LIBRETRO_SDK_COMPAT_POSIX_STRING_H + +#include + +#ifdef _MSC_VER +#include +#endif + +RETRO_BEGIN_DECLS + +#ifdef _WIN32 +#undef strtok_r +#define strtok_r(str, delim, saveptr) retro_strtok_r__(str, delim, saveptr) + +char *strtok_r(char *str, const char *delim, char **saveptr); +#endif + +#ifdef _MSC_VER +#undef strcasecmp +#undef strdup +#define strcasecmp(a, b) retro_strcasecmp__(a, b) +#define strdup(orig) retro_strdup__(orig) +int strcasecmp(const char *a, const char *b); +char *strdup(const char *orig); + +/* isblank is available since MSVC 2013 */ +#if _MSC_VER < 1800 +#undef isblank +#define isblank(c) retro_isblank__(c) +int isblank(int c); +#endif + +#endif + +RETRO_END_DECLS + +#endif diff --git a/libretro-common/include/compat/strcasestr.h b/libretro-common/include/compat/strcasestr.h new file mode 100644 index 0000000..227e253 --- /dev/null +++ b/libretro-common/include/compat/strcasestr.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (strcasestr.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_SDK_COMPAT_STRCASESTR_H +#define __LIBRETRO_SDK_COMPAT_STRCASESTR_H + +#include + +#if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H) +#include "../../../config.h" +#endif + +#ifndef HAVE_STRCASESTR + +#include + +RETRO_BEGIN_DECLS + +/* Avoid possible naming collisions during link + * since we prefer to use the actual name. */ +#define strcasestr(haystack, needle) strcasestr_retro__(haystack, needle) + +char *strcasestr(const char *haystack, const char *needle); + +RETRO_END_DECLS + +#endif + +#endif diff --git a/libretro-common/include/compat/strl.h b/libretro-common/include/compat/strl.h new file mode 100644 index 0000000..5e7a892 --- /dev/null +++ b/libretro-common/include/compat/strl.h @@ -0,0 +1,59 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (strl.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_SDK_COMPAT_STRL_H +#define __LIBRETRO_SDK_COMPAT_STRL_H + +#include +#include + +#if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H) +#include "../../../config.h" +#endif + +#include + +RETRO_BEGIN_DECLS + +#ifdef __MACH__ +#ifndef HAVE_STRL +#define HAVE_STRL +#endif +#endif + +#ifndef HAVE_STRL +/* Avoid possible naming collisions during link since + * we prefer to use the actual name. */ +#define strlcpy(dst, src, size) strlcpy_retro__(dst, src, size) + +#define strlcat(dst, src, size) strlcat_retro__(dst, src, size) + +size_t strlcpy(char *dest, const char *source, size_t size); +size_t strlcat(char *dest, const char *source, size_t size); + +#endif + +char *strldup(const char *s, size_t n); + +RETRO_END_DECLS + +#endif -- cgit v1.2.3