diff --git a/vixie-cron/usr.sbin/cron/crontab.c b/vixie-cron/usr.sbin/cron/crontab.c index 40638fc..c1a3272 100644 --- a/vixie-cron/usr.sbin/cron/crontab.c +++ b/vixie-cron/usr.sbin/cron/crontab.c @@ -56,7 +56,9 @@ static void list_cmd(void), check_error(const char *), parse_args(int c, char *v[]), die(int); -static int replace_cmd(void); +static int replace_cmd(void), + ignore_comments(FILE *); + static void usage(const char *msg) { @@ -247,6 +249,11 @@ list_cmd(void) { /* file is open. copy to stdout, close. */ Set_LineNum(1) + + /* ignore the top few comments since we probably put them there. + */ + ch = ignore_comments(f); + while (EOF != (ch = get_char(f))) putchar(ch); fclose(f); @@ -281,7 +288,7 @@ static void edit_cmd(void) { char n[MAX_FNAME], q[MAX_TEMPSTR], *editor; FILE *f; - int ch, t, x; + int ch, t; struct stat statbuf, xstatbuf; struct timespec mtimespec; struct timeval tv[2]; @@ -337,18 +344,7 @@ edit_cmd(void) { /* ignore the top few comments since we probably put them there. */ - x = 0; - while (EOF != (ch = get_char(f))) { - if ('#' != ch) { - putc(ch, NewCrontab); - break; - } - while (EOF != (ch = get_char(f))) - if (ch == '\n') - break; - if (++x >= NHEADER_LINES) - break; - } + ch = ignore_comments(f); /* copy the rest of the crontab (if any) to the temp file. */ @@ -651,3 +647,24 @@ die(int x) { (void) unlink(TempFilename); _exit(ERROR_EXIT); } + +static int +ignore_comments(FILE *f) { + int ch, x; + + x = 0; + while (EOF != (ch = get_char(f))) { + if ('#' != ch) { + putc(ch, NewCrontab); + break; + } + while (EOF != (ch = get_char(f))) + if (ch == '\n') + break; + if (++x >= NHEADER_LINES) + break; + } + + return ch; +} +