diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-13 12:45:04 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-13 12:45:04 +0000 |
commit | c2cb0f32b44a9918364af39c24b5643388c553f6 (patch) | |
tree | 378b5a002da81f8622913cc6a9aeac873e307ec9 /miscutils | |
parent | 4f3d2deaa499af34c22a7f9be121131b0a5894b5 (diff) | |
download | busybox-c2cb0f32b44a9918364af39c24b5643388c553f6.tar.gz |
- patch from Denis Vlasenko to add and use bb_xopen3()
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/crontab.c | 29 | ||||
-rw-r--r-- | miscutils/mt.c | 3 | ||||
-rw-r--r-- | miscutils/rx.c | 10 |
3 files changed, 15 insertions, 27 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 703d01ecc..1b2f46f3a 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -179,20 +179,16 @@ crontab_main(int ac, char **av) char buf[1024]; snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); - if ((fd = open(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600)) >= 0) { - chown(tmp, getuid(), getgid()); - if ((fi = fopen(pas->pw_name, "r"))) { - while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) - write(fd, buf, n); - } - EditFile(caller, tmp); - remove(tmp); - lseek(fd, 0L, 0); - repFd = fd; - } else { - bb_error_msg_and_die("unable to create %s", tmp); + fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); + chown(tmp, getuid(), getgid()); + if ((fi = fopen(pas->pw_name, "r"))) { + while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) + write(fd, buf, n); } - + EditFile(caller, tmp); + remove(tmp); + lseek(fd, 0L, 0); + repFd = fd; } option = REPLACE; /* fall through */ @@ -289,11 +285,8 @@ GetReplaceStream(const char *user, const char *file) if (ChangeUser(user, 0) < 0) exit(0); - fd = open(file, O_RDONLY); - if (fd < 0) { - bb_error_msg("unable to open %s", file); - exit(0); - } + bb_default_error_retval = 0; + fd = bb_xopen3(file, O_RDONLY, 0); buf[0] = 0; write(filedes[1], buf, 1); while ((n = read(fd, buf, sizeof(buf))) > 0) { diff --git a/miscutils/mt.c b/miscutils/mt.c index 44efedbe3..368fc66b9 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c @@ -101,8 +101,7 @@ int mt_main(int argc, char **argv) break; } - if ((fd = open(file, mode, 0)) < 0) - bb_perror_msg_and_die("%s", file); + fd = bb_xopen3(file, mode, 0); switch (code->value) { case MTTELL: diff --git a/miscutils/rx.c b/miscutils/rx.c index c7e82ead5..3df461349 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /*------------------------------------------------------------------------- * Filename: xmodem.c * Version: $Id: rx.c,v 1.2 2004/03/15 08:28:46 andersen Exp $ @@ -289,13 +290,8 @@ int rx_main(int argc, char **argv) bb_show_usage(); fn = argv[1]; - ttyfd = open("/dev/tty", O_RDWR); - if (ttyfd < 0) - bb_error_msg_and_die("%s: open on /dev/tty failed: %m\n", argv[0]); - - filefd = open(fn, O_RDWR|O_CREAT|O_TRUNC, 0666); - if (filefd < 0) - bb_error_msg_and_die("%s: open on %s failed: %m\n", argv[0], fn); + ttyfd = bb_xopen3("/dev/tty", O_RDWR, 0); + filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666); if (tcgetattr(ttyfd, &tty) < 0) bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]); |