remove agetline

This commit is contained in:
Evan Gates 2014-11-18 12:49:30 -08:00 committed by sin
parent cca0522872
commit 84b08427a1
14 changed files with 13 additions and 28 deletions

View File

@ -27,7 +27,6 @@ LIBUTFSRC =\
LIBUTIL = libutil.a LIBUTIL = libutil.a
LIBUTILSRC =\ LIBUTILSRC =\
libutil/agetcwd.c\ libutil/agetcwd.c\
libutil/agetline.c\
libutil/apathmax.c\ libutil/apathmax.c\
libutil/concat.c\ libutil/concat.c\
libutil/cp.c\ libutil/cp.c\

2
cut.c
View File

@ -121,7 +121,7 @@ cut(FILE *fp)
ssize_t len; ssize_t len;
Range *r; Range *r;
while ((len = agetline(&buf, &size, fp)) != -1) { while ((len = getline(&buf, &size, fp)) != -1) {
if (len && buf[len - 1] == '\n') if (len && buf[len - 1] == '\n')
buf[len - 1] = '\0'; buf[len - 1] = '\0';
if (mode == 'f' && !strchr(buf, delim)) { if (mode == 'f' && !strchr(buf, delim)) {

2
fold.c
View File

@ -64,7 +64,7 @@ fold(FILE *fp, long width)
char *buf = NULL; char *buf = NULL;
size_t size = 0; size_t size = 0;
while (agetline(&buf, &size, fp) != -1) while (getline(&buf, &size, fp) != -1)
foldline(buf, width); foldline(buf, width);
free(buf); free(buf);
} }

2
grep.c
View File

@ -132,7 +132,7 @@ grep(FILE *fp, const char *str)
struct pattern *pnode; struct pattern *pnode;
int match = NoMatch; int match = NoMatch;
for (n = 1; (len = agetline(&buf, &size, fp)) != -1; n++) { for (n = 1; (len = getline(&buf, &size, fp)) != -1; n++) {
/* Remove the trailing newline if one is present. */ /* Remove the trailing newline if one is present. */
if (len && buf[len - 1] == '\n') if (len && buf[len - 1] == '\n')
buf[len - 1] = '\0'; buf[len - 1] = '\0';

2
head.c
View File

@ -56,7 +56,7 @@ head(FILE *fp, const char *str, long n)
ssize_t len; ssize_t len;
unsigned long i = 0; unsigned long i = 0;
while (i < n && ((len = agetline(&buf, &size, fp)) != -1)) { while (i < n && ((len = getline(&buf, &size, fp)) != -1)) {
fputs(buf, stdout); fputs(buf, stdout);
if (buf[len - 1] == '\n') if (buf[len - 1] == '\n')
i++; i++;

View File

@ -1,13 +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"
ssize_t
agetline(char **p, size_t *size, FILE *fp)
{
return getline(p, size, fp);
}

View File

@ -51,7 +51,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
else if (!(cfp = fopen(sumfile, "r"))) else if (!(cfp = fopen(sumfile, "r")))
eprintf("fopen %s:", sumfile); eprintf("fopen %s:", sumfile);
while (agetline(&line, &bufsiz, cfp) != -1) { while (getline(&line, &bufsiz, cfp) != -1) {
if (!(file = strstr(line, " "))) { if (!(file = strstr(line, " "))) {
formatsucks++; formatsucks++;
continue; continue;

View File

@ -13,7 +13,7 @@ getlines(FILE *fp, struct linebuf *b)
size_t size = 0, linelen; size_t size = 0, linelen;
ssize_t len; ssize_t len;
while ((len = agetline(&line, &size, fp)) != -1) { while ((len = getline(&line, &size, fp)) != -1) {
if (++b->nlines > b->capacity) { if (++b->nlines > b->capacity) {
b->capacity += 512; b->capacity += 512;
nline = erealloc(b->lines, b->capacity * sizeof(*b->lines)); nline = erealloc(b->lines, b->capacity * sizeof(*b->lines));

2
nl.c
View File

@ -69,7 +69,7 @@ nl(FILE *fp)
long n = 0; long n = 0;
size_t size = 0; size_t size = 0;
while (agetline(&buf, &size, fp) != -1) { while (getline(&buf, &size, fp) != -1) {
if ((mode == 'a') if ((mode == 'a')
|| (mode == 'p' || (mode == 'p'
&& !regexec(&preg, buf, 0, NULL, 0)) && !regexec(&preg, buf, 0, NULL, 0))

4
tail.c
View File

@ -61,7 +61,7 @@ dropinit(FILE *fp, const char *str, long n)
ssize_t len; ssize_t len;
unsigned long i = 0; unsigned long i = 0;
while (i < n && ((len = agetline(&buf, &size, fp)) != -1)) while (i < n && ((len = getline(&buf, &size, fp)) != -1))
if (len && buf[len - 1] == '\n') if (len && buf[len - 1] == '\n')
i++; i++;
free(buf); free(buf);
@ -78,7 +78,7 @@ taketail(FILE *fp, const char *str, long n)
ring = ecalloc(n, sizeof *ring); ring = ecalloc(n, sizeof *ring);
size = ecalloc(n, sizeof *size); size = ecalloc(n, sizeof *size);
for (i = j = 0; agetline(&ring[i], &size[i], fp) != -1; i = j = (i + 1) % n) for (i = j = 0; getline(&ring[i], &size[i], fp) != -1; i = j = (i + 1) % n)
; ;
if (ferror(fp)) if (ferror(fp))
eprintf("%s: read error:", str); eprintf("%s: read error:", str);

1
text.h
View File

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

2
tr.c
View File

@ -346,7 +346,7 @@ main(int argc, char *argv[])
usage(); usage();
} }
while ((nbytes = agetline(&buf, &size, stdin)) != -1) while ((nbytes = getline(&buf, &size, stdin)) != -1)
mapfunc(buf, nbytes); mapfunc(buf, nbytes);
free(buf); free(buf);
if (ferror(stdin)) if (ferror(stdin))

2
uniq.c
View File

@ -92,7 +92,7 @@ uniq(FILE *fp, const char *str)
char *buf = NULL; char *buf = NULL;
size_t size = 0; size_t size = 0;
while (agetline(&buf, &size, fp) != -1) while (getline(&buf, &size, fp) != -1)
uniqline(buf); uniqline(buf);
} }

View File

@ -128,7 +128,7 @@ uudecode(FILE *fp, FILE *outfp)
#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) ) #define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
#define OUT_OF_RANGE(c) eprintf("character %c out of range: [%d-%d]", (c), 1 + ' ', 077 + ' ' + 1) #define OUT_OF_RANGE(c) eprintf("character %c out of range: [%d-%d]", (c), 1 + ' ', 077 + ' ' + 1)
while ((len = agetline(&bufb, &n, fp)) != -1) { while ((len = getline(&bufb, &n, fp)) != -1) {
p = bufb; p = bufb;
/* trim newlines */ /* trim newlines */
if (len && bufb[len - 1] != '\n') if (len && bufb[len - 1] != '\n')
@ -172,7 +172,7 @@ uudecode(FILE *fp, FILE *outfp)
eprintf("read error:"); eprintf("read error:");
} }
/* check for end or fail */ /* check for end or fail */
len = agetline(&bufb, &n, fp); len = getline(&bufb, &n, fp);
if (len < 3 || strncmp(bufb, "end", 3) != 0 || bufb[3] != '\n') if (len < 3 || strncmp(bufb, "end", 3) != 0 || bufb[3] != '\n')
eprintf("invalid uudecode footer \"end\" not found\n"); eprintf("invalid uudecode footer \"end\" not found\n");
free(bufb); free(bufb);