commit 9ea0be3f07abd86aa852eec11e42663b578970b1
parent e6238dda31b4a82e3806c51f809c3d1c657bfcdc
Author: Robert Ransom <rransom.8774@gmail.com>
Date: Tue, 22 May 2012 11:05:07 +0000
Add missing file (util/getlines.c)
Diffstat:
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/util/getlines.c b/util/getlines.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../text.h"
+#include "../util.h"
+
+void
+getlines(FILE *fp, struct linebuf *b)
+{
+ char *line = NULL;
+ size_t size = 0;
+
+ while(afgets(&line, &size, fp)) {
+ if(++b->nlines > b->capacity && !(b->lines = realloc(b->lines, (b->capacity+=512) * sizeof *b->lines)))
+ eprintf("realloc:");
+ if(!(b->lines[b->nlines-1] = malloc(strlen(line)+1)))
+ eprintf("malloc:");
+ strcpy(b->lines[b->nlines-1], line);
+ }
+ free(line);
+}