Commit 98f7bd289dfb172473b7d7353d4b0f0b09c67937

Edward Thomson 2015-08-05T16:26:43

Merge pull request #3360 from nodegit/master-duplicate-basename-fix Fix duplicate basenames to support older VS on master

diff --git a/src/path.c b/src/path.c
index 8317aaa..9ce5d29 100644
--- a/src/path.c
+++ b/src/path.c
@@ -10,7 +10,7 @@
 #include "repository.h"
 #ifdef GIT_WIN32
 #include "win32/posix.h"
-#include "win32/buffer.h"
+#include "win32/w32_buffer.h"
 #include "win32/w32_util.h"
 #include "win32/version.h"
 #else
diff --git a/src/util.c b/src/util.c
index b08b2b8..b3929bc 100644
--- a/src/util.c
+++ b/src/util.c
@@ -11,7 +11,7 @@
 #include "posix.h"
 
 #ifdef GIT_WIN32
-# include "win32/buffer.h"
+# include "win32/w32_buffer.h"
 #endif
 
 #ifdef _MSC_VER
diff --git a/src/win32/buffer.c b/src/win32/buffer.c
deleted file mode 100644
index 7495018..0000000
--- a/src/win32/buffer.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#include "common.h"
-#include "buffer.h"
-#include "../buffer.h"
-#include "utf-conv.h"
-
-GIT_INLINE(int) handle_wc_error(void)
-{
-	if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
-		errno = ENAMETOOLONG;
-	else
-		errno = EINVAL;
-
-	return -1;
-}
-
-int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
-{
-	int utf8_len, utf8_write_len;
-	size_t new_size;
-
-	if (!len_w)
-		return 0;
-
-	assert(string_w);
-
-	/* Measure the string necessary for conversion */
-	if ((utf8_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string_w, len_w, NULL, 0, NULL, NULL)) == 0)
-		return 0;
-
-	assert(utf8_len > 0);
-
-	GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
-	GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
-
-	if (git_buf_grow(buf, new_size) < 0)
-		return -1;
-
-	if ((utf8_write_len = WideCharToMultiByte(
-			CP_UTF8, WC_ERR_INVALID_CHARS, string_w, len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0)
-		return handle_wc_error();
-
-	assert(utf8_write_len == utf8_len);
-
-	buf->size += utf8_write_len;
-	buf->ptr[buf->size] = '\0';
-	return 0;
-}
-
diff --git a/src/win32/buffer.h b/src/win32/buffer.h
deleted file mode 100644
index 6224398..0000000
--- a/src/win32/buffer.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * 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_win32_buffer_h__
-#define INCLUDE_git_win32_buffer_h__
-
-#include "../buffer.h"
-
-/**
- * Convert a wide character string to UTF-8 and append the results to the
- * buffer.
- */
-int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w);
-
-#endif
diff --git a/src/win32/w32_buffer.c b/src/win32/w32_buffer.c
new file mode 100644
index 0000000..9122baa
--- /dev/null
+++ b/src/win32/w32_buffer.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "common.h"
+#include "w32_buffer.h"
+#include "../buffer.h"
+#include "utf-conv.h"
+
+GIT_INLINE(int) handle_wc_error(void)
+{
+	if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+		errno = ENAMETOOLONG;
+	else
+		errno = EINVAL;
+
+	return -1;
+}
+
+int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
+{
+	int utf8_len, utf8_write_len;
+	size_t new_size;
+
+	if (!len_w)
+		return 0;
+
+	assert(string_w);
+
+	/* Measure the string necessary for conversion */
+	if ((utf8_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string_w, len_w, NULL, 0, NULL, NULL)) == 0)
+		return 0;
+
+	assert(utf8_len > 0);
+
+	GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
+	GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+
+	if (git_buf_grow(buf, new_size) < 0)
+		return -1;
+
+	if ((utf8_write_len = WideCharToMultiByte(
+			CP_UTF8, WC_ERR_INVALID_CHARS, string_w, len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0)
+		return handle_wc_error();
+
+	assert(utf8_write_len == utf8_len);
+
+	buf->size += utf8_write_len;
+	buf->ptr[buf->size] = '\0';
+	return 0;
+}
diff --git a/src/win32/w32_buffer.h b/src/win32/w32_buffer.h
new file mode 100644
index 0000000..6224398
--- /dev/null
+++ b/src/win32/w32_buffer.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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_win32_buffer_h__
+#define INCLUDE_git_win32_buffer_h__
+
+#include "../buffer.h"
+
+/**
+ * Convert a wide character string to UTF-8 and append the results to the
+ * buffer.
+ */
+int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w);
+
+#endif