---
 toys/pending/crontab.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
From 3af5be7fba73521131311c1f77b2c793e1e12461 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Tue, 23 Jul 2019 21:48:02 -0700
Subject: [PATCH 2/2] crontab: switch to getline().

---
 toys/pending/crontab.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/toys/pending/crontab.c b/toys/pending/crontab.c
index 0b1c47db..6c1c65a2 100644
--- a/toys/pending/crontab.c
+++ b/toys/pending/crontab.c
@@ -113,15 +113,17 @@ static int validate_component(int min, int max, char *src)
 
 static int parse_crontab(char *fname)
 {
-  char *line;
-  int lno, fd = xopenro(fname);
-  long plen = 0;
+  FILE *fp = xfopen(fname, "r");
+  long len = 0;
+  char *line = NULL;
+  size_t allocated_length;
+  int lno;
 
-  for (lno = 1; (line = get_rawline(fd, &plen, '\n')); lno++,free(line)) {
+  for (lno = 1; (len = getline(&line, &allocated_length, fp)) > 0; lno++) {
     char *name, *val, *tokens[5] = {0,}, *ptr = line;
     int count = 0;
 
-    if (line[plen - 1] == '\n') line[--plen] = '\0';
+    if (line[len - 1] == '\n') line[--len] = '\0';
     else {
       snprintf(toybuf, sizeof(toybuf), "'%d': premature EOF\n", lno);
       goto OUT;
@@ -200,12 +202,13 @@ static int parse_crontab(char *fname)
         break;
     }
   }
-  xclose(fd);
+  free(line);
+  fclose(fp);
   return 0;
 OUT:
   free(line);
   printf("Error at line no %s", toybuf);
-  xclose(fd);
+  fclose(fp);
   return 1;
 }
 
-- 
2.22.0.657.g960e92d24f-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to