examples: Move xrealloc to common example code
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
diff --git a/examples/common.c b/examples/common.c
index 96f5eaa..1180720 100644
--- a/examples/common.c
+++ b/examples/common.c
@@ -235,3 +235,13 @@ void treeish_to_tree(
git_object_free(obj);
}
+void *xrealloc(void *oldp, size_t newsz)
+{
+ void *p = realloc(oldp, newsz);
+ if (p == NULL) {
+ fprintf(stderr, "Cannot allocate memory, exiting.\n");
+ exit(1);
+ }
+ return p;
+}
+
diff --git a/examples/common.h b/examples/common.h
index adea0d3..af42324 100644
--- a/examples/common.h
+++ b/examples/common.h
@@ -103,3 +103,8 @@ extern int diff_output(
*/
extern void treeish_to_tree(
git_tree **out, git_repository *repo, const char *treeish);
+
+/**
+ * A realloc that exits on failure
+ */
+extern void *xrealloc(void *oldp, size_t newsz);
diff --git a/examples/describe.c b/examples/describe.c
index 4cdf61f..2005de4 100644
--- a/examples/describe.c
+++ b/examples/describe.c
@@ -47,16 +47,6 @@ typedef struct {
typedef struct args_info args_info;
-static void *xrealloc(void *oldp, size_t newsz)
-{
- void *p = realloc(oldp, newsz);
- if (p == NULL) {
- fprintf(stderr, "Cannot allocate memory, exiting.\n");
- exit(1);
- }
- return p;
-}
-
static void opts_add_commit(describe_options *opts, const char *commit)
{
size_t sz;