remove afgets

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-06-01 15:12:33 +02:00 committed by sin
parent fab4b384e7
commit 2ab2d2ee3b
3 changed files with 0 additions and 30 deletions

View File

@ -5,7 +5,6 @@ include config.mk
HDR = crypt.h fs.h text.h md5.h sha1.h sha256.h sha512.h util.h arg.h
LIB = \
util/afgets.o \
util/agetcwd.o \
util/agetline.o \
util/apathmax.o \

1
text.h
View File

@ -8,6 +8,5 @@ struct linebuf {
#define EMPTY_LINEBUF {NULL, 0, 0,}
void getlines(FILE *, struct linebuf *);
char *afgets(char **, size_t *, FILE *);
ssize_t agetline(char **, size_t *, FILE *);
void concat(FILE *, const char *, FILE *, const char *);

View File

@ -1,28 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../text.h"
#include "../util.h"
char *
afgets(char **p, size_t *size, FILE *fp)
{
char buf[BUFSIZ];
size_t n, len = 0;
while(fgets(buf, sizeof buf, fp)) {
len += (n = strlen(buf));
if(len+1 > *size && !(*p = realloc(*p, len+1)))
eprintf("realloc:");
memcpy(&(*p)[len-n], buf, n);
(*p)[len] = '\0';
if(buf[n-1] == '\n' || feof(fp))
break;
}
return (len > 0) ? *p : NULL;
}