aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-07-23 21:48:02 -0700
committerRob Landley <rob@landley.net>2019-07-24 17:42:30 -0500
commit8f5e168584bff66cf0d6645ad2eb36e8884ac396 (patch)
treed1ca1b4acc3dcdcf301ad06b784922297cb0f9a7
parentb14b5d9d8d6e3ae14814436d518785ba8773bf80 (diff)
downloadtoybox-8f5e168584bff66cf0d6645ad2eb36e8884ac396.tar.gz
crontab: switch to getline().
-rw-r--r--toys/pending/crontab.c17
1 files 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;
}