summaryrefslogtreecommitdiff
path: root/src/errors.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-01-13 21:10:50 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-05-19 11:12:13 +0100
commitfe1fb36e57a35c73740fc7ff2286fd0b7b3c0a20 (patch)
tree7d76140932dc1f36dee11e75c348a6810ebb3820 /src/errors.h
parente4b2ef87c75ea48cba55bb32c327051ca82ddd90 (diff)
downloadlibgit2-fe1fb36e57a35c73740fc7ff2286fd0b7b3c0a20.tar.gz
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.
Diffstat (limited to 'src/errors.h')
-rw-r--r--src/errors.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
new file mode 100644
index 000000000..f2af1e37d
--- /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