aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2015-02-07 04:19:50 -0800
committerChris Robinson <[email protected]>2015-02-07 04:19:50 -0800
commit50cdc0ac1e3e69142989c9aa2f27cbeb44ec6c3d (patch)
tree8a166a5724be1f77818189c37abe6f4597e548ce
parent61743a3a0017c567ee62ab50c3da28a5ed2fed8d (diff)
Avoid tracing wide-char strings
Because on Windows, traced strings are written to a char string, which causes UTF-16 strings to be converted to a narrow (non-UTF-8) encoding, potentially losing characters.
-rw-r--r--Alc/alcConfig.c18
-rw-r--r--Alc/helpers.c52
2 files changed, 43 insertions, 27 deletions
diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c
index c8928c3c..acfc97b8 100644
--- a/Alc/alcConfig.c
+++ b/Alc/alcConfig.c
@@ -305,27 +305,33 @@ void ReadALConfig(void)
if(SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE)
{
- size_t p = lstrlenW(buffer);
- _snwprintf(buffer+p, PATH_MAX-p, L"\\alsoft.ini");
+ al_string filepath = AL_STRING_INIT_STATIC();
+ al_string_copy_wcstr(&filepath, buffer);
+ al_string_append_cstr(&filepath, "\\alsoft.ini");
- TRACE("Loading config %ls...\n", buffer);
- f = _wfopen(buffer, L"rt");
+ TRACE("Loading config %s...\n", al_string_get_cstr(filepath));
+ f = al_fopen(al_string_get_cstr(filepath), "rt");
if(f)
{
LoadConfigFromFile(f);
fclose(f);
}
+ al_string_deinit(&filepath);
}
if((str=_wgetenv(L"ALSOFT_CONF")) != NULL && *str)
{
- TRACE("Loading config %ls...\n", str);
- f = _wfopen(str, L"rt");
+ al_string filepath = AL_STRING_INIT_STATIC();
+ al_string_copy_wcstr(&filepath, str);
+
+ TRACE("Loading config %s...\n", al_string_get_cstr(filepath));
+ f = al_fopen(al_string_get_cstr(filepath), "rt");
if(f)
{
LoadConfigFromFile(f);
fclose(f);
}
+ al_string_deinit(&filepath);
}
}
#else
diff --git a/Alc/helpers.c b/Alc/helpers.c
index aa8feebc..674c7eb6 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -457,34 +457,42 @@ FILE *OpenDataFile(const char *fname, const char *subdir)
static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA };
WCHAR *wname=NULL, *wsubdir=NULL;
FILE *f;
- int i;
+ size_t i;
- /* If the path is absolute, open it directly. */
- if(fname[0] != '\0' && fname[1] == ':' && is_slash(fname[2]))
+ wname = FromUTF8(fname);
+ if(!wname)
{
- if((f=al_fopen(fname, "rb")) != NULL)
- {
- TRACE("Opened %s\n", fname);
- return f;
- }
- WARN("Could not open %s\n", fname);
+ ERR("Failed to convert UTF-8 filename: \"%s\"\n", fname);
return NULL;
}
- /* If it's relative, try the current directory first before the data directories. */
- if((f=al_fopen(fname, "rb")) != NULL)
+ /* If the path is absolute, open it directly. */
+ if(wname[0] != '\0' && wname[1] == ':' && is_slash(wname[2]))
+ {
+ f = _wfopen(wname, L"rb");
+ if(f) TRACE("Opened %s\n", fname);
+ else WARN("Could not open %s\n", fname);
+ free(wname);
+ return f;
+ }
+
+ /* Try the current directory first before the data directories. */
+ if((f=_wfopen(wname, L"rb")) != NULL)
{
TRACE("Opened %s\n", fname);
+ free(wname);
return f;
}
- wname = FromUTF8(fname);
wsubdir = FromUTF8(subdir);
- if(!wname)
- ERR("Failed to convert UTF-8 filename: \"%s\"\n", fname);
- else if(!wsubdir)
+ if(!wsubdir)
+ {
ERR("Failed to convert UTF-8 subdir: \"%s\"\n", subdir);
- else for(i = 0;i < 2;i++)
+ free(wname);
+ return NULL;
+ }
+
+ for(i = 0;i < COUNTOF(ids);i++)
{
WCHAR buffer[PATH_MAX];
size_t len;
@@ -506,16 +514,18 @@ FILE *OpenDataFile(const char *fname, const char *subdir)
if((f=_wfopen(buffer, L"rb")) != NULL)
{
- TRACE("Opened %ls\n", buffer);
- free(wname);
- free(wsubdir);
- return f;
+ al_string filepath = AL_STRING_INIT_STATIC();
+ al_string_copy_wcstr(&filepath, buffer);
+ TRACE("Opened %s\n", al_string_get_cstr(filepath));
+ al_string_deinit(&filepath);
+ break;
}
}
- WARN("Could not open %ls\\%ls\n", wsubdir, wname);
free(wname);
free(wsubdir);
+ if(f == NULL)
+ WARN("Could not open %s\\%s\n", subdir, fname);
return NULL;
}