From 027a73a903af306449710ce12bc09e0e3550c6c9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 4 Aug 2016 10:16:59 -0500 Subject: Make xopen() skip stdin/stdout/stderr, add xopen_stdio() if you want stdout, add xopenro() that takes one argument and understands "-" means stdin, and switch over lots of users. --- toys/pending/crontab.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'toys/pending/crontab.c') diff --git a/toys/pending/crontab.c b/toys/pending/crontab.c index 80a881d7..0b1c47db 100644 --- a/toys/pending/crontab.c +++ b/toys/pending/crontab.c @@ -114,7 +114,7 @@ static int validate_component(int min, int max, char *src) static int parse_crontab(char *fname) { char *line; - int lno, fd = xopen(fname, O_RDONLY); + int lno, fd = xopenro(fname); long plen = 0; for (lno = 1; (line = get_rawline(fd, &plen, '\n')); lno++,free(line)) { @@ -214,8 +214,7 @@ static void do_list(char *name) int fdin; snprintf(toybuf, sizeof(toybuf), "%s%s", TT.cdir, name); - if ((fdin = open(toybuf, O_RDONLY)) == -1) - error_exit("No crontab for '%s'", name); + fdin = xopenro(toybuf); xsendfile(fdin, 1); xclose(fdin); } @@ -233,7 +232,7 @@ static void update_crontab(char *src, char *dest) snprintf(toybuf, sizeof(toybuf), "%s%s", TT.cdir, dest); fdout = xcreate(toybuf, O_WRONLY|O_CREAT|O_TRUNC, 0600); - fdin = xopen(src, O_RDONLY); + fdin = xopenro(src); xsendfile(fdin, fdout); xclose(fdin); @@ -277,7 +276,7 @@ static void do_edit(struct passwd *pwd) if (!stat(toybuf, &sb)) { // file exists and have some content. if (sb.st_size) { - srcfd = xopen(toybuf, O_RDONLY); + srcfd = xopenro(toybuf); xsendfile(srcfd, destfd); xclose(srcfd); } -- cgit v1.2.3