aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-07-23 21:47:47 -0700
committerRob Landley <rob@landley.net>2019-07-24 17:16:05 -0500
commit9f5155ecad75b61db83181fa4fcdda1709e420b7 (patch)
tree39133df5654cd46d4f16b7b0640aa969126f9259 /toys
parentd818f5ad26b837aedd2e7ab32997508d5d1e846d (diff)
downloadtoybox-9f5155ecad75b61db83181fa4fcdda1709e420b7.tar.gz
tac: switch to getline().
Diffstat (limited to 'toys')
-rw-r--r--toys/other/tac.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/toys/other/tac.c b/toys/other/tac.c
index d5f72fd2..06e97205 100644
--- a/toys/other/tac.c
+++ b/toys/other/tac.c
@@ -18,20 +18,27 @@ config TAC
static void do_tac(int fd, char *name)
{
struct arg_list *list = NULL;
- char *c;
+ FILE *fp;
- // Read in lines
+ if (fd == -1) {
+ perror_msg_raw(name);
+ return;
+ }
+
+ // Read in lines.
+ fp = xfdopen(fd, "r");
for (;;) {
- struct arg_list *temp;
- long len;
+ char *line = NULL;
+ size_t allocated_length;
- if (!(c = get_rawline(fd, &len, '\n'))) break;
+ if (getline(&line, &allocated_length, fp) <= 0) break;
- temp = xmalloc(sizeof(struct arg_list));
+ struct arg_list *temp = xmalloc(sizeof(struct arg_list));
temp->next = list;
- temp->arg = c;
+ temp->arg = line;
list = temp;
}
+ fclose(fp);
// Play them back.
while (list) {
@@ -45,5 +52,5 @@ static void do_tac(int fd, char *name)
void tac_main(void)
{
- loopfiles(toys.optargs, do_tac);
+ loopfiles_rw(toys.optargs, O_RDONLY, 0, do_tac);
}