From a009d2ac13e65e77d0a41d3cf236b9198f2c92ed Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 21 Mar 2016 01:33:12 +0000 Subject: [PATCH] vc2010 workarounds for libretro-common --- .../libretro-common/compat/compat_snprintf.c | 53 +++++++++++++++++++ .../src/libretro-common/compat/compat_strl.c | 4 +- desmume/src/libretro-common/file/file_list.c | 3 +- .../src/libretro-common/file/retro_dirent.c | 2 + .../src/libretro-common/include/compat/msvc.h | 26 +++++++-- .../libretro-common/include/retro_common.h | 32 +++++++++++ .../src/libretro-common/include/retro_file.h | 1 + .../include/rthreads/rthreads.h | 5 +- 8 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 desmume/src/libretro-common/compat/compat_snprintf.c create mode 100644 desmume/src/libretro-common/include/retro_common.h diff --git a/desmume/src/libretro-common/compat/compat_snprintf.c b/desmume/src/libretro-common/compat/compat_snprintf.c new file mode 100644 index 000000000..5825fd485 --- /dev/null +++ b/desmume/src/libretro-common/compat/compat_snprintf.c @@ -0,0 +1,53 @@ +/* Copyright (C) 2010-2015 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (compat_snprintf.c). + * --------------------------------------------------------------------------------------- + * + * 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. + */ + +/* THIS FILE HAS NOT BEEN VALIDATED ON PLATFORMS BESIDES MSVC */ + +#include + +#include + +/* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 */ + +int c99_vsnprintf_retro__(char *outBuf, size_t size, const char *format, va_list ap) +{ + int count = -1; + + if (size != 0) + count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); + if (count == -1) + count = _vscprintf(format, ap); + + return count; +} + +int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...) +{ + int count; + va_list ap; + + va_start(ap, format); + count = c99_vsnprintf_retro__(outBuf, size, format, ap); + va_end(ap); + + return count; +} \ No newline at end of file diff --git a/desmume/src/libretro-common/compat/compat_strl.c b/desmume/src/libretro-common/compat/compat_strl.c index 9253174d4..d8d89d2f7 100644 --- a/desmume/src/libretro-common/compat/compat_strl.c +++ b/desmume/src/libretro-common/compat/compat_strl.c @@ -29,7 +29,7 @@ /* Implementation of strlcpy()/strlcat() based on OpenBSD. */ -size_t strlcpy_retro__(char *dest, const char *source, size_t size) +size_t strlcpy(char *dest, const char *source, size_t size) { size_t src_size = 0; size_t n = size; @@ -46,7 +46,7 @@ size_t strlcpy_retro__(char *dest, const char *source, size_t size) return src_size; } -size_t strlcat_retro__(char *dest, const char *source, size_t size) +size_t strlcat(char *dest, const char *source, size_t size) { size_t len = strlen(dest); diff --git a/desmume/src/libretro-common/file/file_list.c b/desmume/src/libretro-common/file/file_list.c index 9ed5fe6a0..b0dc5872e 100644 --- a/desmume/src/libretro-common/file/file_list.c +++ b/desmume/src/libretro-common/file/file_list.c @@ -23,10 +23,9 @@ #include #include +#include #include #include -#include -#include void file_list_push(file_list_t *list, const char *path, const char *label, diff --git a/desmume/src/libretro-common/file/retro_dirent.c b/desmume/src/libretro-common/file/retro_dirent.c index 5fa0cb4b8..b031f4b38 100644 --- a/desmume/src/libretro-common/file/retro_dirent.c +++ b/desmume/src/libretro-common/file/retro_dirent.c @@ -23,6 +23,8 @@ #include #include +#include + #if defined(_WIN32) # ifdef _MSC_VER # define setmode _setmode diff --git a/desmume/src/libretro-common/include/compat/msvc.h b/desmume/src/libretro-common/include/compat/msvc.h index 5782f9e36..35c81ead5 100644 --- a/desmume/src/libretro-common/include/compat/msvc.h +++ b/desmume/src/libretro-common/include/compat/msvc.h @@ -25,14 +25,32 @@ #ifdef _MSC_VER +#ifdef __cplusplus +extern "C" { +#endif + /* Pre-MSVC 2015 compilers don't implement snprintf in a cross-platform manner. */ #if _MSC_VER < 1900 -#ifndef snprintf -#define snprintf _snprintf + #include + #ifndef snprintf + #define snprintf c99_snprintf_retro__ + #endif + + int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...); #endif -#ifndef vsnprintf -#define vsnprintf _vsnprintf + +/* 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 + int c99_vsnprintf_retro__(char *outBuf, size_t size, const char *format, va_list ap); #endif + +#ifdef __cplusplus +} #endif #undef UNICODE /* Do not bother with UNICODE at this time. */ diff --git a/desmume/src/libretro-common/include/retro_common.h b/desmume/src/libretro-common/include/retro_common.h new file mode 100644 index 000000000..32ff1a861 --- /dev/null +++ b/desmume/src/libretro-common/include/retro_common.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2010-2016 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (retro_common.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_COMMON_RETRO_COMMON_H +#define _LIBRETRO_COMMON_RETRO_COMMON_H + +//This file is designed to normalize the libretro-common compiling environment. +//It is not to be used in public API headers, as they should be designed as leanly as possible. + +//conditional compilation is handled inside here +#include + +#endif \ No newline at end of file diff --git a/desmume/src/libretro-common/include/retro_file.h b/desmume/src/libretro-common/include/retro_file.h index 8ce8cc175..4af93ac43 100644 --- a/desmume/src/libretro-common/include/retro_file.h +++ b/desmume/src/libretro-common/include/retro_file.h @@ -28,6 +28,7 @@ #include +#include #include #ifdef __cplusplus diff --git a/desmume/src/libretro-common/include/rthreads/rthreads.h b/desmume/src/libretro-common/include/rthreads/rthreads.h index 52a4d9b6f..90ae90fde 100644 --- a/desmume/src/libretro-common/include/rthreads/rthreads.h +++ b/desmume/src/libretro-common/include/rthreads/rthreads.h @@ -28,8 +28,7 @@ #include #include -#if defined(__cplusplus) && !defined(_MSC_VER) - +#if defined(__cplusplus) extern "C" { #endif @@ -171,7 +170,7 @@ int scond_broadcast(scond_t *cond); **/ void scond_signal(scond_t *cond); -#if defined(__cplusplus) && !defined(_MSC_VER) +#if defined(__cplusplus) } #endif