aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2021-03-01libbb: fix detection of relative paths in xreadlink.csymlinkRon Yorston1-1/+1
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.
2021-03-01Allow `rename()` to work across drivesJohannes Schindelin1-1/+2
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2021-03-01Do not use `rename()` for symlinksJohannes Schindelin1-5/+8
That function would rename the _target_, not the link. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2021-03-01Fix `xmalloc_readlink()` againRon Yorston1-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.
2021-03-01win32: let `resolve_symlinks()` _really_ resolve symbolic linksJohannes Schindelin1-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>
2021-03-01readlink(): do `NUL`-terminate the resultJohannes Schindelin1-2/+3
Otherwise we're provoking buffer overruns. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2021-03-01win32(symlink): fix logic to determine the type of the symlinkJohannes Schindelin1-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>
2021-03-01win32: move is_absolute_path()Ron Yorston3-3/+10
Make is_absolute_path() a function rather than a macro and move it from ash.c into mingw.c.
2021-03-01win32: workaround for lazy loading issue on Windows 7Ron Yorston1-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.
2021-02-25which: changes to standalone shell supportRon Yorston1-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.
2021-02-23win32: update sysinfo(2) implementation (again)Ron Yorston1-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.
2021-02-21.gitignore: support building on WindowsJohannes Schindelin3-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>
2021-02-21Add Windows build info to README.mdRon Yorston1-3/+7
2021-02-21win32: work around MSYS2 toolchain weirdnessRon Yorston1-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.
2021-02-21applet_tables: simulate force-renaming on WindowsJohannes Schindelin1-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>
2021-02-21win32: workaround for '0-bit reloc' on MSYS2Ron Yorston2-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.
2021-02-21win32: fixes to build on Windows/MSYS2/mingw-w64Ron Yorston4-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.
2021-02-19win32: update sysinfo(2) implementationRon Yorston2-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.
2021-02-19win32: add uptime to sysinfo(2), enable uptime appletRon Yorston4-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).
2021-02-18free: implement sysinfo(2) and enable free(1)Ron Yorston5-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.
2021-02-17nproc: port to WIN32 and enable by defaultRon Yorston3-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.
2021-02-17winansi: code shrink and improvementsRon Yorston1-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.
2021-02-16libbb: make banner shorterRon Yorston1-2/+2
2021-02-16winansi: don't check return from xmallocRon Yorston1-3/+0
2021-02-15winansi: allow alternative screen buffer to be disabledRon Yorston1-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.
2021-02-15winansi: allow test suite to run on WineRon Yorston1-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.
2021-02-14ash: code shrinkRon Yorston3-11/+1
Since there's only one call to mingw_spawn_forkshell() we might as well just call spawnve() directly from ash.
2021-02-14bc: handle ^C in interactive modeRon Yorston1-0/+13
2021-02-13bc: fix to build on WIN32 and enable in default configurationsRon Yorston3-12/+14
2021-02-13win32: code shrinkRon Yorston3-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.
2021-02-12win32: implement symlink(2)Ron Yorston3-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.
2021-02-12win32: allow symlinks to directories to be unlinkedRon Yorston1-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).
2021-02-12win32: make readlink(2) implementation unconditionalRon Yorston8-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.
2021-02-12libbb: avoid problems with quoted characters in tab completionRon Yorston1-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\+
2021-02-10Reformat README.mdRon Yorston1-2/+1
2021-02-10Link to page on pathnames from README.mdRon Yorston1-4/+5
2021-02-08winansi: code shrinkRon Yorston1-13/+13
Mark floating-point constants as being of type 'float'. Saves 72 bytes.
2021-02-07Update READMERon Yorston1-2/+5
2021-02-07winansi: more accurate colour mappingRon Yorston4-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.
2021-02-07winansi: code shrinkRon Yorston1-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.
2021-02-06win32: code shrinkRon Yorston4-4/+6
Don't compile some code that isn't currently supported for WIN32. Saves 24 bytes.
2021-02-04winansi: tweak colour mappingRon Yorston1-19/+9
2021-02-03libbb: introduce and use fputs_stdoutRon Yorston36-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>
2021-02-03libbb: code shrink fgets_strRon Yorston1-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>
2021-02-03printf: better support for escape sequencesRon Yorston1-48/+60
Upstream printf outputs one character at a time which doesn't play well with emulation of ANSI escape sequences. Previous workarounds for this only applied in limited circumstances. Try a different approach: replace putchar() and printf() calls in the printf applet with custom routines which store the output in memory. It's only really output at the end of the program or when a newline is detected and a non-trivial amount has been collected.
2021-02-03winansi: extend ANSI emulationRon Yorston1-49/+177
Extend ANSI emulation to include: ESC[38;2;R;G;Bm 24-bit foreground colour ESC[48;2;R;G;Bm 24-bit background colour ESC[38;5;Nm 8-bit foreground colour ESC[48;5;Nm 8-bit background colour The colours are selected from the 16 standard console colours. This is unlikely to be aesthetically pleasing but at least it's better than raw escape sequences. Also, add ESC[9m (strike through) as a known but unsupported sequence.
2021-02-03winansi: change default 'skip ANSI emulation' settingRon Yorston4-15/+24
Change the default 'skip ANSI emulation' setting which is used when the environment variable BB_SKIP_ANSI_EMULATION is unset. Previously it was 0 (always emulate) now it's 2 (detect whether or not the terminal supports ANSI escape sequences and behave accordingly). The default value is also now a build-time option.
2021-02-02nl: ensure '-b n' option displays file contentRon Yorston5-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>
2021-02-02cryptpw: typo in usage messageRon Yorston1-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>
2021-02-02vi: fix range selection by forward character motionRon Yorston1-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>