From 6f49b7d9d41833dcadda1faeb27b31bc49e66b0f Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Thu, 23 Apr 2009 00:22:35 +1000 Subject: shell/ash: use dup2() where possible, due to copyfd's inefficencies --- shell/ash.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 7cc452d20..9f916b8a3 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -4875,13 +4875,21 @@ dupredirect(union node *redir, int f) if (redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD) { if (redir->ndup.dupfd >= 0) { /* if not ">&-" */ +#ifdef __MINGW32__ + dup2(redir->ndup.dupfd, fd); +#else copyfd(redir->ndup.dupfd, fd); +#endif } return; } - if (f != fd) { + if (f >= 0 && f != fd) { +#ifdef __MINGW32__ + dup2(f, fd); +#else copyfd(f, fd); +#endif close(f); } } @@ -4978,7 +4986,11 @@ popredir(int drop) if (rp->renamed[i] != EMPTY) { if (!drop) { close(i); +#ifdef __MINGW32__ + dup2(rp->renamed[i], i); +#else copyfd(rp->renamed[i], i); +#endif } close(rp->renamed[i]); } -- cgit v1.2.3-55-g6feb