win32: move type definitions for improved inclusion Move some win32 type definitions to a standalone file so that they can be included before other header files try to use the definitions.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
diff --git a/src/common.h b/src/common.h
index 03679fc..8a5761a 100644
--- a/src/common.h
+++ b/src/common.h
@@ -47,6 +47,7 @@
# include <ws2tcpip.h>
# include "win32/msvc-compat.h"
# include "win32/mingw-compat.h"
+# include "win32/w32_common.h"
# include "win32/win32-compat.h"
# include "win32/error.h"
# include "win32/version.h"
@@ -76,6 +77,7 @@
#include "git2/types.h"
#include "git2/errors.h"
+#include "errors.h"
#include "thread-utils.h"
#include "integer.h"
@@ -110,80 +112,6 @@
do { int _err = (code); if (_err) return _err; } while (0)
/**
- * Set the error message for this thread, formatting as needed.
- */
-
-void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
-
-/**
- * Set the error message for a regex failure, using the internal regex
- * error code lookup and return a libgit error code.
- */
-int git_error_set_regex(const p_regex_t *regex, int error_code);
-
-/**
- * Set error message for user callback if needed.
- *
- * If the error code in non-zero and no error message is set, this
- * sets a generic error message.
- *
- * @return This always returns the `error_code` parameter.
- */
-GIT_INLINE(int) git_error_set_after_callback_function(
- int error_code, const char *action)
-{
- if (error_code) {
- const git_error *e = git_error_last();
- if (!e || !e->message)
- git_error_set(e ? e->klass : GIT_ERROR_CALLBACK,
- "%s callback returned %d", action, error_code);
- }
- return error_code;
-}
-
-#ifdef GIT_WIN32
-#define git_error_set_after_callback(code) \
- git_error_set_after_callback_function((code), __FUNCTION__)
-#else
-#define git_error_set_after_callback(code) \
- git_error_set_after_callback_function((code), __func__)
-#endif
-
-/**
- * Gets the system error code for this thread.
- */
-int git_error_system_last(void);
-
-/**
- * Sets the system error code for this thread.
- */
-void git_error_system_set(int code);
-
-/**
- * Structure to preserve libgit2 error state
- */
-typedef struct {
- int error_code;
- unsigned int oom : 1;
- git_error error_msg;
-} git_error_state;
-
-/**
- * Capture current error state to restore later, returning error code.
- * If `error_code` is zero, this does not clear the current error state.
- * You must either restore this error state, or free it.
- */
-extern int git_error_state_capture(git_error_state *state, int error_code);
-
-/**
- * Restore error state to a previous value, returning saved error code.
- */
-extern int git_error_state_restore(git_error_state *state);
-
-/** Free an error state. */
-extern void git_error_state_free(git_error_state *state);
-
-/**
* Check a versioned structure for validity
*/
GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name)
diff --git a/src/errors.h b/src/errors.h
new file mode 100644
index 0000000..f2af1e3
--- /dev/null
+++ b/src/errors.h
@@ -0,0 +1,88 @@
+/*
+ * 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_errors_h__
+#define INCLUDE_errors_h__
+
+#include "posix_regex.h"
+#include "common.h"
+
+/*
+ * Set the error message for this thread, formatting as needed.
+ */
+
+void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
+
+/**
+ * Set the error message for a regex failure, using the internal regex
+ * error code lookup and return a libgit error code.
+ */
+int git_error_set_regex(const p_regex_t *regex, int error_code);
+
+/**
+ * Set error message for user callback if needed.
+ *
+ * If the error code in non-zero and no error message is set, this
+ * sets a generic error message.
+ *
+ * @return This always returns the `error_code` parameter.
+ */
+GIT_INLINE(int) git_error_set_after_callback_function(
+ int error_code, const char *action)
+{
+ if (error_code) {
+ const git_error *e = git_error_last();
+ if (!e || !e->message)
+ git_error_set(e ? e->klass : GIT_ERROR_CALLBACK,
+ "%s callback returned %d", action, error_code);
+ }
+ return error_code;
+}
+
+#ifdef GIT_WIN32
+#define git_error_set_after_callback(code) \
+ git_error_set_after_callback_function((code), __FUNCTION__)
+#else
+#define git_error_set_after_callback(code) \
+ git_error_set_after_callback_function((code), __func__)
+#endif
+
+/**
+ * Gets the system error code for this thread.
+ */
+int git_error_system_last(void);
+
+/**
+ * Sets the system error code for this thread.
+ */
+void git_error_system_set(int code);
+
+/**
+ * Structure to preserve libgit2 error state
+ */
+typedef struct {
+ int error_code;
+ unsigned int oom : 1;
+ git_error error_msg;
+} git_error_state;
+
+/**
+ * Capture current error state to restore later, returning error code.
+ * If `error_code` is zero, this does not clear the current error state.
+ * You must either restore this error state, or free it.
+ */
+extern int git_error_state_capture(git_error_state *state, int error_code);
+
+/**
+ * Restore error state to a previous value, returning saved error code.
+ */
+extern int git_error_state_restore(git_error_state *state);
+
+/** Free an error state. */
+extern void git_error_state_free(git_error_state *state);
+
+#endif
diff --git a/src/win32/path_w32.h b/src/win32/path_w32.h
index facbced..afd0aa1 100644
--- a/src/win32/path_w32.h
+++ b/src/win32/path_w32.h
@@ -8,37 +8,8 @@
#define INCLUDE_win32_path_w32_h__
#include "common.h"
-
#include "vector.h"
-/*
- * Provides a large enough buffer to support Windows paths: MAX_PATH is
- * 260, corresponding to a maximum path length of 259 characters plus a
- * NULL terminator. Prefixing with "\\?\" adds 4 characters, but if the
- * original was a UNC path, then we turn "\\server\share" into
- * "\\?\UNC\server\share". So we replace the first two characters with
- * 8 characters, a net gain of 6, so the maximum length is MAX_PATH+6.
- */
-#define GIT_WIN_PATH_UTF16 MAX_PATH+6
-
-/* Maximum size of a UTF-8 Win32 path. We remove the "\\?\" or "\\?\UNC\"
- * prefixes for presentation, bringing us back to 259 (non-NULL)
- * characters. UTF-8 does have 4-byte sequences, but they are encoded in
- * UTF-16 using surrogate pairs, which takes up the space of two characters.
- * Two characters in the range U+0800 -> U+FFFF take up more space in UTF-8
- * (6 bytes) than one surrogate pair (4 bytes).
- */
-#define GIT_WIN_PATH_UTF8 (259 * 3 + 1)
-
-/*
- * The length of a Windows "shortname", for 8.3 compatibility.
- */
-#define GIT_WIN_PATH_SHORTNAME 13
-
-/* Win32 path types */
-typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
-typedef char git_win32_utf8_path[GIT_WIN_PATH_UTF8];
-
/**
* Create a Win32 path (in UCS-2 format) from a UTF-8 string.
*
diff --git a/src/win32/w32_common.h b/src/win32/w32_common.h
new file mode 100644
index 0000000..f9e74b9
--- /dev/null
+++ b/src/win32/w32_common.h
@@ -0,0 +1,39 @@
+/*
+ * 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_w32_common_h__
+#define INCLUDE_win32_w32_common_h__
+
+/*
+ * Provides a large enough buffer to support Windows paths: MAX_PATH is
+ * 260, corresponding to a maximum path length of 259 characters plus a
+ * NULL terminator. Prefixing with "\\?\" adds 4 characters, but if the
+ * original was a UNC path, then we turn "\\server\share" into
+ * "\\?\UNC\server\share". So we replace the first two characters with
+ * 8 characters, a net gain of 6, so the maximum length is MAX_PATH+6.
+ */
+#define GIT_WIN_PATH_UTF16 MAX_PATH+6
+
+/* Maximum size of a UTF-8 Win32 path. We remove the "\\?\" or "\\?\UNC\"
+ * prefixes for presentation, bringing us back to 259 (non-NULL)
+ * characters. UTF-8 does have 4-byte sequences, but they are encoded in
+ * UTF-16 using surrogate pairs, which takes up the space of two characters.
+ * Two characters in the range U+0800 -> U+FFFF take up more space in UTF-8
+ * (6 bytes) than one surrogate pair (4 bytes).
+ */
+#define GIT_WIN_PATH_UTF8 (259 * 3 + 1)
+
+/*
+ * The length of a Windows "shortname", for 8.3 compatibility.
+ */
+#define GIT_WIN_PATH_SHORTNAME 13
+
+/* Win32 path types */
+typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
+typedef char git_win32_utf8_path[GIT_WIN_PATH_UTF8];
+
+#endif