aboutsummaryrefslogtreecommitdiff
path: root/win32 (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* win32: more changes to console/terminal modesRon Yorston2023-03-071-19/+19
| | | | | | | | | | | | | | | | | | Allowing virtual terminal input mode to be set if available proved to be unhelpful: cmd.exe doesn't understand such newfangled stuff (though PowerShell does). The allowed values of BB_TERMINAL_MODE are changed to: 0 Force console mode. 1 Force virtual terminal mode for output. 2 Force virtual terminal mode for input. 3 Force virtual terminal mode for input and output. 4 Support virtual terminal input if enabled. Don't alter mode. 5 Support virtual terminal input if enabled. Set virtual terminal mode for output, if possible. The default is 5.
* win32: virtual terminal input fixesRon Yorston2023-03-061-4/+1
| | | | | | | | | | | - Disable ENABLE_PROCESSED_INPUT in raw mode. Otherwise ^C isn't immediately detected during shell command line editing with virtual terminal input enabled. - Switch read_key()/unix_readkey() to windows_read_key()/read_key(). This allows the shell `read` builtin to use windows_read_key(). Without this change `read` fails when virtual terminal input is enabled.
* win32: enable Unix read_key() for virtual terminalRon Yorston2023-03-051-1/+4
| | | | | | | Until now busybox-w32 has used a native Windows implementation of read_key(). Build the upstream Unix implementation and use it instead of the native version when virtual terminal input mode is enabled.
* win32: add virtual terminal support to termios(3)Ron Yorston2023-03-052-111/+45
| | | | | | | | | | | | Modify `struct termios` to support Windows virtual terminals. Native console mode flags replace the Unix `c_?flag` structure members. Remove unsupported flags from termios.h. Add implementations of tcgetattr(3)/tcsetattr(3) to get/set console flags when virtual terminal input mode is enabled. Add support for emulating raw mode to get_termios_and_make_raw(). This (and related functions) are exposed but not yet used.
* win32: changes to console mode handlingRon Yorston2023-03-051-20/+56
| | | | | | | | | | | | | | | | | | | Add the environment variable BB_TERMINAL_MODE as a more general way of controlling console/terminal mode setting. The default remains unchanged: use virtual terminal mode for output if possible but fall back to the console API with emulated ANSI escape sequences. Currently valid settings are: 0 Force use of console mode 1 Force use of virtual terminal mode for output 5 Prefer virtual terminal mode for output, fall back to console Other values won't do anything useful until code elsewhere has been updated. BB_SKIP_ANSI_EMULATION remains available for backwards compatibility. If both variables are set BB_TERMINAL_MODE takes precedence.
* win32: revise poll(2) for use in ncRon Yorston2023-03-031-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit 5b3b468ec (nc: use poll() instead of select()) changed `nc` to use poll(2) instead of select(2), obviously. In busybox-w32 select(2) had already been hacked to support `nc`. To avoid hacking poll(2) too the upstream change was reverted (c2002eae3). Later `nc` was altered to include the code for both poll and select (3c85cc0c4). Make the changes necessary for poll(2) to work with `nc` on Windows. These are all in the function windows_compute_revents(). Treat a character file that isn't a console as a normal file. Without this `nc 127.0.0.1 1234 </dev/null` doesn't work. Return 0 instead of POLLHUP if GetNumberOfConsoleInputEvents() indicates no events are available. Without this communication between two instances of `nc` which are both using keyboard input isn't as asynchronous as one would like. Only process key press events: key releases are ignored. Without this `nc 127.0.0.1 1234` won't receive anything from the server until the local user presses a key. In the default case, which now includes disk files and character files, detect polling for reads as well as writes. Without this `nc 127.0.0.1 1234 <local_file` doesn't work.
* win32: update poll(2) to match latest gnulib versionRon Yorston2023-03-031-12/+37
|
* win32: try to recover from strange console modeRon Yorston2023-02-211-4/+14
| | | | | | | | | | | | | | | | | | | | | | Execute a remote command on a Windows server using ssh: ~$ ssh localhost 'echo hello' rmy@localhost's password: hello If such a command is run from a busybox-w32 shell the console enters a strange mode when the command completes. Attempt to recover by setting the console back to a default mode. - This doesn't work in a legacy console. - The new mode may not be _exactly_ correct, but it's better than how ssh leaves it. Costs 80-96 bytes. (GitHub issue #288)
* win32: shuffle skip_ansi_emulation() codeRon Yorston2023-02-191-6/+8
| | | | | Rearrange code to avoid unnecessary tests when the environment variable BB_SKIP_ANSI_EMULATION is set.
* win32: work around problem with ConEmuRon Yorston2023-02-191-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | When running the busybox-w32 shell in ConEmu, if: - ANSI emulation is disabled (which it will be, by default) - a non-builtin command is run there is a window of a few seconds after the command completes during which ConEmu is in XTerm mode. During this time any attempt to use the arrows keys will result in [A[B[C[D appearing. This appears to be a common problem: https://github.com/Maximus5/ConEmu/issues/2316 Try to detect if we're running under ConEmu and alter the default behaviour to prefer ANSI emulation. The user can override this preference by setting BB_SKIP_ANSI_EMULATION if desired. By a quirk of fate, old MSYS2 programs (from 2021) which required a workaround in busybox-w32 (commit 54d2ea4b4) are immune to the problem with ConEmu. (GitHib issue #287)
* win32: only change console mode if necessaryRon Yorston2023-02-191-7/+10
| | | | | In skip_ansi_emulation() only call SetConsoleMode() if the new mode differs from the current mode.
* win32: skip ACL check in stat(2) when running as rootFRP-4881-ga6c5fd4ebRon Yorston2023-02-131-1/+2
| | | | | | | | | | Commit 88965fe20 (win32: use ACL check to clarify write permission) added code to check if a file had write permission due to an ACL entry. When running with elevated privileges this check is unnecessary as "user" permissions will be sufficient. This also prevents write permission for "other" being set without respecting umask.
* ash,make: fix CRLF handlingRon Yorston2023-01-301-2/+3
| | | | | | | Fix remove_cr() so it only removes CRs which are part of a CRLF pair, not every CR. Add a test case for the shell.
* win32: provide a default value for HOMERon Yorston2023-01-291-5/+11
| | | | | | | | | | | | | | | | The busybox-w32 shell initialises HOME when it starts. However, if applets are run outside the environment provided by the shell they may find HOME is unset. This caused a problem for 'vi' as it was unable to locate its .exrc. If HOME isn't available in the environment make getenv(3) provide a sensible default value. The shell must use the *real* getenv(3) when determining if HOME is already set. Also, unrelated to the above, the shell shouldn't treat failure of getpwuid(3) as a fatal error. Costs 72-80 bytes.
* win32: another stat(2) + access time fixRon Yorston2023-01-261-1/+1
| | | | | | | | Use FILE_SHARE_READ when opening a file to check if it's an executable. Without that other processes running in parallel might be unable to access the file. (GitHub issue #284)
* make: allow building as pdpmake onlyRon Yorston2023-01-241-0/+1
| | | | | | | | | Commit f261d2d27 (make: make + sh configuration) added 'pdpmake' as an alias for 'make'. It should have been possible to include 'pdpmake' in a build without also including 'make'. Adjust the build configuration so this works as intended.
* win32: only count subdirectories if necessaryRon Yorston2023-01-231-3/+15
| | | | | | | | | | | | | | | | | Commit 7fb95a2a5 (win32: try to get link count for directories) allowed stat(2) to report accurate values of st_nlink for directories. There are only a couple of places in busybox-w32 where these values are required. Disable counting of subdirectories by default and only enable it when necessary. Microsoft kindly provide directories to test edge cases like this: C:/Windows/WinSxS (contains many subdirectories) C:/Windows/WinSxS/Manifests (contains many files) Adds 84-112 bytes.
* win32: limit setting of errno when lazy loading failsRon Yorston2023-01-221-3/+3
| | | | | | | | | | | | The function get_proc_addr() facilitates dynamic loading of functions from DLLs. In the event of failure it set errno to ENOSYS. This is sometimes useful, such as in the implementations of link(2), symlink(2) and realpath(3). However, many other uses of lazy loading can recover from failure or simply don't care. In these cases setting errno is unnecessary and may be counterproductive. (GitHub issue #283)
* win32: reset errno in read_key()Ron Yorston2023-01-221-0/+1
| | | | | | | | | | | | | The WIN32 implementation of read_key() didn't reset errno to zero, unlike the upstream version. This could result in invalid non-zero errno values after calls to lineedit_read_key(). For example, after an attempt to run a non-existent command in the shell errno is set to ENOENT. If the shell had vi line edit mode enabled any command that reads an additional character (e.g. 'c' or 'd') would see the non-zero errno and report EOF. (GitHub issue #283)
* win32: more minor improvements to stat(2)Ron Yorston2023-01-181-29/+26
| | | | | | | | | | | | | | | | The previous commit incorrectly stated that preventing the access time of a file from being updated only required it to be opened with GENERIC_READ access. In fact, even though we don't want to update the access time, SetFileTime() also requires the file to have been opened with FILE_WRITE_ATTRIBUTES access. There's no need to explicitly avoid device files when checking for execute mode: since device files are now 'character special' they are excluded by the test that the file is 'regular'. Device files should be excluded when trying to obtain extra file data using GetFileInformationByHandle(). It shouldn't be possible for CreateFile() to open then, so there's no point in trying.
* win32: minor improvements to stat(2)Ron Yorston2023-01-171-9/+9
| | | | | | | | | | | Commit b11352dcb (win32: prevent stat(2) from updating access times) requested GENERIC_ALL access when opening files. It appears that GENERIC_READ is sufficient and also faster. The code to find the actual size of compressed or sparse files only needs to be invoked for regular files. Avoiding unnecessary calls to GetCompressedFileSize() makes stat(2) slightly faster and gives a more accurate number of blocks for symbolic links.
* win32: use ACL check to clarify write permissionRon Yorston2023-01-161-27/+30
| | | | | | | | | | | | | | | | | On Microsoft Windows a user's home directory doesn't belong to them: it actually belongs to the 'system' user. stat(2) was only using ownership to determine write permissions, so it seemed that the user was unable to write to their own home directory. Use a call to AccessCheck() to determine if files can be accessed due to an entry in their ACL. User home directories and a few other files (e.g. C:/Users/Public) now have the correct write permission. This feature is enabled by FEATURE_EXTRA_FILE_DATA. Costs 220-256 bytes. (GitHub issue #280)
* win32: fix permissions of read-only directoryRon Yorston2023-01-111-1/+1
| | | | | | | | | | | | Commit 15fcbd19c8 (win32: special case for devices files in stat(2)) caused write permissions on directories to respect the read-only attribute. This is incorrect: the read-only attribute doesn't apply to directories in the same way as to normal files. Give directories write permission unconditionally, as before, though respecting umask. (GitHub issue #280)
* win32: improve seeding of PRNGsRon Yorston2023-01-112-60/+10
| | | | | | | | | | | | | | | | | busybox-w32 provides two PRNG implementations which are used in the emulation of /dev/urandom. The ad hoc method of seeding them has been replaced by calls to RtlGenRandom. The documentation for RtlGenRandom indicates it has been deprecated in favour of CryptGenRandom. The documentation for the latter indicates it has been deprecated in favour of the 'Cryptography Next Generation APIs'. Nonetheless, RtlGenRandom remains available in every version of Windows since XP. In the unlikely event that RtlGenRandom fails simply use the current time as the seed. Saves 192 bytes in the default configuration.
* win32: speed up getc(3) wrapperRon Yorston2022-12-301-2/+2
| | | | | | | | The grep applet was found to be rather slow. A major reason for this is the implementation of getc(3). Using _getc_nolock() and inlining is_console_in() speeds things up by a factor of three. (GitHub issue #278)
* win32: always allow d_type member of struct direntRon Yorston2022-12-222-4/+0
| | | | | | | | The d_type member of struct dirent is required by the implementation of glob(3). As a result it isn't possible to build the make applet unless FEATURE_EXTRA_FILE_DATA is configured. Allow d_type unconditionally.
* win32: prevent stat(2) from updating access timesRon Yorston2022-12-221-4/+19
| | | | | | | | | | | | | | | | | The WIN32 implementation of stat(2) reads the contents of some files to see if they're executable. This may update the file access time. Avoid this by a special call to SetFileTime() after opening the file. For details see: https://devblogs.microsoft.com/oldnewthing/20111010-00/?p=9433 https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime File access times aren't updated by default in recent versions of Windows. This commit is only necessary if updating of file access times is explicitly enabled: fsutil behavior set DisableLastAccess 0
* win32: revert special treatment of Unix-style absolute pathsRon Yorston2022-10-262-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Commit 605972390 (win32: handle Unix-style absolute paths for executables) added special treatment of paths for executables starting with a slash. Such paths are absolute on Unix but are relative to the current drive on Windows. On reflection this commit did more than necessary. Later commits provided special treatment only for paths starting with locations traditionally used to contain binaries on Unix. This is probably sufficient. Problems introduced by commit 605972390 include: - If the current drive isn't the system drive tab completion of a command starting with a slash confusingly references the system drive. - Building busybox-w32 with w64devkit fails on drives other than the system drive. Revert the changes introduced by commit 605972390. This saves 192 bytes. (GitHub issue #239)
* win32: fix warning in timegm(3)Ron Yorston2022-10-251-1/+0
| | | | | | | | | | | Building on Windows using w64devkit resulted in a new warning in timegm(3). The compiler didn't like a reference to the unnamed temporary in: if (!is_leap) is_leap = &(int){0}; is_leap is always non-NULL in the limited version of the code used here so the offending line can simply be removed.
* win32: revise creation of resourcesRon Yorston2022-10-252-3/+5
| | | | | | | | | | | As reported in https://github.com/skeeto/w64devkit/issues/35 there's a problem creating Windows resources using the native version of `windres`. Avoid passing arguments to `windres` that it can't handle by stringizing the version string locally in resource.rc. (GitHub issue #239)
* win32: use xmalloc_follow_symlinks() in stat(2)Ron Yorston2022-09-271-16/+9
| | | | | | | | Commit 31467ddfc (win32: changes to stat(2) implementation) followed symlinks manually. Unfortunately the implementation was incorrect. Use xmalloc_follow_symlinks() instead. Saves 32-48 bytes.
* make: new appletRon Yorston2022-08-013-0/+433
| | | | | | | | | This is an experimental implementation of make for busybox-w32, based on my public domain POSIX make: https://frippery.org/make/ (GitHub issue #44)
* Workaround for incomplete junctions created by PowerShellRon Yorston2022-06-251-12/+32
| | | | | | | | | | | | | Scoop uses PowerShell's New-Item to create junctions. However, these junctions lack a PrintName. This is a known issue which has caused problems even for Windows' File Explorer: https://github.com/PowerShell/PowerShell/issues/12923 Revert commit 32de287bb (win32: code shrink readlink(2)) to that readlink(2) uses SubstituteName instead. (GitHub issue #261)
* win32: bug fix in fnmatch(3)Ron Yorston2022-06-231-2/+5
| | | | | | | | | | | | | | | | | | | | | A user reports: Here is the shell script that causes me problems: var=foo:bar echo ${var#*[[:space:]]} What expect I to see echoed is foo:bar, however what I see bar. It seems that the [[:space:]] character class is matching the colon character in addition to whitespace characters. I see the same problem with the [[:blank:]] character class. This is due to a bug in the WIN32 implementation of fnmatch(3) which is derived from an old snapshot of glibc code (glibc commit 7814856974 from 1999-09-12). The bug was fixed in glibc by commit 83b1b6d8fa of 2000-07-04. Apply the equivalent fix to our version.
* win32: changes to stat(2) implementationFRP-4716-g31467ddfcRon Yorston2022-05-231-15/+22
| | | | | | | | | | | - Use repeated calls to readlink(2) rather than xmalloc_realpath() when asked to follow symlinks. - Drop the non-standard feature that caused readlink(2) to return only the target string length. This improves compatibility with BusyBox on Linux at a cost of 16-32 bytes.
* win32: code shrink fstat(2)Ron Yorston2022-05-231-11/+8
| | | | Reduce duplicated code. Saves 16-48 bytes.
* win32: let stat(2) return correct st_size for symlinkRon Yorston2022-05-221-5/+8
| | | | | | Previously stat(2) set st_size to the length of the canonicalised symlink target. Call readlink(2) to get the actual length of the target string.
* win32: code shrink readlink(2)Ron Yorston2022-05-221-32/+12
| | | | | | | Use PrintName rather than SubstituteName from the reparse data buffer. This avoids the need to normalise the name. Saves 240 bytes.
* win32: code shrink directory testsRon Yorston2022-05-221-15/+19
| | | | | | | | | | Add a function to check if a file is a directory and use it in various places. Replace some uses of S_ISDIR() with a test of the Windows file attributes. Saves 32-48 bytes.
* win32: return reparse tag in struct statRon Yorston2022-05-191-6/+14
| | | | | | | | If a file is a junction or symlink return its tag in the st_tag member of struct stat. get_symlink_data() and is_symlink() also return the tag or zero, as appropriate.
* jn: make junctions acceptable to WindowsRon Yorston2022-05-171-5/+9
| | | | | | | Junctions created by 'jn' contained incorrect data: the length of the target name was off-by-one. (GitHub issue #251)
* jn: new appletRon Yorston2022-05-161-1/+132
| | | | | | | | | | | | Add a Windows-specific applet to create a directory junction. Usage: jn DIR JUNC where DIR must be an existing directory on a local drive and JUNC must not currently exist. There isn't a simple WIN32 API to create directory junctions. The implementation of mklink in ReactOS provided useful inspiration.
* win32: try to get link count for directoriesRon Yorston2022-05-153-1/+36
| | | | | | | | | | | | | On Unix the link count of a directory reflects the number of subdirectories it contains. Enhance readdir(3) to return file types and use this to count subdirectories when stat(2) is called for a directory. As with other features that might slow down stat(2) this is controlled by the build-time setting FEATURE_EXTRA_FILE_DATA. (Commit d82db8e9a 'win32: make stat(2) fetch additional metadata'). (GitHub issue #254)
* win32: treat junctions as symlinksRon Yorston2022-05-141-6/+13
| | | | | | | | | | | | | | | | | Directory junctions were always followed to their target so they appeared to *be* directories. This resulted in counter-intuitive behaviour: - a directory junction could be removed with rmdir even though the directory wasn't empty; - 'rm -rf' on a directory junction deleted it but also deleted the contents of the linked directory. A better approximation is to treat directory junctions as symbolic links. (GitHub issue #254)
* ash: export certain variables to the environment immediatelyRon Yorston2022-05-082-2/+2
| | | | | | | | | | | The environment variables BB_OVERRIDE_APPLETS, BB_SKIP_ANSI_EMULATION and BB_SYSTEMROOT affect of the behaviour of the shell itself. Setting them as shell variables is insufficient for them to affect the current shell. When these three variables are exported from the shell they are now placed in the environment immediately. Conversely, when they're unset or unexported they're removed from the environment.
* win32: fix 'cd' to symlink with relative path as targetRon Yorston2022-05-071-1/+1
| | | | | | | | | | | | | Commit 69d328022 (win32: track current directory of mapped drives) replaced a call to xmalloc_realpath() with one to xmalloc_readlink(). This was incorrect. Although the argument is now guaranteed to be a symlink it's still necessary to resolve it to an absolute path. Otherwise the fix in commit 585d17d26 (win32: canonicalize path in chdir(2)) doesn't work for symlinks with a relative path as their target. (GitHub issue #147)
* win32: search PATH for missing Unix-style executablesRon Yorston2022-05-062-31/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 41ef232fc5 (win32: use built-in applets for non-existent binaries with Unix-style paths) alters what happens when trying to find an executable. If all of the following apply: - the pathname starts with one of the standard directories for Unix executables (/bin, /usr/bin, /sbin, /usr/sbin); - the file isn't found relative to the system root; - the basename matches an applet then the applet is run. Further extend the procedure so that if the first two conditions are met and either: - the PREFER_APPLETS and SH_STANDALONE features are enabled and the basename *doesn't* match an applet or - the PREFER_APPLETS and SH_STANDALONE features are disabled then PATH is searched for the basename. This affects: - how interpreters and binaries are spawned by mingw_spawn_interpreter() and mingw_spawnvp(); - how 'which' and the shell search for binaries. Special steps need to be taken in the shell to avoid treating shell built-ins and functions as applets. As a consequence of this change: - An executable that isn't an applet, say curl.exe, can be run as /usr/bin/curl so long as it's in a directory in PATH. It doesn't have to be in C:/usr/bin. - If the PREFER_APPLETS and SH_STANDALONE features are disabled binaries can be run using paths referring to standard Unix directories even if they're installed elsewhere in PATH.
* win32: better fix for empty environment variablesRon Yorston2022-05-052-9/+8
| | | | | | | | | | | | | | | | | | | It appears the CRT and OS each have a copy of the environment. mingw_putenv() fools the CRT into accepting an empty environment variable by calling _putenv("V=0") then truncating the new value by hand. But _putenv() also updates the OS environment with the fake 'V=0' value. Commit 5b48ca53b (win32: pass NULL to spawnve, not environ) resulted in this fake value being used and hence empty variables getting the value '0'. - Add a call to SetEnvironmentVariable() in mingw_putenv() to update the OS environment. - Restore the use of NULL environment pointers in mingw_spawnvp(). - Add a test. (GitHub issue #250)
* win32: revert changes related to environment variablesRon Yorston2022-05-042-12/+21
| | | | | | | | | | Revert the change to mingw_putenv() in the previous commit. When compiling for MSVCRT (i.e. not for UCRT) revert some of the changes from commit 5b48ca53b (win32: pass NULL to spawnve, not environ). (GitHub issue #250)
* win32: new code to set empty environment variableRon Yorston2022-05-031-12/+8
| | | | | | | | | | | | | | Windows environment variables: a never-ending source of fun. It seems the recent hack to work around problems in UCRT breaks the hack to set empty environment variables. The change to the empty variable isn't reflected in the environment seen by the C runtime. Use the WIN32 API to set the empty variable then set a dummy variable to make the C runtime take notice. (GitHub issue #250)