aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-08-10 09:44:58 -0700
committerRob Landley <rob@landley.net>2019-08-12 04:44:00 -0500
commit30cb3aa0e33daa20d6adb0825979f79e615c9c47 (patch)
tree8134f1634c5640ffd196895fa4e4f11e8af10364 /lib/lib.c
parent9dc24d994efc3837e248ef8db9b3976e8775235e (diff)
downloadtoybox-30cb3aa0e33daa20d6adb0825979f79e615c9c47.tar.gz
sort: move off get_rawline.
This was the last user of get_rawline, which lets us remove it.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 53962a59..282e16d3 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -699,8 +699,7 @@ void loopfiles_lines(char **argv, void (*function)(char **pline, long len))
}
// Slow, but small.
-
-char *get_rawline(int fd, long *plen, char end)
+char *get_line(int fd)
{
char c, *buf = NULL;
long len = 0;
@@ -708,20 +707,12 @@ char *get_rawline(int fd, long *plen, char end)
for (;;) {
if (1>read(fd, &c, 1)) break;
if (!(len & 63)) buf=xrealloc(buf, len+65);
- if ((buf[len++]=c) == end) break;
+ if ((buf[len++]=c) == '\n') break;
+ }
+ if (buf) {
+ buf[len]=0;
+ if (buf[--len]=='\n') buf[len]=0;
}
- if (buf) buf[len]=0;
- if (plen) *plen = len;
-
- return buf;
-}
-
-char *get_line(int fd)
-{
- long len;
- char *buf = get_rawline(fd, &len, '\n');
-
- if (buf && buf[--len]=='\n') buf[len]=0;
return buf;
}