diff options
author | Vicent Martà <vicent@github.com> | 2012-09-04 14:19:24 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-09-04 14:19:24 -0700 |
commit | 4d3834038bd0aaef63d62c54900f6ddafec09515 (patch) | |
tree | e1cc8e3bc55d73e3e00f876a220fcfc462938f60 /src/fileops.c | |
parent | c9d223f0de390e8b28af7c7513d03340001c2580 (diff) | |
parent | 0f4c61754bd123b3bee997b397187c9b813ca3e4 (diff) | |
download | libgit2-4d3834038bd0aaef63d62c54900f6ddafec09515.tar.gz |
Merge pull request #856 from libgit2/utf8-win
Windows: Perform UTF-8 path conversion on the Stack
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/src/fileops.c b/src/fileops.c index 76ef8c910..95eacb5f1 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -54,11 +54,10 @@ int git_futils_creat_locked(const char *path, const mode_t mode) int fd; #ifdef GIT_WIN32 - wchar_t* buf; + wchar_t buf[GIT_WIN_PATH]; - buf = gitwin_to_utf16(path); + git__utf8_to_16(buf, GIT_WIN_PATH, path); fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode); - git__free(buf); #else fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode); #endif @@ -382,16 +381,16 @@ static int win32_expand_path(struct win32_path *s_root, const wchar_t *templ) static int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename) { - int error = 0; - size_t len; + size_t len, alloc_len; wchar_t *file_utf16 = NULL; - char *file_utf8 = NULL; + char file_utf8[GIT_PATH_MAX]; if (!root || !filename || (len = strlen(filename)) == 0) return GIT_ENOTFOUND; /* allocate space for wchar_t path to file */ - file_utf16 = git__calloc(root->len + len + 2, sizeof(wchar_t)); + alloc_len = root->len + len + 2; + file_utf16 = git__calloc(alloc_len, sizeof(wchar_t)); GITERR_CHECK_ALLOC(file_utf16); /* append root + '\\' + filename as wchar_t */ @@ -400,29 +399,20 @@ static int win32_find_file(git_buf *path, const struct win32_path *root, const c if (*filename == '/' || *filename == '\\') filename++; - if (gitwin_append_utf16(file_utf16 + root->len - 1, filename, len + 1) != - (int)len + 1) { - error = -1; - goto cleanup; - } + git__utf8_to_16(file_utf16 + root->len - 1, alloc_len, filename); /* check access */ if (_waccess(file_utf16, F_OK) < 0) { - error = GIT_ENOTFOUND; - goto cleanup; + git__free(file_utf16); + return GIT_ENOTFOUND; } - /* convert to utf8 */ - if ((file_utf8 = gitwin_from_utf16(file_utf16)) == NULL) - error = -1; - else { - git_path_mkposix(file_utf8); - git_buf_attach(path, file_utf8, 0); - } + git__utf16_to_8(file_utf8, file_utf16); + git_path_mkposix(file_utf8); + git_buf_sets(path, file_utf8); -cleanup: git__free(file_utf16); - return error; + return 0; } #endif |