]>
git.proxmox.com Git - libgit2.git/blob - examples/common.h
af42324c23c6e4ab3495984bedeaa2dabcc1a712
2 * Utilities library for libgit2 examples
4 * Written by the libgit2 contributors
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
21 * Check libgit2 error code, printing error to stderr on failure and
22 * exiting the program.
24 extern void check_lg2(int error
, const char *message
, const char *extra
);
27 * Exit the program, printing error to stderr
29 extern void fatal(const char *message
, const char *extra
);
32 * Check if a string has the given prefix. Returns 0 if not prefixed
33 * or the length of the prefix if it is.
35 extern size_t is_prefixed(const char *str
, const char *pfx
);
38 * Match an integer string, returning 1 if matched, 0 if not.
40 extern int is_integer(int *out
, const char *str
, int allow_negative
);
47 #define ARGS_INFO_INIT { argc, argv, 0 }
50 * Check current `args` entry against `opt` string. If it matches
51 * exactly, take the next arg as a string; if it matches as a prefix with
52 * an equal sign, take the remainder as a string; if value not supplied,
53 * default value `def` will be given. otherwise return 0.
55 extern int optional_str_arg(
56 const char **out
, struct args_info
*args
, const char *opt
, const char *def
);
59 * Check current `args` entry against `opt` string. If it matches
60 * exactly, take the next arg as a string; if it matches as a prefix with
61 * an equal sign, take the remainder as a string; otherwise return 0.
63 extern int match_str_arg(
64 const char **out
, struct args_info
*args
, const char *opt
);
67 * Check current `args` entry against `opt` string parsing as uint16. If
68 * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
69 * is a prefix (equal sign optional), take the remainder of the arg as a
70 * uint16_t value; otherwise return 0.
72 extern int match_uint16_arg(
73 uint16_t *out
, struct args_info
*args
, const char *opt
);
76 * Check current `args` entry against `opt` string parsing as uint32. If
77 * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
78 * is a prefix (equal sign optional), take the remainder of the arg as a
79 * uint32_t value; otherwise return 0.
81 extern int match_uint32_arg(
82 uint32_t *out
, struct args_info
*args
, const char *opt
);
85 * Check current `args` entry against `opt` string parsing as int. If
86 * `opt` matches exactly, take the next arg as an int value; if it matches
87 * as a prefix (equal sign optional), take the remainder of the arg as a
88 * int value; otherwise return 0.
90 extern int match_int_arg(
91 int *out
, struct args_info
*args
, const char *opt
, int allow_negative
);
94 * Basic output function for plain text diff output
95 * Pass `FILE*` such as `stdout` or `stderr` as payload (or NULL == `stdout`)
97 extern int diff_output(
98 const git_diff_delta
*, const git_diff_hunk
*, const git_diff_line
*, void*);
101 * Convert a treeish argument to an actual tree; this will call check_lg2
102 * and exit the program if `treeish` cannot be resolved to a tree
104 extern void treeish_to_tree(
105 git_tree
**out
, git_repository
*repo
, const char *treeish
);
108 * A realloc that exits on failure
110 extern void *xrealloc(void *oldp
, size_t newsz
);