File Coverage

deps/libgit2/src/libgit2/errors.h
Criterion Covered Total %
statement 6 6 100.0
branch 3 8 37.5
condition n/a
subroutine n/a
pod n/a
total 9 14 64.2


line stmt bran cond sub pod time code
1             /*
2             * Copyright (C) the libgit2 contributors. All rights reserved.
3             *
4             * This file is part of libgit2, distributed under the GNU GPL v2 with
5             * a Linking Exception. For full terms see the included COPYING file.
6             */
7              
8             #ifndef INCLUDE_errors_h__
9             #define INCLUDE_errors_h__
10              
11             #include "common.h"
12              
13             /*
14             * `vprintf`-style formatting for the error message for this thread.
15             */
16             void git_error_vset(int error_class, const char *fmt, va_list ap);
17              
18             /**
19             * Set error message for user callback if needed.
20             *
21             * If the error code in non-zero and no error message is set, this
22             * sets a generic error message.
23             *
24             * @return This always returns the `error_code` parameter.
25             */
26 6           GIT_INLINE(int) git_error_set_after_callback_function(
27             int error_code, const char *action)
28             {
29 6 50         if (error_code) {
30 6           const git_error *e = git_error_last();
31 6 50         if (!e || !e->message)
    0          
32 6 50         git_error_set(e ? e->klass : GIT_ERROR_CALLBACK,
33             "%s callback returned %d", action, error_code);
34             }
35 6           return error_code;
36             }
37              
38             #ifdef GIT_WIN32
39             #define git_error_set_after_callback(code) \
40             git_error_set_after_callback_function((code), __FUNCTION__)
41             #else
42             #define git_error_set_after_callback(code) \
43             git_error_set_after_callback_function((code), __func__)
44             #endif
45              
46             /**
47             * Gets the system error code for this thread.
48             */
49             int git_error_system_last(void);
50              
51             /**
52             * Sets the system error code for this thread.
53             */
54             void git_error_system_set(int code);
55              
56             /**
57             * Structure to preserve libgit2 error state
58             */
59             typedef struct {
60             int error_code;
61             unsigned int oom : 1;
62             git_error error_msg;
63             } git_error_state;
64              
65             /**
66             * Capture current error state to restore later, returning error code.
67             * If `error_code` is zero, this does not clear the current error state.
68             * You must either restore this error state, or free it.
69             */
70             extern int git_error_state_capture(git_error_state *state, int error_code);
71              
72             /**
73             * Restore error state to a previous value, returning saved error code.
74             */
75             extern int git_error_state_restore(git_error_state *state);
76              
77             /** Free an error state. */
78             extern void git_error_state_free(git_error_state *state);
79              
80             #endif