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/dd.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'toys/pending/dd.c') diff --git a/toys/pending/dd.c b/toys/pending/dd.c index 9990a0f4..b09a7dfe 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -143,16 +143,6 @@ static void status() } } -static int xmove_fd(int fd) -{ - int newfd; - - if (fd > STDERR_FILENO) return fd; - if ((newfd = fcntl(fd, F_DUPFD, 3) < 0)) perror_exit("dupfd IO"); - close(fd); - return newfd; -} - static void setup_inout() { /* for C_BS, in/out is done as it is. so only in.sz is enough. @@ -164,10 +154,8 @@ static void setup_inout() if (!TT.in.name) { TT.in.name = "stdin"; TT.in.fd = STDIN_FILENO; - } else { - TT.in.fd = xopen(TT.in.name, O_RDONLY); - TT.in.fd = xmove_fd(TT.in.fd); - } + } else TT.in.fd = xopenro(TT.in.name); + //setup outout if (!TT.out.name) { TT.out.name = "stdout"; @@ -176,7 +164,6 @@ static void setup_inout() int flags = O_WRONLY|O_CREAT; if (!(toys.optflags&C_NOTRUNC)) flags |= O_TRUNC; TT.out.fd = xcreate(TT.out.name, flags, 0666); - TT.out.fd = xmove_fd(TT.out.fd); } if (TT.in.offset) { -- cgit v1.2.3