Commit 841034a35ee34190fa1cc136acccfa1a4abaed39

Russell Belfer 2013-08-13T09:45:56

Reintroduce type for UTF8 win32 path conversions

diff --git a/src/win32/dir.c b/src/win32/dir.c
index 0ea5124..22050e8 100644
--- a/src/win32/dir.c
+++ b/src/win32/dir.c
@@ -24,7 +24,7 @@ static int init_filter(char *filter, size_t n, const char *dir)
 
 git__DIR *git__opendir(const char *dir)
 {
-	char filter[GIT_WIN_PATH_UTF8];
+	git_win32_path_as_utf8 filter;
 	git_win32_path filter_w;
 	git__DIR *new = NULL;
 
diff --git a/src/win32/dir.h b/src/win32/dir.h
index 3875ab1..60883ff 100644
--- a/src/win32/dir.h
+++ b/src/win32/dir.h
@@ -11,7 +11,7 @@
 
 struct git__dirent {
 	int d_ino;
-	char d_name[GIT_WIN_PATH_UTF8];
+	git_win32_path_as_utf8 d_name;
 };
 
 typedef struct {
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 3a626f7..2d54794 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -109,10 +109,10 @@ static int do_lstat(
 		 * the length of the path pointed to, which we expect everywhere else
 		 */
 		if (S_ISLNK(fMode)) {
-			char target[GIT_WIN_PATH_UTF8];
+			git_win32_path_as_utf8 target;
 			int readlink_result;
 
-			readlink_result = p_readlink(file_name, target, GIT_WIN_PATH_UTF8);
+			readlink_result = p_readlink(file_name, target, sizeof(target));
 
 			if (readlink_result == -1)
 				return -1;
@@ -300,7 +300,7 @@ int p_getcwd(char *buffer_out, size_t size)
 
 int p_stat(const char* path, struct stat* buf)
 {
-	char target[GIT_WIN_PATH_UTF8];
+	git_win32_path_as_utf8 target;
 	int error = 0;
 
 	error = do_lstat(path, buf, 0);
@@ -308,7 +308,7 @@ int p_stat(const char* path, struct stat* buf)
 	/* We need not do this in a loop to unwind chains of symlinks since
 	 * p_readlink calls GetFinalPathNameByHandle which does it for us. */
 	if (error >= 0 && S_ISLNK(buf->st_mode) &&
-		(error = p_readlink(path, target, GIT_WIN_PATH_UTF8)) >= 0)
+		(error = p_readlink(path, target, sizeof(target))) >= 0)
 		error = do_lstat(target, buf, 0);
 
 	return error;
diff --git a/src/win32/utf-conv.h b/src/win32/utf-conv.h
index 1d008db..3af7758 100644
--- a/src/win32/utf-conv.h
+++ b/src/win32/utf-conv.h
@@ -4,13 +4,12 @@
  * This file is part of libgit2, distributed under the GNU GPL v2 with
  * a Linking Exception. For full terms see the included COPYING file.
  */
+#ifndef INCLUDE_git_utfconv_h__
+#define INCLUDE_git_utfconv_h__
 
 #include <wchar.h>
 #include "common.h"
 
-#ifndef INCLUDE_git_utfconv_h__
-#define INCLUDE_git_utfconv_h__
-
 /* Maximum characters in a Windows path plus one for NUL byte */
 #define GIT_WIN_PATH_UTF16 (260 + 1)
 
@@ -19,6 +18,8 @@
 
 typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
 
+typedef char git_win32_path_as_utf8[GIT_WIN_PATH_UTF8];
+
 /* dest_size is the size of dest in wchar_t's */
 int git__utf8_to_16(wchar_t * dest, size_t dest_size, const char *src);
 /* dest_size is the size of dest in char's */
@@ -29,7 +30,7 @@ GIT_INLINE(int) git_win32_path_from_c(git_win32_path dest, const char *src)
 	return git__utf8_to_16(dest, GIT_WIN_PATH_UTF16, src);
 }
 
-GIT_INLINE(int) git_win32_path_to_c(char *dest, const git_win32_path src)
+GIT_INLINE(int) git_win32_path_to_c(git_win32_path_as_utf8 dest, const wchar_t *src)
 {
 	return git__utf16_to_8(dest, GIT_WIN_PATH_UTF8, src);
 }