diff options
author | Chris Robinson <[email protected]> | 2017-10-07 14:48:07 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-10-07 14:48:07 -0700 |
commit | d57eca57a93a78f9d04de0bc562319dcff6ccbc7 (patch) | |
tree | 2d79836a5bc3059b1eb6cf822c21eb770697b4ec /common/win_main_utf8.h | |
parent | 71ce90d083af6d654cba5d5b394f04fdade9ba1c (diff) |
Use _wfopen_s to silence MSVC security warnings
Diffstat (limited to 'common/win_main_utf8.h')
-rw-r--r-- | common/win_main_utf8.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/common/win_main_utf8.h b/common/win_main_utf8.h index 821312d7..faddc257 100644 --- a/common/win_main_utf8.h +++ b/common/win_main_utf8.h @@ -1,10 +1,10 @@ #ifndef WIN_MAIN_UTF8_H #define WIN_MAIN_UTF8_H -/* For Windows systems this overrides main() so that the argv strings are UTF-8 - * encoded, and also overrides fopen to accept UTF-8 filenames. Working with - * wmain directly complicates cross-platform compatibility, while normal main() - * in Windows uses the current codepage (which has limited availability of +/* For Windows systems this provides a way to get UTF-8 encoded argv strings, + * and also overrides fopen to accept UTF-8 filenames. Working with wmain + * directly complicates cross-platform compatibility, while normal main() in + * Windows uses the current codepage (which has limited availability of * characters). * * For MinGW, you must link with -municode @@ -19,6 +19,7 @@ static FILE *my_fopen(const char *fname, const char *mode) WCHAR *wname=NULL, *wmode=NULL; int namelen, modelen; FILE *file = NULL; + errno_t err; namelen = MultiByteToWideChar(CP_UTF8, 0, fname, -1, NULL, 0); modelen = MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0); @@ -34,7 +35,12 @@ static FILE *my_fopen(const char *fname, const char *mode) MultiByteToWideChar(CP_UTF8, 0, fname, -1, wname, namelen); MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, modelen); - file = _wfopen(wname, wmode); + err = _wfopen_s(&file, wname, wmode); + if(err) + { + errno = err; + file = NULL; + } free(wname); |