From dfb29ae06cc17275a0ea89330c19fc7470349692 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Thu, 23 Apr 2009 00:20:01 +1000 Subject: 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 --- shell/ash.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) static int copyfd(int from, int to) { +#ifdef __MINGW32__ + char* fds = ckmalloc(to); + int i,fd; + memset(fds,0,to); + while ((fd = dup(from)) < to && fd >= 0) + fds[fd] = 1; + for (i = 0;i < to;i ++) + if (fds[i]) + close(i); + free(fds); + return fd; +#else int newfd; newfd = fcntl(from, F_DUPFD, to); @@ -4853,6 +4865,7 @@ copyfd(int from, int to) ash_msg_and_raise_error("%d: %m", from); } return newfd; +#endif } static void @@ -4920,7 +4933,11 @@ redirect(union node *redir, int flags) if (fd == newfd) continue; if (sv && *(p = &sv->renamed[fd]) == EMPTY) { +#ifdef __MINGW32__ + i = copyfd(fd, 10); +#else i = fcntl(fd, F_DUPFD, 10); +#endif if (i == -1) { i = errno; -- cgit v1.2.3-55-g6feb