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
|
#include "die.h"
#include <assert.h> // assert
#include <stdio.h> // fprintf, vfprintf, fputc, stderr
#include <stdlib.h> // exit, EXIT_FAILURE
#include <stdarg.h> // va_*
#include <git2.h> // git_*
#include <string.h> // strerror
#include <errno.h> // errno
void die(const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fputc('\n', stderr);
#ifndef NDEBUG
git_libgit2_shutdown();
#endif
exit(EXIT_FAILURE);
}
// Die but include the last git error.
void noreturn die_git(const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
const git_error *e = git_error_last();
assert(e != NULL && "die_git called without error");
fprintf(stderr, ": %s\n", e->message);
#ifndef NDEBUG
git_libgit2_shutdown();
#endif
exit(EXIT_FAILURE);
}
// Die but include errno information.
void noreturn die_errno(const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fprintf(stderr, ": %s\n", strerror(errno));
#ifndef NDEBUG
git_libgit2_shutdown();
#endif
exit(EXIT_FAILURE);
}
|