diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 00:22:35 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 04:44:45 +1000 |
commit | 6f49b7d9d41833dcadda1faeb27b31bc49e66b0f (patch) | |
tree | af44bfbc2c1935c94507378ed6a8b4886de29bee /shell | |
parent | dfb29ae06cc17275a0ea89330c19fc7470349692 (diff) | |
download | busybox-w32-6f49b7d9d41833dcadda1faeb27b31bc49e66b0f.tar.gz busybox-w32-6f49b7d9d41833dcadda1faeb27b31bc49e66b0f.tar.bz2 busybox-w32-6f49b7d9d41833dcadda1faeb27b31bc49e66b0f.zip |
shell/ash: use dup2() where possible, due to copyfd's inefficencies
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 14 |
1 files changed, 13 insertions, 1 deletions
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) | |||
4875 | 4875 | ||
4876 | if (redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD) { | 4876 | if (redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD) { |
4877 | if (redir->ndup.dupfd >= 0) { /* if not ">&-" */ | 4877 | if (redir->ndup.dupfd >= 0) { /* if not ">&-" */ |
4878 | #ifdef __MINGW32__ | ||
4879 | dup2(redir->ndup.dupfd, fd); | ||
4880 | #else | ||
4878 | copyfd(redir->ndup.dupfd, fd); | 4881 | copyfd(redir->ndup.dupfd, fd); |
4882 | #endif | ||
4879 | } | 4883 | } |
4880 | return; | 4884 | return; |
4881 | } | 4885 | } |
4882 | 4886 | ||
4883 | if (f != fd) { | 4887 | if (f >= 0 && f != fd) { |
4888 | #ifdef __MINGW32__ | ||
4889 | dup2(f, fd); | ||
4890 | #else | ||
4884 | copyfd(f, fd); | 4891 | copyfd(f, fd); |
4892 | #endif | ||
4885 | close(f); | 4893 | close(f); |
4886 | } | 4894 | } |
4887 | } | 4895 | } |
@@ -4978,7 +4986,11 @@ popredir(int drop) | |||
4978 | if (rp->renamed[i] != EMPTY) { | 4986 | if (rp->renamed[i] != EMPTY) { |
4979 | if (!drop) { | 4987 | if (!drop) { |
4980 | close(i); | 4988 | close(i); |
4989 | #ifdef __MINGW32__ | ||
4990 | dup2(rp->renamed[i], i); | ||
4991 | #else | ||
4981 | copyfd(rp->renamed[i], i); | 4992 | copyfd(rp->renamed[i], i); |
4993 | #endif | ||
4982 | } | 4994 | } |
4983 | close(rp->renamed[i]); | 4995 | close(rp->renamed[i]); |
4984 | } | 4996 | } |