diff options
author | Etienne Samson <samson.etienne@gmail.com> | 2018-01-17 02:25:36 +0100 |
---|---|---|
committer | Etienne Samson <samson.etienne@gmail.com> | 2018-01-25 22:11:19 +0100 |
commit | 3fa5e5779a636bad077af4aeb3006cc9defd2f66 (patch) | |
tree | 12476f01a968fecd617be772e3d7f2ed62bd63af | |
parent | b67200186fe65cfeb2d87a3c408186ae1d17b091 (diff) | |
download | libgit2-3fa5e5779a636bad077af4aeb3006cc9defd2f66.tar.gz |
examples: Move xrealloc to common example code
-rw-r--r-- | examples/common.c | 10 | ||||
-rw-r--r-- | examples/common.h | 5 | ||||
-rw-r--r-- | examples/describe.c | 10 |
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; |