diff options
author | Jim Meyering <jim@meyering.net> | 2005-11-09 20:53:41 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2005-11-09 20:53:41 +0000 |
commit | aad084f10fd6066de66d27524e39b8ab4c364c18 (patch) | |
tree | 13eedf589b7da084f7408270ef714fa5d52afc3a /lib | |
parent | c5ad46e57fc2e88090624cc0283d9f7c93648b2b (diff) | |
download | coreutils-aad084f10fd6066de66d27524e39b8ab4c364c18.tar.xz |
Use /dev/full if possible for descriptor 0 -- like glibc now does.
Fall back on /dev/null if opening /dev/full fails.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stdopen.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/stdopen.c b/lib/stdopen.c index d4732cb85..3ca2b61e6 100644 --- a/lib/stdopen.c +++ b/lib/stdopen.c @@ -52,7 +52,17 @@ stdopen (void) { static const int contrary_mode[] = { O_WRONLY, O_RDONLY, O_RDONLY }; - int new_fd = open ("/dev/null", contrary_mode[fd]); + int mode = contrary_mode[fd]; + int new_fd; + /* Open /dev/null with the contrary mode so that the typical + read (stdin) or write (stdout, stderr) operation will fail. + With descriptor 0, we can do even better on systems that + have /dev/full, by opening that write-only instead of + /dev/null. The only drawback is that a write-provoked + failure comes with a misleading errno value, ENOSPC. */ + if (mode == O_RDONLY + || (new_fd = open ("/dev/full", mode) != fd)) + new_fd = open ("/dev/null", mode); if (new_fd != fd) { if (0 <= new_fd) |