aboutsummaryrefslogtreecommitdiff
path: root/include/mingw.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* win32: export xappendword()Ron Yorston2023-04-231-0/+1
| | | | | | | Export the function xappendword() from make. Use it in drop and watch. Saves 8-80 bytes, an unusually large disparity.
* win32: case-sensitivity in tab completionRon Yorston2023-04-191-1/+0
| | | | | | | | | | | | | | | | | | The tab-completion code treated all matches as case-insensitive because that's how Microsoft Windows handles filenames. This is now inadequate, as shell builtins, functions and aliases are case sensitive. Modify the treatment of case-sensitivity in tab completion: - Track whether each potential match is case-insensitive (filename) or case-sensitive (shell builtin, function or alias). - When comparing matches use a case-insensitive comparison if either value is a filename. Otherwise use a case-sensitive comparison. Adds 64 bytes.
* win32: add fake HUP and QUIT signalsRon Yorston2023-04-031-0/+2
| | | | | | | | | | | It's fairly common for shell scripts to trap this set of signals: EXIT HUP INT QUIT TERM (or the numeric equivalent: 0 1 2 3 15) Add definitions for SIGHUP and SIGQUIT. We don't take any action if traps are defined for them, but at least scripts won't fail. (GitHub issue #303)
* win32: delay adjusting code pageRon Yorston2023-03-171-1/+0
| | | | | | | | | | | Commit 93a63809f9 (win32: add support for the euro currency symbol) caused all invocations of busybox-w32 to change code page 850 to 858. This has been known to cause problems with fonts in PowerShell (GitHub issue #207). Delay changing the code page until an i/o operation is imminent. Instances of PowerShell started by the `drop` applet during ssh login thus no longer have their code page adjusted.
* runuser: add 'drop' as an alias for runuserRon Yorston2023-03-161-0/+1
| | | | | | | | | | | | | | | | | | | The 'drop' alias for 'runuser' relaxes a number of constraints that were introduced for compatibility: - It works even if the current process doesn't have elevated privileges. - It isn't necessary to specify the name of the user. - Any command can be invoked, not just the BusyBox shell. - If the command doesn't specify a path 'drop' will first look for a BusyBox applet then search PATH. Adds 320-336 when built along with runuser. (GitHub issue #240)
* win32: code shrink detection of executablesRon Yorston2023-03-161-1/+2
| | | | | | | | | | | | Add a function, file_is_win32_exe(), to detect if a path refers to an executable. It tries adding extensions if necessary. Use this in a number of places to replace common code of the form path = alloc_ext_space(cmd); if (add_win32_extension(path) || file_is_executable(path)) Saves 32-48 bytes.
* runuser: new appletRon Yorston2023-03-131-0/+2
| | | | | | | | | | | | | | | | | | | | | Add a cut down, Windows-specific implementation of `runuser` from util-linux. This allows elevated privileges to be dropped when running in an SSH session. It also works when using `su` or starting busybox-w32 'as administrator'. There are complications: - The method used to drop privileges leaves the access token in the TokenIsElevated state. Detecting this is likely to be fragile. - The unprivileged shell is started by CreateProcessAsUserA(). In older versions of Windows this has to be loaded dynamically. Adds about 900 bytes. (GitHub issue #240)
* win32: changes to console mode handlingRon Yorston2023-03-051-1/+4
| | | | | | | | | | | | | | | | | | | 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: only count subdirectories if necessaryRon Yorston2023-01-231-0/+1
| | | | | | | | | | | | | | | | | 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: revised implementation of setlinebuf(3)Ron Yorston2022-12-311-1/+1
| | | | | | | | | Microsoft Windows' setvbuf() doesn't support line buffering and doesn't accept 0 as a valid value for the buffer size argument. Replace the old macro definition with an implementation that doesn't do anything. It's only used if debug is enabled in ash so there's no effect on the default build.
* win32: remove declaration of vfork(2)Ron Yorston2022-10-311-1/+0
| | | | | | | Since vfork(2) is never used in busybox-w32 there's no need to declare it. Doing so provokes clang to issue a warning. (GitHub issue #239)
* win32: revert special treatment of Unix-style absolute pathsRon Yorston2022-10-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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: return reparse tag in struct statRon Yorston2022-05-191-0/+1
| | | | | | | | 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: new appletRon Yorston2022-05-161-0/+1
| | | | | | | | | | | | 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.
* which,ash: changes to which/command/typeRon Yorston2022-05-011-0/+1
| | | | | | | | | | | | | | | | | | | 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)
* date: enable FEATURE_DATE_NANORon Yorston2022-04-221-0/+1
| | | | | | | | | 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.
* realpath: improved support for Windows pathsRon Yorston2021-10-131-0/+3
| | | | | | | | | | | | | | | | 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: rename is_absolute_path()Ron Yorston2021-10-121-1/+1
| | | | | As the comment pointed out is_absolute_path() was misnamed. Rename it to is_relative_path() and change the sense of all tests.
* ash: improve signal handlingRon Yorston2021-09-211-0/+1
| | | | | | | | | | | | 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: changes to allow timezones in datesRon Yorston2021-09-171-0/+3
| | | | | | | | | | | | | | 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: better handling of nested symlinksRon Yorston2021-08-121-0/+3
| | | | | | | | | | | | | | 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: partial implementation of sync(2)Ron Yorston2021-06-071-1/+2
| | | | | | | | | | Provide a partial implementation of sync(2), so sync(1) can actually do something in some circumstances: - Only logical drives are handled. - Flushing buffers requires administrative privileges. If run as a normal user nothing will happen.
* sync: enable in default configurationRon Yorston2021-06-071-1/+1
| | | | | Enable the sync applet by default. It doesn't actually do anything useful but at least it prevents some scripts from failing.
* win32: rename update_dev_fd() as update_special_fd()Ron Yorston2021-06-071-1/+1
| | | | Avoid confusion between special devices and /dev/fd.
* win32: implement futimens(2)/utimensat(2)Ron Yorston2021-05-141-0/+10
| | | | | The touch applet has been changed to use futimens(2)/utimensat(2). Provide implementations of these for WIN32.
* win32: move is_absolute_path()Ron Yorston2021-03-011-0/+1
| | | | | Make is_absolute_path() a function rather than a macro and move it from ash.c into mingw.c.
* win32: update sysinfo(2) implementationRon Yorston2021-02-191-2/+0
| | | | | | | | | | 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.
* free: implement sysinfo(2) and enable free(1)Ron Yorston2021-02-181-0/+22
| | | | | | | | | | | | | 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.
* ash: code shrinkRon Yorston2021-02-141-1/+0
| | | | | Since there's only one call to mingw_spawn_forkshell() we might as well just call spawnve() directly from ash.
* win32: implement symlink(2)Ron Yorston2021-02-121-1/+1
| | | | | | | | | | | | | | | | | | | | | 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: make readlink(2) implementation unconditionalRon Yorston2021-02-121-4/+0
| | | | | | | 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.
* win32: code shrinkRon Yorston2021-02-061-4/+0
| | | | | Don't compile some code that isn't currently supported for WIN32. Saves 24 bytes.
* tls: avoid unnecessary changes to POSIX build, part 2Ron Yorston2021-01-251-0/+4
| | | | | | | | | | | | | | On reflection, the previous commit may have been ill-advised. There are many calls to open_read_close() and most shouldn't be able to access special devices. (Though in practice only a few are enabled in busybox-w32.) Nonetheless, I've implemented a new mechanism which uses the macro MINGW_SPECIAL() to mark calls to functions that are allowed to access special devices. An unrelated change is to avoid compiling fputs_stdout() in coreutils/printf.c for the POSIX build.
* Merge branch 'busybox' into mergeRon Yorston2021-01-141-0/+1
|
* winansi: intercept calls to fputc(3)Ron Yorston2020-12-071-0/+2
| | | | | | | | | | | | | Perform code page translation for fputc(3). It's only used in a few places but is needed to fix things like: $ echo € | dos2unix Ç $ paste -d € file1 file2 1Ç2 Unfortunately it breaks the inventive use of dos2unix in GitHub issue #203.
* ash, ls: improve support for 'c:path'Ron Yorston2020-08-281-6/+0
| | | | | | | | | | Revert commit 249f68e3c (win32: append '/' to bare drive name in opendir). Instead add better handling for paths of the form 'c:path' to ls and expmeta() in ash. Adds 64 bytes.
* win32: code shrink Unix-style path handlingRon Yorston2020-08-231-9/+1
| | | | | | | | Replace auto_add_system_drive() with alloc_system_drive() which leaves space for a possible filename extension. This makes it possible to drop alloc_win32_extension() and auto_win32_extension(). Saves 144 bytes.
* win32: use built-in applets for non-existent binaries with Unix-style pathsRon Yorston2020-08-131-0/+1
| | | | | | | | | | | | | | | | | | | | Shell scripts moved from Unix may contain hard-coded paths to binaries such as /bin/sh. A recent commit made it possible to execute such binaries reliably, but that does require them to be installed. As an alternative solution: if a binary with a standard Unix path prefix can't be found but is available as a built-in applet, run the applet. Add the function unix_path() to detect paths starting with /bin, /usr/bin, /sbin or /usr/sbin. Use this function in: - the 'which' applet - shellexec(), describe_command() and find_command() in ash - mingw_spawn_1() See GitHub issue #195.
* win32: handle Unix-style absolute paths for executablesRon Yorston2020-08-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | As noted in commit 548ec7045 (win32: interpret absolute paths as relative to %SYSTEMDRIVE%) a path starting with a '/' in the Unix world is treated as relative to the current drive by Windows. To avoid ambiguity that commit considered certain such paths to be relative to %SYSTEMDRIVE%. Extend this to paths representing executables. Add the functions need_system_drive() and auto_add_system_drive() to detect the need for a system drive prefix and to add it if necessary. Use these functions in: - the 'which' applet - the find_executable() function - tab-completion code - PATH look-up, shellexec(), describe_command() and find_command() in ash - parse_interpreter() and mingw_spawn_1() With these changes executable paths starting with a slash are handled consistently, whatever the current drive.
* win32: use a static buffer in get_system_drive()Ron Yorston2020-08-131-1/+1
| | | | | | | Allocate static storage for the system drive string instead of making a new allocation on every call. This is easier to manage. Adds 16 bytes.
* win32: code shrinkRon Yorston2020-08-131-1/+1
| | | | | | | | | | Add a new function, has_path(), to detect that an executable name doesn't require a path look-up. Also, since is_absolute_path() is now only used in shell/ash.c move its definition there from include/mingw.h. Saves 128 bytes.
* win32: move code to fork (de)compressor to a functionRon Yorston2020-08-051-0/+1
| | | | | | | | Use a new common function, mingw_fork_compressor(), to implement fork_transformer() in open_transformer.c and vfork_compressor() in tar.c. Saves 160 bytes.
* win32: code shrink kill(2)Ron Yorston2020-07-251-1/+1
| | | | | | | | - Drop exit_code argument from kill_SIGTERM_by_handle() - Pass signal number rather than exit code to other functions - Merge kill_SIGKILL() and kill_SIGTEST() Saves 112 bytes.
* win32: import strndup from gnulibRon Yorston2020-07-091-0/+5
|
* win32: return raw file attributes in struct mingw_statRon Yorston2020-07-091-0/+1
| | | | | | Until now the emulated stat(2) system calls have only returned a synthesised Unix-style mode value. Also return the raw Windows file attributes.
* win32: fix networking problemsRon Yorston2020-06-031-0/+1
| | | | | | | | | The subprocess that handles incoming connections for httpd didn't work. It has an accepted connection on stdin and calls getpeername() to obtain its details, but getpeername() didn't initialise networking. ssl_client only seems to deal with file descriptors. Expose init_winsock() again and call it from ssl_client.
* win32: only initialise networking if necessaryRon Yorston2020-06-011-1/+7
| | | | | | A call to initialise networking is made during start up even if the applet doesn't need it. Instead, only initialise networking when a call is made to a function that definitely requires it.
* ash: simplify spawning during forkshellRon Yorston2020-06-011-0/+1
| | | | | | | | | | | | | spawn_forkshell() uses mingw_spawn_proc() to start the child shell. mingw_spawn_proc() then calls mingw_spawn_1() which determines that "sh" is an applet, thus calling mingw_spawn_applet() which finally calls spawnveq(). Not only is this convoluted it also won't work if PREFER_APPLETS and SH_STANDALONE aren't enabled. Simplify matters by adding a new function, mingw_spawn_forkshell(), which is tailored for just this case.
* dd: fix handling of 'conv=notrunc seek=N'Ron Yorston2020-05-201-1/+1
| | | | | | | | | | | | | | | | | | Commit e6680912a (dd: create a sparse file when seek=N is used) broke the use of 'conv=notrunc seek=N' to modify existing files. Rename seek_sparse() to make_sparse() and: - add an argument to specify the start of the sparse region; - call make_sparse() before ftruncate(); - call make_sparse() only if: * we can determine the size of the file; * the file is not open in append mode; * the file is being extended. This should fix GitHub issue #186.
* ash: reset ANSI emulation when BB_SKIP_ANSI_EMULATION changesRon Yorston2020-04-131-0/+1
| | | | | Update the skip status on the first call to skip_ansi_emulation() and whenever the BB_SKIP_ANSI_EMULATION variable changes.