summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2008-03-31 08:37:36 +0200
committerJim Meyering <meyering@redhat.com>2008-03-31 08:37:58 +0200
commite373bb193357481573913ccf28dc14675f172d5a (patch)
tree56d968f7d410e20a1afb4811d71e3bb631fe8f81 /lib
parent72e962c97e30fa8a9146d90fa36098137ce0ee0f (diff)
downloadcoreutils-e373bb193357481573913ccf28dc14675f172d5a.tar.xz
dd bug fix: accept e.g., if=/dev/stdin and of=/dev/stdout
* lib/fd-reopen.c: Work even if FILE is "/dev/stdin". Problem reported by Geoffrey Lee in <http://bugs.debian.org/290727>. * tests/dd/misc: Check for this bug.
Diffstat (limited to 'lib')
-rw-r--r--lib/fd-reopen.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/fd-reopen.c b/lib/fd-reopen.c
index 2ce467873..c12fef602 100644
--- a/lib/fd-reopen.c
+++ b/lib/fd-reopen.c
@@ -1,6 +1,6 @@
/* Invoke open, but return either a desired file descriptor or -1.
- Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,15 +31,13 @@
int
fd_reopen (int desired_fd, char const *file, int flags, mode_t mode)
{
- int fd;
+ int fd = open (file, flags, mode);
- close (desired_fd);
- fd = open (file, flags, mode);
if (fd == desired_fd || fd < 0)
return fd;
else
{
- int fd2 = fcntl (fd, F_DUPFD, desired_fd);
+ int fd2 = dup2 (fd, desired_fd);
int saved_errno = errno;
close (fd);
errno = saved_errno;