This commit is contained in:
twinaphex 2017-12-04 06:15:14 +01:00
parent 5b942023fc
commit 2bf01e9905
8 changed files with 89 additions and 40 deletions

View file

@ -892,7 +892,7 @@ void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
char buf[128];
buf[0] = '\0';
snprintf(buf, sizeof(buf), STRING_REP_UINT64, val);
snprintf(buf, sizeof(buf), "%" PRIu64, val);
config_set_string(conf, key, buf);
}

View file

@ -219,6 +219,17 @@ int32_t path_get_size(const char *path)
return -1;
}
static bool path_mkdir_error(int ret)
{
#if defined(VITA)
return (ret == SCE_ERROR_ERRNO_EEXIST);
#elif defined(PSP) || defined(_3DS) || defined(WIIU)
return (ret == -1);
#else
return (ret < 0 && errno == EEXIST);
#endif
}
/**
* path_mkdir:
* @dir : directory
@ -230,10 +241,13 @@ int32_t path_get_size(const char *path)
bool path_mkdir(const char *dir)
{
/* Use heap. Real chance of stack overflow if we recurse too hard. */
char *basedir = strdup(dir);
const char *target = NULL;
bool sret = false;
bool norecurse = false;
char *basedir = NULL;
if (dir && *dir)
basedir = strdup(dir);
if (!basedir)
return false;
@ -249,8 +263,8 @@ bool path_mkdir(const char *dir)
}
else
{
target = basedir;
sret = path_mkdir(basedir);
target = basedir;
sret = path_mkdir(basedir);
if (sret)
{
@ -274,16 +288,9 @@ bool path_mkdir(const char *dir)
#endif
/* Don't treat this as an error. */
#if defined(VITA)
if ((ret == SCE_ERROR_ERRNO_EEXIST) && path_is_directory(dir))
if (path_mkdir_error(ret) && path_is_directory(dir))
ret = 0;
#elif defined(PSP) || defined(_3DS) || defined(WIIU)
if ((ret == -1) && path_is_directory(dir))
ret = 0;
#else
if (ret < 0 && errno == EEXIST && path_is_directory(dir))
ret = 0;
#endif
if (ret < 0)
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
sret = (ret == 0);

View file

@ -24,7 +24,9 @@
#if defined(__linux__)
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

View file

@ -20,13 +20,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <file/nbio.h>
#if defined(HAVE_MMAP) && defined(BSD)
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <direct.h>
#else
@ -35,6 +39,20 @@
#include <fcntl.h>
#include <sys/mman.h>
#ifdef __APPLE__
#ifndef O_CLOEXEC
#define O_CLOEXEC 0x1000000
#endif
#else
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
#endif
struct nbio_mmap_unix_t
{
int fd;

View file

@ -56,7 +56,11 @@ static void *nbio_mmap_win32_open(const char * filename, unsigned mode)
{
static const DWORD dispositions[] = { OPEN_EXISTING, CREATE_ALWAYS, OPEN_ALWAYS, OPEN_EXISTING, CREATE_ALWAYS };
HANDLE mem;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
LARGE_INTEGER len;
#else
SIZE_T len;
#endif
struct nbio_mmap_win32_t* handle = NULL;
void* ptr = NULL;
bool is_write = (mode == NBIO_WRITE || mode == NBIO_UPDATE || mode == BIO_WRITE);
@ -74,17 +78,28 @@ static void *nbio_mmap_win32_open(const char * filename, unsigned mode)
if (file == INVALID_HANDLE_VALUE)
return NULL;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* GetFileSizeEx is new for Windows 2000 */
GetFileSizeEx(file, &len);
mem = CreateFileMapping(file, NULL, is_write ? PAGE_READWRITE : PAGE_READONLY, 0, 0, NULL);
ptr = MapViewOfFile(mem, is_write ? (FILE_MAP_READ|FILE_MAP_WRITE) : FILE_MAP_READ, 0, 0, len.QuadPart);
#else
GetFileSize(file, &len);
mem = CreateFileMapping(file, NULL, is_write ? PAGE_READWRITE : PAGE_READONLY, 0, 0, NULL);
ptr = MapViewOfFile(mem, is_write ? (FILE_MAP_READ|FILE_MAP_WRITE) : FILE_MAP_READ, 0, 0, len);
#endif
CloseHandle(mem);
handle = (struct nbio_mmap_win32_t*)malloc(sizeof(struct nbio_mmap_win32_t));
handle->file = file;
handle->is_write = is_write;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
handle->len = len.QuadPart;
#else
handle->len = len;
#endif
handle->ptr = ptr;
return handle;
@ -108,7 +123,11 @@ static bool nbio_mmap_win32_iterate(void *data)
static void nbio_mmap_win32_resize(void *data, size_t len)
{
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
LARGE_INTEGER len_li;
#else
SIZE_T len_li;
#endif
HANDLE mem;
struct nbio_mmap_win32_t* handle = (struct nbio_mmap_win32_t*)data;
@ -125,8 +144,14 @@ static void nbio_mmap_win32_resize(void *data, size_t len)
abort();
}
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* SetFilePointerEx is new for Windows 2000 */
len_li.QuadPart = len;
SetFilePointerEx(handle->file, len_li, NULL, FILE_BEGIN);
#else
len_li = len;
SetFilePointer(handle->file, len_li, NULL, FILE_BEGIN);
#endif
if (!SetEndOfFile(handle->file))
{

View file

@ -179,16 +179,13 @@ bool gl_check_capability(enum gl_capability_enum enum_idx)
&& !gl_query_extension("EXT_framebuffer_object"))
return false;
if (glGenFramebuffers
&& glBindFramebuffer
&& glFramebufferTexture2D
&& glCheckFramebufferStatus
&& glDeleteFramebuffers
&& glGenRenderbuffers
&& glBindRenderbuffer
&& glFramebufferRenderbuffer
&& glRenderbufferStorage
&& glDeleteRenderbuffers)
if (gl_query_extension("ARB_framebuffer_object"))
return true;
if (gl_query_extension("EXT_framebuffer_object"))
return true;
if (major >= 3)
return true;
break;
#endif

View file

@ -75,19 +75,18 @@ typedef int ssize_t;
#include <sys/types.h>
#endif
#ifdef _WIN32
#define STRING_REP_INT64 "%I64d"
#define STRING_REP_UINT64 "%I64u"
#define STRING_REP_USIZE "%Iu"
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L && !defined(VITA) && !defined(WIIU)
#define STRING_REP_INT64 "%lld"
#define STRING_REP_UINT64 "%llu"
#define STRING_REP_USIZE "%zu"
#else
#define STRING_REP_INT64 "%lld"
#define STRING_REP_UINT64 "%llu"
#define STRING_REP_USIZE "%lu"
#ifdef _MSC_VER
#ifndef PRId64
#define PRId64 "I64d"
#define PRIu64 "I64u"
#define PRIuPTR "Iu"
#endif
#else
#include <inttypes.h>
#endif
#define STRING_REP_INT64 "%" PRId64
#define STRING_REP_UINT64 "%" PRIu64
#define STRING_REP_USIZE "%" PRIuPTR
/*
I would like to see retro_inline.h moved in here; possibly boolean too.

View file

@ -169,8 +169,9 @@ void filestream_set_size(RFILE *stream)
* If bufsize is > 0 for unbuffered modes (like RFILE_MODE_WRITE), file will instead be fully buffered.
* Returns a pointer to an RFILE if opened successfully, otherwise NULL.
**/
RFILE *filestream_open(const char *path, unsigned mode, ssize_t bufsize)
RFILE *filestream_open(const char *path, unsigned mode, ssize_t unused)
{
ssize_t bufsize = 0x4000;
int flags = 0;
int mode_int = 0;
#if defined(HAVE_BUFFERED_IO)