--- vixie-cron-4.1.20060426/usr.sbin/cron/crontab.c +++ vixie-cron-4.1.20060426/usr.sbin/cron/crontab.c @@ -55,7 +55,8 @@ static void list_cmd(void), edit_cmd(void), check_error(const char *), parse_args(int c, char *v[]), - die(int); + die(int), + copy_crontab(FILE *f, FILE *t); static int replace_cmd(void); static void @@ -229,7 +230,6 @@ static void list_cmd(void) { char n[MAX_FNAME]; FILE *f; - int ch; log_it(RealUser, Pid, "LIST", User); if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { @@ -247,8 +247,7 @@ list_cmd(void) { /* file is open. copy to stdout, close. */ Set_LineNum(1) - while (EOF != (ch = get_char(f))) - putchar(ch); + copy_crontab(f, stdout); fclose(f); } @@ -281,7 +280,7 @@ static void edit_cmd(void) { char n[MAX_FNAME], q[MAX_TEMPSTR], *editor; FILE *f; - int ch, t, x; + int t; struct stat statbuf, xstatbuf; struct timespec mtimespec; struct timeval tv[2]; @@ -334,27 +333,7 @@ edit_cmd(void) { } Set_LineNum(1) - - /* 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; - } - - /* copy the rest of the crontab (if any) to the temp file. - */ - if (EOF != ch) - while (EOF != (ch = get_char(f))) - putc(ch, NewCrontab); + copy_crontab(f, NewCrontab); fclose(f); if (fflush(NewCrontab) < OK) { perror(Filename); @@ -651,3 +630,29 @@ die(int x) { (void) unlink(TempFilename); _exit(ERROR_EXIT); } + +static void +copy_crontab(FILE *f, FILE *t) +{ + int ch, x = 0; + + /* skip the top few comments since we probably put them there. + */ + while (EOF != (ch = get_char(f))) { + if ('#' != ch) { + putc(ch, t); + break; + } + while (EOF != (ch = get_char(f))) + if (ch == '\n') + break; + if ((EOF == ch) || (++x >= NHEADER_LINES)) + break; + } + + /* copy the rest of the crontab (if any). + */ + if (EOF != ch) + while (EOF != (ch = get_char(f))) + putc(ch, t); +}