diff options
author | Ron Yorston <rmy@pobox.com> | 2012-04-03 15:41:32 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-04-03 15:41:32 +0100 |
commit | 6a82920046979ff373ec55b1ace6e542c8cb13f5 (patch) | |
tree | 67137494e1b45940ce1ae6a348e68e56135bbad2 /win32 | |
parent | d0b801b9459f48a6dd5446fb77070639b8c1462b (diff) | |
download | busybox-w32-6a82920046979ff373ec55b1ace6e542c8cb13f5.tar.gz busybox-w32-6a82920046979ff373ec55b1ace6e542c8cb13f5.tar.bz2 busybox-w32-6a82920046979ff373ec55b1ace6e542c8cb13f5.zip |
Make fake fcntl(F_DUPFD) for WIN32
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 52 |
1 files changed, 40 insertions, 12 deletions
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 | ||
696 | int fcntl(int fd UNUSED_PARAM, int cmd, ...) | 696 | int 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 |