aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 00:20:01 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 04:44:45 +1000
commitdfb29ae06cc17275a0ea89330c19fc7470349692 (patch)
tree97abd04b04ed223bbad23f1dfa1b6861e63493a6 /shell
parent8884ff80ee749c86b284ecdfe2dbf41a0e68f55a (diff)
downloadbusybox-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.c17
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)
4844static int 4844static int
4845copyfd(int from, int to) 4845copyfd(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
4858static void 4871static 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;