aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-04-03 15:41:32 +0100
committerRon Yorston <rmy@pobox.com>2012-04-03 15:41:32 +0100
commit6a82920046979ff373ec55b1ace6e542c8cb13f5 (patch)
tree67137494e1b45940ce1ae6a348e68e56135bbad2
parentd0b801b9459f48a6dd5446fb77070639b8c1462b (diff)
downloadbusybox-w32-6a82920046979ff373ec55b1ace6e542c8cb13f5.tar.gz
busybox-w32-6a82920046979ff373ec55b1ace6e542c8cb13f5.tar.bz2
busybox-w32-6a82920046979ff373ec55b1ace6e542c8cb13f5.zip
Make fake fcntl(F_DUPFD) for WIN32
-rw-r--r--.gitignore1
-rw-r--r--include/mingw.h2
-rw-r--r--shell/ash.c18
-rw-r--r--win32/mingw.c52
4 files changed, 46 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 0a0c65bc3..54369de10 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@ Config.in
18# Normal output 18# Normal output
19# 19#
20/busybox 20/busybox
21/busybox.exe
21/busybox_old 22/busybox_old
22/busybox_unstripped* 23/busybox_unstripped*
23 24
diff --git a/include/mingw.h b/include/mingw.h
index f89297df9..9c9767b3e 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -139,6 +139,8 @@ int mingw_rename(const char*, const char*);
139#define fopen mingw_fopen 139#define fopen mingw_fopen
140#define rename mingw_rename 140#define rename mingw_rename
141 141
142#define setlinebuf(fd) setvbuf(fd, (char *) NULL, _IOLBF, 0)
143
142/* 144/*
143 * ANSI emulation wrappers 145 * ANSI emulation wrappers
144 */ 146 */
diff --git a/shell/ash.c b/shell/ash.c
index 68d39c1f3..4766af34a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -950,7 +950,7 @@ static void
950opentrace(void) 950opentrace(void)
951{ 951{
952 char s[100]; 952 char s[100];
953#if defined(O_APPEND) && !ENABLE_PLATFORM_MINGW32 953#ifdef O_APPEND
954 int flags; 954 int flags;
955#endif 955#endif
956 956
@@ -975,7 +975,7 @@ opentrace(void)
975 return; 975 return;
976 } 976 }
977 } 977 }
978#if defined(O_APPEND) && !ENABLE_PLATFORM_MINGW32 978#ifdef O_APPEND
979 flags = fcntl(fileno(tracefile), F_GETFL); 979 flags = fcntl(fileno(tracefile), F_GETFL);
980 if (flags >= 0) 980 if (flags >= 0)
981 fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND); 981 fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
@@ -3904,7 +3904,7 @@ setjobctl(int on)
3904 if (--fd < 0) 3904 if (--fd < 0)
3905 goto out; 3905 goto out;
3906 } 3906 }
3907 fd = copyfd(fd, 10); 3907 fd = fcntl(fd, F_DUPFD, 10);
3908 if (ofd >= 0) 3908 if (ofd >= 0)
3909 close(ofd); 3909 close(ofd);
3910 if (fd < 0) 3910 if (fd < 0)
@@ -5506,18 +5506,6 @@ copyfd(int from, int to)
5506 /*if (from != to)*/ 5506 /*if (from != to)*/
5507 newfd = dup2(from, to); 5507 newfd = dup2(from, to);
5508 } else { 5508 } else {
5509 if (ENABLE_PLATFORM_MINGW32) {
5510 char* fds = ckmalloc(to);
5511 int i,fd;
5512 memset(fds,0,to);
5513 while ((fd = dup(from)) < to && fd >= 0)
5514 fds[fd] = 1;
5515 for (i = 0;i < to;i ++)
5516 if (fds[i])
5517 close(i);
5518 free(fds);
5519 return fd;
5520 }
5521 newfd = fcntl(from, F_DUPFD, to); 5509 newfd = fcntl(from, F_DUPFD, to);
5522 } 5510 }
5523 if (newfd < 0) { 5511 if (newfd < 0) {
diff --git a/win32/mingw.c b/win32/mingw.c
index 219ef96b8..c9b00bbcd 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -693,18 +693,46 @@ int mingw_mkdir(const char *path, int mode UNUSED_PARAM)
693 return mkdir(path); 693 return mkdir(path);
694} 694}
695 695
696int fcntl(int fd UNUSED_PARAM, int cmd, ...) 696int fcntl(int fd, int cmd, ...)
697{ 697{
698 /* 698 va_list arg;
699 * F_GETFL needs to be dealt at higher level 699 int result = -1;
700 * Usually it does not matter if the call is 700 char *fds;
701 * fcntl(fd, F_SETFL, fcntl(fd, F_GETFD) | something) 701 int target, i, newfd;
702 * because F_SETFL is not supported 702
703 */ 703 va_start(arg, cmd);
704 if (cmd == F_GETFD || cmd == F_SETFD || cmd == F_GETFL) 704
705 return 0; 705 switch (cmd) {
706 errno = ENOSYS; 706 case F_GETFD:
707 return -1; 707 case F_SETFD:
708 case F_GETFL:
709 /*
710 * Our fake F_GETFL won't matter if the return value is used as
711 * fcntl(fd, F_SETFL, ret|something);
712 * because F_SETFL isn't supported either.
713 */
714 result = 0;
715 break;
716 case F_DUPFD:
717 target = va_arg(arg, int);
718 fds = xzalloc(target);
719 while ((newfd = dup(fd)) < target && newfd >= 0) {
720 fds[newfd] = 1;
721 }
722 for (i = 0; i < target; ++i) {
723 if (fds[i]) {
724 close(i);
725 }
726 }
727 free(fds);
728 result = newfd;
729 default:
730 errno = ENOSYS;
731 break;
732 }
733
734 va_end(arg);
735 return result;
708} 736}
709 737
710#undef unlink 738#undef unlink