vc2010 workarounds for libretro-common

This commit is contained in:
zeromus 2016-03-21 01:33:12 +00:00
parent 2c127b73b0
commit a009d2ac13
8 changed files with 115 additions and 11 deletions

View File

@ -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 <retro_common.h>
#include <stdarg.h>
/* 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;
}

View File

@ -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);

View File

@ -23,10 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <retro_common.h>
#include <file/file_list.h>
#include <compat/strcasestr.h>
#include <compat/posix_string.h>
#include <compat/strl.h>
void file_list_push(file_list_t *list,
const char *path, const char *label,

View File

@ -23,6 +23,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <retro_common.h>
#if defined(_WIN32)
# ifdef _MSC_VER
# define setmode _setmode

View File

@ -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 <stdlib.h>
#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 <stdarg.h>
#include <stdlib.h>
#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. */

View File

@ -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 <compat/msvc.h>
#endif

View File

@ -28,6 +28,7 @@
#include <sys/types.h>
#include <retro_common.h>
#include <boolean.h>
#ifdef __cplusplus

View File

@ -28,8 +28,7 @@
#include <retro_inline.h>
#include <retro_miscellaneous.h>
#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