tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[PATCH] rfc: reuse previously closed descriptor in freopen()
What is the advantage to not reuse previously closed descriptor for fd >= 3?
---
lib/libc/stdio/freopen.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index c5909a7..180e807 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -165,7 +165,7 @@ freopen(file, mode, fp)
* to maintain the descriptor. Various C library routines (perror)
* assume stderr is always fd STDERR_FILENO, even if being freopen'd.
*/
- if (wantfd >= 0 && f != wantfd) {
+ if (wantfd >= 0 && f != wantfd && f < 3) {
if (dup2(f, wantfd) >= 0) {
(void) close(f);
f = wantfd;
--
1.5.2.5
Home |
Main Index |
Thread Index |
Old Index