[hackers] [sbase] Add missing file (util/getlines.c) || Robert Ransom

From: <hg_AT_suckless.org>
Date: Tue, 22 May 2012 13:08:56 +0200 (CEST)

changeset: 136:86aa1bae5ce2
tag: tip
user: Robert Ransom <rransom.8774_AT_gmail.com>
date: Tue May 22 11:05:07 2012 +0000
files: util/getlines.c
description:
Add missing file (util/getlines.c)


diff -r c69bda5d1bc2 -r 86aa1bae5ce2 util/getlines.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/util/getlines.c Tue May 22 11:05:07 2012 +0000
_AT_@ -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);
+}
Received on Tue May 22 2012 - 13:08:56 CEST

This archive was generated by hypermail 2.3.0 : Tue May 22 2012 - 13:12:19 CEST