--- ed.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ed.c b/ed.c index 5511a9e..97fa5e8 100644 --- a/ed.c +++ b/ed.c _AT_@ -20,6 +20,12 @@ #define NUMLINES 32 #define CACHESIZ 4096 +typedef struct { + char *str; + size_t cap; + size_t siz; +} String; + struct hline { off_t seek; char global; _AT_@ -111,6 +117,23 @@ prevln(int line) return (line < 0) ? lastln : line; } +static char * +addchar_(char c, String *s) +{ + size_t cap = s->cap, siz = s->siz; + char *t = s->str; + + if (siz >= cap && + (cap > SIZE_MAX - LINESIZE || + (t = realloc(t, cap += LINESIZE)) == NULL)) + error("out of memory"); + t[siz++] = c; + s->siz = siz; + s->cap = cap; + s->str = t; + return t; +} + static char * addchar(char c, char *t, size_t *capacity, size_t *size) { -- 2.14.2Received on Tue Mar 06 2018 - 12:57:54 CET
This archive was generated by hypermail 2.3.0 : Tue Mar 06 2018 - 13:01:21 CET