commit 60c772fbc055621cb0809ed0912f1de073e2eae9
parent e36ea386aa79b9dfe279605d0d3bea4fd69116e2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sat, 5 Jul 2014 14:03:29 +0000
crond: use getline
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat:
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/crond.c b/crond.c
@@ -243,22 +243,22 @@ loadentries(void)
{
struct ctabentry *cte;
FILE *fp;
- char line[PATH_MAX], *p;
- char *col;
- int r = 0;
- int y;
+ char *line = NULL, *p, *col;
+ int r = 0, y;
+ size_t size = 0;
+ ssize_t len;
if ((fp = fopen(config, "r")) == NULL) {
logerr("error: can't open %s\n", config);
return -1;
}
- for (y = 0; fgets(line, sizeof(line), fp); y++) {
+ for (y = 0; (len = getline(&line, &size, fp)) != -1; y++) {
p = line;
if (line[0] == '#' || line[0] == '\n' || line[0] == '\0')
continue;
- if (line[strlen(line) - 1] == '\n')
- line[strlen(line) - 1] = '\0';
+ if(line[len - 1] == '\n')
+ line[--len] = '\0';
cte = emalloc(sizeof(*cte));
@@ -324,6 +324,7 @@ loadentries(void)
unloadentries();
fclose(fp);
+ free(line);
return r;
}