aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
Diffstat (limited to 'toys/other')
-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);
}