aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* | win32: adjust handling of executable extensionsRon Yorston2024-04-222-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Mixing Windows and Unix-style filename extensions was causing problems. Tweak how extensions are handled to try and improve matters: - Consistently check whether the unaltered filename is an executable before trying adding extensions. - Check .exe and .com before .sh. Saves up to 16 bytes. (GitHub issue #405)
* | make: allow mixed macros and targets on command lineRon Yorston2024-04-212-8/+41
| | | | | | | | | | | | | | | | | | | | | | | | POSIX requires macro definitions to appear before targets on the command line. Allow mixed macros and targets as an extension. All macros on the command line are read first, then the targets are processed. Costs 64-80 bytes. (GitHub issue #406)
* | make: change how macros are read from the environmentRon Yorston2024-04-211-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally there was no validation of macro names imported from the environment. However, process_macros() failed to account for the additional flag bit at this level. Thus, for example, SHELL was imported when it shouldn't have been. The problem the lack of validation was supposed to address was that of environment variables with invalid names, which the user may not have control over, causing a fatal error. As an alternative, silently ignore variables with invalid names on import from the environment.
* | make: skip shell -e option when running commandsRon Yorston2024-04-202-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | POSIX says, regarding execution of commands: The execution line shall then be executed by a shell as if it were passed as the argument to the system() interface, except that if errors are not being ignored then the shell -e option shall also be in effect. As a non-POSIX extension, skip the use of the -e option. This is how GNU make and BSD make behave. (GitHub issue #409)
* | win32: make stat(2) fail for /dev/zero, /dev/urandomRon Yorston2024-04-201-1/+2
| | | | | | | | | | | | | | | | | | | | /dev/zero and /dev/urandom are only available internally and as arguments to 'dd'. Since users can't otherwise access them they shouldn't be treated as existing by stat(2). With this change stat(1) and test(1) will deny their existence. (GitHub issue #282)
* | yes: code shrinkRon Yorston2024-04-181-5/+0
| | | | | | | | | | | | | | | | | | Now that putchar() is implemented using winansi_fputc() it isn't necessary to perform an explicit substitution in 'yes'. This was previously done so 'yes' could check for a broken pipe. Saves 16-32 bytes.
* | free: bloat reductionRon Yorston2024-04-181-1/+1
| | | | | | | | | | | | | | Allow the compiler to inline parse_meminfo() so it can spot some optimisations. Saves 208-240 bytes.
* | ash: move setting of current directoryRon Yorston2024-04-091-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The undocumented '-d' shell option is used to set the current directory in shells started by the 'su' applet of busybox-w32. In this case, the shell isn't a login shell. If a login shell sets the current working directory in /etc/profile it's possible the user may wish to override this with '-d'. This didn't work, though, because the directory is changed before /etc/profile is processed. Move the changing of the directory to that specified by '-d' so it happens after the processing of /etc/profile and ~/.profile. This won't affect the intended use of '-d'. (GitHub issue #403)
* | time: code shrinkRon Yorston2024-04-091-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | Commit 54dbf0fa5 (time: mitigation for interleaved output) added buffering to stderr in the 'time' applet. @avih pointed out that it isn't necessary to provide an explicit buffer. Saves 16 bytes in the 64-bit build. (GitHub issue #396)
* | ash: add title built-inRon Yorston2024-04-093-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement a 'title' built-in for ash. It's very simple-minded, performs almost no error checking and is completely non-portable. - With no arguments it prints the current console title. - If arguments are provided the *first only* is set as the console title. Costs 88-116 bytes. (GitHub issue #401)
* | timeout: fix handling of timeoutsRon Yorston2024-04-081-12/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'timeout' applet, by default, accepted fractional seconds but ignored the fraction. Moreover, in busybox-w32, even the integer part was incorrectly handled. Rewrite the (Windows) code to fix both problems. A patch has also been submitted to fix upstream. If that is accepted the Windows port will need to be updated to match. Saves 8-16 bytes. (GitHub issue #400)
* | win32: ascii-optimize winansi_fputc, winansi_putcharAvi Halachmi (:avih)2024-04-061-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Other winansi IO wrappers, like winansi_fputs, optimize by calling the libc API directly if no special handling is needed, e.g. if the input is fully ASCII and without escape sequences - without converting the output codepage or interpreting escapes. Now the fputc and putchar wrappers do that as well. And as a simplification, putchar is now also a wrapper of fputc. Other than possibly minor speedup, this can also help buffered streams remain buffered, because the codepage conversion using writeCon_utf8 is unbuffered and first flushes the stream, so by avoiding the conversion and calling the libc API directly, we also avoid premature flush of a buffered stream. This did happen, as "time" is buffered since commit 54dbf0fa5, so previously it was flushed early when using putchar, while now it remains buffered by default (but can still be flushed early if the -f format string contains non-ASCII chars).
* | win32: UTF8_OUTPUT: flush stream before conversionAvi Halachmi (:avih)2024-04-061-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | writeCon_utf8 is unbuffered - it writes directly using WriteConsoleW, but some winansi libc IO wrappers, like fputs, use the libc API directly if the content doesn't need any special handling (e.g. all ASCII and no escape sequences), and so if the stream is buffered, and if only some parts of it go through writeCon_utf8, then we can get wrong output order due to some parts being buffered and some not. Case in point, the recent commit 54dbf0fa5 made the output of "time" buffered, and so if only parts of it go through writeCon_utf8, then we get bad output order. This did actually happen, because not all the winasi wrappers have this ASCII-only optimization (e.g. winansi_putchar), and "time" did end up with wrong output order. Even if all the winansi wrappers were ASCII-optimized, "time" could still have unicode output, e.g. with -f. Fix it by flushing the stream before converting using writeCon_utf8.
* | time: mitigation for interleaved outputRon Yorston2024-04-061-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the 'time' applet is run in a pipeline, like so: time seq 1 10 | tail -2 stdout from 'tail' and stderr from 'time' can be interleaved. This is particularly the case with the ConEmu terminal emulator. The interleaving can be reduced, though not eliminated, by buffering the output of 'time'. Adds 40-44 bytes. (GitHub issue #396)
* | md5/shaXsum: accept uppercase hex stringsRon Yorston2024-04-031-0/+4
| | | | | | | | | | | | | | | | | | The coreutils versions of md5sum and the like accept uppercase hex strings from checksum files specified with the '-c' option. Use a case-insensitive comparison so BusyBox does the same. (GitHub issue #394)
* | win32: unicode: new wcwidth: allow enabling bidiAvi Halachmi (:avih)2024-04-021-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | interval, in_interval_table, and in_uint16_table were previously not compiled when using the new wcwidth (commit c188a345a) because they're used by the old wcwidth but not by the new one. But they're also used by the BIDI routines. mingw64u_defconfig doesn't enable bidi (rightly - it's not working well), but it'd still be nice to allow enabling bidi while the new wcwidth is in effect. Enable the tables lookup code if BIDI is enabled.
* | Revert "unicode: identify emoji width and modifiers"Avi Halachmi (:avih)2024-03-291-8/+0
| | | | | | | | | | | | | | This reverts commit 878b3cd27fe83f2b0ff476b884c34d165be0072c. It's no longer required, since the last commit uses a new wcwidth implementation which covers the cases added by commit 878b3cd2 .
* | win32: unicode: use newer wcwidth by defaultAvi Halachmi (:avih)2024-03-294-0/+683
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a new wcwidth implementation at libbb/wcwidth_alt.c, and uses it instead of the existing implementation when compiling for windows and CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000 - which is the case with the unicode configs/mingw64u_defconfig. The windows-target condition keeps non-windows build unmodified, and the last supported wchar threshold is a semi-hack to allow switching between implementations without adding a new config option (the old code supports codepoints up to 0x2ffff). The new file wcwidth_alt.c was generated by a new scripts/mkwcwidth, which prints a wcwidth implementation using latest unicode data from a local clone of https://github.com/jquast/wcwidth . This repo is the main python wcwidth implementation, and is maintained and up to date. Functional differences from the existing implementation: - Unicode 15.1.0 (latest) with the new version (about 450 ranges of wide and zero-width codepoints), compared to roughly Unicode 5.0 of the existing code (nearly 20 years old spec, about 150 ranges). The new spec includes, among others, various wide icons and emojis, which can now be edited correctly at the shell prompt, have correct alignment in 'ls', etc. - The old implementation returns -1 (non-printable) for surrogates, while the new code returns 1, though this is inconsequential, and POSIX doesn't care. Also libc implementations vary in this regard. Technical differences: - The old version compiles less code/data when the last supported wchar is smaller, while the new version doesn't. This doesn't matter because the new version is enabled only for the full range. - The new version is smaller and relatively straight forward, and fully automated (generated), so updates to newer spec is trivial. The old version mixes data, ad-hoc code (tailored to the data), and preprocessor checks, and is hard to automate updates. The old version has various forms of 32 and 16 bit data ranges, in several arrays, while the new version uses single data array with unified form of 32 bits per range, with two rules: - A data range can't span Unicode planes (enforced, but unlikely required, and if yes, code to split ranges would be simple). - A range can't hold more than 32768 codepoints, so bigger ranges are split automatically (currently there are 2 such ranges). Performance wise, the new version should be faster, even with three times the data ranges. Both versions do effectively at most one binary search in one Unicode plane data, but the new version finds both zero-width and wide-width results in this one search, while the old version only finds zero-width, and to detect wide-width it does an additional linear series of manual range tests, but since most results are width 1, this sequence is performed in most (non-ASCII) calls. In a cursory comparison of the new wcwidth with glibc and musl-libc (both use O(1) lookup tables), with few bodies of text, we're in the same ballpark, with typical speed of 60% or better. Bloat-wise, the new version is about 180 bytes code and 1800 bytes data. If it had similar number of data ranges as the old code (150), the new version would be about 200 bytes smaller, but because the new version has 450 data ranges, it's about 1K bigger.
* | ash: strip path from NOFORK applet namesRon Yorston2024-03-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 26ba73098 (win32: search PATH for missing Unix-style executables) extended the cases in which PATH would be searched for executables specified with a Unix-style path. A side effect of this change was to pass the Unix-style path as argv[0] to NOFORK applets. The 'uname' applet examines argv[0] to determine how to behave. When invoked as '/bin/uname' it returned unexpected results. Other applets may be similarly affected. When a NOFORK applet is invoked in evalcommand(), strip any path. Costs 16 bytes. (GitHub issue #392)
* | make: allow '#' to be escaped with a backslashRon Yorston2024-03-112-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | POSIX doesn't allow the '#' comment marker to be escaped, though some implementations do. As a non-POSIX extension allow '#' to be escaped with a preceding backslash. It isn't necessary to escape '#' in macro expansions or command lines: these cases are covered by an existing extension. Commit 0aceca867 (make: comments in macro expansions and command lines) Adds 16-32 bytes. (pdpmake GitHub issue 38)
* | win32: improvements to realpath(3)Ron Yorston2024-03-091-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous commit unnecessarily duplicated the path returned from resolve_symlinks(), resulting in a memory leak. Thanks to avih for spotting this. Even if we can't canonicalise the path in resolve_symlinks() we can at least return the result of resolving the trailing symlink. Moreover, this can be done both when the necessary API is missing and when the filesystem doesn't support it. Not perfect, but better than nothing, and there's no cost. This change gets rid of a handful of realpath-related test failures on ReactOS and Windows XP. Some background: Commit 8ebe81483 returned the raw path when the required API was missing. This was reverted in commit f902184fa because it caused an infinite loop (GitHub issue #204). Commit 31467ddfc fixed the cause of the loop, which is why it's now safe to reintroduce a fallback return. (GitHub commit #389)
* | win32: let realpath(3) work on flaky filesystemsRon Yorston2024-03-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | Some filesystems don't support the feature required to resolve symlinks for realpath(3). In such cases just carry on without resolving symlinks. This is a trade-off between correctness and convenience. Adds 16 bytes. (GitHub issue #389)
* | su: free all allocated memoryRon Yorston2024-03-081-14/+18
| | | | | | | | | | | | Ensure memory is freed even on early exit. Saves 0-16 bytes.
* | su: handle restricted disk driversRon Yorston2024-03-071-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Certain tools which allow disk image files and RAM disks to be mounted were found to lack a feature used to implement realpath(3). This resulted in a segfault in the 'su' applet when it was run in such a virtual filesystem. 'su' uses realpath(3) to canonicalise the current directory. This is only really required to handle network shares mapped to a drive letter. (GitHub issue #148) - If the call to realpath(3) fails for some reason fall back to using the current directory determined by calling getcwd(3). - If getcwd(3) fails simply don't pass any directory to the shell being started by 'su'. Also, ensure all allocated memory is freed, if required. (GitHub issue #389) Adds 16-32 bytes.
* | ash: fix 'read' built-in performance regressionRon Yorston2024-03-061-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Commits 8e6991733 and b2901ce8e fixed problems with the 'read' shell built-in when the '-t' option was used. However, they result in a performance penalty. This pipeline: seq -w 0 999999 | while read line; do :; done takes 10 times longer than prior to the changes. If no timeout is specified don't call poll(2). Costs 16 bytes in a 32-bit build; 0 in 64-bit.
* | tls: use C code for x86_64 sp_256_sub_8_p256_mod()Ron Yorston2024-03-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There's an upstream bug report: https://bugs.busybox.net/show_bug.cgi?id=15679 that if BusyBox is built for x86_64 with gcc and the use of OpenSSL for wget is disabled, failures ensue. A similar issue also affects the busybox-w32 build with the comparable configuration. The problem appears to be in the assembly code for the function sp_256_sub_8_p256_mod(), as forcing the use of the provided C code seems to fix both upstream and busybox-w32. Since my knowledge of x64_64 assembler is non-existent, someone else will need to determine the actual issue. For the moment, just avoid the faulty code. Saves 32 bytes in the 64-bit build. (GitHub issue #263)
* | win32: add a comment about LTO to mkreleaseRon Yorston2024-02-251-2/+7
| |
* | win32: add BB_VER.h to .gitignoreRon Yorston2024-02-251-0/+1
| |
* | Update README.mdRon Yorston2024-02-231-2/+7
| |
* | win32: fix uname(2) if ARM architecture is undefinedFRP-5301-gda71f7c57Ron Yorston2024-02-201-0/+2
| | | | | | | | | | Older versions of mingw don't define PROCESSOR_ARCHITECTURE_ARM64. Don't let this stop the build.
* | build system: fix for older GNU makeRon Yorston2024-02-201-3/+9
| | | | | | | | | | | | | | | | Commit 992387539 (build system: more clang/llvm tweaks) added a test in scripts/Makefile.build which used the intcmp function. This isn't present in GNU make prior to 4.4. Rewrite the test so it works with older versions of GNU make.
* | build system: avoid full rebuild when EXTRAVERSION changesRon Yorston2024-02-167-2/+25
| | | | | | | | | | | | | | | | | | | | The last two commits allow EXTRAVERSION to track the current state of a git repository. The build system was unable to determine which files were affected by changes to EXTRAVERSION and caused a full rebuild when it changed. Alter how the version information is passed to the code so only a handful of files need to be rebuilt when it changes.
* | build system: improvements to EXTRAVERSION detectionRon Yorston2024-02-161-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous commit to detect EXTRAVERSION more accurately was lacking in some respects: - Only attempt to detect EXTRAVERSION if it's currently set to the default value '.git'. - Use immediate-expansion macro assignments to avoid time-consuming repeated evaluations. - Remove a useless use of cat. - Correctly allow for the output being sent to a separate directory.
* | build system: try to find a more precise EXTRAVERSIONRon Yorston2024-02-152-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | The default EXTRAVERSION is .git. Use some clues to determine a more precise EXTRAVERSION: - git describe - A .frp_describe file embedded in the release tarball - The name of the build directory: tarballs of release tags from GitLab and GitHub include the version in the directory name.
* | httpd: enable interpreter script featureRon Yorston2024-02-115-18/+38
| | | | | | | | | | | | | | | | | | | | | | | | The web server in BusyBox has an optional feature to allow pages with a given suffix to be processed by a script interpreter: PHP, for example. Enable this in the busybox-w32 build. Costs 256-320 bytes. (GitHub issue #266)
* | httpd: code shrinkRon Yorston2024-02-111-10/+7
| | | | | | | | | | | | | | | | | | | | When setting up the arguments for the CGI handler: - Use '-I0' rather than two separate arguments. - Use memcpy() to copy the server arguments. Saves 32 bytes.
* | httpd: avoid unnecessary process creationRon Yorston2024-02-091-3/+4
| | | | | | | | | | | | | | | | | | | | | | The httpd server made unnecessary calls to detach from the console. Avoiding this saves one process creation when a file is being served and two for a CGI script. Then again, commit ad4bd5bbd (win32: avoid console windows from CGI scripts) results in a console host always being created for a CGI script even if it turns out to be unnecessary. So the net saving is only one process for CGI scripts.
* | ash: allow nofork applets in Windows on ARM + UCRTRon Yorston2024-02-081-1/+2
| | | | | | | | | | | | | | | | | | | | Commit ea8742bc16 (ash: workaround environment issue in Windows on ARM) prevented nofork applets from being run without a fork in standalone shell mode in Windows on ARM. This was due to a deficiency in the handling of the 'environ' global. However, the problem is specific to MSVCRT. If the target is UCRT nofork applets can be made to work without a fork.
* | win32: avoid console windows from CGI scriptsRon Yorston2024-02-071-1/+1
| | | | | | | | | | | | | | | | | | When httpd is run in the background its processes are detached from the console. CGI scripts could create subprocesses which needed a console, resulting in annoying console windows appearing. Prevent this by changing the creation flags for CGI scripts to CREATE_NO_WINDOW.
* | win32: update sample script for release buildRon Yorston2024-02-032-36/+67
| | | | | | | | | | Update the mkrelease script to include cross-compilation of the Windows on ARM binary on Linux using llvm-mingw.
* | win32: stat(1) requires find_mount_point()Ron Yorston2024-02-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | In the Microsoft Windows build stat(1) requires find_mount_point() from libbb. This won't be available unless df(1) is also enabled. Add a dependency so stat(1) can be built without df(1). This may result in find_mount_point() being compiled needlessly in some upstream builds, but we can live with that. (GitHub issue #385)
* | win32: rearrange applet override handlingRon Yorston2024-02-024-36/+38
| | | | | | | | | | | | | | | | | | | | - Rename some functions to be more meaningful. - Adjust conditional compilation to clarify which code is required for 'standalone shell' and 'exec prefers applets' settings. This shouldn't result in any change to the behaviour or size of default builds.
* | win32: UTF8_OUTPUT: recover quicker from bad byteAvi Halachmi (:avih)2024-01-311-12/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an unexpected value is detected in UTF-8, we should print the placeholder codepoint, and then recover whenever we detect a value which is valid for starting a new UTF-8 codepoint (including ASCII7). However, previously, we only tested recovery at the bytes following the unexpected one, and so if the first unexpected value was also valid for a new codepoint, then didn't rcover it. Now we check for recovery from the first unexpected byte, which, if recoverable, requires both placeholder printout and recovery, so the recovery "unwinding" is modified a bit to allow placeholder. Example of of a sequence which now recovers quicker than before: (where UTF-8 for U+1F600 "😀" is: 0xF0 0x9F 0x98 0x80) printf "\xF0\xF0\x9F\x98\x80A" Previously: ?A Now: ?😀A
* | win32: import dirname(3) from mingw-w64Ron Yorston2024-01-302-0/+288
| | | | | | | | | | | | | | | | | | | | | | | | | | The mingw-w64 project has updated its implementation of dirname(3). In some circumstances the new version doesn't preserve the type of the user-supplied top-level directory separator. As a result of this the dirname-handles-root test case failed. Import the new implementation and tweak it to preserve the type of the separator. This only affects mingw-w64 versions 12 and above. Currently only the aarch64 build using llvm-mingw is affected.
* | ls: support NO_COLOR environment variableRon Yorston2024-01-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | If the NO_COLOR environment variable is set and is not empty 'ls' won't output ANSI colour codes. This is an alternative to the existing approach of setting 'LS_COLORS=none'. See https://no-color.org/. Costs 24-32 bytes. (GitHub issue #382)
* | win32: avoid invalid freeRon Yorston2024-01-241-3/+5
| | | | | | | | | | | | In external_exists() in appletlib.c it's necessary to take a copy of the pointer to the allocated variable path1 so it can be freed: find_executable() will change its value.
* | win32: hardcode numeric value of MANIFEST resourceRon Yorston2024-01-231-2/+3
| | | | | | | | | | It seems windres in llvm doesn't understand MANIFEST resources. Use the numeric value 24 instead.
* | Fix POSIX build in standalone shell modeRon Yorston2024-01-233-4/+7
| | | | | | | | | | | | | | The conditional compilation to control standalone shell mode was incorrect when building for POSIX. This hadn't been noticed before as it had only been tested in the default configuration where standalone shell mode is disabled.
* | build system: try a different exception methodRon Yorston2024-01-211-1/+1
| | | | | | | | Use -fsjls-exceptions with clang.
* | build system: actually detect lack of --warn-commonRon Yorston2024-01-211-1/+7
| | | | | | | | | | | | | | | | Commit 992387539 (build system: more clang/llvm tweaks) falsely claimed that the lack of the --warn-common linker option was being detected. It wasn't, but it is now.