Revert "Support Unicode on Windows"

This reverts commit b2b30a90c3.
This commit is contained in:
M4xw committed 2026-09-12 01:23:20 +02:00
1 parent cf00a1d1b4
commit 0926b5fed5
14 files changed
+73 -113

No files matched your search

+3 -3
View File
@@ -382,7 +382,7 @@ static m64p_error write_configlist_file(void)
if (filepath == NULL)
return M64ERR_NO_MEMORY;
fPtr = osal_file_open(filepath, "wb");
fPtr = fopen(filepath, "wb");
if (fPtr == NULL)
{
DebugMessage(M64MSG_ERROR, "Couldn't open configuration file '%s' for writing.", filepath);
@@ -471,7 +471,7 @@ m64p_error ConfigInit(const char *ConfigDirOverride, const char *DataDirOverride
if (filepath == NULL)
return M64ERR_NO_MEMORY;
fPtr = osal_file_open(filepath, "rb");
fPtr = fopen(filepath, "rb");
if (fPtr == NULL)
{
DebugMessage(M64MSG_INFO, "Couldn't open configuration file '%s'. Using defaults.", filepath);
@@ -635,7 +635,7 @@ EXPORT m64p_error CALL ConfigExternalOpen(const char *FileName, m64p_handle *Han
struct external_config* ext_config;
long ftell_result;
size_t filelen = 0;
if (FileName == NULL || (fPtr = osal_file_open(FileName, "rb")) == NULL)
if (FileName == NULL || (fPtr = fopen(FileName, "rb")) == NULL)
{
DebugMessage(M64MSG_ERROR, "Unable to open config file '%s'.", FileName);
return M64ERR_INPUT_INVALID;
@@ -33,8 +33,8 @@ const char procfile[] = "/proc/cpuinfo";
static unsigned char check_arm_cpu_feature(const char* feature)
{
unsigned char status = 0;
FILE *pFile = osal_file_open(procfile, "r");
FILE *pFile = fopen(procfile, "r");
if (pFile != NULL)
{
char line[1024];
@@ -57,8 +57,8 @@ static unsigned char check_arm_cpu_feature(const char* feature)
static unsigned char get_arm_cpu_implementer(void)
{
unsigned char implementer = 0;
FILE *pFile = osal_file_open(procfile, "r");
FILE *pFile = fopen(procfile, "r");
if (pFile != NULL)
{
char line[1024];
@@ -80,8 +80,8 @@ static unsigned char get_arm_cpu_implementer(void)
static unsigned short get_arm_cpu_part(void)
{
unsigned short part = 0;
FILE *pFile = osal_file_open(procfile, "r");
FILE *pFile = fopen(procfile, "r");
if (pFile != NULL)
{
char line[1024];
+4 -4
View File
@@ -843,7 +843,7 @@ void recomp_dbg_init(void)
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
#if RECOMPILER_DEBUG >= NEW_DYNAREC_ARM
FILE * pFile = osal_file_open ("jump_table.txt","w");
FILE * pFile = fopen ("jump_table.txt","w");
uintptr_t * src = (uintptr_t *)((char *)base_addr+(1<<TARGET_SIZE_2)-JUMP_TABLE_SIZE);
while((char *)src<(char *)base_addr+(1<<TARGET_SIZE_2))
@@ -924,7 +924,7 @@ extern unsigned int using_tlb;
if((disasm == 0) || (handle == 0)) return;
sprintf(filename, "0x%.8x.txt",addr);
pFile = osal_file_open (filename,"w");
pFile = fopen (filename,"w");
for(int i=0;i<slen;i++)
disassemble(i, pFile);
@@ -933,7 +933,7 @@ extern unsigned int using_tlb;
fclose(pFile);
sprintf(filename, "%s_0x%.8x.txt","debug",addr);
pFile = osal_file_open (filename,"w");
pFile = fopen (filename,"w");
for(int i=0;i<slen;i++)
debugging(i, pFile);
@@ -942,7 +942,7 @@ extern unsigned int using_tlb;
fclose(pFile);
sprintf(filename, "%s_0x%.8x.txt",ARCH_NAME,addr);
pFile = osal_file_open (filename,"w");
pFile = fopen (filename,"w");
size = (intptr_t)end - (intptr_t)beginning;
size = (size < 0) ? (-size) : size;
+3 -3
View File
@@ -528,7 +528,7 @@ void dynarec_init_block(struct r4300_core* r4300, uint32_t address)
if (!already_exist)
{
#if defined(PROFILE_R4300)
r4300->recomp.pfProfile = osal_file_open("instructionaddrs.dat", "ab");
r4300->recomp.pfProfile = fopen("instructionaddrs.dat", "ab");
long x86addr = (long) b->code;
int mipsop = -2; /* -2 == NOTCOMPILED block at beginning of x86 code */
if (fwrite(&mipsop, 1, 4, r4300->recomp.pfProfile) != 4 || // write 4-byte MIPS opcode
@@ -645,7 +645,7 @@ void dynarec_recompile_block(struct r4300_core* r4300, const uint32_t* iw, struc
init_cache(r4300, block->block + (func & 0xFFF) / 4);
#if defined(PROFILE_R4300)
r4300->recomp.pfProfile = osal_file_open("instructionaddrs.dat", "ab");
r4300->recomp.pfProfile = fopen("instructionaddrs.dat", "ab");
#endif
for (i = (func & 0xFFF) / 4, finished = 0; finished != 2; ++i)
@@ -843,7 +843,7 @@ void profile_write_end_of_code_blocks(struct r4300_core* r4300)
{
size_t i;
r4300->recomp.pfProfile = osal_file_open("instructionaddrs.dat", "ab");
r4300->recomp.pfProfile = fopen("instructionaddrs.dat", "ab");
for (i = 0; i < 0x100000; ++i) {
if (r4300->cached_interp.invalid_code[i] == 0 && r4300->cached_interp.blocks[i] != NULL && r4300->cached_interp.blocks[i]->code != NULL && r4300->cached_interp.blocks[i]->block != NULL)
+1 -2
View File
@@ -40,7 +40,6 @@
#include "device/device.h"
#include "main.h"
#include "md5.h"
#include "osal/files.h"
#include "osal/preproc.h"
#include "osd/osd.h"
#include "rom.h"
@@ -597,7 +596,7 @@ void romdatabase_open(void)
return;
/* Open romdatabase. */
if (pathname == NULL || (fPtr = osal_file_open(pathname, "rb")) == NULL)
if (pathname == NULL || (fPtr = fopen(pathname, "rb")) == NULL)
{
DebugMessage(M64MSG_ERROR, "Unable to open rom database file '%s'.", pathname);
return;
+9 -10
View File
@@ -43,7 +43,6 @@
#include "device/device.h"
#include "main/list.h"
#include "main/main.h"
#include "osal/files.h"
#include "osal/preproc.h"
#include "osd/osd.h"
#include "plugin/plugin.h"
@@ -203,7 +202,7 @@ static int savestates_load_m64p(struct device* dev, char *filepath)
SDL_LockMutex(savestates_lock);
f = osal_gzopen(filepath, "rb");
f = gzopen(filepath, "rb");
if(f==NULL)
{
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Could not open state file: %s", filepath);
@@ -1348,7 +1347,7 @@ static int savestates_load_pj64_unc(struct device* dev, char *filepath)
FILE *f;
/* Open the file. */
f = osal_file_open(filepath, "rb");
f = fopen(filepath, "rb");
if (f == NULL)
{
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Could not open state file: %s", filepath);
@@ -1369,7 +1368,7 @@ static int savestates_load_pj64_unc(struct device* dev, char *filepath)
static savestates_type savestates_detect_type(char *filepath)
{
unsigned char magic[4];
FILE *f = osal_file_open(filepath, "rb");
FILE *f = fopen(filepath, "rb");
if (f == NULL)
{
DebugMessage(M64MSG_STATUS, "Could not open state file %s\n", filepath);
@@ -1409,21 +1408,21 @@ int savestates_load(void)
// try M64P type first
type = savestates_type_m64p;
filepath = savestates_generate_path(type);
fPtr = osal_file_open(filepath, "rb"); // can I open this?
fPtr = fopen(filepath, "rb"); // can I open this?
if (fPtr == NULL)
{
free(filepath);
// try PJ64 zipped type second
type = savestates_type_pj64_zip;
filepath = savestates_generate_path(type);
fPtr = osal_file_open(filepath, "rb"); // can I open this?
fPtr = fopen(filepath, "rb"); // can I open this?
if (fPtr == NULL)
{
free(filepath);
// finally, try PJ64 uncompressed
type = savestates_type_pj64_unc;
filepath = savestates_generate_path(type);
fPtr = osal_file_open(filepath, "rb"); // can I open this?
fPtr = fopen(filepath, "rb"); // can I open this?
if (fPtr == NULL)
{
free(filepath);
@@ -1443,7 +1442,7 @@ int savestates_load(void)
}
filepath = savestates_generate_path(type);
if (filepath != NULL)
fPtr = osal_file_open(filepath, "rb"); // can I open this?
fPtr = fopen(filepath, "rb"); // can I open this?
if (fPtr == NULL)
{
if (filepath != NULL)
@@ -1488,7 +1487,7 @@ static void savestates_save_m64p_work(struct work_struct *work)
SDL_LockMutex(savestates_lock);
// Write the state to a GZIP file
f = osal_gzopen(save->filepath, "wb");
f = gzopen(save->filepath, "wb");
if (f==NULL)
{
@@ -2140,7 +2139,7 @@ static int savestates_save_pj64_unc(const struct device* dev, char *filepath)
{
FILE *f;
f = osal_file_open(filepath, "wb");
f = fopen(filepath, "wb");
if (f == NULL)
{
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Could not create PJ64 state file: %s", filepath);
+2 -2
View File
@@ -97,7 +97,7 @@ static int SaveRGBBufferToFile(const char *filename, const unsigned char *buf, i
return 3;
}
// open the file to write
FILE *savefile = osal_file_open(filename, "wb");
FILE *savefile = fopen(filename, "wb");
if (savefile == NULL)
{
DebugMessage(M64MSG_ERROR, "Error opening '%s' to save screenshot.", filename);
@@ -195,7 +195,7 @@ static char *GetNextScreenshotPath(void)
for (; CurrentShotIndex < 1000; CurrentShotIndex++)
{
sprintf(NumberPtr, "%03i.png", CurrentShotIndex);
FILE *pFile = osal_file_open(ScreenshotPath, "r");
FILE *pFile = fopen(ScreenshotPath, "r");
if (pFile == NULL)
break;
fclose(pFile);
+6 -6
View File
@@ -49,7 +49,7 @@
file_status_t read_from_file(const char *filename, void *data, size_t size)
{
FILE *f = osal_file_open(filename, "rb");
FILE *f = fopen(filename, "rb");
if (f == NULL)
{
return file_open_error;
@@ -67,7 +67,7 @@ file_status_t read_from_file(const char *filename, void *data, size_t size)
file_status_t write_to_file(const char *filename, const void *data, size_t size)
{
FILE *f = osal_file_open(filename, "wb");
FILE *f = fopen(filename, "wb");
if (f == NULL)
{
return file_open_error;
@@ -90,8 +90,8 @@ file_status_t write_chunk_to_file(const char *filename, const void *data, size_t
/* first try to open with rb+ to avoid wiping existing content,
* otherwise create file */
if ((f = osal_file_open(filename, "rb+")) == NULL) {
if ((f = osal_file_open(filename, "wb")) == NULL) {
if ((f = fopen(filename, "rb+")) == NULL) {
if ((f = fopen(filename, "wb")) == NULL) {
return file_open_error;
}
}
@@ -126,7 +126,7 @@ file_status_t load_file(const char* filename, void** buffer, size_t* size)
/* open file */
ret = file_open_error;
fd = osal_file_open(filename, "rb");
fd = fopen(filename, "rb");
if (fd == NULL)
{
return file_open_error;
@@ -188,7 +188,7 @@ file_status_t get_file_size(const char* filename, size_t* size)
/* open file */
ret = file_open_error;
fd = osal_file_open(filename, "rb");
fd = fopen(filename, "rb");
if (fd == NULL)
{
return file_open_error;
-6
View File
@@ -26,8 +26,6 @@
#if !defined (OSAL_FILES_H)
#define OSAL_FILES_H
#include <zlib.h>
/* some file-related preprocessor definitions */
#if defined(WIN32)
#include <io.h> // For _unlink()
@@ -45,7 +43,6 @@
#include <unistd.h> // for unlink()
#define OSAL_DIR_SEPARATORS "/"
#define WIDE_OSAL_DIR_SEPARATORS L"/"
/* PATH_MAX only may be defined by limits.h */
#ifndef PATH_MAX
@@ -64,8 +61,5 @@ extern const char * osal_get_user_configpath(void);
extern const char * osal_get_user_datapath(void);
extern const char * osal_get_user_cachepath(void);
extern FILE * osal_file_open (const char *filename, const char *mode);
extern gzFile osal_gzopen(const char *filename, const char *mode);
#endif /* OSAL_FILES_H */
-9
View File
@@ -223,12 +223,3 @@ const char * osal_get_user_cachepath(void)
return osal_get_user_configpath();
}
FILE * osal_file_open ( const char * filename, const char * mode )
{
return fopen (filename, mode);
}
gzFile osal_gzopen(const char *filename, const char *mode)
{
return gzopen(filename, mode);
}
-8
View File
@@ -232,12 +232,4 @@ const char * osal_get_user_cachepath(void)
return NULL;
}
FILE * osal_file_open(const char *filename, const char *mode)
{
return fopen (filename, mode);
}
gzFile osal_gzopen(const char *filename, const char *mode)
{
return gzopen(filename, mode);
}
+36 -51
View File
@@ -64,10 +64,8 @@ static int search_dir_file(char *destpath, const char *path, const char *filenam
strcat(destpath, "\\");
strcat(destpath, filename);
wchar_t w_destpath[PATH_MAX];
MultiByteToWideChar(CP_UTF8, 0, destpath, -1, w_destpath, PATH_MAX);
/* test for a valid file */
if (_wstat(w_destpath, &fileinfo) != 0)
if (_stat(destpath, &fileinfo) != 0)
return 2;
if ((fileinfo.st_mode & _S_IFREG) == 0)
return 3;
@@ -80,48 +78,52 @@ static int search_dir_file(char *destpath, const char *path, const char *filenam
int osal_mkdirp(const char *dirpath, int mode)
{
wchar_t mypath[MAX_PATH];
wchar_t *currpath, *lastchar;
char *mypath, *currpath, *lastchar;
struct _stat fileinfo;
// Create a copy of the path, so we can modify it
if (MultiByteToWideChar(CP_UTF8, 0, dirpath, -1, mypath, MAX_PATH) == 0)
mypath = currpath = _strdup(dirpath);
if (mypath == NULL)
return 1;
currpath = &mypath[0];
// if the directory path ends with a separator, remove it
lastchar = mypath + wcslen(mypath) - 1;
if (wcschr(WIDE_OSAL_DIR_SEPARATORS, *lastchar) != NULL)
lastchar = mypath + strlen(mypath) - 1;
if (strchr(OSAL_DIR_SEPARATORS, *lastchar) != NULL)
*lastchar = 0;
// Terminate quickly if the path already exists
if (_wstat(mypath, &fileinfo) == 0 && (fileinfo.st_mode & _S_IFDIR))
return 0;
if (_stat(mypath, &fileinfo) == 0 && (fileinfo.st_mode & _S_IFDIR))
goto goodexit;
while ((currpath = wcspbrk(currpath + 1, WIDE_OSAL_DIR_SEPARATORS)) != NULL)
while ((currpath = strpbrk(currpath + 1, OSAL_DIR_SEPARATORS)) != NULL)
{
// if slash is right after colon, then we are looking at drive name prefix (C:\) and should
// just skip it, because _stat and _mkdir will both fail for "C:"
if (currpath > mypath && currpath[-1] == L':')
if (currpath > mypath && currpath[-1] == ':')
continue;
*currpath = L'\0';
if (_wstat(mypath, &fileinfo) != 0)
*currpath = '\0';
if (_stat(mypath, &fileinfo) != 0)
{
if (_wmkdir(mypath) != 0)
return 1;
if (_mkdir(mypath) != 0)
goto errorexit;
}
else if (!(fileinfo.st_mode & _S_IFDIR))
{
return 1;
goto errorexit;
}
*currpath = WIDE_OSAL_DIR_SEPARATORS[0];
*currpath = OSAL_DIR_SEPARATORS[0];
}
// Create full path
if (_wmkdir(mypath) != 0)
return 1;
if (_mkdir(mypath) != 0)
goto errorexit;
goodexit:
free(mypath);
return 0;
errorexit:
free(mypath);
return 1;
}
const char * osal_get_shared_filepath(const char *filename, const char *firstsearch, const char *secondsearch)
@@ -150,8 +152,7 @@ const char * osal_get_shared_filepath(const char *filename, const char *firstsea
const char * osal_get_user_configpath(void)
{
static wchar_t chHomePath[MAX_PATH];
static char outString[MAX_PATH];
static char chHomePath[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pMalloc;
struct _stat fileinfo;
@@ -159,37 +160,35 @@ const char * osal_get_user_configpath(void)
// Get item ID list for the path of user's personal directory
SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl);
// get the path in a char string
SHGetPathFromIDListW(pidl, chHomePath);
SHGetPathFromIDList(pidl, chHomePath);
// do a bunch of crap just to free some memory
SHGetMalloc(&pMalloc);
pMalloc->lpVtbl->Free(pMalloc, pidl);
pMalloc->lpVtbl->Release(pMalloc);
// tack on 'mupen64plus'
if (chHomePath[wcslen(chHomePath)-1] != L'\\')
wcscat(chHomePath, L"\\");
wcscat(chHomePath, L"Mupen64Plus");
if (chHomePath[strlen(chHomePath)-1] != '\\')
strcat(chHomePath, "\\");
strcat(chHomePath, "Mupen64Plus");
// if this directory doesn't exist, then make it
if (_wstat(chHomePath, &fileinfo) == 0)
if (_stat(chHomePath, &fileinfo) == 0)
{
wcscat(chHomePath, L"\\");
WideCharToMultiByte(CP_UTF8, 0, chHomePath, -1, outString, MAX_PATH, NULL, NULL);
return outString;
strcat(chHomePath, "\\");
return chHomePath;
}
else
{
WideCharToMultiByte(CP_UTF8, 0, chHomePath, -1, outString, MAX_PATH, NULL, NULL);
osal_mkdirp(outString, 0);
if (_wstat(chHomePath, &fileinfo) == 0)
osal_mkdirp(chHomePath, 0);
if (_stat(chHomePath, &fileinfo) == 0)
{
strcat(outString, "\\");
return outString;
strcat(chHomePath, "\\");
return chHomePath;
}
}
/* otherwise we are in trouble */
DebugMessage(M64MSG_ERROR, "Failed to open configuration directory '%ls'.", chHomePath);
DebugMessage(M64MSG_ERROR, "Failed to open configuration directory '%s'.", chHomePath);
return NULL;
}
@@ -205,18 +204,4 @@ const char * osal_get_user_cachepath(void)
return osal_get_user_configpath();
}
FILE * osal_file_open ( const char * filename, const char * mode )
{
wchar_t wstr_filename[PATH_MAX];
wchar_t wstr_mode[64];
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wstr_filename, PATH_MAX);
MultiByteToWideChar(CP_UTF8, 0, mode, -1, wstr_mode, 64);
return _wfopen (wstr_filename, wstr_mode);
}
gzFile osal_gzopen(const char *filename, const char *mode)
{
wchar_t wstr_filename[PATH_MAX];
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wstr_filename, PATH_MAX);
return gzopen_w(wstr_filename, mode);
}
+2 -2
View File
@@ -119,7 +119,7 @@ int main(int argc, void *argv[])
/* open r4300 opcode/x86 address table generated from emulator run */
printf("Loading %s...\n", argv[1]);
pfIn = osal_file_open(argv[1], "rb");
pfIn = fopen(argv[1], "rb");
if (pfIn == NULL)
{
printf("Couldn't open input file: %s\n", argv[1]);
@@ -168,7 +168,7 @@ int main(int argc, void *argv[])
/* open the profiling sample data file */
printf("Loading %s...\n", argv[2]);
pfIn = osal_file_open(argv[2], "rb");
pfIn = fopen(argv[2], "rb");
if (pfIn == NULL)
{
printf("Couldn't open input file: %s\n", argv[2]);
+1 -1
View File
@@ -120,7 +120,7 @@ int main(int argc, char *argv[])
return 1;
}
filename = argv[1];
pfTest = osal_file_open(filename, "rb");
pfTest = fopen(filename, "rb");
if (pfTest == NULL)
{
printf("Error: cannot open savestate file '%s' for reading.\n", filename);