summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2014-05-13 10:06:27 +0000
committerHiltjo Posthuma <hiltjo@codemadness.org>2014-05-13 10:06:27 +0000
commitc3b5da658eeef51b1444060aa107fc413ea0f436 (patch)
tree434ed88a19c1b22dc03cc9e782a2522a409d6e3b
parent79eb0f67b83fca3d8917845fe0c913cd0e10e2f2 (diff)
util: use standard getline() function to get lines
this is standard since POSIX 200809L Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
-rw-r--r--util.c38
1 files changed, 1 insertions, 37 deletions
diff --git a/util.c b/util.c
index b501cd0..35ebb75 100644
--- a/util.c
+++ b/util.c
@@ -33,43 +33,7 @@ strlcpy(char *dst, const char *src, size_t siz) {
while (*s++)
;
}
- return(s - src - 1); /* count does not include NUL */
-}
-
-char *
-afgets(char **p, size_t *size, FILE *fp) {
- char buf[BUFSIZ], *alloc = NULL;
- size_t n, len = 0, allocsiz;
- int end = 0;
-
- while(!end && !feof(fp) && fgets(buf, sizeof(buf), fp)) {
- n = strlen(buf);
- if(buf[n - 1] == '\n') { /* dont store newlines. */
- buf[n - 1] = '\0';
- n--;
- end = 1; /* newline found, end */
- }
- len += n;
- allocsiz = len + 1;
- if(allocsiz > *size) {
- if((alloc = realloc(*p, allocsiz))) {
- *p = alloc;
- *size = allocsiz;
- } else {
- free(*p);
- *p = NULL;
- fputs("error: could not realloc\n", stderr);
- exit(EXIT_FAILURE);
- return NULL;
- }
- }
- strlcpy((*p + (len - n)), buf, n + 1);
- }
- if(*p && len > 0) {
- (*p)[len] = '\0';
- return *p;
- }
- return NULL;
+ return(s - src - 1); /* count does not include NUL */
}
/* print link; if link is relative use baseurl to make it absolute */