diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-04-29 18:12:51 -0400 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2015-05-01 12:31:44 -0400 |
| commit | cd39e4e2f3cc27a2976c9a8e0058f9e32d1f1c8f (patch) | |
| tree | 09d8dc56bccd21b408ce049e13276d16d6493fd4 /src/path.c | |
| parent | f63a1b729bc74e1e72f80f75843b8f2042f3f81f (diff) | |
| download | libgit2-cd39e4e2f3cc27a2976c9a8e0058f9e32d1f1c8f.tar.gz | |
git_buf_put_w: introduce utf16->utf8 conversion
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/src/path.c b/src/path.c index 6c9852b79..5b9fb935e 100644 --- a/src/path.c +++ b/src/path.c @@ -10,6 +10,7 @@ #include "repository.h" #ifdef GIT_WIN32 #include "win32/posix.h" +#include "win32/buffer.h" #include "win32/w32_util.h" #else #include <dirent.h> @@ -1134,7 +1135,7 @@ int git_path_diriter_init( return 0; } -static int diriter_update_utf16(git_path_diriter *diriter) +static int diriter_update_paths(git_path_diriter *diriter) { size_t filename_len, path_len; @@ -1156,29 +1157,9 @@ static int diriter_update_utf16(git_path_diriter *diriter) diriter->current.cFileName, filename_len * sizeof(wchar_t)); diriter->path[path_len-1] = L'\0'; - return 0; -} - -static int diriter_update_utf8(git_path_diriter *diriter) -{ - git_win32_utf8_path filename_utf8; - wchar_t *filename_utf16; - int filename_utf8_len; - - /* Don't copy the full UTF-16 path into the UTF-8 path, only do the - * UTF16 -> UTF8 conversion of the filename portion. This prevents us - * from trying to encode the parent path differently, which would be - * bad since we do arithmetic based on the already computed parent len. - */ - - filename_utf16 = &diriter->path[diriter->parent_len + 1]; - - if ((filename_utf8_len = git_win32_path_to_utf8(filename_utf8, filename_utf16)) < 0) - return filename_utf8_len; - git_buf_truncate(&diriter->path_utf8, diriter->parent_utf8_len); git_buf_putc(&diriter->path_utf8, '/'); - git_buf_put(&diriter->path_utf8, filename_utf8, (size_t)filename_utf8_len); + git_buf_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len); if (git_buf_oom(&diriter->path_utf8)) return -1; @@ -1200,7 +1181,7 @@ int git_path_diriter_next(git_path_diriter *diriter) return GIT_ITEROVER; } while (skip_dot && git_path_is_dot_or_dotdotW(diriter->current.cFileName)); - if (diriter_update_utf16(diriter) < 0 || diriter_update_utf8(diriter) < 0) + if (diriter_update_paths(diriter) < 0) return -1; return 0; |
