Commit 3fa5e577 by Etienne Samson

examples: Move xrealloc to common example code

parent b6720018
...@@ -235,3 +235,13 @@ void treeish_to_tree( ...@@ -235,3 +235,13 @@ void treeish_to_tree(
git_object_free(obj); 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;
}
...@@ -103,3 +103,8 @@ extern int diff_output( ...@@ -103,3 +103,8 @@ extern int diff_output(
*/ */
extern void treeish_to_tree( extern void treeish_to_tree(
git_tree **out, git_repository *repo, const char *treeish); git_tree **out, git_repository *repo, const char *treeish);
/**
* A realloc that exits on failure
*/
extern void *xrealloc(void *oldp, size_t newsz);
...@@ -47,16 +47,6 @@ typedef struct { ...@@ -47,16 +47,6 @@ typedef struct {
typedef struct args_info args_info; 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) static void opts_add_commit(describe_options *opts, const char *commit)
{ {
size_t sz; size_t sz;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment