Re: [PATCH] make devmem map only a single page at end of memory
On Tue, Apr 13, 2010 at 6:14 AM, Michael Abbott mich...@araneidae.co.uk wrote: + off_t page_mask = ~(off_t)(page_size - 1); + size_t map_length; int fd; ... - virt_addr = (char*)map_base + (target (page_size - 1)); + virt_addr = (char*)map_base + (target page_mask); Bug in the last line shown. -- vda ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: hwclock -w takes 24 seconds
I fixed syncing code so that it widens sync window very fast. But then I disabled it anyway, it's too big and in my testing, RTC isn't setting time with ~0.5sec precision anyway (!!!). Fixed in git, will be in 1.16.2 -- vda Couple remarks: 1. Why would we care to synchronize time in from_sys_clock() and not to do it in to_sys_clock()? I had it in both places, but the restored time was always offset by ~0.5s and thanks to your below comment I now know why. But anyway. This code was my own invention and it looks like it was a bad idea in general. 2. Linux kernel will attempt to update RTC at 500ms mark and not at a second mark. Do they known something better? Hmm, I didn't know that. Perhaps they thought this minimizes average error in setting RTC time. -- vda ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: Busybox 1.16.x dnsd alignment problems
Are you saying that here: # define move_from_unaligned16(v, u16p) (memcpy((v), (u16p), 2)) memcpy may be opportunistic and if u16p has type uin16_t, memcpy will be optimized to assignment? Definitely yes. Please find a way which works for your arch and compiler, and let me know. Parhaps this? # define move_from_unaligned16(v, u16p) (memcpy((v), (void*)(u16p), 2)) This also was my first idea, but it doesn't work. Seems like gcc tries to be super clever, ignoring the cast and using the original pointer type instead. Maybe something like # define move_from_unaligned16(v, u16p) {void* src=(void*)(u16p);memcpy((v), src, 2);} will do the trick. I will try it tomorrow. Denys Vlasenko schrieb: On Wed, Apr 14, 2010 at 6:02 AM, Lars Reemts l...@reemts.de wrote: Hello, I'm using busybox on a AT91SAM9261 (arm920t) processor with gcc 4.3.4. Yesterday I ran into some problems using dnsd. DNS queries from a windows host were not properly decoded and hence not answered. Digging into the code the problem turned out to be two different problems, both related to halfword alignment. The first one (in dnsd_main()) is related to the alignment of buffer where the incoming network packets are stored. It was declared and allocated as uint8_t buf[] in dnsd.c:462. This tells the compiler that the buffer is containing byte data and gives it the freedom to allocate the buffer at any address. In my setup it starts at an odd address. When processing an incoming packet later on in process_packet() the buffer is accessed as containing 2 byte data, which leads to alignment problems. Allocating the buffer as uint16_t buf[] solves the problem for me. The second one (in process_packet()) was particularly hard to track down. It boils down to move_from_unaligned16(), which is #defined as 2 byte memcpy() in platform.h not working correctly for 16 bit source pointer types. For these the compiler assumes the pointer to already be aligned and replaces the 2 byte memcpy() by a half word load and a half word store assembler instruction. The solution is to ensure the source pointer is pointing to a single byte data type. Are you saying that here: # define move_from_unaligned16(v, u16p) (memcpy((v), (u16p), 2)) memcpy may be opportunistic and if u16p has type uin16_t, memcpy will be optimized to assignment? If so, this should be prevented from happening. We WANT to be damn sure any address, however badly unaligned, will work in this macro. Please find a way which works for your arch and compiler, and let me know. Parhaps this? # define move_from_unaligned16(v, u16p) (memcpy((v), (void*)(u16p), 2)) Please have a look at the attached patch which solves both problems. I'm not sure whether the solution for the second problem should be done in platform.h. + /* allocate the buffer as uint16_t[] to make sure it is aligned at a uint16 boundary */ + uint16_t _buf[MAX_PACK_LEN/2 + 1]; + uint8_t *buf = (uint8_t*)_buf; Unfortunately gcc is too stupid to not generate bigger code for this. So I went with slapping ALIGN4 on the byte array instead. The fix is here: http://busybox.net/downloads/fixes-1.16.1/busybox-1.16.1-dnsd.patch -- Lars Reemts, Lange Wieke 1, 26817 Rhauderfehn, Germany Tel: +49 4952 942290, Fax: +49 4952 942291 mailto: l...@reemts.de ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: Busybox 1.16.x dnsd alignment problems
Unfortunately # define move_from_unaligned16(v, u16p) {void* src=(void*)(u16p);memcpy((v), src, 2);} also didn't do it. The only solution I've found working is doing it the hard way by hand: # define move_from_unaligned16(v, u16p) do { \ *((uint8_t*)v) = *((uint8_t*)u16p); \ *(((uint8_t*)v)+1) = *(((uint8_t*)u16p)+1); \ } while (0) Lars Reemts schrieb: Are you saying that here: # define move_from_unaligned16(v, u16p) (memcpy((v), (u16p), 2)) memcpy may be opportunistic and if u16p has type uin16_t, memcpy will be optimized to assignment? Definitely yes. Please find a way which works for your arch and compiler, and let me know. Parhaps this? # define move_from_unaligned16(v, u16p) (memcpy((v), (void*)(u16p), 2)) This also was my first idea, but it doesn't work. Seems like gcc tries to be super clever, ignoring the cast and using the original pointer type instead. Maybe something like # define move_from_unaligned16(v, u16p) {void* src=(void*)(u16p);memcpy((v), src, 2);} will do the trick. I will try it tomorrow. Denys Vlasenko schrieb: On Wed, Apr 14, 2010 at 6:02 AM, Lars Reemts l...@reemts.de wrote: Hello, I'm using busybox on a AT91SAM9261 (arm920t) processor with gcc 4.3.4. Yesterday I ran into some problems using dnsd. DNS queries from a windows host were not properly decoded and hence not answered. Digging into the code the problem turned out to be two different problems, both related to halfword alignment. The first one (in dnsd_main()) is related to the alignment of buffer where the incoming network packets are stored. It was declared and allocated as uint8_t buf[] in dnsd.c:462. This tells the compiler that the buffer is containing byte data and gives it the freedom to allocate the buffer at any address. In my setup it starts at an odd address. When processing an incoming packet later on in process_packet() the buffer is accessed as containing 2 byte data, which leads to alignment problems. Allocating the buffer as uint16_t buf[] solves the problem for me. The second one (in process_packet()) was particularly hard to track down. It boils down to move_from_unaligned16(), which is #defined as 2 byte memcpy() in platform.h not working correctly for 16 bit source pointer types. For these the compiler assumes the pointer to already be aligned and replaces the 2 byte memcpy() by a half word load and a half word store assembler instruction. The solution is to ensure the source pointer is pointing to a single byte data type. Are you saying that here: # define move_from_unaligned16(v, u16p) (memcpy((v), (u16p), 2)) memcpy may be opportunistic and if u16p has type uin16_t, memcpy will be optimized to assignment? If so, this should be prevented from happening. We WANT to be damn sure any address, however badly unaligned, will work in this macro. Please find a way which works for your arch and compiler, and let me know. Parhaps this? # define move_from_unaligned16(v, u16p) (memcpy((v), (void*)(u16p), 2)) Please have a look at the attached patch which solves both problems. I'm not sure whether the solution for the second problem should be done in platform.h. + /* allocate the buffer as uint16_t[] to make sure it is aligned at a uint16 boundary */ + uint16_t _buf[MAX_PACK_LEN/2 + 1]; + uint8_t *buf = (uint8_t*)_buf; Unfortunately gcc is too stupid to not generate bigger code for this. So I went with slapping ALIGN4 on the byte array instead. The fix is here: http://busybox.net/downloads/fixes-1.16.1/busybox-1.16.1-dnsd.patch -- Lars Reemts, Lange Wieke 1, 26817 Rhauderfehn, Germany Tel: +49 4952 942290, Fax: +49 4952 942291 mailto: l...@reemts.de ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH] make devmem map only a single page at end of memory
On Wed, 14 Apr 2010, Denys Vlasenko wrote: On Tue, Apr 13, 2010 at 6:14 AM, Michael Abbott mich...@araneidae.co.uk wrote: + off_t page_mask = ~(off_t)(page_size - 1); + size_t map_length; int fd; ... - virt_addr = (char*)map_base + (target (page_size - 1)); + virt_addr = (char*)map_base + (target page_mask); Bug in the last line shown. Yes indeed, hurriedly corrected in a followup message, but easily missed.___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: Busybox 1.16.x dnsd alignment problems
So I went with slapping ALIGN4 on the byte array instead. The ALIGN4 doesn't compile for me. gcc complains not to know the ALIGN4 macro. Had to change it to: uint8_t buf[MAX_PACK_LEN + 1] __attribute__ ((aligned (4))); Denys Vlasenko schrieb: On Wed, Apr 14, 2010 at 6:02 AM, Lars Reemts l...@reemts.de wrote: Hello, I'm using busybox on a AT91SAM9261 (arm920t) processor with gcc 4.3.4. Yesterday I ran into some problems using dnsd. DNS queries from a windows host were not properly decoded and hence not answered. Digging into the code the problem turned out to be two different problems, both related to halfword alignment. The first one (in dnsd_main()) is related to the alignment of buffer where the incoming network packets are stored. It was declared and allocated as uint8_t buf[] in dnsd.c:462. This tells the compiler that the buffer is containing byte data and gives it the freedom to allocate the buffer at any address. In my setup it starts at an odd address. When processing an incoming packet later on in process_packet() the buffer is accessed as containing 2 byte data, which leads to alignment problems. Allocating the buffer as uint16_t buf[] solves the problem for me. The second one (in process_packet()) was particularly hard to track down. It boils down to move_from_unaligned16(), which is #defined as 2 byte memcpy() in platform.h not working correctly for 16 bit source pointer types. For these the compiler assumes the pointer to already be aligned and replaces the 2 byte memcpy() by a half word load and a half word store assembler instruction. The solution is to ensure the source pointer is pointing to a single byte data type. Are you saying that here: # define move_from_unaligned16(v, u16p) (memcpy((v), (u16p), 2)) memcpy may be opportunistic and if u16p has type uin16_t, memcpy will be optimized to assignment? If so, this should be prevented from happening. We WANT to be damn sure any address, however badly unaligned, will work in this macro. Please find a way which works for your arch and compiler, and let me know. Parhaps this? # define move_from_unaligned16(v, u16p) (memcpy((v), (void*)(u16p), 2)) Please have a look at the attached patch which solves both problems. I'm not sure whether the solution for the second problem should be done in platform.h. + /* allocate the buffer as uint16_t[] to make sure it is aligned at a uint16 boundary */ + uint16_t _buf[MAX_PACK_LEN/2 + 1]; + uint8_t *buf = (uint8_t*)_buf; Unfortunately gcc is too stupid to not generate bigger code for this. So I went with slapping ALIGN4 on the byte array instead. The fix is here: http://busybox.net/downloads/fixes-1.16.1/busybox-1.16.1-dnsd.patch -- Lars Reemts, Lange Wieke 1, 26817 Rhauderfehn, Germany Tel: +49 4952 942290, Fax: +49 4952 942291 mailto: l...@reemts.de ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH] make devmem map only a single page at end of memory
Michael Abbott kirjoitti viestissään (lähetysaika torsdag 15 april 2010): Didn't I already do this? Yes, you did. Thank you for that. Hopefully we can get this into a release at some point :) Now, about why this was a problem in the first place: I'm using an AT91RM9200, Atmel system-on-a-chip with an arm 920T core. This processor has lots of I/O registers that can be conveniently read and written with devmem. Unfortunately, some of these registers reside at the very end of the 32-bit address space, and mapping these registers didn't work when the two-page map wrapped around to zero. -- jorgen.pihlfly...@ajeco.fi (040-5240412) ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: Busybox 1.16.x dnsd alignment problems
Unfortunately # define move_from_unaligned16(v, u16p) {void* src=(void*)(u16p);memcpy((v), src, 2);} also didn't do it. The only solution I've found working is doing it the hard way by hand: # define move_from_unaligned16(v, u16p) do { \ *((uint8_t*)v) = *((uint8_t*)u16p); \ *(((uint8_t*)v)+1) = *(((uint8_t*)u16p)+1); \ } while (0) I think something like below would be cleaner: union uu { unsigned short us; unsigned char b[2]; }; /* Endian independed version */ static inline unsigned short get_unaligned16(void *p) { union uu mm; unsigned char *b = (unsigned char *)p; mm.b[0] = b[0]; mm.b[1] = b[1]; return mm.us; } and then adapt the code to it. Or look at how the linux kernel does it. ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH] httpd_indexcgi.c: fix compile error
Signed-off-by: Kim B. Heino kim.he...@bluegiga.com diff -ur orig/networking/httpd_indexcgi.c busybox-1.16.1/networking/httpd_indexcgi.c --- orig/networking/httpd_indexcgi.c2010-03-20 04:58:07.0 +0200 +++ busybox-1.16.1/networking/httpd_indexcgi.c 2010-04-15 15:19:32.773974069 +0300 @@ -315,7 +315,7 @@ if (S_ISREG(cdir-dl_mode)) fmt_ull(cdir-dl_size); fmt_str(td class=dt); - tm = gmtime(cdir-dl_mtime); + ptm = gmtime(cdir-dl_mtime); fmt_04u(1900 + ptm-tm_year); *dst++ = '-'; fmt_02u(ptm-tm_mon + 1); *dst++ = '-'; fmt_02u(ptm-tm_mday); *dst++ = ' '; ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH] make devmem map only a single page at end of memory
On Thu, Apr 15, 2010 at 12:37 AM, Michael Abbott mich...@araneidae.co.uk wrote: On Wed, 14 Apr 2010, Denys Vlasenko wrote: On Tue, Apr 13, 2010 at 6:14 AM, Michael Abbott mich...@araneidae.co.uk wrote: + off_t page_mask = ~(off_t)(page_size - 1); + size_t map_length; int fd; ... - virt_addr = (char*)map_base + (target (page_size - 1)); + virt_addr = (char*)map_base + (target page_mask); Bug in the last line shown. Yes indeed, hurriedly corrected in a followup message, but easily missed. I made my own fix because for such a simple problem, bikeshed painting effect kicks in and everyone wants to (and is able to) do it himself. Sorry... If you can make it do the same with smaller code... -- vda ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH] httpd_indexcgi.c: fix compile error
On Thu, Apr 15, 2010 at 5:26 AM, Kim B. Heino kim.he...@bluegiga.com wrote: Signed-off-by: Kim B. Heino kim.he...@bluegiga.com diff -ur orig/networking/httpd_indexcgi.c busybox-1.16.1/networking/httpd_indexcgi.c --- orig/networking/httpd_indexcgi.c 2010-03-20 04:58:07.0 +0200 +++ busybox-1.16.1/networking/httpd_indexcgi.c 2010-04-15 15:19:32.773974069 +0300 @@ -315,7 +315,7 @@ if (S_ISREG(cdir-dl_mode)) fmt_ull(cdir-dl_size); fmt_str(td class=dt); - tm = gmtime(cdir-dl_mtime); + ptm = gmtime(cdir-dl_mtime); fmt_04u(1900 + ptm-tm_year); *dst++ = '-'; fmt_02u(ptm-tm_mon + 1); *dst++ = '-'; fmt_02u(ptm-tm_mday); *dst++ = ' '; Thanks! I put it in hotfixes too: http://busybox.net/downloads/fixes-1.16.1/busybox-1.16.1-indexcgi.patch -- vda ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: Allow udhcp to not send a clientid
On Wed, Apr 14, 2010 at 9:11 PM, Alkis Georgopoulos alk...@gmail.com wrote: Στις 15-04-2010, ημέρα Πεμ, και ώρα 01:41 +0300, ο/η Alkis Georgopoulos έγραψε: Στις 14-04-2010, ημέρα Τετ, και ώρα 13:56 -0700, ο/η Denys Vlasenko έγραψε: Use option -C. It is documented in udhcpc --help. Ah, I found it at http://git.busybox.net/busybox/tree/networking/udhcp/dhcpc.c?h=1_16_stableid=53283adb24765a7afb4d6298661c3c1a8d6f5601 clientid-none\0 No_argument C Is this in some Debian/Ubuntu package? Or isn't busybox compiled with udhcpc support in them? Is there a separate package maintained for udhcpc somewhere? It was. That's probably why they still have a separate pkg. But then it was basically merged into busybox. Ping them and let them know they are using ancient code. They can either drop the package altogether or use busybox in it - enable only udhcpc in bbox config, keeping package name the same and thus not breaking systems which expect such package to exist. -- vda ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
RE: hwclock -w takes 24 seconds
2. Linux kernel will attempt to update RTC at 500ms mark and not at a second mark. Do they known something better? Perhaps they thought this minimizes average error in setting RTC time. Perhaps most RTC-reading ends up on a 1-second mark, and thus moving the writing avoids conflicts that at best result in a delay of the write? Just guessing. -- Jim ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: hwclock -w takes 24 seconds
Em 15-04-2010 04:11, Denys Vlasenko escreveu: 2. Linux kernel will attempt to update RTC at 500ms mark and not at a second mark. Do they known something better? Hmm, I didn't know that. Perhaps they thought this minimizes average error in setting RTC time. This makes sense. One problem in updating RTC is that you could move the time back and thus have the same second happening again. Some software bay be unaware and repeat itself. Updating at 500ms mark is nice, if each adjustent is small and thus will avoid non-monotonicity Alain ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 00/39] Windows port, base and archival/
Hi, This is something I think good enough to go upstream. The rest of my work is on: git://github.com/pclouds/busybox-w32.git wip Caveat: crappy, constantly rebased stuff as it's work in progress. However it may tell where this port leads to. If we don't count regex.c there are about 3k more lines to go. Nguyá» n Thái Ngá»c Duy (39): ar: do not filter listing if there is no extra argument This is a regression, not related to Windows port at all. Config.in: add target platform selection Config.in: add target platform WIN32 Config.in: disable all commmands when TARGET_WIN32 is selected win32: Refuse to build on Windows/MinGW unless TARGET_WIN32 is selected win32: add missing system headers platform.h: support MinGW port win32: add termios.h win32: add mingw.h libbb.h: support MinGW port win32: platform.h: add bswap_xx() libbb: exclude files that will not compile on Windows libbb: update messages.c to support Windows win32: Import fnmatch source win32: set binary I/O mode by default win32: add sleep() win32: add mkstemp() win32: add gettimeofday() win32: add pipe() win32: add gmtime_r() win32: add localtime_r() win32: add getpwuid() win32: add signal routines and SIGALRM support win32: add function to map windows errors to posix ones win32: add link() win32: add strsep() win32: add realpath() win32: add get_busybox_exec_path(), which is bb_busybox_exec_path win32: add mkdir() win32: add waitpid() win32: add fcntl() win32: add poll() win32: add getenv(), setenv(), unsetenv() and clearenv() Makefile: support building executable with extension Makefile: support building on Windows using MinGW compiler Add README.win32 Very basic stuff just enough to make a succesful build. You will have a nice 52K busybox.exe, with no applets. gzip: rename eof due to symbol conflict on Windows win32: getopt32: set optind = 0 on Windows win32: Unmask archival We now have some archival applets. Config.in| 34 Makefile | 16 +- Makefile.custom | 22 +- Makefile.flags |6 + README.win32 | 38 archival/Config.in |7 + archival/ar.c|3 +- archival/gzip.c |6 + console-tools/Config.in |1 + coreutils/Config.in |1 + debianutils/Config.in|1 + e2fsprogs/Config.in |1 + editors/Config.in|1 + findutils/Config.in |1 + include/libbb.h | 20 ++ include/mingw.h | 292 +++ include/platform.h | 35 +++- init/Config.in |1 + libbb/get_console.c |4 + libbb/getopt32.c |2 +- libbb/getpty.c |3 + libbb/inet_common.c |4 + libbb/kernel_version.c |5 + libbb/login.c|5 + libbb/makedev.c |5 + libbb/match_fstype.c |4 + libbb/messages.c |7 + libbb/safe_gethostname.c |4 + libbb/signals.c |2 + libbb/udp_io.c |2 + libbb/xconnect.c |2 + libbb/xfuncs.c |4 + libbb/xfuncs_printf.c|4 + libbb/xgethostbyname.c |4 + loginutils/Config.in |1 + mailutils/Config.in |1 + miscutils/Config.in |1 + modutils/Config.in |1 + networking/Config.in |1 + printutils/Config.in |1 + procps/Config.in |1 + runit/Config.in |1 + shell/Config.in |1 + sysklogd/Config.in |1 + util-linux/Config.in |1 + win32/Kbuild | 10 + win32/env.c | 119 +++ win32/fnmatch.c | 488 ++ win32/fnmatch.h | 84 win32/mingw.c| 465 +++ win32/process.c | 10 + win32/termios.h | 124 52 files changed, 1836 insertions(+), 22 deletions(-) create mode 100644 README.win32 create mode 100644 include/mingw.h create mode 100644 win32/Kbuild create mode 100644 win32/env.c create mode 100644 win32/fnmatch.c create mode 100644 win32/fnmatch.h create mode 100644 win32/grp.h create mode 100644 win32/mingw.c create mode 100644 win32/netdb.h create mode 100644 win32/process.c create mode 100644 win32/pwd.h create mode 100644 win32/sys/ioctl.h create mode 100644 win32/sys/mman.h create mode 100644 win32/sys/poll.h create mode 100644 win32/sys/socket.h create mode 100644 win32/sys/wait.h create mode 100644 win32/termios.h ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 01/39] ar: do not filter listing if there is no extra argument
If ar t foo.a is called, the filter will be called unconditionally However, accept list is empty, so filter will fail. In the end nothing will be printed. This is a regresion from 535584c (ar: add archive creation support) Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- archival/ar.c |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/archival/ar.c b/archival/ar.c index 9039747..1b7b66a 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -235,7 +235,8 @@ int ar_main(int argc UNUSED_PARAM, char **argv) : O_RDONLY ); - archive_handle-filter = filter_accept_list; + if (*argv) + archive_handle-filter = filter_accept_list; while (*argv) { llist_add_to_end(archive_handle-accept, *argv++); } ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 02/39] Config.in: add target platform selection
Currently there is only one choice: POSIX. However non-POSIX platform may be supported in future. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- Config.in | 11 +++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Config.in b/Config.in index 40af911..0d9f005 100644 --- a/Config.in +++ b/Config.in @@ -9,6 +9,17 @@ config HAVE_DOT_CONFIG bool default y +choice + prompt Target platform + default TARGET_POSIX + help + Target platform you are building busybox for + +config TARGET_POSIX + bool POSIX + +endchoice + menu Busybox Settings menu General Configuration ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 03/39] Config.in: add target platform WIN32
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- Config.in |3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Config.in b/Config.in index 0d9f005..8cf6a22 100644 --- a/Config.in +++ b/Config.in @@ -18,6 +18,9 @@ choice config TARGET_POSIX bool POSIX +config TARGET_WIN32 + bool MS Windows + endchoice menu Busybox Settings ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 04/39] Config.in: disable all commmands when TARGET_WIN32 is selected
When TARGET_WIN32 is selected, all commands will be invisible. They will be unmasked when they are supported. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- Config.in | 20 archival/Config.in |1 + console-tools/Config.in |1 + coreutils/Config.in |1 + debianutils/Config.in |1 + e2fsprogs/Config.in |1 + editors/Config.in |1 + findutils/Config.in |1 + init/Config.in |1 + loginutils/Config.in|1 + mailutils/Config.in |1 + miscutils/Config.in |1 + modutils/Config.in |1 + networking/Config.in|1 + printutils/Config.in|1 + procps/Config.in|1 + runit/Config.in |1 + shell/Config.in |1 + sysklogd/Config.in |1 + util-linux/Config.in|1 + 20 files changed, 39 insertions(+), 0 deletions(-) diff --git a/Config.in b/Config.in index 8cf6a22..ece513b 100644 --- a/Config.in +++ b/Config.in @@ -47,6 +47,7 @@ config EXTRA_COMPAT config INCLUDE_SUSv2 bool Enable obsolete features removed before SUSv3 default y + depends on !TARGET_WIN32 help This option will enable backwards compatibility with SuSv2, specifically, old-style numeric options ('command -1 file') @@ -121,6 +122,7 @@ config FEATURE_COMPRESS_USAGE config FEATURE_INSTALLER bool Support --install [-s] to install applet links at runtime default n + depends on !TARGET_WIN32 help Enable 'busybox --install [-s]' support. This will allow you to use busybox at runtime to create hard links or symlinks for all the @@ -129,6 +131,7 @@ config FEATURE_INSTALLER config LOCALE_SUPPORT bool Enable locale support (system needs locale for this to work) default n + depends on !TARGET_WIN32 help Enable this if your system has locale support and you would like busybox to support locale settings. @@ -136,6 +139,7 @@ config LOCALE_SUPPORT config UNICODE_SUPPORT bool Support Unicode default n + depends on !TARGET_WIN32 help This makes various applets aware that one byte is not one character on screen. @@ -247,6 +251,7 @@ config LONG_OPTS config FEATURE_DEVPTS bool Use the devpts filesystem for Unix98 PTYs default y + depends on !TARGET_WIN32 help Enable if you want BusyBox to use Unix98 PTY support. If enabled, busybox will use /dev/ptmx for the master side of the pseudoterminal @@ -269,6 +274,7 @@ config FEATURE_CLEAN_UP config FEATURE_UTMP bool Support utmp file default n + depends on !TARGET_WIN32 help The file /var/run/utmp is used to track who is currently logged in. With this option on, certain applets (getty, login, telnetd etc) @@ -279,6 +285,7 @@ config FEATURE_WTMP bool Support wtmp file default n select FEATURE_UTMP + depends on !TARGET_WIN32 help The file /var/run/wtmp is used to track when users have logged into and logged out of the system. @@ -289,6 +296,7 @@ config FEATURE_WTMP config FEATURE_PIDFILE bool Support writing pidfiles default n + depends on !TARGET_WIN32 help This option makes some applets (e.g. crond, syslogd, inetd) write a pidfile in /var/run. Some applications rely on them. @@ -296,6 +304,7 @@ config FEATURE_PIDFILE config FEATURE_SUID bool Support for SUID/SGID handling default n + depends on !TARGET_WIN32 help With this option you can install the busybox binary belonging to root with the suid bit set, and it will automatically drop @@ -314,6 +323,7 @@ config FEATURE_SUID_CONFIG bool Runtime SUID/SGID configuration via /etc/busybox.conf default n if FEATURE_SUID depends on FEATURE_SUID + depends on !TARGET_WIN32 help Allow the SUID / SGID state of an applet to be determined at runtime by checking /etc/busybox.conf. (This is sort of a poor man's sudo.) @@ -355,6 +365,7 @@ config FEATURE_SUID_CONFIG_QUIET config SELINUX bool Support NSA Security Enhanced Linux default n + depends on !TARGET_WIN32 help Enable support for SELinux in applets ls, ps, and id. Also provide the option of compiling in SELinux applets. @@ -389,6 +400,7 @@ config FEATURE_PREFER_APPLETS config BUSYBOX_EXEC_PATH string Path to BusyBox executable default /proc/self/exe + depends on !TARGET_WIN32 help When Busybox applets need to run other busybox applets, BusyBox sometimes needs to exec() itself. When the /proc filesystem is @@ -401,6 +413,7 @@ config BUSYBOX_EXEC_PATH config FEATURE_SYSLOG bool #No description makes it a hidden option default n + depends on !TARGET_WIN32 #help # This option is auto-selected when you select any applet which may # send its output to syslog. You do not need to select it manually. @@ -408,6 +421,7 @@ config FEATURE_SYSLOG config FEATURE_HAVE_RPC bool #No description makes it a hidden option default n + depends on !TARGET_WIN32 #help # This is automatically selected if any of enabled applets need it. # You do not need to
[PATCH 05/39] win32: Refuse to build on Windows/MinGW unless TARGET_WIN32 is selected
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- include/platform.h |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/include/platform.h b/include/platform.h index 2d3821c..32180b5 100644 --- a/include/platform.h +++ b/include/platform.h @@ -7,6 +7,10 @@ #ifndef BB_PLATFORM_H #define BB_PLATFORM_H 1 +#if defined(__MINGW32__) !ENABLE_TARGET_WIN32 +# error You must select target platform MS Windows, or it won't build +#endif + /* Assume all these functions exist by default. Platforms where it is not * true will #undef them below. */ ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 06/39] win32: add missing system headers
These empty headers are to prevent #include errors. Of course those #include may be wrapped inside #ifdefs and excluded, but that would turn libbb.h into a #ifdef mess. Note that all missing declaration is in mingw.h, not in these files. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 win32/grp.h create mode 100644 win32/netdb.h create mode 100644 win32/pwd.h create mode 100644 win32/sys/ioctl.h create mode 100644 win32/sys/mman.h create mode 100644 win32/sys/poll.h create mode 100644 win32/sys/socket.h create mode 100644 win32/sys/wait.h create mode 100644 win32/termios.h diff --git a/win32/grp.h b/win32/grp.h new file mode 100644 index 000..e69de29 diff --git a/win32/netdb.h b/win32/netdb.h new file mode 100644 index 000..e69de29 diff --git a/win32/pwd.h b/win32/pwd.h new file mode 100644 index 000..e69de29 diff --git a/win32/sys/ioctl.h b/win32/sys/ioctl.h new file mode 100644 index 000..e69de29 diff --git a/win32/sys/mman.h b/win32/sys/mman.h new file mode 100644 index 000..e69de29 diff --git a/win32/sys/poll.h b/win32/sys/poll.h new file mode 100644 index 000..e69de29 diff --git a/win32/sys/socket.h b/win32/sys/socket.h new file mode 100644 index 000..e69de29 diff --git a/win32/sys/wait.h b/win32/sys/wait.h new file mode 100644 index 000..e69de29 diff --git a/win32/termios.h b/win32/termios.h new file mode 100644 index 000..e69de29 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 07/39] platform.h: support MinGW port
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- include/platform.h | 28 1 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/platform.h b/include/platform.h index 32180b5..24169e4 100644 --- a/include/platform.h +++ b/include/platform.h @@ -7,8 +7,14 @@ #ifndef BB_PLATFORM_H #define BB_PLATFORM_H 1 -#if defined(__MINGW32__) !ENABLE_TARGET_WIN32 -# error You must select target platform MS Windows, or it won't build +#if ENABLE_TARGET_WIN32 +# if !defined(__MINGW32__) /* HOSTCC is called */ +# undef ENABLE_TARGET_WIN32 +# endif +#else +# if defined(__MINGW32__) +# error You must select target platform MS Windows, or it won't build +# endif #endif /* Assume all these functions exist by default. Platforms where it is not @@ -143,7 +149,7 @@ /* Make all declarations hidden (-fvisibility flag only affects definitions) */ /* (don't include system headers after this until corresponding pop!) */ -#if __GNUC_PREREQ(4,1) +#if __GNUC_PREREQ(4,1) !ENABLE_TARGET_WIN32 # define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN _Pragma(GCC visibility push(hidden)) # define POP_SAVED_FUNCTION_VISIBILITY _Pragma(GCC visibility pop) #else @@ -233,7 +239,8 @@ typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; /* Compiler dependent settings - */ #if (defined __digital__ defined __unix__) \ - || defined __APPLE__ || defined __FreeBSD__ + || defined __APPLE__ || defined __FreeBSD__ \ + || ENABLE_TARGET_WIN32 # undef HAVE_MNTENT_H # undef HAVE_SYS_STATFS_H #else @@ -348,6 +355,16 @@ typedef unsigned smalluint; # undef HAVE_STRCHRNUL #endif +#if ENABLE_TARGET_WIN32 +# undef HAVE_FDPRINTF +# undef HAVE_MKDTEMP +# undef HAVE_SETBIT +# undef HAVE_STRCASESTR +# undef HAVE_STRCHRNUL +# undef HAVE_STRSIGNAL +# undef HAVE_VASPRINTF +#endif + #if defined(__WATCOMC__) # undef HAVE_FDPRINTF # undef HAVE_MEMRCHR @@ -399,6 +416,9 @@ extern char *strchrnul(const char *s, int c) FAST_FUNC; #endif #ifndef HAVE_VASPRINTF +# if ENABLE_TARGET_WIN32 +# include stdarg.h +# endif extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; #endif ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 11/39] win32: platform.h: add bswap_xx()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- include/platform.h |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/include/platform.h b/include/platform.h index 24169e4..2ad2918 100644 --- a/include/platform.h +++ b/include/platform.h @@ -170,6 +170,13 @@ # define bswap_32 __bswap32 # define bswap_16 __bswap16 # define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN) +#elif ENABLE_TARGET_WIN32 +# define __BIG_ENDIAN 0 +# define __LITTLE_ENDIAN 1 +# define __BYTE_ORDER __LITTLE_ENDIAN +# define bswap_16(x) x) 0xFF00) 8) | (((x) 0xFF) 8)) +# define bswap_32(x) ((bswap_16(((x) 0xL) 16)) | (bswap_16((x) 0xL) 16)) +# define bswap_64(x) ((bswap_32(((x) 0xLL) 32)) | (bswap_32((x) 0xLL) 32)) #elif !defined __APPLE__ # include byteswap.h # include endian.h ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 21/39] win32: add localtime_r()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 1a47665..9ce7bc3 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -69,3 +69,10 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result) memcpy(result, gmtime(timep), sizeof(struct tm)); return result; } + +struct tm *localtime_r(const time_t *timep, struct tm *result) +{ + /* localtime() in MSVCRT.DLL is thread-safe, but not reentrant */ + memcpy(result, localtime(timep), sizeof(struct tm)); + return result; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 10/39] libbb.h: support MinGW port
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- include/libbb.h | 20 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 976120e..ebb8045 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -75,6 +75,11 @@ # include arpa/inet.h #elif defined __APPLE__ # include netinet/in.h +#elif ENABLE_TARGET_WIN32 +# define WINVER 0x0501 +# include winsock2.h +# include ws2tcpip.h +# undef s_addr #else # include arpa/inet.h # if !defined(__socklen_t_defined) !defined(_SOCKLEN_T_DECLARED) @@ -90,7 +95,9 @@ /* Some libc's forget to declare these, do it ourself */ +#if !ENABLE_TARGET_WIN32 extern char **environ; +#endif #if defined(__GLIBC__) __GLIBC__ 2 int vdprintf(int d, const char *format, va_list ap); #endif @@ -128,6 +135,10 @@ int sysinfo(struct sysinfo* info); # define BUFSIZ 4096 #endif +/* Can't use ENABLE_TARGET_WIN32 because it's also called by host compiler */ +#if ENABLE_TARGET_WIN32 +# include mingw.h +#endif /* Make all declarations hidden (-fvisibility flag only affects definitions) */ /* (don't include system headers after this until corresponding pop!) */ @@ -470,6 +481,7 @@ void xlisten(int s, int backlog) FAST_FUNC; void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, socklen_t tolen) FAST_FUNC; +#if !ENABLE_TARGET_WIN32 /* SO_REUSEADDR allows a server to rebind to an address that is already * in use by old connections to e.g. previous server instance which is * killed or crashed. Without it bind will fail until all such connections @@ -582,6 +594,7 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags, struct sockaddr *from, struct sockaddr *to, socklen_t sa_size) FAST_FUNC; +#endif char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; @@ -720,6 +733,9 @@ char *safe_getdomainname(void) FAST_FUNC; char* str_tolower(char *str) FAST_FUNC; char *utoa(unsigned n) FAST_FUNC; +#if ENABLE_TARGET_WIN32 +# define itoa bb_itoa +#endif char *itoa(int n) FAST_FUNC; /* Returns a pointer past the formatted number, does NOT null-terminate */ char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; @@ -1546,7 +1562,11 @@ extern const char bb_path_group_file[]; extern const char bb_path_motd_file[]; extern const char bb_path_wtmp_file[]; extern const char bb_dev_null[]; +#if ENABLE_TARGET_WIN32 +#define bb_busybox_exec_path get_busybox_exec_path() +#else extern const char bb_busybox_exec_path[]; +#endif /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, * but I want to save a few bytes here */ extern const char bb_PATH_root_path[]; /* PATH=/sbin:/usr/sbin:/bin:/usr/bin */ ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 23/39] win32: add signal routines and SIGALRM support
The implementation for SIGALRM only because Git needs it (I think for progress display or something). Probably not hurt having it. Although the only thing needed here are stubs. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 124 + 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 2b97761..72e2399 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -90,3 +90,127 @@ struct passwd *getpwuid(int uid) p.pw_dir = NULL; return p; } + +static HANDLE timer_event; +static HANDLE timer_thread; +static int timer_interval; +static int one_shot; +static sighandler_t timer_fn = SIG_DFL; + +/* The timer works like this: + * The thread, ticktack(), is a trivial routine that most of the time + * only waits to receive the signal to terminate. The main thread tells + * the thread to terminate by setting the timer_event to the signalled + * state. + * But ticktack() interrupts the wait state after the timer's interval + * length to call the signal handler. + */ + +static __stdcall unsigned ticktack(void *dummy UNUSED_PARAM) +{ + while (WaitForSingleObject(timer_event, timer_interval) == WAIT_TIMEOUT) { + if (timer_fn == SIG_DFL) + bb_error_msg_and_die(Alarm); + if (timer_fn != SIG_IGN) + timer_fn(SIGALRM); + if (one_shot) + break; + } + return 0; +} + +static int start_timer_thread(void) +{ + timer_event = CreateEvent(NULL, FALSE, FALSE, NULL); + if (timer_event) { + timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL); + if (!timer_thread ) { + errno = ENOMEM; + return -1; + } + } else { + errno = ENOMEM; + return -1; + } + return 0; +} + +static void stop_timer_thread(void) +{ + if (timer_event) + SetEvent(timer_event); /* tell thread to terminate */ + if (timer_thread) { + int rc = WaitForSingleObject(timer_thread, 1000); + if (rc == WAIT_TIMEOUT) + fprintf(stderr, timer thread did not terminate timely); + else if (rc != WAIT_OBJECT_0) + fprintf(stderr, waiting for timer thread failed: %lu, + GetLastError()); + CloseHandle(timer_thread); + } + if (timer_event) + CloseHandle(timer_event); + timer_event = NULL; + timer_thread = NULL; +} + +static inline int is_timeval_eq(const struct timeval *i1, const struct timeval *i2) +{ + return i1-tv_sec == i2-tv_sec i1-tv_usec == i2-tv_usec; +} + +int setitimer(int type UNUSED_PARAM, struct itimerval *in, struct itimerval *out) +{ + static const struct timeval zero; + static int atexit_done; + + if (out != NULL) { + errno = EINVAL; + return -1; + } + if (!is_timeval_eq(in-it_interval, zero) + !is_timeval_eq(in-it_interval, in-it_value)) { + errno = EINVAL; + return -1; + } + + if (timer_thread) + stop_timer_thread(); + + if (is_timeval_eq(in-it_value, zero) + is_timeval_eq(in-it_interval, zero)) + return 0; + + timer_interval = in-it_value.tv_sec * 1000 + in-it_value.tv_usec / 1000; + one_shot = is_timeval_eq(in-it_interval, zero); + if (!atexit_done) { + atexit(stop_timer_thread); + atexit_done = 1; + } + return start_timer_thread(); +} + +int sigaction(int sig, struct sigaction *in, struct sigaction *out) +{ + if (sig != SIGALRM) { + errno = EINVAL; + return -1; + } + if (out != NULL) { + errno = EINVAL; + return -1; + } + + timer_fn = in-sa_handler; + return 0; +} + +#undef signal +sighandler_t mingw_signal(int sig, sighandler_t handler) +{ + sighandler_t old = timer_fn; + if (sig != SIGALRM) + return signal(sig, handler); + timer_fn = handler; + return old; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 24/39] win32: add function to map windows errors to posix ones
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 113 + 1 files changed, 113 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 72e2399..afd017e 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -2,6 +2,119 @@ unsigned int _CRT_fmode = _O_BINARY; +static int err_win_to_posix(DWORD winerr) +{ + int error = ENOSYS; + switch(winerr) { + case ERROR_ACCESS_DENIED: error = EACCES; break; + case ERROR_ACCOUNT_DISABLED: error = EACCES; break; + case ERROR_ACCOUNT_RESTRICTION: error = EACCES; break; + case ERROR_ALREADY_ASSIGNED: error = EBUSY; break; + case ERROR_ALREADY_EXISTS: error = EEXIST; break; + case ERROR_ARITHMETIC_OVERFLOW: error = ERANGE; break; + case ERROR_BAD_COMMAND: error = EIO; break; + case ERROR_BAD_DEVICE: error = ENODEV; break; + case ERROR_BAD_DRIVER_LEVEL: error = ENXIO; break; + case ERROR_BAD_EXE_FORMAT: error = ENOEXEC; break; + case ERROR_BAD_FORMAT: error = ENOEXEC; break; + case ERROR_BAD_LENGTH: error = EINVAL; break; + case ERROR_BAD_PATHNAME: error = ENOENT; break; + case ERROR_BAD_PIPE: error = EPIPE; break; + case ERROR_BAD_UNIT: error = ENODEV; break; + case ERROR_BAD_USERNAME: error = EINVAL; break; + case ERROR_BROKEN_PIPE: error = EPIPE; break; + case ERROR_BUFFER_OVERFLOW: error = ENAMETOOLONG; break; + case ERROR_BUSY: error = EBUSY; break; + case ERROR_BUSY_DRIVE: error = EBUSY; break; + case ERROR_CALL_NOT_IMPLEMENTED: error = ENOSYS; break; + case ERROR_CANNOT_MAKE: error = EACCES; break; + case ERROR_CANTOPEN: error = EIO; break; + case ERROR_CANTREAD: error = EIO; break; + case ERROR_CANTWRITE: error = EIO; break; + case ERROR_CRC: error = EIO; break; + case ERROR_CURRENT_DIRECTORY: error = EACCES; break; + case ERROR_DEVICE_IN_USE: error = EBUSY; break; + case ERROR_DEV_NOT_EXIST: error = ENODEV; break; + case ERROR_DIRECTORY: error = EINVAL; break; + case ERROR_DIR_NOT_EMPTY: error = ENOTEMPTY; break; + case ERROR_DISK_CHANGE: error = EIO; break; + case ERROR_DISK_FULL: error = ENOSPC; break; + case ERROR_DRIVE_LOCKED: error = EBUSY; break; + case ERROR_ENVVAR_NOT_FOUND: error = EINVAL; break; + case ERROR_EXE_MARKED_INVALID: error = ENOEXEC; break; + case ERROR_FILENAME_EXCED_RANGE: error = ENAMETOOLONG; break; + case ERROR_FILE_EXISTS: error = EEXIST; break; + case ERROR_FILE_INVALID: error = ENODEV; break; + case ERROR_FILE_NOT_FOUND: error = ENOENT; break; + case ERROR_GEN_FAILURE: error = EIO; break; + case ERROR_HANDLE_DISK_FULL: error = ENOSPC; break; + case ERROR_INSUFFICIENT_BUFFER: error = ENOMEM; break; + case ERROR_INVALID_ACCESS: error = EACCES; break; + case ERROR_INVALID_ADDRESS: error = EFAULT; break; + case ERROR_INVALID_BLOCK: error = EFAULT; break; + case ERROR_INVALID_DATA: error = EINVAL; break; + case ERROR_INVALID_DRIVE: error = ENODEV; break; + case ERROR_INVALID_EXE_SIGNATURE: error = ENOEXEC; break; + case ERROR_INVALID_FLAGS: error = EINVAL; break; + case ERROR_INVALID_FUNCTION: error = ENOSYS; break; + case ERROR_INVALID_HANDLE: error = EBADF; break; + case ERROR_INVALID_LOGON_HOURS: error = EACCES; break; + case ERROR_INVALID_NAME: error = EINVAL; break; + case ERROR_INVALID_OWNER: error = EINVAL; break; + case ERROR_INVALID_PARAMETER: error = EINVAL; break; + case ERROR_INVALID_PASSWORD: error = EPERM; break; + case ERROR_INVALID_PRIMARY_GROUP: error = EINVAL; break; + case ERROR_INVALID_SIGNAL_NUMBER: error = EINVAL; break; + case ERROR_INVALID_TARGET_HANDLE: error = EIO; break; + case ERROR_INVALID_WORKSTATION: error = EACCES; break; + case ERROR_IO_DEVICE: error = EIO; break; + case ERROR_IO_INCOMPLETE: error = EINTR; break; + case ERROR_LOCKED: error = EBUSY; break; + case ERROR_LOCK_VIOLATION: error = EACCES; break; + case ERROR_LOGON_FAILURE: error = EACCES; break; + case ERROR_MAPPED_ALIGNMENT: error = EINVAL; break; + case ERROR_META_EXPANSION_TOO_LONG: error = E2BIG; break; + case ERROR_MORE_DATA: error = EPIPE; break; + case ERROR_NEGATIVE_SEEK: error = ESPIPE; break; + case ERROR_NOACCESS: error = EFAULT; break; + case ERROR_NONE_MAPPED: error = EINVAL; break; + case ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break; + case ERROR_NOT_READY: error = EAGAIN; break; + case ERROR_NOT_SAME_DEVICE: error = EXDEV; break; + case ERROR_NO_DATA: error = EPIPE; break; + case ERROR_NO_MORE_SEARCH_HANDLES: error = EIO; break; + case ERROR_NO_PROC_SLOTS: error = EAGAIN; break; + case ERROR_NO_SUCH_PRIVILEGE: error = EACCES; break; + case ERROR_OPEN_FAILED: error = EIO; break; + case ERROR_OPEN_FILES: error = EBUSY; break; + case ERROR_OPERATION_ABORTED: error = EINTR; break; + case ERROR_OUTOFMEMORY: error = ENOMEM; break; + case ERROR_PASSWORD_EXPIRED: error = EACCES; break; + case ERROR_PATH_BUSY: error = EBUSY; break; + case ERROR_PATH_NOT_FOUND: error = ENOENT; break; + case ERROR_PIPE_BUSY: error = EBUSY; break; + case ERROR_PIPE_CONNECTED: error = EPIPE; break; + case ERROR_PIPE_LISTENING: error = EPIPE; break; + case
[PATCH 25/39] win32: add link()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 21 + 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index afd017e..eccd37c 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -327,3 +327,24 @@ sighandler_t mingw_signal(int sig, sighandler_t handler) timer_fn = handler; return old; } + +int link(const char *oldpath, const char *newpath) +{ + typedef BOOL WINAPI (*T)(const char*, const char*, LPSECURITY_ATTRIBUTES); + static T create_hard_link = NULL; + if (!create_hard_link) { + create_hard_link = (T) GetProcAddress( + GetModuleHandle(kernel32.dll), CreateHardLinkA); + if (!create_hard_link) + create_hard_link = (T)-1; + } + if (create_hard_link == (T)-1) { + errno = ENOSYS; + return -1; + } + if (!create_hard_link(newpath, oldpath, NULL)) { + errno = err_win_to_posix(GetLastError()); + return -1; + } + return 0; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 12/39] libbb: exclude files that will not compile on Windows
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- libbb/get_console.c |4 libbb/getpty.c |3 +++ libbb/inet_common.c |4 libbb/kernel_version.c |5 + libbb/login.c|5 + libbb/makedev.c |5 + libbb/match_fstype.c |4 libbb/safe_gethostname.c |4 libbb/signals.c |2 ++ libbb/udp_io.c |2 ++ libbb/xconnect.c |2 ++ libbb/xfuncs.c |4 libbb/xfuncs_printf.c|4 libbb/xgethostbyname.c |4 14 files changed, 52 insertions(+), 0 deletions(-) diff --git a/libbb/get_console.c b/libbb/get_console.c index 74022b5..244c2dc 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c @@ -10,6 +10,8 @@ #include libbb.h +#if !ENABLE_TARGET_WIN32 + /* From linux/kd.h */ enum { KDGKBTYPE = 0x4B33 }; /* get keyboard type */ @@ -78,3 +80,5 @@ void FAST_FUNC console_make_active(int fd, const int vt_num) xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)vt_num); xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)vt_num); } + +#endif diff --git a/libbb/getpty.c b/libbb/getpty.c index 4bffd9a..f3c7f5c 100644 --- a/libbb/getpty.c +++ b/libbb/getpty.c @@ -8,6 +8,8 @@ #include libbb.h +#if !ENABLE_TARGET_WIN32 + #define DEBUG 0 int FAST_FUNC xgetpty(char *line) @@ -62,3 +64,4 @@ int FAST_FUNC xgetpty(char *line) #endif /* FEATURE_DEVPTS */ bb_error_msg_and_die(can't find free pty); } +#endif diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 0fc08d6..1be21ed 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -11,6 +11,8 @@ #include libbb.h #include inet_common.h +#if !ENABLE_TARGET_WIN32 + int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst) { struct hostent *hp; @@ -219,3 +221,5 @@ char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric) } #endif /* CONFIG_FEATURE_IPV6 */ + +#endif diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c index cc23712..63e3953 100644 --- a/libbb/kernel_version.c +++ b/libbb/kernel_version.c @@ -8,6 +8,9 @@ */ #include libbb.h + +#if !ENABLE_TARGET_WIN32 + /* After libbb.h, since it needs sys/types.h on some systems */ #include sys/utsname.h /* for uname(2) */ @@ -36,3 +39,5 @@ int FAST_FUNC get_linux_version_code(void) } return r; } + +#endif diff --git a/libbb/login.c b/libbb/login.c index 740c588..dfbe072 100644 --- a/libbb/login.c +++ b/libbb/login.c @@ -10,6 +10,9 @@ */ #include libbb.h + +#if !ENABLE_TARGET_WIN32 + /* After libbb.h, since it needs sys/types.h on some systems */ #include sys/utsname.h @@ -130,3 +133,5 @@ int FAST_FUNC sanitize_env_if_suid(void) return 1; /* we indeed were run by different user! */ } + +#endif diff --git a/libbb/makedev.c b/libbb/makedev.c index ca71fdb..7e5f7e2 100644 --- a/libbb/makedev.c +++ b/libbb/makedev.c @@ -8,6 +8,9 @@ /* We do not include libbb.h - #define makedev() is there! */ #include platform.h + +#if !ENABLE_TARGET_WIN32 + #include features.h #include sys/sysmacros.h @@ -22,3 +25,5 @@ unsigned long long FAST_FUNC bb_makedev(unsigned int major, unsigned int minor) return makedev(major, minor); } #endif + +#endif diff --git a/libbb/match_fstype.c b/libbb/match_fstype.c index 9360e75..81bee80 100644 --- a/libbb/match_fstype.c +++ b/libbb/match_fstype.c @@ -12,6 +12,8 @@ #include libbb.h +#if !ENABLE_TARGET_WIN32 + int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype) { int match = 1; @@ -40,3 +42,5 @@ int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype) return !match; } + +#endif diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c index 05e0954..89302ef 100644 --- a/libbb/safe_gethostname.c +++ b/libbb/safe_gethostname.c @@ -25,6 +25,9 @@ */ #include libbb.h + +#if !ENABLE_TARGET_WIN32 + #include sys/utsname.h /* @@ -72,3 +75,4 @@ char* FAST_FUNC safe_getdomainname(void) return xstrdup(r 0 ? ? : buf); #endif } +#endif diff --git a/libbb/signals.c b/libbb/signals.c index a528756..8ca903e 100644 --- a/libbb/signals.c +++ b/libbb/signals.c @@ -11,6 +11,7 @@ #include libbb.h +#if !ENABLE_TARGET_WIN32 /* All known arches use small ints for signals */ smallint bb_got_signal; @@ -119,3 +120,4 @@ void FAST_FUNC signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int)) sa.sa_handler = handler; sigaction_set(sig, sa); } +#endif diff --git a/libbb/udp_io.c b/libbb/udp_io.c index 24237be..dd98484 100644 --- a/libbb/udp_io.c +++ b/libbb/udp_io.c @@ -8,6 +8,7 @@ */ #include libbb.h +#if !ENABLE_TARGET_WIN32 /* * This asks kernel to let us know dst addr/port of incoming packets * We don't check for errors here. Not supported == won't be used @@ -177,3 +178,4 @@ recv_from_to(int fd, void *buf, size_t len, int flags, return recv_length; #endif } +#endif diff --git a/libbb/xconnect.c b/libbb/xconnect.c index
[PATCH 26/39] win32: add strsep()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 18 ++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index eccd37c..937e942 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -348,3 +348,21 @@ int link(const char *oldpath, const char *newpath) } return 0; } + +char *strsep(char **stringp, const char *delim) +{ + char *s, *old_stringp; + if (!*stringp) + return NULL; + old_stringp = s = *stringp; + while (*s) { + if (strchr(delim, *s)) { + *s = '\0'; + *stringp = s+1; + return old_stringp; + } + s++; + } + *stringp = NULL; + return old_stringp; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 29/39] win32: add mkdir()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 98a45e2..5aba8f5 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -380,3 +380,9 @@ const char *get_busybox_exec_path(void) GetModuleFileName(NULL, path, PATH_MAX); return path; } + +#undef mkdir +int mingw_mkdir(const char *path, int mode UNUSED_PARAM) +{ + return mkdir(path); +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 27/39] win32: add realpath()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |5 + 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 937e942..981968a 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -366,3 +366,8 @@ char *strsep(char **stringp, const char *delim) *stringp = NULL; return old_stringp; } + +char *realpath(const char *path, char *resolved_path) +{ + return strcpy(resolved_path, path); +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 22/39] win32: add getpwuid()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 14 ++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 9ce7bc3..2b97761 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -76,3 +76,17 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) memcpy(result, localtime(timep), sizeof(struct tm)); return result; } + +struct passwd *getpwuid(int uid) +{ + static char user_name[100]; + static struct passwd p; + + DWORD len = sizeof(user_name); + if (!GetUserName(user_name, len)) + return NULL; + p.pw_name = user_name; + p.pw_gecos = unknown; + p.pw_dir = NULL; + return p; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 13/39] libbb: update messages.c to support Windows
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- libbb/messages.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/libbb/messages.c b/libbb/messages.c index 1d0e587..c3ddbf3 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -43,8 +43,13 @@ const char bb_path_shadow_file[] ALIGN1 = /etc/shadow; const char bb_path_group_file[] ALIGN1 = /etc/group; const char bb_path_gshadow_file[] ALIGN1 = /etc/gshadow; const char bb_path_motd_file[] ALIGN1 = /etc/motd; +#if ENABLE_TARGET_WIN32 +/* this one is only used in diff and ash at the moment */ +const char bb_dev_null[] ALIGN1 = nul; +#else const char bb_dev_null[] ALIGN1 = /dev/null; const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH; +#endif const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, * but I want to save a few bytes here. Check libbb.h before changing! */ @@ -57,6 +62,7 @@ const int const_int_1 = 1; * and it will end up in bss */ const int const_int_0 = 0; +#if !ENABLE_TARGET_WIN32 /* No wtmp on Windows */ #include utmp.h /* This is usually something like /var/adm/wtmp or /var/log/wtmp */ const char bb_path_wtmp_file[] ALIGN1 = @@ -67,6 +73,7 @@ const char bb_path_wtmp_file[] ALIGN1 = #else #error unknown path to wtmp file #endif +#endif /* We use it for global data via *(struct global*)bb_common_bufsiz1. * Since gcc insists on aligning struct global's members, it would be a pity ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 28/39] win32: add get_busybox_exec_path(), which is bb_busybox_exec_path
This function will become bb_busybox_exec_path because there is no fixed installation location on Windows. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |9 + 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 981968a..98a45e2 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -371,3 +371,12 @@ char *realpath(const char *path, char *resolved_path) { return strcpy(resolved_path, path); } + +const char *get_busybox_exec_path(void) +{ + static char path[PATH_MAX] = ; + + if (!*path) + GetModuleFileName(NULL, path, PATH_MAX); + return path; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 31/39] win32: add fcntl()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |8 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 5aba8f5..cb0e7be 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -386,3 +386,11 @@ int mingw_mkdir(const char *path, int mode UNUSED_PARAM) { return mkdir(path); } + +int fcntl(int fd UNUSED_PARAM, int cmd, ...) +{ + if (cmd == F_GETFD || cmd == F_SETFD || cmd == F_GETFL) + return 0; + errno = EINVAL; + return -1; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 30/39] win32: add waitpid()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/Kbuild|1 + win32/process.c | 10 ++ 2 files changed, 11 insertions(+), 0 deletions(-) create mode 100644 win32/process.c diff --git a/win32/Kbuild b/win32/Kbuild index f065d42..315f808 100644 --- a/win32/Kbuild +++ b/win32/Kbuild @@ -6,3 +6,4 @@ lib-y:= lib-$(CONFIG_TARGET_WIN32) += fnmatch.o lib-$(CONFIG_TARGET_WIN32) += mingw.o +lib-$(CONFIG_TARGET_WIN32) += process.o diff --git a/win32/process.c b/win32/process.c new file mode 100644 index 000..77d19fb --- /dev/null +++ b/win32/process.c @@ -0,0 +1,10 @@ +#include libbb.h + +int waitpid(pid_t pid, int *status, unsigned options) +{ + /* Windows does not understand parent-child */ + if (options == 0 pid != -1) + return _cwait(status, pid, 0); + errno = EINVAL; + return -1; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 32/39] win32: add poll()
Only works for pipes, as commented in the source code. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 69 + 1 files changed, 69 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index cb0e7be..c156adc 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -176,6 +176,75 @@ int pipe(int filedes[2]) return 0; } +int poll(struct pollfd *ufds, unsigned int nfds, int timeout) +{ + int i, pending; + + if (timeout = 0) { + if (nfds == 0) { + Sleep(timeout); + return 0; + } + errno = EINVAL; + return -1; + } + + /* When there is only one fd to wait for, then we pretend that + * input is available and let the actual wait happen when the + * caller invokes read(). + */ + if (nfds == 1) { + if (!(ufds[0].events POLLIN)) { + errno = EINVAL; + return -1; + } + ufds[0].revents = POLLIN; + return 0; + } + +repeat: + pending = 0; + for (i = 0; i nfds; i++) { + DWORD avail = 0; + HANDLE h = (HANDLE) _get_osfhandle(ufds[i].fd); + if (h == INVALID_HANDLE_VALUE) + return -1; /* errno was set */ + + if (!(ufds[i].events POLLIN)) { + errno = EINVAL; + return -1; + } + + /* this emulation works only for pipes */ + if (!PeekNamedPipe(h, NULL, 0, NULL, avail, NULL)) { + int err = GetLastError(); + if (err == ERROR_BROKEN_PIPE) { +ufds[i].revents = POLLHUP; +pending++; + } else { +errno = EINVAL; +return -1; + } + } else if (avail) { + ufds[i].revents = POLLIN; + pending++; + } else + ufds[i].revents = 0; + } + if (!pending) { + /* The only times that we spin here is when the process + * that is connected through the pipes is waiting for + * its own input data to become available. But since + * the process (pack-objects) is itself CPU intensive, + * it will happily pick up the time slice that we are + * relinguishing here. + */ + Sleep(0); + goto repeat; + } + return 0; +} + struct tm *gmtime_r(const time_t *timep, struct tm *result) { /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */ ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 33/39] win32: add getenv(), setenv(), unsetenv() and clearenv()
clearenv() is not supported yet. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/Kbuild |1 + win32/env.c | 119 ++ 2 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 win32/env.c diff --git a/win32/Kbuild b/win32/Kbuild index 315f808..26b0269 100644 --- a/win32/Kbuild +++ b/win32/Kbuild @@ -4,6 +4,7 @@ lib-y:= +lib-$(CONFIG_TARGET_WIN32) += env.o lib-$(CONFIG_TARGET_WIN32) += fnmatch.o lib-$(CONFIG_TARGET_WIN32) += mingw.o lib-$(CONFIG_TARGET_WIN32) += process.o diff --git a/win32/env.c b/win32/env.c new file mode 100644 index 000..376ad9d --- /dev/null +++ b/win32/env.c @@ -0,0 +1,119 @@ +#include libbb.h + +char **copy_environ(const char *const *envp) +{ + char **env; + int i = 0; + while (envp[i]) + i++; + env = xmalloc((i+1)*sizeof(*env)); + for (i = 0; envp[i]; i++) + env[i] = xstrdup(envp[i]); + env[i] = NULL; + return env; +} + +void free_environ(char **env) +{ + int i; + for (i = 0; env[i]; i++) + free(env[i]); + free(env); +} + +static int lookup_env(char **env, const char *name, size_t nmln) +{ + int i; + + for (i = 0; env[i]; i++) { + if (0 == strncmp(env[i], name, nmln) + '=' == env[i][nmln]) + /* matches */ + return i; + } + return -1; +} + +#undef getenv +char *mingw_getenv(const char *name) +{ + char *result = getenv(name); + if (!result !strcmp(name, TMPDIR)) { + /* on Windows it is TMP and TEMP */ + result = getenv(TMP); + if (!result) + result = getenv(TEMP); + } + return result; +} + +int setenv(const char *name, const char *value, int replace) +{ + int out; + size_t namelen, valuelen; + char *envstr; + + if (!name || !value) return -1; + if (!replace) { + char *oldval = NULL; + oldval = getenv(name); + if (oldval) return 0; + } + + namelen = strlen(name); + valuelen = strlen(value); + envstr = malloc((namelen + valuelen + 2)); + if (!envstr) return -1; + + memcpy(envstr, name, namelen); + envstr[namelen] = '='; + memcpy(envstr + namelen + 1, value, valuelen); + envstr[namelen + valuelen + 1] = 0; + + out = putenv(envstr); + /* putenv(3) makes the argument string part of the environment, + * and changing that string modifies the environment --- which + * means we do not own that storage anymore. Do not free + * envstr. + */ + + return out; +} + +/* + * If name contains '=', then sets the variable, otherwise it unsets it + */ +char **env_setenv(char **env, const char *name) +{ + char *eq = strchrnul(name, '='); + int i = lookup_env(env, name, eq-name); + + if (i 0) { + if (*eq) { + for (i = 0; env[i]; i++) +; + env = xrealloc(env, (i+2)*sizeof(*env)); + env[i] = xstrdup(name); + env[i+1] = NULL; + } + } + else { + free(env[i]); + if (*eq) + env[i] = xstrdup(name); + else + for (; env[i]; i++) +env[i] = env[i+1]; + } + return env; +} + +void unsetenv(const char *env) +{ + env_setenv(environ, env); +} + +int clearenv(void) +{ + bb_error_msg_and_die(clearenv() is not supported); +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 14/39] win32: Import fnmatch source
This was extracted from commit e56b799d6ad8afba4168fffa7218d44c041a72d2 in Git repository. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/Kbuild|7 + win32/fnmatch.c | 488 +++ win32/fnmatch.h | 84 ++ 3 files changed, 579 insertions(+), 0 deletions(-) create mode 100644 win32/Kbuild create mode 100644 win32/fnmatch.c create mode 100644 win32/fnmatch.h diff --git a/win32/Kbuild b/win32/Kbuild new file mode 100644 index 000..7f89f17 --- /dev/null +++ b/win32/Kbuild @@ -0,0 +1,7 @@ +# Makefile for busybox +# +# Licensed under the GPL v2, see the file LICENSE in this tarball. + +lib-y:= + +lib-$(CONFIG_TARGET_WIN32) += fnmatch.o diff --git a/win32/fnmatch.c b/win32/fnmatch.c new file mode 100644 index 000..1f4ead5 --- /dev/null +++ b/win32/fnmatch.c @@ -0,0 +1,488 @@ +/* Copyright (C) 1991, 92, 93, 96, 97, 98, 99 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H +# include config.h +#endif + +/* Enable GNU extensions in fnmatch.h. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include errno.h +#include fnmatch.h +#include ctype.h + +#if HAVE_STRING_H || defined _LIBC +# include string.h +#else +# include strings.h +#endif + +#if defined STDC_HEADERS || defined _LIBC +# include stdlib.h +#endif + +/* For platform which support the ISO C amendement 1 functionality we + support user defined character classes. */ +#if defined _LIBC || (defined HAVE_WCTYPE_H defined HAVE_WCHAR_H) +/* Solaris 2.5 has a bug: wchar.h must be included before wctype.h. */ +# include wchar.h +# include wctype.h +#endif + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#if defined _LIBC || !defined __GNU_LIBRARY__ + + +# if defined STDC_HEADERS || !defined isascii +# define ISASCII(c) 1 +# else +# define ISASCII(c) isascii(c) +# endif + +# ifdef isblank +# define ISBLANK(c) (ISASCII (c) isblank (c)) +# else +# define ISBLANK(c) ((c) == ' ' || (c) == '\t') +# endif +# ifdef isgraph +# define ISGRAPH(c) (ISASCII (c) isgraph (c)) +# else +# define ISGRAPH(c) (ISASCII (c) isprint (c) !isspace (c)) +# endif + +# define ISPRINT(c) (ISASCII (c) isprint (c)) +# define ISDIGIT(c) (ISASCII (c) isdigit (c)) +# define ISALNUM(c) (ISASCII (c) isalnum (c)) +# define ISALPHA(c) (ISASCII (c) isalpha (c)) +# define ISCNTRL(c) (ISASCII (c) iscntrl (c)) +# define ISLOWER(c) (ISASCII (c) islower (c)) +# define ISPUNCT(c) (ISASCII (c) ispunct (c)) +# define ISSPACE(c) (ISASCII (c) isspace (c)) +# define ISUPPER(c) (ISASCII (c) isupper (c)) +# define ISXDIGIT(c) (ISASCII (c) isxdigit (c)) + +# define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) + +# if defined _LIBC || (defined HAVE_WCTYPE_H defined HAVE_WCHAR_H) +/* The GNU C library provides support for user-defined character classes + and the functions from ISO C amendement 1. */ +# ifdef CHARCLASS_NAME_MAX +# define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX +# else +/* This shouldn't happen but some implementation might still have this + problem. Use a reasonable default value. */ +# define CHAR_CLASS_MAX_LENGTH 256 +# endif + +# ifdef _LIBC +# define IS_CHAR_CLASS(string) __wctype (string) +# else +# define IS_CHAR_CLASS(string) wctype (string) +# endif +# else +# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ + +# define IS_CHAR_CLASS(string) \ + (STREQ (string, alpha) || STREQ (string, upper) \ +|| STREQ (string, lower) || STREQ (string, digit) \ +|| STREQ (string, alnum) || STREQ (string, xdigit) \ +|| STREQ (string, space) || STREQ (string, print) \ +|| STREQ (string, punct) || STREQ (string,
[PATCH 34/39] Makefile: support building executable with extension
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- Makefile| 15 --- Makefile.custom | 22 +++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 1481f01..a40be79 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ PATCHLEVEL = 17 SUBLEVEL = 0 EXTRAVERSION = .git NAME = Unnamed +X = # *DOCUMENTATION* # To see a list of typical targets execute make help @@ -516,7 +517,7 @@ endif # command line. # This allow a user to issue only 'make' to build a kernel including modules # Defaults busybox but it is usually overridden in the arch makefile -all: busybox doc +all: busybox$(X) doc -include $(srctree)/arch/$(ARCH)/Makefile @@ -699,16 +700,16 @@ debug_kallsyms: .tmp_map$(last_kallsyms) endif # ifdef CONFIG_KALLSYMS # busybox image - including updated kernel symbols -busybox_unstripped: $(busybox-all) FORCE +busybox_unstripped$(X): $(busybox-all) FORCE $(call if_changed_rule,busybox__) $(Q)rm -f .old_version -busybox: busybox_unstripped +busybox$(X): busybox_unstripped$(X) ifeq ($(SKIP_STRIP),y) $(Q)cp $ $@ else $(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \ - busybox_unstripped -o $@ + busybox_unstripped$(X) -o $@ # strip is confused by PIE executable and does not set exec bits $(Q)chmod a+x $@ endif @@ -944,7 +945,7 @@ endif # CONFIG_MODULES # Directories files removed with 'make clean' CLEAN_DIRS += $(MODVERDIR) _install 0_lib -CLEAN_FILES += busybox busybox_unstripped* busybox.links \ +CLEAN_FILES += busybox$(X) busybox_unstripped* busybox.links \ System.map .kernelrelease \ .tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map @@ -957,7 +958,7 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \ include/applet_tables.h \ applets/usage \ .kernelrelease Module.symvers tags TAGS cscope* \ - busybox_old + busybox_old$(X) # clean - Delete most, but leave enough to build external modules # @@ -1234,7 +1235,7 @@ endif #ifeq ($(mixed-targets),1) PHONY += checkstack checkstack: - $(OBJDUMP) -d busybox $$(find . -name '*.ko') | \ + $(OBJDUMP) -d busybox$(X) $$(find . -name '*.ko') | \ $(PERL) $(src)/scripts/checkstack.pl $(ARCH) kernelrelease: diff --git a/Makefile.custom b/Makefile.custom index ecba6bd..857ccf4 100644 --- a/Makefile.custom +++ b/Makefile.custom @@ -81,29 +81,29 @@ checkhelp: $(patsubst %,$(srctree)/%,$(wildcard $(patsubst %,%/Config.in,$(busybox-dirs) ./))) .PHONY: sizes -sizes: busybox_unstripped +sizes: busybox_unstripped$(X) $(NM) --size-sort $() .PHONY: bloatcheck -bloatcheck: busybox_old busybox_unstripped - @$(srctree)/scripts/bloat-o-meter busybox_old busybox_unstripped - @$(CROSS_COMPILE)size busybox_old busybox_unstripped +bloatcheck: busybox_old$(X) busybox_unstripped$(X) + @$(srctree)/scripts/bloat-o-meter busybox_old$(X) busybox_unstripped$(X) + @$(CROSS_COMPILE)size busybox_old$(X) busybox_unstripped$(X) .PHONY: baseline -baseline: busybox_unstripped - @mv busybox_unstripped busybox_old +baseline: busybox_unstripped$(X) + @mv busybox_unstripped$(X) busybox_old$(X) .PHONY: objsizes -objsizes: busybox_unstripped +objsizes: busybox_unstripped$(X) $(srctree)/scripts/objsizes .PHONY: stksizes -stksizes: busybox_unstripped - $(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq +stksizes: busybox_unstripped$(X) + $(CROSS_COMPILE)objdump -d busybox_unstripped$(X) | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq .PHONY: bigdata -bigdata: busybox_unstripped - $(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [trw] ' +bigdata: busybox_unstripped$(X) + $(CROSS_COMPILE)nm --size-sort busybox_unstripped$(X) | grep -vi ' [trw] ' # Documentation Targets .PHONY: doc ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 39/39] win32: Unmask archival
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- archival/Config.in |8 +++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/archival/Config.in b/archival/Config.in index 3319ae8..32817cf 100644 --- a/archival/Config.in +++ b/archival/Config.in @@ -4,7 +4,6 @@ # menu Archival Utilities - depends on !TARGET_WIN32 config FEATURE_SEAMLESS_LZMA bool Make tar, rpm, modprobe etc understand .lzma data @@ -99,6 +98,7 @@ config BZIP2 config CPIO bool cpio default n + depends on !TARGET_WIN32 help cpio is an archival utility program used to create, modify, and extract contents from archives. @@ -128,6 +128,7 @@ config FEATURE_CPIO_P config DPKG bool dpkg default n + depends !TARGET_WIN32 select FEATURE_SEAMLESS_GZ help dpkg is a medium-level tool to install, build, remove and manage @@ -183,6 +184,7 @@ config FEATURE_GZIP_LONG_OPTIONS config LZOP bool lzop default n + depends on WIN32_NET help Lzop compression/decompresion. @@ -198,18 +200,21 @@ config LZOP_COMPR_HIGH config RPM2CPIO bool rpm2cpio default n + depends on WIN32_NET help Converts an RPM file into a CPIO archive. config RPM bool rpm default n + depends on !TARGET_WIN32 help Mini RPM applet - queries and extracts RPM packages. config TAR bool tar default n + depends on !TARGET_WIN32 help tar is an archiving program. It's commonly used with gzip to create compressed archives. It's probably the most widely used @@ -277,6 +282,7 @@ config FEATURE_TAR_UNAME_GNAME bool Enable use of user and group names default n depends on TAR + depends on !TARGET_WIN32 help Enables use of user and group names in tar. This affects contents listings (-t) and preserving permissions when unpacking (-p). ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 16/39] win32: add sleep()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index a85d81a..b92fa82 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1,3 +1,9 @@ #include libbb.h unsigned int _CRT_fmode = _O_BINARY; + +unsigned int sleep (unsigned int seconds) +{ + Sleep(seconds*1000); + return 0; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 35/39] Makefile: support building on Windows using MinGW compiler
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- Makefile |1 + Makefile.flags |6 ++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Makefile b/Makefile index a40be79..9648604 100644 --- a/Makefile +++ b/Makefile @@ -481,6 +481,7 @@ libs-y := \ sysklogd/ \ util-linux/ \ util-linux/volume_id/ \ + win32/ \ endif # KBUILD_EXTMOD diff --git a/Makefile.flags b/Makefile.flags index 60bb888..3daccc8 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -97,7 +97,13 @@ CFLAGS += $(strip $(subst ,,$(CONFIG_EXTRA_CFLAGS))) #)) endif +ifeq ($(CONFIG_TARGET_WIN32),y) +# These defintions are not strictly needed, but they help shut up fnmatch.c warnings +CFLAGS += -Iwin32 -DHAVE_STRING_H=1 -DHAVE_CONFIG_H=0 +X = .exe +else LDLIBS += m crypt +endif ifeq ($(CONFIG_PAM),y) LDLIBS += pam pam_misc ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 36/39] Add README.win32
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- README.win32 | 38 ++ 1 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 README.win32 diff --git a/README.win32 b/README.win32 new file mode 100644 index 000..73e37cc --- /dev/null +++ b/README.win32 @@ -0,0 +1,38 @@ +Status +== + +I would consider this port experimental. Things may work, or may not. +Things may never work because of huge differences between Linux and +Windows. Or things may work in future, if you report the faults to +busy...@busybox.net, especially with patches. + +pclo...@gmail.com +15/04/2010 + +Building + + +You need MinGW compiler and a POSIX environment (so that make +menuconfig works). I cross compile from Linux, but MSYS or Cygwin +should be OK. + +In order to compile the WinGW port you need to: + +Start with make menuconfig: + + - Select target platform as MS Windows + - If you cross compile, set + Busybox Settings - Build Options - Cross Compiler Prefix + - Select whatever applets/features you like + +Do make + +Attempts to make it work with MS Visual Studio are appreciated. You +can start with porting kconfig ;-) + +Limitation +== + + - Use forward slashes. Backslash support is very limited. + - Do not do wild things with Windows drive notation, like archiving a + whole drive. If you want it, tell us, preferably with patches. ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 37/39] gzip: rename eof due to symbol conflict on Windows
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- archival/gzip.c |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/archival/gzip.c b/archival/gzip.c index a327d54..effee7f 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -1577,6 +1577,9 @@ static void compress_block(ct_data * ltree, ct_data * dtree) * trees or store, and output the encoded block to the zip file. This function * returns the total compressed length for the file so far. */ +#ifdef __MINGW32__ +#define eof eof_ +#endif static ulg flush_block(char *buf, ulg stored_len, int eof) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ @@ -1660,6 +1663,9 @@ static ulg flush_block(char *buf, ulg stored_len, int eof) return G2.compressed_len 3; } +#ifdef __MINGW32__ +#undef eof +#endif /* === ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 15/39] win32: set binary I/O mode by default
Text mode is default on Windows, which is just bad. This file also hosts many functions that were extracted from commit e56b799d6ad8afba4168fffa7218d44c041a72d2 in Git repository, under directory compat. Some functions are modified/added by me, but usually credits go to Git developers. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/Kbuild |1 + win32/mingw.c |3 +++ 2 files changed, 4 insertions(+), 0 deletions(-) create mode 100644 win32/mingw.c diff --git a/win32/Kbuild b/win32/Kbuild index 7f89f17..f065d42 100644 --- a/win32/Kbuild +++ b/win32/Kbuild @@ -5,3 +5,4 @@ lib-y:= lib-$(CONFIG_TARGET_WIN32) += fnmatch.o +lib-$(CONFIG_TARGET_WIN32) += mingw.o diff --git a/win32/mingw.c b/win32/mingw.c new file mode 100644 index 000..a85d81a --- /dev/null +++ b/win32/mingw.c @@ -0,0 +1,3 @@ +#include libbb.h + +unsigned int _CRT_fmode = _O_BINARY; ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 17/39] win32: add mkstemp()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |8 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index b92fa82..3611872 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -7,3 +7,11 @@ unsigned int sleep (unsigned int seconds) Sleep(seconds*1000); return 0; } + +int mkstemp(char *template) +{ + char *filename = mktemp(template); + if (filename == NULL) + return -1; + return open(filename, O_RDWR | O_CREAT, 0600); +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 38/39] win32: getopt32: set optind = 0 on Windows
I haven't dug deep into this, but experiments show that optind = 1 does not work. Maybe MinGW guys took getopt from glibc? Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- libbb/getopt32.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libbb/getopt32.c b/libbb/getopt32.c index b5f83c1..f7d77cb 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -534,7 +534,7 @@ getopt32(char **argv, const char *applet_opts, ...) * run_nofork_applet_prime() does this, but we might end up here * also via gunzip_main() - gzip_main(). Play safe. */ -#ifdef __GLIBC__ +#if defined(__GLIBC__) || ENABLE_TARGET_WIN32 optind = 0; #else /* BSD style */ optind = 1; ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 08/39] win32: add termios.h
Just some declaration enough to build. Proper TTY support may come later, targeting Cygwin-based terminals. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/termios.h | 124 +++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/win32/termios.h b/win32/termios.h index e69de29..1586723 100644 --- a/win32/termios.h +++ b/win32/termios.h @@ -0,0 +1,124 @@ +/* iflag bits */ +#define IGNBRK 0x1 +#define BRKINT 0x2 +#define IGNPAR 0x4 +#define IMAXBEL 0x8 +#define INPCK 0x00010 +#define ISTRIP 0x00020 +#define INLCR 0x00040 +#define IGNCR 0x00080 +#define ICRNL 0x00100 +#define IXON 0x00400 +#define IXOFF 0x01000 +#define IUCLC 0x04000 +#define IXANY 0x08000 +#define PARMRK 0x1 + +/* oflag bits */ + +#define OPOST 0x1 +#define OLCUC 0x2 +#define OCRNL 0x4 +#define ONLCR 0x8 +#define ONOCR 0x00010 +#define ONLRET 0x00020 +#define OFILL 0x00040 +#define CRDLY 0x00180 +#define CR0 0x0 +#define CR1 0x00080 +#define CR2 0x00100 +#define CR3 0x00180 +#define NLDLY 0x00200 +#define NL0 0x0 +#define NL1 0x00200 +#define BSDLY 0x00400 +#define BS0 0x0 +#define BS1 0x00400 +#define TABDLY 0x01800 +#define TAB0 0x0 +#define TAB1 0x00800 +#define TAB2 0x01000 +#define TAB3 0x01800 +#define XTABS 0x01800 +#define VTDLY 0x02000 +#define VT0 0x0 +#define VT1 0x02000 +#define FFDLY 0x04000 +#define FF0 0x0 +#define FF1 0x04000 +#define OFDEL 0x08000 + +/* lflag bits */ +#define ISIG 0x0001 +#define ICANON 0x0002 +#define ECHO 0x0004 +#define ECHOE 0x0008 +#define ECHOK 0x0010 +#define ECHONL 0x0020 +#define NOFLSH 0x0040 +#define TOSTOP 0x0080 +#define IEXTEN 0x0100 +#define FLUSHO 0x0200 +#define ECHOKE 0x0400 +#define ECHOCTL 0x0800 + +#define VDISCARD 1 +#define VEOL 2 +#define VEOL2 3 +#define VEOF 4 +#define VERASE 5 +#define VINTR 6 +#define VKILL 7 +#define VLNEXT 8 +#define VMIN 9 +#define VQUIT 10 +#define VREPRINT 11 +#define VSTART 12 +#define VSTOP 13 +#define VSUSP 14 +#define VSWTC 15 +#define VTIME 16 +#define VWERASE 17 + +#define TCIFLUSH0 +#define TCSAFLUSH 1 +#define TCSANOW 2 +#define TCSADRAIN 3 +#define TCSADFLUSH 4 + +#define B0 000 /* hang up */ +#define B50 001 +#define B75 002 +#define B110 003 +#define B134 004 +#define B150 005 +#define B200 006 +#define B300 007 +#define B600 010 +#define B1200 011 +#define B1800 012 +#define B2400 013 +#define B4800 014 +#define B9600 015 + +typedef unsigned char cc_t; +typedef unsigned int tcflag_t; +typedef unsigned int speed_t; +typedef unsigned short otcflag_t; +typedef unsigned char ospeed_t; + +#define NCCS 18 +struct termios { + tcflag_t c_iflag; + tcflag_t c_oflag; + tcflag_t c_cflag; + tcflag_t c_lflag; + char c_line; + cc_t c_cc[NCCS]; + speed_t c_ispeed; + speed_t c_ospeed; +}; + +int tcflush(int fd, int queue_selector); +int tcgetattr(int fd, struct termios *t); +int tcsetattr(int fd, int mode, const struct termios *t); ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 20/39] win32: add gmtime_r()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 09d746f..1a47665 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -62,3 +62,10 @@ int pipe(int filedes[2]) return -1; return 0; } + +struct tm *gmtime_r(const time_t *timep, struct tm *result) +{ + /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */ + memcpy(result, gmtime(timep), sizeof(struct tm)); + return result; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 09/39] win32: add mingw.h
This file is like libbb.h for MinGW port. Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- include/mingw.h | 292 +++ 1 files changed, 292 insertions(+), 0 deletions(-) create mode 100644 include/mingw.h diff --git a/include/mingw.h b/include/mingw.h new file mode 100644 index 000..62cae38 --- /dev/null +++ b/include/mingw.h @@ -0,0 +1,292 @@ +#include fnmatch.h +#include sys/utime.h + +#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; } +#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; } + +/* + * sys/types.h + */ +typedef int gid_t; +typedef int uid_t; +typedef int pid_t; + +/* + * arpa/inet.h + */ +static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); } +#define ntohl git_ntohl + +/* + * fcntl.h + */ +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 3 +#define FD_CLOEXEC 0x1 +#define O_NONBLOCK 04000 + +/* + * grp.h + */ + +struct group { + char *gr_name; + char *gr_passwd; + gid_t gr_gid; + char **gr_mem; +}; +IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM); +IMPL(getgrgid,struct group *,NULL,gid_t gid UNUSED_PARAM); +NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM); +static inline void endgrent(void) {} + +/* + * limits.h + */ +#define NAME_MAX 255 +#define MAXSYMLINKS 20 + + +/* + * poll.h + */ +struct pollfd { + int fd; /* file descriptor */ + short events; /* requested events */ + short revents;/* returned events */ +}; +typedef unsigned long nfds_t; +#define POLLIN 1 +#define POLLHUP 2 + +int poll(struct pollfd *ufds, unsigned int nfds, int timeout); + +/* + * pwd.h + */ +struct passwd { + char *pw_name; + char *pw_gecos; + char *pw_dir; + uid_t pw_uid; + gid_t pw_gid; +}; + +IMPL(getpwnam,struct passwd *,NULL,const char *name UNUSED_PARAM); +struct passwd *getpwuid(int uid); + +/* + * signal.h + */ +#define SIGHUP 1 +#define SIGQUIT 3 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGWINCH 28 + +#define SIG_UNBLOCK 1 + +typedef void (__cdecl *sighandler_t)(int); +struct sigaction { + sighandler_t sa_handler; + unsigned sa_flags; + int sa_mask; +}; +#define sigemptyset(x) (void)0 +#define SA_RESTART 0 + +int sigaction(int sig, struct sigaction *in, struct sigaction *out); +sighandler_t mingw_signal(int sig, sighandler_t handler); +NOIMPL(sigfillset,int *mask UNUSED_PARAM); +#define signal mingw_signal + +/* + * stdio.h + */ +#define fseeko(f,o,w) fseek(f,o,w) + +int fdprintf(int fd, const char *format, ...); + +/* + * stdlib.h + */ +#define WIFEXITED(x) ((unsigned)(x) 259) /* STILL_ACTIVE */ +#define WEXITSTATUS(x) ((x) 0xff) +#define WIFSIGNALED(x) ((unsigned)(x) 259) +#define WTERMSIG(x) ((x) 0x7f) + +int clearenv(void); +char *mingw_getenv(const char *name); +int mkstemp(char *template); +char *realpath(const char *path, char *resolved_path); +int setenv(const char *name, const char *value, int replace); +void unsetenv(const char *env); + +#define getenv mingw_getenv +/* + * string.h + */ +char *strsep(char **stringp, const char *delim); + +/* + * sys/socket.h + */ +#define hstrerror strerror + +NOIMPL(mingw_socket,int domain UNUSED_PARAM, int type UNUSED_PARAM, int protocol UNUSED_PARAM); +NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM); +NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); +NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM); + +/* Windows declaration is different */ +#define socket mingw_socket +#define sendto mingw_sendto +#define listen mingw_listen +#define bind mingw_bind + +/* + * sys/stat.h + */ +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_ISVTX 01000 +#ifndef S_IRWXU +#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +#endif +#define S_IRWXG (S_IRWXU 3) +#define S_IRWXO (S_IRWXG 3) + +#define S_IFSOCK 014 +#define S_IFLNK012 /* Symbolic link */ +#define S_ISLNK(x) (((x) S_IFMT) == S_IFLNK) +#define S_ISSOCK(x) 0 + +#define S_IRGRP (S_IRUSR 3) +#define S_IWGRP (S_IWUSR 3) +#define S_IXGRP (S_IXUSR 3) +#define S_IROTH (S_IRGRP 3) +#define S_IWOTH (S_IWGRP 3) +#define S_IXOTH (S_IXGRP 3) + +NOIMPL(fchmod,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); +NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); +int mingw_mkdir(const char *path, int mode); + +#define mkdir mingw_mkdir +#define lstat stat + +/* + * sys/sysmacros.h + */ +#define makedev(a,b) 0*(a)*(b) /* avoid unused warning */
[PATCH 18/39] win32: add gettimeofday()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c | 40 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 3611872..020e9c4 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -15,3 +15,43 @@ int mkstemp(char *template) return -1; return open(filename, O_RDWR | O_CREAT, 0600); } + +/* + * This is like mktime, but without normalization of tm_wday and tm_yday. + */ +static time_t tm_to_time_t(const struct tm *tm) +{ + static const int mdays[] = { + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 + }; + int year = tm-tm_year - 70; + int month = tm-tm_mon; + int day = tm-tm_mday; + + if (year 0 || year 129) /* algo only works for 1970-2099 */ + return -1; + if (month 0 || month 11) /* array bounds */ + return -1; + if (month 2 || (year + 2) % 4) + day--; + return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + + tm-tm_hour * 60*60 + tm-tm_min * 60 + tm-tm_sec; +} + +int gettimeofday(struct timeval *tv, void *tz) +{ + SYSTEMTIME st; + struct tm tm; + GetSystemTime(st); + tm.tm_year = st.wYear-1900; + tm.tm_mon = st.wMonth-1; + tm.tm_mday = st.wDay; + tm.tm_hour = st.wHour; + tm.tm_min = st.wMinute; + tm.tm_sec = st.wSecond; + tv-tv_sec = tm_to_time_t(tm); + if (tv-tv_sec 0) + return -1; + tv-tv_usec = st.wMilliseconds*1000; + return 0; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 19/39] win32: add pipe()
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- win32/mingw.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 020e9c4..09d746f 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -55,3 +55,10 @@ int gettimeofday(struct timeval *tv, void *tz) tv-tv_usec = st.wMilliseconds*1000; return 0; } + +int pipe(int filedes[2]) +{ + if (_pipe(filedes, PIPE_BUF, 0) 0) + return -1; + return 0; +} ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: hwclock -w takes 24 seconds
On Thursday 15 April 2010 10:55:47 Cathey, Jim wrote: 2. Linux kernel will attempt to update RTC at 500ms mark and not at a second mark. Do they known something better? Perhaps they thought this minimizes average error in setting RTC time. Perhaps most RTC-reading ends up on a 1-second mark, and thus moving the writing avoids conflicts that at best result in a delay of the write? Just guessing. Actually it sounds like the battery backed up clock hardware records info a half-second off from the volatile clock, so you _have_ to set it at the half second mark (either a half second before or a half second after the time yo're setting it, dunno which) if you want it to play back an accurate time. -- Jim Rob -- Latency is more important than throughput. It's that simple. - Linus Torvalds ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 01/39] ar: do not filter listing if there is no extra argument
2010/4/15 Nguyễn Thái Ngọc Duy pclo...@gmail.com: If ar t foo.a is called, the filter will be called unconditionally However, accept list is empty, so filter will fail. In the end nothing will be printed. This is a regresion from 535584c (ar: add archive creation support) Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com Applied, thanks! -- vda ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 37/39] gzip: rename eof due to symbol conflict on Windows
On Thu, Apr 15, 2010 at 10:02:22PM +0200, Nguy�n Thái Ng�c Duy wrote: +#ifdef __MINGW32__ +#define eof eof_ +#endif Rather than special-casing eof in the MingW32 case, why not just rename the instances of eof in the code to something else? It seems to be used in ways local to this file so it shouldn't affect anything else. Dan -- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 35/39] Makefile: support building on Windows using MinGW compiler
On Thu, Apr 15, 2010 at 10:02:20PM +0200, Nguy�n Thái Ng�c Duy wrote: +ifeq ($(CONFIG_TARGET_WIN32),y) Many parts of this patch series depend on CONFIG_TARGET_WIN32. But it seems many instances are really specific to MingW32 rather than generically Win32. If someone later does a Cygwin port, or a MSVC port, I imagine much of what's conditionally compiled with CONFIG_TARGET_WIN32 won't be relevant. Does it make sense to change this variable to CONFIG_TARGET_MINGW32 instead? Dan -- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 26/39] win32: add strsep()
On Thu, Apr 15, 2010 at 10:01:34PM +0200, Nguy�n Thái Ng�c Duy wrote: +char *strsep(char **stringp, const char *delim) strsep() is a non-standard function that other platforms need in addition to Windows. Attached is an alternate patch, part of a series improving portability that I haven't submitted here yet, that adds it to platform.c Dan -- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved diff --git a/include/platform.h b/include/platform.h index f87add5..0dadf42 100644 --- a/include/platform.h +++ b/include/platform.h @@ -16,6 +16,7 @@ #define HAVE_SETBIT 1 #define HAVE_STRCASESTR 1 #define HAVE_STRCHRNUL 1 +#define HAVE_STRSEP 1 #define HAVE_STRSIGNAL 1 #define HAVE_VASPRINTF 1 @@ -168,10 +169,10 @@ #if defined(__BIG_ENDIAN__) __BIG_ENDIAN__ # define BB_BIG_ENDIAN 1 # define BB_LITTLE_ENDIAN 0 -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif defined(__BYTE_ORDER) __BYTE_ORDER == __BIG_ENDIAN # define BB_BIG_ENDIAN 1 # define BB_LITTLE_ENDIAN 0 -#elif __BYTE_ORDER == __LITTLE_ENDIAN +#elif (defined(__BYTE_ORDER) __BYTE_ORDER == __LITTLE_ENDIAN) || defined(__386__) # define BB_BIG_ENDIAN 0 # define BB_LITTLE_ENDIAN 1 #else @@ -353,6 +354,7 @@ typedef unsigned smalluint; # undef HAVE_SETBIT # undef HAVE_STRCASESTR # undef HAVE_STRCHRNUL +# undef HAVE_STRSEP # undef HAVE_STRSIGNAL # undef HAVE_VASPRINTF #endif @@ -391,6 +393,10 @@ extern char *strcasestr(const char *s, const char *pattern) FAST_FUNC; extern char *strchrnul(const char *s, int c) FAST_FUNC; #endif +#ifndef HAVE_STRSEP +extern char *strsep(char **stringp, const char *delim) FAST_FUNC; +#endif + #ifndef HAVE_STRSIGNAL /* Not exactly the same: instead of Stopped it shows STOP etc */ # define strsignal(sig) get_signame(sig) diff --git a/libbb/platform.c b/libbb/platform.c index 17ad3f7..7a8b176 100644 --- a/libbb/platform.c +++ b/libbb/platform.c @@ -107,3 +107,30 @@ char* FAST_FUNC strcasestr(const char *s, const char *pattern) return 0; } #endif + +#ifndef HAVE_STRSEP +/* Copyright (C) 2004 Free Software Foundation, Inc. */ +char* FAST_FUNC strsep(char **stringp, const char *delim) +{ + char *start = *stringp; + char *ptr; + + if (!start) + return NULL; + + if (!*delim) + ptr = start + strlen(start); + else { + ptr = strpbrk(start, delim); + if (!ptr) { + *stringp = NULL; + return start; + } + } + + *ptr = '\0'; + *stringp = ptr + 1; + + return start; +} +#endif ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 27/39] win32: add realpath()
On Thu, Apr 15, 2010 at 10:01:35PM +0200, Nguy�n Thái Ng�c Duy wrote: +char *realpath(const char *path, char *resolved_path) +{ + return strcpy(resolved_path, path); +} I assume you mean this as a temporary stub to enable compilation. If so, it should have a comment as such. I would expect a real implementation to canonicalize the path by resolving junctions, subst drives, maybe network mount point, etc. Dan -- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 31/39] win32: add fcntl()
On Thu, Apr 15, 2010 at 10:02:16PM +0200, Nguy�n Thái Ng�c Duy wrote: +int fcntl(int fd UNUSED_PARAM, int cmd, ...) +{ + if (cmd == F_GETFD || cmd == F_SETFD || cmd == F_GETFL) + return 0; + errno = EINVAL; + return -1; +} Returing 0 makes sense for F_GETFD and F_SETFD, but won't returning 0 be wrong for F_GETFL if some file status flags are set on open? Dan -- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox