summaryrefslogtreecommitdiff
path: root/win32 (follow)
Commit message (Collapse)AuthorAgeFilesLines
* 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)
* which,ash: changes to which/command/typeRon Yorston2022-05-011-0/+21
| | | | | | | | | | | | | | | | | | | Change how 'which' detects if it was run from a standalone shell: the shell passes the undocumented '-s' option. This is stricter and more reliable than the previous method of checking the name of the binary. Add a function to determine the binary associated with a given applet name. This makes it possible for 'which' and 'command -v' to list the correct binary even for applets other than 'busybox'. For example, when the binary is called 'sh.exe' 'which sh' will report its path. In standalone shell mode 'command -V' and 'type' now report "xxx is a builtin applet" rather than "xxx is xxx", which is true but not very illuminating. (GitHub issue #248)
* win32: clarify documentation of is_relative_path()Ron Yorston2022-04-301-3/+8
|
* win32: conditional compilation in process.cRon Yorston2022-04-241-10/+10
| | | | | | | Drop the use of ENABLE_FEATURE_SH_STANDALONE in process.c In mingw_spawn_interpreter() check for an applet *before* trying to run the interpreter using the path provided.
* win32: proper conditional compilation in popen.cRon Yorston2022-04-231-9/+14
| | | | | | | | | | | In mingw_fork_compressor() the code to prefer applets over external programs should be conditionally compiled based on the setting of ENABLE_FEATURE_PREFER_APPLETS. In mingw_popen() there's no need to use ENABLE_FEATURE_SH_STANDALONE for the same purpose. ENABLE_FEATURE_PREFER_APPLETS is sufficient. Save a few bytes by sharing a format string in mingw_fork_compressor().
* date: enable FEATURE_DATE_NANORon Yorston2022-04-222-0/+13
| | | | | | | | | Provide a WIN32 implementation of clock_gettime(2), though only with support for CLOCK_REALTIME. This makes it possible to enable FEATURE_DATE_NANO which adds support for the %N date format. MinGW-w64 has clock_gettime(2) but it's in the winpthreads library and we don't want to bother with that.
* win32: minor adjustments to file permissionsRon Yorston2022-04-191-8/+9
| | | | | | | | | | | | | Mask the file permission bits in mingw_umask(), not when it's called from run_applet_no_and_exit(). Rather than hardcode write permissions for group and other in file_attr_to_st_mode() and mingw_fstat() make them respect the current umask setting. In mingw_fstat() there's no need to check the mode using S_ISDIR(): the hardcoded mode doesn't set S_IFDIR. The compiler had already figured this out so there's no reduction in bloat.
* win32: fake file ownership on FAT filesystemsRon Yorston2022-02-171-5/+11
| | | | | | | | | | | | | busybox-w32 tries to display the ownership of files by comparing the security identifier (SID) of the current user with that of the file on disk. For filesystems that don't support SIDs this resulted in files being listed as owned by root. It appears that filesystems without support for file ownership return a null SID. In such cases pretend the file belongs to the current user. GitHub issue #241.
* Increment date in resourcesRon Yorston2022-02-141-1/+1
|
* winansi: detect if running under WineRon Yorston2021-12-221-2/+11
| | | | | | | | | | | | | | Detect if running under Wine by checking for the wine_get_version function in ntdll.dll. This is how the Wine Developer FAQ suggests doing it. If running under Wine and not otherwise configured: - use ANSI emulation; - don't use alternate screen buffer in vi/less. Explicit settings of BB_SKIP_ANSI_EMULATION and BB_ALT_BUFFER will override the Wine defaults.
* win32: fix implementation of readlink(2)Ron Yorston2021-11-251-3/+2
| | | | | | | | | | | | Commit 35e32c2a71 (readlink(): do `NUL`-terminate the result) changed how our implementation of readlink(2) handles the case where the link is too long for the buffer. This broke xmalloc_readlink() which expects readlink(2) to behave as documented. As a results symbolic links with 80 or more characters didn't work properly. Revert the commit. (GitHub issue #237)
* win32: add link to LWN article on shebangRon Yorston2021-11-141-1/+2
|
* win32: rename mingw_spawn_1Ron Yorston2021-11-011-8/+8
| | | | | | | | | | The name of the function mingw_spawn_1() wasn't particularly meaningful. Remove its envp argument (as all of its current callers pass a NULL pointer) and rename it mingw_spawnvp() to better reflect what it does. The path search it performs isn't the standard one: it has features specific to busybox-w32.
* win32: pass NULL to spawnve, not environRon Yorston2021-10-281-4/+4
| | | | | | | | | | | | Building busybox-w32 for use with UCRT results in mysterious failures. (GitHub issue #234) These are somehow related to the environment values passed to spawnve. In several places the global environ pointer was being passed to spawnve so the child would inherit its environment from the parent. This can also be achieved by passing a NULL pointer. This prevents the failures in at least some cases and also makes the binary smaller.
* win32: rmdir(2) shouldn't delete symlinksFRP-4487-gd239d2d52Ron Yorston2021-10-171-1/+8
| | | | | | | | On Linux rmdir(2) refuses to delete a symlink to a directory on the obvious grounds that a symlink isn't a directory. Windows' rmdir() is less discriminating. Make our implementation of rmdir(2) behave more like Linux.
* win32: code shrinkRon Yorston2021-10-161-9/+16
| | | | | | | | | There are a few places in mingw.c where we want to determine if a file is a symbolic link. Previously these called mingw_lstat() which collects far more information than is actually needed. Create a new is_symlink() function which does the minimum work necessary.
* realpath: improved support for Windows pathsRon Yorston2021-10-131-3/+2
| | | | | | | | | | | | | | | | Upstream commit 94eb1c4dc (libbb: better coreutils compatibility for realpath) made some changes to xmalloc_realpath_coreutils(). This now needs to be updated to handle Windows paths. - Expose the macro is_unc_path() and part of the recent change to bb_get_last_path_component_nostrip() as a separate funtion, get_last_slash(); - Convert a couple of errors relating to network filesystems to ENOENT; - Adjust xmalloc_realpath_coreutils() to handle Windows directory separators, relative paths and UNC paths.
* win32: fix creation of relative symlinksRon Yorston2021-10-121-2/+5
| | | | | | | | Symlinks containing '.' or '..' (such as '../target', './target' or 'dir/./target') were successfully created but couldn't be accessed. It turns out Windows requires paths of that form to use backslashes rather than forward slashes.
* win32: rename is_absolute_path()Ron Yorston2021-10-121-8/+8
| | | | | As the comment pointed out is_absolute_path() was misnamed. Rename it to is_relative_path() and change the sense of all tests.
* win32: use is_dir_sep() everywhereRon Yorston2021-10-121-4/+3
| | | | | The is_dir_sep() macro, which has been around since the start of busybox-w32, can be used instead of is_path_sep().
* ash: improve signal handlingRon Yorston2021-09-211-0/+9
| | | | | | | | | | | | Allow waitpid() to detect SIGTERM/SIGKILL by checking the (Windows) status returned by GetExitCodeProcess() and updating the Unix status to suit. This allows ash to detect when a process has been 'signalled'. Provide our own implementation of strsignal(3) which returns expanded text for SIGTERM/SIGKILL. Costs 192 bytes.
* win32: limited version of timegm(3)Ron Yorston2021-09-181-84/+13
| | | | | | | | | | | | | timegm(3) from musl checks that the calculated time_t value can be broken out into a struct tm without overflow. The limiting factor is that tm_year is an int. Our only use of timegm(3) is followed by a call to localtime(3). The Microsoft version of this only works for time_t values between 0 and INT_MAX (32-bit) or 0 and 32535215999 (64-bit). Enforce these limits in timegm(3), thus avoiding the use of musl's __secs_to_tm() and saving 624 bytes.
* win32: don't affect POSIX buildRon Yorston2021-09-171-1/+1
|
* win32: changes to allow timezones in datesRon Yorston2021-09-173-5/+238
| | | | | | | | | | | | | | Create mingw_strptime() to return timezone offset as a separate argument (since Microsoft's struct tm doesn't have the required member). Import timegm() from musl. Update parse_datestr() to use mingw_strptime(). Enable FEATURE_TIMEZONE in the default configuration. GitHub issue #230.
* win32: use inet_pton() from muslRon Yorston2021-09-031-183/+75
| | | | Saves 88 bytes.
* win32: fix entropy collection for isaacRon Yorston2021-09-021-20/+10
| | | | | | | | | The condition to detect the end of the environment string was wrong. Don't bother calculating the MD5SUM of the environment, just XOR the bytes into the data. This reduces bloat by 320 bytes but only in the non-default case.
* win32: code shrinkRon Yorston2021-08-271-0/+2
| | | | | | | | Turn off the 'if-conversion' optimisation for err_win_to_posix(). My tests actually have this being slightly faster than with the optimisation enabled, though within the variation of the measurement. Saves 288 bytes.
* win32: code shrink uname(2)Ron Yorston2021-08-161-8/+4
| | | | | | | If GetVersionEx() fails just assume the OS version numbers remain set to zero and print them as-is. Saves 48 bytes.
* win32: implement utimes(2) using utimensat(2)Ron Yorston2021-08-151-38/+18
| | | | Saves 176 bytes.
* win32: tidy up fetching of system directoryRon Yorston2021-08-141-14/+17
| | | | | | | | | | | | Add a new function, getsysdir(), to fetch and cache the system directory. This avoids the non-intuitive use of getpwuid() in get_system_drive(). The call to GetSystemDirectory() in get_proc_addr() can't be replaced because getsysdir() calls realpath() which requires a call to get_proc_addr(). No change in the size of the binary.
* win32: code shrinkRon Yorston2021-08-141-14/+14
| | | | | | | | | There doesn't seem to be any need to call OpenThreadToken() in file_owner(): OpenProcessToken() should suffice. Also, tidy up gethomedir() without any change in functionality. Saves 56 bytes.
* win32: treat devices as character special filesRon Yorston2021-08-131-1/+3
| | | | | | | | | | | | | Commit 15fcbd19c (win32: special case for devices files in stat(2)) added special treatment in stat(2) for device files. As a result of this change device files appeared to be regular files which broke the use of /dev/null with noclobber in the shell. Device files now appear as character special files (as they do on Unix). GitHub issue #225.
* win32: better handling of nested symlinksRon Yorston2021-08-121-0/+8
| | | | | | | | | | | | | | Our realpath(3) implementation uses xmalloc_follow_symlinks() to expand symlinks. This detects when symlinks are too deeply nested but didn't set errno, so anything calling realpath(3) was unable to say what had gone wrong. (For example, 'ls -L' or 'stat -L'.) Set errno to ELOOP. This then leads to the problem that Windows doesn't know about ELOOP so reports 'Unknown error'. Add a replacement for strerror(3) which returns a sensible message. Costs 96 bytes.
* win32: code shrink character class detectionRon Yorston2021-08-095-18/+83
| | | | | | | Add a routine to detect the names of character classes. Use it in fnmatch(3) and regcomp(3), replacing local code in the former. Saves 216 bytes.
* win32: fix fnmatch(3) handling of xdigitRon Yorston2021-08-091-1/+1
| | | | | | | | | | | | | | | | The glob pattern '[[:xdigit::]]*' didn't return the matches expected. It turns out the implementation (from glibc) fails to detect 'xdigit' as a valid character class. Changing the definition of CHAR_CLASS_MAX_LENGTH to 7 fixes the problem. This was never an issue in glibc because it uses a different definition. More modern versions of fnmatch(3) in glibc and gnulib also make CHAR_CLASS_MAX_LENGTH long enough. The code for fnmatch(3) was taken from glibc at commit 7814856974388a856a575fa45f88d502c8a1ab29. This was the last version before the code was rearraged to better support multibyte characters.