Introduce a wrapper Q_fopen() and replace fopen() with it.

On Unix platforms unicode is implemented through UTF-8 which is
transparent for applications. But on Windows a UTF-16 dialect is
used which needs alteration at application side. This wrapper is
another step to unicode support on Windows, now we can replace
fopen() by a function that converts our internal UTF-8 pathes to
Windows UTF-16 dialect.

This is a noop for Unix platforms. The Windows build is broken,
the compiler errors out in shared.h. This will be fixed in a
later commit.

Caveats:
* fopen() calls in 3rd party code (std_* and unzip) are not replaced.
  This may become a problem. We need to check that.
* In the Unix specific code fopen() isn't replaced since it's not
  necessayry.
This commit is contained in:
Yamagi Burmeister 2018-02-05 07:43:26 +01:00
parent bcb7364507
commit 37ea3e1d58
15 changed files with 38 additions and 28 deletions

View file

@ -284,7 +284,7 @@ void VID_WriteScreenshot( int width, int height, int comp, const void* data )
{
FILE *f;
Com_sprintf(checkname, sizeof(checkname), "%s/scrnshot/q2_%04d.%s", gameDir, i, supportedFormats[format]);
f = fopen(checkname, "rb");
f = Q_fopen(checkname, "rb");
if (!f)
{

View file

@ -165,7 +165,7 @@ Con_Dump_f(void)
Com_Printf("Dumped console text to %s.\n", name);
FS_CreatePath(name);
f = fopen(name, "w");
f = Q_fopen(name, "w");
if (!f)
{

View file

@ -477,7 +477,7 @@ CL_CheckOrDownloadFile(char *filename)
not opened yet */
CL_DownloadFileName(name, sizeof(name), cls.downloadtempname);
fp = fopen(name, "r+b");
fp = Q_fopen(name, "r+b");
if (fp)
{
@ -587,7 +587,7 @@ CL_ParseDownload(void)
FS_CreatePath(name);
cls.download = fopen(name, "wb");
cls.download = Q_fopen(name, "wb");
if (!cls.download)
{

View file

@ -837,7 +837,7 @@ Key_WriteConsoleHistory()
Com_sprintf(path, sizeof(path), "%sconsole_history.txt", Sys_GetHomeDir());
}
FILE* f = fopen(path, "w");
FILE* f = Q_fopen(path, "w");
if(f==NULL)
{
@ -884,7 +884,7 @@ Key_ReadConsoleHistory()
Com_sprintf(path, sizeof(path), "%sconsole_history.txt", Sys_GetHomeDir());
}
FILE* f = fopen(path, "r");
FILE* f = Q_fopen(path, "r");
if(f==NULL)
{
Com_DPrintf("Opening console history %s for reading failed!\n", path);

View file

@ -178,7 +178,7 @@ CL_Record_f(void)
Com_Printf("recording to %s.\n", name);
FS_CreatePath(name);
cls.demofile = fopen(name, "wb");
cls.demofile = Q_fopen(name, "wb");
if (!cls.demofile)
{
@ -604,7 +604,7 @@ CL_WriteConfiguration(void)
Com_sprintf(path, sizeof(path), "%s/config.cfg", FS_Gamedir());
f = fopen(path, "w");
f = Q_fopen(path, "w");
if (!f)
{

View file

@ -144,12 +144,12 @@ Com_VPrintf(int print_level, const char *fmt, va_list argptr)
if (logfile_active->value > 2)
{
logfile = fopen(name, "a");
logfile = Q_fopen(name, "a");
}
else
{
logfile = fopen(name, "w");
logfile = Q_fopen(name, "w");
}
}

View file

@ -501,7 +501,7 @@ Cvar_WriteVariables(char *path)
char buffer[1024];
FILE *f;
f = fopen(path, "a");
f = Q_fopen(path, "a");
for (var = cvar_vars; var; var = var->next)
{

View file

@ -389,7 +389,7 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
{
/* PAK */
file_from_pak = true;
handle->file = fopen(pack->name, "rb");
handle->file = Q_fopen(pack->name, "rb");
if (handle->file)
{
@ -428,12 +428,12 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
/* Search in a directory tree. */
Com_sprintf(path, sizeof(path), "%s/%s", search->path, handle->name);
handle->file = fopen(path, "rb");
handle->file = Q_fopen(path, "rb");
if (!handle->file)
{
Q_strlwr(path);
handle->file = fopen(path, "rb");
handle->file = Q_fopen(path, "rb");
}
if (!handle->file)
@ -668,7 +668,7 @@ FS_LoadPAK(const char *packPath)
dpackheader_t header; /* PAK file header. */
dpackfile_t info[MAX_FILES_IN_PACK]; /* PAK info. */
handle = fopen(packPath, "rb");
handle = Q_fopen(packPath, "rb");
if (handle == NULL)
{

View file

@ -342,7 +342,7 @@ Qcommon_Frame(int msec)
log_stats_file = 0;
}
log_stats_file = fopen("stats.log", "w");
log_stats_file = Q_fopen("stats.log", "w");
if (log_stats_file)
{

View file

@ -254,6 +254,16 @@ int Q_strlcat(char *dst, const char *src, int size);
/* ============================================= */
/* Unicode wrappers around fopen(). */
#ifdef _WIN32
#error "Not implemented yet"
#else
#define Q_fopen(file, mode) fopen(file, mode)
#endif
/* ============================================= */
short BigShort(short l);
short LittleShort(short l);
int BigLong(int l);

View file

@ -293,7 +293,7 @@ SVCmd_WriteIP_f(void)
gi.cprintf(NULL, PRINT_HIGH, "Writing %s.\n", name);
f = fopen(name, "wb");
f = Q_fopen(name, "wb");
if (!f)
{

View file

@ -772,7 +772,7 @@ WriteGame(const char *filename, qboolean autosave)
SaveClientData();
}
f = fopen(filename, "wb");
f = Q_fopen(filename, "wb");
if (!f)
{
@ -824,7 +824,7 @@ ReadGame(const char *filename)
gi.FreeTags(TAG_GAME);
f = fopen(filename, "rb");
f = Q_fopen(filename, "rb");
if (!f)
{
@ -980,7 +980,7 @@ WriteLevel(const char *filename)
edict_t *ent;
FILE *f;
f = fopen(filename, "wb");
f = Q_fopen(filename, "wb");
if (!f)
{
@ -1071,7 +1071,7 @@ ReadLevel(const char *filename)
int i;
edict_t *ent;
f = fopen(filename, "rb");
f = Q_fopen(filename, "rb");
if (!f)
{

View file

@ -509,7 +509,7 @@ SV_ServerRecord_f(void)
Com_Printf("recording to %s.\n", name);
FS_CreatePath(name);
svs.demofile = fopen(name, "wb");
svs.demofile = Q_fopen(name, "wb");
if (!svs.demofile)
{

View file

@ -141,7 +141,7 @@ SV_CheckForSavegame(void)
Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav",
FS_Gamedir(), sv.name);
f = fopen(name, "rb");
f = Q_fopen(name, "rb");
if (!f)
{

View file

@ -80,14 +80,14 @@ CopyFile(char *src, char *dst)
Com_DPrintf("CopyFile (%s, %s)\n", src, dst);
f1 = fopen(src, "rb");
f1 = Q_fopen(src, "rb");
if (!f1)
{
return;
}
f2 = fopen(dst, "wb");
f2 = Q_fopen(dst, "wb");
if (!f2)
{
@ -168,7 +168,7 @@ SV_WriteLevelFile(void)
Com_sprintf(name, sizeof(name), "%s/save/current/%s.sv2",
FS_Gamedir(), sv.name);
f = fopen(name, "wb");
f = Q_fopen(name, "wb");
if (!f)
{
@ -224,7 +224,7 @@ SV_WriteServerFile(qboolean autosave)
Com_DPrintf("SV_WriteServerFile(%s)\n", autosave ? "true" : "false");
Com_sprintf(name, sizeof(name), "%s/save/current/server.ssv", FS_Gamedir());
f = fopen(name, "wb");
f = Q_fopen(name, "wb");
if (!f)
{
@ -367,7 +367,7 @@ SV_Loadgame_f(void)
/* make sure the server.ssv file exists */
Com_sprintf(name, sizeof(name), "%s/save/%s/server.ssv",
FS_Gamedir(), Cmd_Argv(1));
f = fopen(name, "rb");
f = Q_fopen(name, "rb");
if (!f)
{