Add git_has_win32_version helper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/src/common.h b/src/common.h
index 235da04..02d9ce9 100644
--- a/src/common.h
+++ b/src/common.h
@@ -29,9 +29,10 @@
# include "win32/msvc-compat.h"
# include "win32/mingw-compat.h"
# include "win32/error.h"
+# include "win32/version.h"
# ifdef GIT_THREADS
# include "win32/pthread.h"
-#endif
+# endif
#else
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index ba5d1d5..e502001 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -509,11 +509,7 @@ replay:
/* Check for Windows 7. This workaround is only necessary on
* Windows Vista and earlier. Windows 7 is version 6.1. */
- DWORD dwVersion = GetVersion();
-
- if (LOBYTE(LOWORD(dwVersion)) < 6 ||
- (LOBYTE(LOWORD(dwVersion)) == 6 &&
- HIBYTE(LOWORD(dwVersion)) < 1)) {
+ if (!git_has_win32_version(6, 1)) {
wchar_t *location;
DWORD location_length;
int redirect_cmp;
@@ -991,7 +987,7 @@ static int winhttp_receivepack(
{
/* WinHTTP only supports Transfer-Encoding: chunked
* on Windows Vista (NT 6.0) and higher. */
- s->chunked = LOBYTE(LOWORD(GetVersion())) >= 6;
+ s->chunked = git_has_win32_version(6, 0);
if (s->chunked)
s->parent.write = winhttp_stream_write_chunked;
diff --git a/src/win32/error.c b/src/win32/error.c
index 4f169cf..4a9a063 100644
--- a/src/win32/error.c
+++ b/src/win32/error.c
@@ -45,7 +45,7 @@ char *git_win32_get_error_message(DWORD error_code)
(LPWSTR)&lpMsgBuf, 0, NULL)) {
/* Invalid code point check supported on Vista+ only */
- if (LOBYTE(LOWORD(GetVersion())) >= 6)
+ if (git_has_win32_version(6, 0))
dwFlags = WC_ERR_INVALID_CHARS;
else
dwFlags = 0;
diff --git a/src/win32/version.h b/src/win32/version.h
new file mode 100644
index 0000000..803cc60
--- /dev/null
+++ b/src/win32/version.h
@@ -0,0 +1,20 @@
+/*
+ * 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_win32_version_h__
+#define INCLUDE_win32_version_h__
+
+#include <windows.h>
+
+GIT_INLINE(int) git_has_win32_version(int major, int minor)
+{
+ WORD wVersion = LOWORD(GetVersion());
+
+ return LOBYTE(wVersion) > major ||
+ (LOBYTE(wVersion) == major && HIBYTE(wVersion) >= minor);
+}
+
+#endif
\ No newline at end of file