summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtienne Samson <samson.etienne@gmail.com>2018-01-17 02:25:36 +0100
committerEtienne Samson <samson.etienne@gmail.com>2018-01-25 22:11:19 +0100
commit3fa5e5779a636bad077af4aeb3006cc9defd2f66 (patch)
tree12476f01a968fecd617be772e3d7f2ed62bd63af
parentb67200186fe65cfeb2d87a3c408186ae1d17b091 (diff)
downloadlibgit2-3fa5e5779a636bad077af4aeb3006cc9defd2f66.tar.gz
examples: Move xrealloc to common example code
-rw-r--r--examples/common.c10
-rw-r--r--examples/common.h5
-rw-r--r--examples/describe.c10
3 files changed, 15 insertions, 10 deletions
diff --git a/examples/common.c b/examples/common.c
index 96f5eaa8e..118072044 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 adea0d318..af42324c2 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 4cdf61f75..2005de4ae 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;