Memory maps enhancements on Windows; see issue #578
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <myfile.h>
|
||||
#include <cstdarg>
|
||||
#include <glibmm.h>
|
||||
#include <safegtk.h>
|
||||
#ifdef RAWZOR_SUPPORT
|
||||
#include <rwz_sdk.h>
|
||||
#endif
|
||||
@@ -65,7 +66,7 @@ int munmap(void *start, size_t length)
|
||||
|
||||
IMFILE* fopen (const char* fname)
|
||||
{
|
||||
int fd = ::open(fname,O_RDONLY);
|
||||
int fd = safe_open_ReadOnly(fname);
|
||||
if ( fd < 0 )
|
||||
return 0;
|
||||
|
||||
|
@@ -227,7 +227,7 @@ FILE * safe_g_fopen_WriteBinLock(const Glib::ustring& fname) {
|
||||
// g_fopen just uses _wfopen internally on Windows, does not lock access and has no options to set this
|
||||
// so use a native function to work around this problem
|
||||
wchar_t *wFname = (wchar_t*)g_utf8_to_utf16 (fname.c_str(), -1, NULL, NULL, NULL);
|
||||
HANDLE hFile = CreateFileW(wFname, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
HANDLE hFile = CreateFileW(wFname, GENERIC_READ | GENERIC_WRITE, 0 /* no sharing allowed */, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
g_free(wFname);
|
||||
|
||||
if (hFile==INVALID_HANDLE_VALUE)
|
||||
@@ -241,6 +241,26 @@ FILE * safe_g_fopen_WriteBinLock(const Glib::ustring& fname) {
|
||||
return f;
|
||||
}
|
||||
|
||||
// Covers old UNIX ::open, which expects ANSI instead of UTF8 on Windows
|
||||
int safe_open_ReadOnly(const char *fname) {
|
||||
int fd=-1;
|
||||
|
||||
#ifdef WIN32
|
||||
// First convert UTF8 to UTF16, then use Windows function to open
|
||||
wchar_t *wFname = (wchar_t*)g_utf8_to_utf16 (fname, -1, NULL, NULL, NULL);
|
||||
HANDLE hFile = CreateFileW(wFname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
g_free(wFname);
|
||||
|
||||
// convert back to old file descriptor format
|
||||
if (hFile!=INVALID_HANDLE_VALUE) fd = _open_osfhandle((intptr_t)hFile, 0);
|
||||
#else
|
||||
fd = ::open(fname, O_RDONLY);
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
FILE * safe_g_fopen(const Glib::ustring& src,const gchar *mode)
|
||||
{
|
||||
return g_fopen(src.c_str(),mode);
|
||||
|
@@ -32,6 +32,8 @@ std::string safe_filename_from_utf8 (const Glib::ustring& utf8_str);
|
||||
|
||||
FILE * safe_g_fopen(const Glib::ustring& src,const gchar *mode);
|
||||
FILE * safe_g_fopen_WriteBinLock(const Glib::ustring& fname);
|
||||
int safe_open_ReadOnly(const char *fname);
|
||||
|
||||
bool safe_file_test (const Glib::ustring& filename, Glib::FileTest test);
|
||||
int safe_g_remove(const Glib::ustring& filename);
|
||||
int safe_g_rename(const Glib::ustring& oldFilename, const Glib::ustring& newFilename);
|
||||
|
Reference in New Issue
Block a user