aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* libbb: fix detection of relative paths in xreadlink.csymlinkRon Yorston2021-03-012-1/+5
| | | | | | In xmalloc_follow_symlinks() the code to detect relative paths needs to be altered for WIN32. We don't want C:/path to be treated as a relative path.
* Allow `rename()` to work across drivesJohannes Schindelin2021-03-011-1/+2
| | | | Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* Do not use `rename()` for symlinksJohannes Schindelin2021-03-011-5/+8
| | | | | | That function would rename the _target_, not the link. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* Fix `xmalloc_readlink()` againRon Yorston2021-03-011-1/+1
| | | | | | | | | | | | | | | | | | In e86a3ddd8 (win32: make readlink(2) implementation unconditional, 2021-02-12), we removed the special casing of `errno == ENOSYS` when trying to follow symlinks. However, that handling really was necessary: - When we followed a symlink, and found a non-symlink, and then called `readlink()` with that non-symlink, we got `errno == ENOSYS` on Windows (translated from `ERROR_NOT_A_REPARSE_POINT`), and we did want to stop the loop and return the current path in that case. (Noted by Johannes Schindelin.) - When readlink() called DeviceIoControl() for files on certain filesystems (e.g. FAT or a CDROM) it returned `errno == ENOSYS` (translated from ERROR_INVALID_FUNCTION). Revert the part of the patch which handled `ENOSYS` on Windows.
* win32: let `resolve_symlinks()` _really_ resolve symbolic linksJohannes Schindelin2021-03-011-1/+9
| | | | | | | | | When one tries to call `CreateFile()` with a reparse point, it will trigger an `ERROR_INVALID_NAME` unless `FILE_FLAG_OPEN_REPARSE_POINT` is passed. However, _when_ that flag is passed, it does not open a handle to the symlink _target_, but to the symlink itself. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* readlink(): do `NUL`-terminate the resultJohannes Schindelin2021-03-011-2/+3
| | | | | | Otherwise we're provoking buffer overruns. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* win32(symlink): fix logic to determine the type of the symlinkJohannes Schindelin2021-03-011-1/+10
| | | | | | | | | | | | | | | | | | | | On Windows, there are file symlinks and directory symlinks. When trying to `opendir()` a symlink marked as `file`, it will fail. Even if the target is a directory. Because it's the wrong symlink type. To address this, our `symlink()` function calls `stat(target, ...)` to see whether the target exists and is a directory. The problem is that this `target` can be a relative path, and the link path can _also_ be a relative path. Example: `symlink("dir", "uh/oh")`. In this example, the target might say `dir`, but it is relative to `uh/oh`, i.e. we need to `stat("uh/dir", ...)`. This is necessary to pass the `cp` tests because they first create such a directory symlink and then try to copy it while dereferencing symlinks, i.e. calling `opendir()` on the symlink. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* win32: move is_absolute_path()Ron Yorston2021-03-013-3/+10
| | | | | Make is_absolute_path() a function rather than a macro and move it from ash.c into mingw.c.
* win32: workaround for lazy loading issue on Windows 7Ron Yorston2021-03-011-0/+14
| | | | | | | | Investigating why free(1) wasn't working on Windows 7 I found it's possible for LoadLibraryEx to fail with exactly the flags we're using. Work around this. This probably also explains GitHub issue #204.
* which: changes to standalone shell supportRon Yorston2021-02-251-19/+27
| | | | | | | | | | | | | | | - If 'which' is run from an executable called 'which.exe' it suggests we aren't in a standalone-shell-mode shell. Don't run any standalone-shell-specific code. - Use case-insensitive comparisons when testing the names of executables. - When the argument is 'busybox' any executable name starting with 'busybox' should match. - Since 'busybox' is now treated as an applet in standalone shell mode there's no need to test for this explicitly.
* win32: update sysinfo(2) implementation (again)Ron Yorston2021-02-231-14/+31
| | | | | | | | | | Use another API call: EnumPageFiles(). This seems to provide more reliable information about page file usage than the previous ad hoc method. It also allows the call to GlobalMemoryStatusEx() to be removed. With these changes free(1) works sensibly on Windows XP, though not ReactOS.
* .gitignore: support building on WindowsJohannes Schindelin2021-02-213-0/+7
| | | | | | | | | | | | | | These items are already listed, albeit without `.exe` suffix. Presumably, this is because BusyBox-w32 is traditionally cross-compiled on Linux. However, we are about to introduce a CI build definition that builds BusyBox-w32 in MSYS2 (using mingw-w64-gcc), meaning that those executables might very well exist _with_ `.exe` suffix. Let's ignore those, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* Add Windows build info to README.mdRon Yorston2021-02-211-3/+7
|
* win32: work around MSYS2 toolchain weirdnessRon Yorston2021-02-211-0/+9
| | | | | | | | | The Windows/MSYS2/mingw-w64 toolchain has platform-specific prefixes on many of its binaries but not all. As a result the mingw cross-compilation configurations *nearly* work. If we're cross compiling and the generated name $AR doesn't exist as a binary assume were using MSYS2 and make the necessary tweaks.
* applet_tables: simulate force-renaming on WindowsJohannes Schindelin2021-02-211-0/+9
| | | | | | | | | | On Windows, you cannot `rename(source, target)` if `target` exists or if a file handle to `source` is still open. This patch is similar in spirit to 02958a6ee (kbuild: simulate force-renaming on Windows, 2017-02-01). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* win32: workaround for '0-bit reloc' on MSYS2Ron Yorston2021-02-212-0/+3
| | | | | | | | | | | | | There seems to be a bug in the Windows/MSYS2/mingw-w64 toolchain which results in the generated win32/resources/built-in.o lacking relocation data. Forcing an actual C program to be linked along with the resources appears to be an effective workaround. When the toolchain bug is resolved this commit can be reverted. See GitHub issue #200.
* win32: fixes to build on Windows/MSYS2/mingw-w64Ron Yorston2021-02-214-6/+8
| | | | | | | | | | | | | To investigate GitHub issue #200 it was necessary to perform build on Window using the MSYS2/mingw-w64 toolchain. This threw up some issues: - The settings for _WIN32_WINNT and __USE_MINGW_ANSI_STDIO differ from those in Fedora resulting in compiler errors and warnings. Force the defaults I'm used to. - The workaround to allow native compilation of mconf.c was broken by a subsequent upstream change. Make it work again.
* win32: update sysinfo(2) implementationRon Yorston2021-02-192-15/+23
| | | | | | | | | | Add a call to GetPerformanceInfo. Treat the SystemCache member of the PERFORMANCE_INFORMATION structure as buffer RAM. Deduct it from available RAM. The numbers reported by 'free' move about in vaguely sensible ways when I start and stop programs, though I still don't know if they're in any way accurate.
* win32: add uptime to sysinfo(2), enable uptime appletRon Yorston2021-02-194-8/+5
| | | | | | | | | | Fill the uptime member of the sysinfo structure. With this change we can: - use sysinfo(2) in the 'ps' applet; - enable the 'uptime' applet (though without useful support for load averages).
* free: implement sysinfo(2) and enable free(1)Ron Yorston2021-02-185-2/+63
| | | | | | | | | | | | | This is an experimental implementation of sysinfo(2)/free(1). It uses the WIN32 API GlobalMemoryStatusEx() to obtain information about memory. It seems that the 'total pagefile' value includes total RAM as well as pagefile and 'available pagefile' includes available RAM. So the RAM values are deducted. I've no idea what corresponds to Linux buffers and cache.
* nproc: port to WIN32 and enable by defaultRon Yorston2021-02-173-4/+34
| | | | | | Use the WIN32 API GetProcessAffinityMask() to obtain the number of processors configured and the number available to the current process. This only works for up to 64 processors.
* winansi: code shrink and improvementsRon Yorston2021-02-171-41/+15
| | | | | | | | | | | | | | | | | | | | Commit b0b7ab792 (winansi: code shrink) noted that combining reverse vidoe escape sequences (e.g. ESC[7;27m) didn't work properly. Make further changes to improve the situation: - revert to keeping the current attributes in a static variable; - when reverse video is enabled switch the intensity as well as the colour components; - move the code from set_console_attr() into its only caller, process_escape(); - use 0xffff instead of 0 as a flag to indicate the attributes haven't been initialised. Saves 44 bytes and seems to work better.
* libbb: make banner shorterRon Yorston2021-02-161-2/+2
|
* winansi: don't check return from xmallocRon Yorston2021-02-161-3/+0
|
* winansi: allow alternative screen buffer to be disabledRon Yorston2021-02-151-0/+7
| | | | | | | | The alternative console screen buffer (used by less and vi) doesn't work in Wine. Setting the environment variable BB_ALT_BUFFER to 0 causes a screen reset instead.
* winansi: allow test suite to run on WineRon Yorston2021-02-151-3/+3
| | | | | | | | | | | | Running the test suite on Wine failed because in seq 4 0 8 | head -n 10 'seq' didn't detect the broken pipe when 'head' terminated and carried on forever. Fix this by adding a call to ferror(3) in winansi_vfprintf(). Also, use xstrdup() and xmalloc() in a couple of places.
* ash: code shrinkRon Yorston2021-02-143-11/+1
| | | | | Since there's only one call to mingw_spawn_forkshell() we might as well just call spawnve() directly from ash.
* bc: handle ^C in interactive modeRon Yorston2021-02-141-0/+13
|
* bc: fix to build on WIN32 and enable in default configurationsRon Yorston2021-02-133-12/+14
|
* win32: code shrinkRon Yorston2021-02-133-7/+17
| | | | | | | | Rewrite the recent change to tab completion so it only needs one call to sprintf. Then replace sprintf with strcpy/stpcpy, both there and in a couple of other places. Saves 40 bytes.
* win32: implement symlink(2)Ron Yorston2021-02-123-12/+55
| | | | | | | | | | | | | | | | | | | | | Provide an implementation of symlink(2). Calls to symlink(2) will fail in default Windows installations unless running with elevated privileges. Failure to create a symlink when extracting files from an archive is therefore treated as a non-fatal error. There are two ways to permit the creation of symlinks: - Edit security policy to give users the 'Create symbolic links' privilege. Unfortunately this doesn't work for users who are an Administrator. - Enable developer mode, which is available in later versions of Windows 10. The ability to create symlinks is not available in Windows XP or ReactOS.
* win32: allow symlinks to directories to be unlinkedRon Yorston2021-02-121-1/+13
| | | | | | Windows distinguishes between symlinks to directories and files. A symlink to a directory must be deleted by calling rmdir(2) rather than unlink(2).
* win32: make readlink(2) implementation unconditionalRon Yorston2021-02-128-30/+1
| | | | | | | There doesn't seem to be much advantage in having readlink(2) as a configuration option. Making it unconditional reduces divergence from upstream and allows the removal of a check for ENOSYS that's been in busybox-w32 since the start.
* libbb: avoid problems with quoted characters in tab completionRon Yorston2021-02-121-3/+11
| | | | | | | | | | | | | | | | | | | | | Commit 9e341902d (libbb: copy entire match during tab-completion) adjusted the display of matches during tab completion to make any changes in case visible. Unfortunately the presence of quoted special characters upsets the display: $ touch t+1+2+3 t+1+4+5 $ ls t+1<TAB> changes the command to: $ lst\+1\+ In such cases just revert to the upstream code which only displays the tail of the match, giving: $ ls t+1\+
* Reformat README.mdRon Yorston2021-02-101-2/+1
|
* Link to page on pathnames from README.mdRon Yorston2021-02-101-4/+5
|
* winansi: code shrinkRon Yorston2021-02-081-13/+13
| | | | | | Mark floating-point constants as being of type 'float'. Saves 72 bytes.
* Update READMERon Yorston2021-02-071-2/+5
|
* winansi: more accurate colour mappingRon Yorston2021-02-074-22/+111
| | | | | | Use a more accurate technique to map RGB colours to standard Windows console colours. Since this costs 648 bytes it's configurable but is enabled by default.
* winansi: code shrinkRon Yorston2021-02-071-90/+71
| | | | | | | | | | | | | | | | | | | Refactor handling of ESC[38...m and ESC[48...m: - At lower levels deal only with the standard console foreground colours. This makes handling of foreground and background colours more similar. - Many '|=' assignments (to combine attribute values) have been replaced by simple assinments. - Use a common routine to convert RGB to console colours; colours in the 8-bit 6x6x6 cube are scaled up to make use of this. - Detect invalid escape sequences to avoid setting incorrect colour values. Saves 296 bytes.
* win32: code shrinkRon Yorston2021-02-064-4/+6
| | | | | Don't compile some code that isn't currently supported for WIN32. Saves 24 bytes.
* Merge branch 'busybox' into mergeRon Yorston2021-02-0547-178/+202
|\
| * libbb: introduce and use fputs_stdoutRon Yorston2021-02-0336-66/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta fputs_stdout - 12 +12 zxc_vm_process 7237 7230 -7 yes_main 85 78 -7 write_block 380 373 -7 wrapf 305 298 -7 strings_main 437 430 -7 show_bridge 353 346 -7 rev_main 384 377 -7 put_prompt_custom 58 51 -7 put_cur_glyph_and_inc_cursor 168 161 -7 print_numbered_lines 152 145 -7 print_named_ascii 130 123 -7 print_name 135 128 -7 print_login_issue 386 379 -7 print_ascii 208 201 -7 powertop_main 1249 1242 -7 od_main 1789 1782 -7 logread_main 518 511 -7 head_main 804 797 -7 display_process_list 1319 1312 -7 cut_main 1002 995 -7 bb_dump_dump 1550 1543 -7 bb_ask_noecho 393 386 -7 baseNUM_main 702 695 -7 expand_main 755 745 -10 dumpleases_main 497 487 -10 write1 12 - -12 putcsi 37 23 -14 print_login_prompt 55 41 -14 paste_main 525 511 -14 cat_main 440 426 -14 print_it 245 230 -15 print_addrinfo 1188 1171 -17 print_rule 770 750 -20 print_linkinfo 842 822 -20 httpd_main 791 771 -20 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/34 up/down: 12/-341) Total: -329 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: code shrink fgets_strRon Yorston2021-02-031-12/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use a NULL value of maxsz_p to indicate to xmalloc_fgets_internal() that the caller doesn't care about the maximum size of the buffer. This allows the default maximum size to be set once in xmalloc_fgets_internal() instead of separately in each caller. function old new delta xmalloc_fgets_internal 273 287 +14 xmalloc_fgets_str 30 9 -21 xmalloc_fgetline_str 33 12 -21 xmalloc_fgets_str_len 38 10 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 14/-70) Total: -56 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * nl: ensure '-b n' option displays file contentRon Yorston2021-02-025-3/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The command 'nl -b n' should output no line numbers, just some spaces as a placeholder followed by the actual file content. Add tests for line numbering by cat and nl. The correct results were obtained from coreutils. function old new delta print_numbered_lines 152 157 +5 .rodata 182456 182453 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-3) Total: 2 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cryptpw: typo in usage messageRon Yorston2021-02-021-3/+3
| | | | | | | | | | | | | | '[-p N]' should be '[-P N]' in the trivial usage message. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * vi: fix range selection by forward character motionRon Yorston2021-02-021-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Selection of ranges for change/delete/yank by forward character motion commands (SPACE or 'l') was incorrect. The range was always one character whereas vi allows the size of the range to be specified. Fix this by executing the motion command the required number of times. There is a complication when the range is at the end of a line. We need to distinguish between a range which excludes the last character and one which includes it. This requires comparing the actual range with that expected from the command count. (With the additional quirk that a command count of zero is equivalent to a command count of one.) function old new delta find_range 587 619 +32 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: code shrink and speed up index_in_strings()Ron Yorston2021-02-021-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewrite index_in_strings() to replace calls to strcmp()/strlen(). With this change searching for valid names in the applet_names array (for example) is 40% faster. The code has to assume the strings aren't sorted, so will always scan the entire array when presented with an invalid name. function old new delta index_in_strings 63 56 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-7) Total: -7 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: code shrink and speed up find_applet_by_name()Ron Yorston2021-02-021-79/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | find_applet_by_name() determines the appropriate range of applet indices to check for the given name and performs a linear search in applet_names[]. Revise the code so the index of the upper bound of the range, 'max', isn't calculated. Instead check the value of the first non-matching character to see if we've reached the end of the range. This new code speeds up the time to find a valid applet name by 6% and halves the time to detect that a given name is invalid. The average time to detect an invalid name is now the same as for a valid one. function old new delta find_applet_by_name 155 133 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-22) Total: -22 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * awk: allow printf('%c') to output NUL, closes 13486Ron Yorston2021-02-022-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Treat the output of printf as binary rather than a null-terminated string so that NUL characters can be output. This is considered to be a GNU extension, though it's also available in mawk and FreeBSD's awk. function old new delta evaluate 3487 3504 +17 awk_printf 504 519 +15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>