Skip to content

Commit 3fa5e57

Browse files
committed
examples: Move xrealloc to common example code
1 parent b672001 commit 3fa5e57

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

examples/common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,13 @@ void treeish_to_tree(
235235
git_object_free(obj);
236236
}
237237

238+
void *xrealloc(void *oldp, size_t newsz)
239+
{
240+
void *p = realloc(oldp, newsz);
241+
if (p == NULL) {
242+
fprintf(stderr, "Cannot allocate memory, exiting.\n");
243+
exit(1);
244+
}
245+
return p;
246+
}
247+

examples/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ extern int diff_output(
103103
*/
104104
extern void treeish_to_tree(
105105
git_tree **out, git_repository *repo, const char *treeish);
106+
107+
/**
108+
* A realloc that exits on failure
109+
*/
110+
extern void *xrealloc(void *oldp, size_t newsz);

examples/describe.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ typedef struct {
4747

4848
typedef struct args_info args_info;
4949

50-
static void *xrealloc(void *oldp, size_t newsz)
51-
{
52-
void *p = realloc(oldp, newsz);
53-
if (p == NULL) {
54-
fprintf(stderr, "Cannot allocate memory, exiting.\n");
55-
exit(1);
56-
}
57-
return p;
58-
}
59-
6050
static void opts_add_commit(describe_options *opts, const char *commit)
6151
{
6252
size_t sz;

0 commit comments

Comments
 (0)