diff --git a/file/config_file.c b/file/config_file.c index 87f7223..70f7b64 100644 --- a/file/config_file.c +++ b/file/config_file.c @@ -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); } diff --git a/file/file_path.c b/file/file_path.c index 1643b0d..62ee9f2 100644 --- a/file/file_path.c +++ b/file/file_path.c @@ -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); diff --git a/file/nbio/nbio_linux.c b/file/nbio/nbio_linux.c index 7b40551..3395a2c 100644 --- a/file/nbio/nbio_linux.c +++ b/file/nbio/nbio_linux.c @@ -24,7 +24,9 @@ #if defined(__linux__) +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include #include #include diff --git a/file/nbio/nbio_unixmmap.c b/file/nbio/nbio_unixmmap.c index 25ec106..80325da 100644 --- a/file/nbio/nbio_unixmmap.c +++ b/file/nbio/nbio_unixmmap.c @@ -20,13 +20,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #if defined(HAVE_MMAP) && defined(BSD) -#include -#include - #ifdef _WIN32 #include #else @@ -35,6 +39,20 @@ #include #include +#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; diff --git a/file/nbio/nbio_windowsmmap.c b/file/nbio/nbio_windowsmmap.c index 42a22a1..caf0d72 100644 --- a/file/nbio/nbio_windowsmmap.c +++ b/file/nbio/nbio_windowsmmap.c @@ -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)) { diff --git a/gfx/gl_capabilities.c b/gfx/gl_capabilities.c index 221aa2a..695650e 100644 --- a/gfx/gl_capabilities.c +++ b/gfx/gl_capabilities.c @@ -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 diff --git a/include/retro_common_api.h b/include/retro_common_api.h index 659f90d..ef0860b 100644 --- a/include/retro_common_api.h +++ b/include/retro_common_api.h @@ -75,19 +75,18 @@ typedef int ssize_t; #include #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 +#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. diff --git a/streams/file_stream.c b/streams/file_stream.c index 9f6ad73..c4dcddf 100644 --- a/streams/file_stream.c +++ b/streams/file_stream.c @@ -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)