Commit 3fa5e5779a636bad077af4aeb3006cc9defd2f66

Etienne Samson 2018-01-17T02:25:36

examples: Move xrealloc to common example code

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;