X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=config%2Futil.c;h=138894ef49ea18545468de9b1021c58505d36454;hb=d44655a5f52f765a5f5aa86cebed06abbe64a51b;hp=6e7fbf1968090463f37ec1af70d65fb0af28a391;hpb=320cfce45cb7016f265df42c9512414fb8e5d1e1;p=carl9170fw.git diff --git a/config/util.c b/config/util.c index 6e7fbf1..138894e 100644 --- a/config/util.c +++ b/config/util.c @@ -88,16 +88,6 @@ struct gstr str_new(void) return gs; } -/* Allocate and assign growable string */ -struct gstr str_assign(const char *s) -{ - struct gstr gs; - gs.s = strdup(s); - gs.len = strlen(s) + 1; - gs.max_width = 0; - return gs; -} - /* Free storage for growable string */ void str_free(struct gstr *gs) { @@ -114,7 +104,7 @@ void str_append(struct gstr *gs, const char *s) if (s) { l = strlen(gs->s) + strlen(s) + 1; if (l > gs->len) { - gs->s = realloc(gs->s, l); + gs->s = xrealloc(gs->s, l); gs->len = l; } strcat(gs->s, s); @@ -156,4 +146,11 @@ void *xcalloc(size_t nmemb, size_t size) exit(1); } - +void *xrealloc(void *p, size_t size) +{ + p = realloc(p, size); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +}