diff options
author | Sv. Lockal <lockalsash@gmail.com> | 2012-05-14 17:28:36 +0400 |
---|---|---|
committer | Sv. Lockal <lockalsash@gmail.com> | 2012-05-14 17:28:36 +0400 |
commit | e0e97dfca70c475069ab207c24bffc4da1fa7701 (patch) | |
tree | a31f6041c3a81bd36544b07cbc2dda417c96bcaa /source | |
parent | a54f63b32d9230788c58d7b4e9ae49a1d18fd511 (diff) |
Fix for BLI_gzopen to work with utf filenames in windows
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index e6d06484e74..958de59c4b3 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -211,33 +211,31 @@ FILE *BLI_fopen(const char *filename, const char *mode) void *BLI_gzopen(const char *filename, const char *mode) { - gzFile gzfile; + FILE *file; + gzFile gzfile = NULL; + wchar_t short_name_16[256]; - if (!filename || !mode) { + if (!filename || !mode) return 0; - } - else { - wchar_t short_name_16[256]; - char short_name[256]; - int i = 0; - /* xxx Creates file before transcribing the path */ - if (mode[0] == 'w') - fclose(ufopen(filename, "a")); + /* xxx Creates file before transcribing the path */ + if (mode[0] == 'w') + fclose(ufopen(filename, "a")); - UTF16_ENCODE(filename); + UTF16_ENCODE(filename); + UTF16_ENCODE(mode); - GetShortPathNameW(filename_16, short_name_16, 256); + GetShortPathNameW(filename_16, short_name_16, 256); - for (i = 0; i < 256; i++) { - short_name[i] = (char)short_name_16[i]; + if ((file = _wfopen(short_name_16, mode_16))) { + if (!(gzfile = gzdopen(fileno(file), mode))) { + fclose(file); } - - gzfile = gzopen(short_name, mode); - - UTF16_UN_ENCODE(filename); } + UTF16_UN_ENCODE(mode); + UTF16_UN_ENCODE(filename); + return gzfile; } |