diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 00:20:01 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 04:44:45 +1000 |
commit | dfb29ae06cc17275a0ea89330c19fc7470349692 (patch) | |
tree | 97abd04b04ed223bbad23f1dfa1b6861e63493a6 /shell | |
parent | 8884ff80ee749c86b284ecdfe2dbf41a0e68f55a (diff) | |
download | busybox-w32-dfb29ae06cc17275a0ea89330c19fc7470349692.tar.gz busybox-w32-dfb29ae06cc17275a0ea89330c19fc7470349692.tar.bz2 busybox-w32-dfb29ae06cc17275a0ea89330c19fc7470349692.zip |
shell/ash: reimplement copy_fd as Windows does not have F_DUPFD
This implementation is quite inefficient. Looking forward to an improvement
when we manage file handle table ourselves
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c index b4e7b78a8..7cc452d20 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4844,6 +4844,18 @@ openredirect(union node *redir) | |||
4844 | static int | 4844 | static int |
4845 | copyfd(int from, int to) | 4845 | copyfd(int from, int to) |
4846 | { | 4846 | { |
4847 | #ifdef __MINGW32__ | ||
4848 | char* fds = ckmalloc(to); | ||
4849 | int i,fd; | ||
4850 | memset(fds,0,to); | ||
4851 | while ((fd = dup(from)) < to && fd >= 0) | ||
4852 | fds[fd] = 1; | ||
4853 | for (i = 0;i < to;i ++) | ||
4854 | if (fds[i]) | ||
4855 | close(i); | ||
4856 | free(fds); | ||
4857 | return fd; | ||
4858 | #else | ||
4847 | int newfd; | 4859 | int newfd; |
4848 | 4860 | ||
4849 | newfd = fcntl(from, F_DUPFD, to); | 4861 | newfd = fcntl(from, F_DUPFD, to); |
@@ -4853,6 +4865,7 @@ copyfd(int from, int to) | |||
4853 | ash_msg_and_raise_error("%d: %m", from); | 4865 | ash_msg_and_raise_error("%d: %m", from); |
4854 | } | 4866 | } |
4855 | return newfd; | 4867 | return newfd; |
4868 | #endif | ||
4856 | } | 4869 | } |
4857 | 4870 | ||
4858 | static void | 4871 | static void |
@@ -4920,7 +4933,11 @@ redirect(union node *redir, int flags) | |||
4920 | if (fd == newfd) | 4933 | if (fd == newfd) |
4921 | continue; | 4934 | continue; |
4922 | if (sv && *(p = &sv->renamed[fd]) == EMPTY) { | 4935 | if (sv && *(p = &sv->renamed[fd]) == EMPTY) { |
4936 | #ifdef __MINGW32__ | ||
4937 | i = copyfd(fd, 10); | ||
4938 | #else | ||
4923 | i = fcntl(fd, F_DUPFD, 10); | 4939 | i = fcntl(fd, F_DUPFD, 10); |
4940 | #endif | ||
4924 | 4941 | ||
4925 | if (i == -1) { | 4942 | if (i == -1) { |
4926 | i = errno; | 4943 | i = errno; |