aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/sort
Commit message (Collapse)AuthorAgeFilesLines
* sort: Const correctness for C23Lexi Winter2026-08-031-1/+1
| | | | | | | | | | | | | | | | On some platforms, e.g. Linux Clang 22.1.8 / glibc 2.43, strchr() now implements the C23 behaviour where passing a const pointer to strchr() also returns a const pointer. This breaks sort during the bootstrap build, since it assumes the return value is always a mutable pointer. As the returned pointer is never used to modify the value, fix this by making the temporary variable const. MFC after: 1 week Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58491
* src: Use gnu17 as the default C standard for userland instead of gnu99Minsoo Choo2025-02-111-1/+0
| | | | | | | | | | | | | | | | | | | | | | Tracking newer versions of C (and C++) permits assuming newer language features in the base system. Some C11 extensions are already used in the base system but implemented on top of GNU C extensions such as _Alignas and _Static_assert. In some cases the fallback versions in cdefs.h are more limited than the native C11 extensions. Even though C11 is the next major version of C, C17 is chosen instead since C17 does not add new features to C but merely fixes defects in C11. It is also well supported by a wide range of clang (7.0.0+) and GCC (8.1+) versions. Along with changing the default, this change also removes explicit requests for c11 via the CSTD variable in various Makefiles. Libraries and binaries for ZFS continue to use c99. PR: 284039 (exp-run) Reviewed by: imp, arichardson, emaste Differential Revision: https://reviews.freebsd.org/D43237
* Update Makefile.depend filesSimon J. Gerraty2024-10-141-0/+10
| | | | | | | After building packages we have a number of new and updated Makefile.depend files Reviewed by: stevek
* Remove residual blank line at start of MakefileWarner Losh2024-07-152-2/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* sort: Only build FreeBSD-specific ALTMON_x stuff when ATLMON_1 is definedWarner Losh2023-12-071-0/+10
| | | | | | | | | | | | | | | On MacOS, we bootstrap sort. Since ALTMON_* are not defined there, the build blows up. Since we don't need this feature for the FreeBSD build process, and since we won't use it unless we actually install the NL files that have this data in it, just #ifdef it out for now. In the extremely unlikely event that the FreeBSD bootstrap/build process grows this dependency, we can evaluate the best solution then (which most likely is going to be not depend on the local's month names). Fixes: 3d44dce90a69 (MacOS builds and github CI) Sponsored by: Netflix Reviewed by: jrtc27, jlduran@gmail.com, markj Differential Revision: https://reviews.freebsd.org/D42868
* sort: test against all month formats in month-sortChristos Margiolis2023-12-014-44/+262
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The CLDR specification [1] defines three possible month formats: - Abbreviation (e.g Jan, Ιαν) - Full (e.g January, Ιανουαρίου) - Standalone (e.g January, Ιανουάριος) Many languages use different case endings depending on whether the month is referenced as a standalone word (nominative case), or in date context (genitive, partitive, etc.). sort(1)'s -M option currently sorts months by testing input against only the abbrevation format, which is essentially a substring of the full format. While this works fine for languages like English, where there are no cases, for languages where there is a different case ending between the abbreviation/full and standalone formats, it is not sufficient. For example, in Greek, "May" can take the following forms: Abbreviation: Μαΐ (genitive case) Full: Μαΐου (genitive case) Standalone: Μάιος (nominative case) If we use the standalone format in Greek, sort(1) will not able to match "Μαΐ" to "Μάιος" and the sort will fail. This change makes sort(1) test against all three formats. It also works when the input contains mixed formats. [1] https://cldr.unicode.org/translation/date-time/date-time-patterns Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D42847
* usr.bin: Automated cleanup of cdefs and other formattingWarner Losh2023-11-272-2/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* usr.bin: Remove ancient SCCS tags.Warner Losh2023-11-271-2/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-164-4/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-167-14/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-167-7/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1214-14/+14
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* sort: deindent file_reader_free and cleanup its usageBaptiste Daroussin2022-10-131-8/+6
|
* sort: simplify file_reader_cleanBaptiste Daroussin2022-10-131-18/+11
| | | | | | Deindent the function, remove useless tests: - free already test if argument is NULL - closefile already test if the input is stdin or null
* sort: deindent closefileBaptiste Daroussin2022-10-131-11/+9
|
* sort: use asprintf(3) instead of malloc + snprintf(3)Baptiste Daroussin2022-10-131-9/+7
|
* sort: deindent openfileBaptiste Daroussin2022-10-131-30/+29
|
* sort: simplify the code to handle -z flagBaptiste Daroussin2022-10-131-7/+5
|
* sort: cleanup now unused structutre and prototypesBaptiste Daroussin2022-10-131-7/+0
|
* sort: unify the code to read from FILE *Baptiste Daroussin2022-10-131-94/+0
| | | | | | | | Previously the code to read from a local file or stdin was sperarated After the change to remove the home made line reader used for stdin (replaced by getdelim) it apprears that the rest of the code which is used to read from any FILE * but stdin can benefit from the exact same change.
* sort: remove unused functionBaptiste Daroussin2022-10-132-59/+0
|
* sort: use memset to initialize structure when possibleBaptiste Daroussin2022-10-131-6/+2
|
* sort: use mkstemp(3) instead of reinventing itBaptiste Daroussin2022-10-121-6/+6
| | | | MFC After: 1 week
* sort: replace home made line reader by getdelim(3)Baptiste Daroussin2022-10-122-115/+12
| | | | | | | | | | | | | | The previous code had bug when reading lines with an unexpected encoding, returning without the full line being captured. This result in sort complaining with "sort: Illegal byte sequence" Using getdelim(3) instead of the home made code, fixes the situation. PR: 241679 Reported by: Ronald F. Guilmette <rfg-freebsd@tristatelogic.com> MFC After: 1 week Reviewed by: markj, imp Differential Revision: https://reviews.freebsd.org/D36948
* sort: remove NLS supportBaptiste Daroussin2022-10-126-70/+1
| | | | | | NLS support for sort(1) is: 1/ incomplete: many error string are not using nls 2/ only covers hu_HU.ISO8859-2
* sort: replace malloc+memset with callocBaptiste Daroussin2022-10-123-14/+7
|
* sort: add wrapper around callocBaptiste Daroussin2022-10-122-0/+11
|
* Move sort to runtimeDoug Rabson2022-07-291-0/+1
| | | | Allows pkg bootstrap without having to install FreeBSD-utilities
* sort: Fix message catalogue usageMark Johnston2022-01-282-10/+12
| | | | | | | | | | | | | - Check that catopen() succeeded before calling catclose(). musl will crash in the latter if the catalogue descriptor is -1. - Keep the message catalogue open for most of sort(1)'s actual operation. - Don't use catgets(3) to print error messages if catopen(3) had failed. Reviewed by: arichardson, emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34081
* sort: Fix random sortMark Johnston2021-10-291-1/+1
| | | | | | | | | | bwsrawdata() is supposed to return the string buffer. PR: 259451 Reported by: sigsys@gmail.com Fixes: d053fb22f6d3 ("usr.bin/sort: Avoid UBSan errors") MFC after: 3 days Sponsored by: The FreeBSD Foundation
* usr.bin/sort: Avoid UBSan errorsAlex Richardson2021-07-063-145/+155
| | | | | | | | | | | | | UBSan complains about out-of-bounds accesses for zero-length arrays. To avoid this we can use flexible array members. However, the C standard does not allow for structures that only contain flexible array members, so we move the length parameters into that structure too. Split out from D28233. Reviewed By: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31009
* sort: Change default algorithm to mergesortCyril Zhang2021-06-171-2/+2
| | | | | | | | | | | This results in a significant improvement in the runtime of sort(1) when radix sort cannot be used. This comes at the expense of increased memory usage, but this is small relative to sort's overall memory usage. PR: 255551 Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30319
* sort: Hook NetBSD tests up to the buildMark Johnston2021-05-131-2/+2
| | | | | MFC after: 1 week Sponsored by: The FreeBSD Foundation
* sort: Cache value of MB_CUR_MAXCyril Zhang2021-05-135-34/+45
| | | | | | | | | | | | | | Every usage of MB_CUR_MAX results in a call to __mb_cur_max. This is inefficient and redundant. Caching the value of MB_CUR_MAX in a global variable removes these calls and speeds up the runtime of sort. For numeric sorting, runtime is almost halved in some tests. PR: 255551 PR: 255840 Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30170
* sort: Stop "fixing" obsolete key syntax after -- flagCyril Zhang2021-05-131-0/+5
| | | | | | | | PR: 255798 Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30234
* Fix -Wpointer-sign warnings in bwstring.cAlex Richardson2020-09-101-7/+7
| | | | Notes: svn path=/head/; revision=365582
* sort(1): Remove duplicate option checkGordon Bergling2020-09-081-1/+1
| | | | | | | | | | | Reviewed by: lwhsu, emaste Approved by: emaste Obtained from: DragonFlyBSD MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D23892 Notes: svn path=/head/; revision=365458
* sort(1): Fix two wchar-related bugs in radixsortConrad Meyer2020-06-231-4/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sort(1)'s radixsort implementation was broken for multibyte LC_CTYPEs in at least two ways: * In actual radix sort, it would only bucket the least significant byte from each wchar, ignoring the 24 most-significant bits of each unicode character. * In degenerate cases / "fast paths," it would fall back to another sorting algorithm (default: mergesort) with a bogus comparator offset. The string comparison functions in sort(1) take an offset in units of the operating character size. However, radixsort was passing an offset in units of bytes. The byte offset must be divided by sizeof(wchar_t). This revision addresses both discovered issues. Some example testcases: $ (echo 耳 ; echo 脳 ; echo 耳) | \ LC_CTYPE=ja_JP.UTF-8 LC_COLLATE=C LANG=C sort --radixsort --debug $ (echo 耳 ; echo 脳 ; echo 耳) | \ LC_CTYPE=C LC_COLLATE=C LANG=C sort --radixsort --debug $ (for i in $(jot 34); do echo 耳耳耳耳耳; echo 耳耳耳耳脳; echo 耳耳耳耳脴; done) | \ LC_CTYPE=ja_JP.UTF-8 LC_COLLATE=C LANG=C sort --radixsort --debug PR: 247494 Reported by: knu MFC after: I do not intend to, but parties interested in stable might want to Notes: svn path=/head/; revision=362545
* Update Makefile.depend filesSimon J. Gerraty2019-12-111-2/+0
| | | | | | | | | | | | | Update a bunch of Makefile.depend files as a result of adding Makefile.depend.options files Reviewed by: bdrewery MFC after: 1 week Sponsored by: Juniper Networks Differential Revision: https://reviews.freebsd.org/D22494 Notes: svn path=/head/; revision=355617
* Add Makefile.depend.optionsSimon J. Gerraty2019-12-111-0/+8
| | | | | | | | | | | | | | | | | | | | Leaf directories that have dependencies impacted by options need a Makefile.depend.options file to avoid churn in Makefile.depend DIRDEPS for cases such as OPENSSL, TCP_WRAPPERS etc can be set in local.dirdeps-options.mk which can add to those set in Makefile.depend.options See share/mk/dirdeps-options.mk Reviewed by: bdrewery MFC after: 1 week Sponsored by: Juniper Networks Differential Revision: https://reviews.freebsd.org/D22469 Notes: svn path=/head/; revision=355616
* Adjust history, info source from v1's manualsSevan Janiyan2019-09-041-2/+2
| | | | | | | | | https://www.bell-labs.com/usr/dmr/www/1stEdman.html MFC after: 5 days Notes: svn path=/head/; revision=351811
* sort(1): Memoize MD5 computation to reduce repeated computationConrad Meyer2019-04-133-0/+36
| | | | | | | | | | | | | | | | Experimentally, reduces sort -R time of a 148160 line corpus from about 3.15s to about 0.93s on this particular system. There's probably room for improvement using some digest other than md5, but I don't want to look at sort(1) anymore. Some discussion of other possible improvements in the Test Plan section of the Differential. PR: 230792 Reviewed by: jhb (earlier version) Differential Revision: https://reviews.freebsd.org/D19885 Notes: svn path=/head/; revision=346175
* sort(1): Simplify and bound random seedingConrad Meyer2019-04-111-41/+58
| | | | | | | | | | | | | | | | | | | | | Bound input file processing length to avoid the issue reported in [1]. For simplicity, only allow regular file and character device inputs. For character devices, only allow /dev/random (and /dev/urandom symblink). 32 bytes of random is perfectly sufficient to seed MD5; we don't need any more. Users that want to use large files as seeds are encouraged to truncate those files down to an appropriate input file via tools like sha256(1). (This does not change the sort algorithm of sort -R.) [1]: https://lists.freebsd.org/pipermail/freebsd-hackers/2018-August/053152.html PR: 230792 Reported by: Ali Abdallah <aliovx AT gmail.com> Relnotes: yes Notes: svn path=/head/; revision=346116
* sort(1): Whitespace and style cleanupConrad Meyer2019-04-111-86/+85
| | | | | | | | | No functional change. Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=346110
* sort(1): randomcoll: Skip the memory allocation entirelyConrad Meyer2019-04-041-15/+6
| | | | | | | | | | | | | | | | | | | | | There's no reason to order based on strcmp of ASCII digests instead of memcmp of the raw digests. While here, remove collision fallback. If you collide two MD5s, they're probably the same string anyway. If robustness against MD5 collisions is desired, maybe we shouldn't use MD5. None of the behavior of sort -R is specified by POSIX, so we're free to implement this however we like. E.g., using a 128-bit counter and block cipher to generate unique indices for each line of input. PR: 230792 (2/many) Relnotes: This will change the sort order for a given dataset with a given seed. Other similarly breaking changes are planned. Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=345896
* sort(1): randomcoll: Don't sort on ENOMEMConrad Meyer2019-04-041-19/+9
| | | | | | | | PR: 230792 (1/many) Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=345891
* Don't use absolute path to sed when building usr.bin/joinAlex Richardson2018-08-231-1/+1
| | | | | | | | | This is required to build sort on Linux hosts since sed is in /bin there. Approved By: jhb (mentor) Notes: svn path=/head/; revision=338265
* sort(1): Fix -m when only implicit stdin is used for inputKyle Evans2018-06-203-5/+9
| | | | | | | | | | | | | | | | | | | | | Observe: printf "a\nb\nc\n" > /tmp/foo # Next command results in no output cat /tmp/foo | sort -m # Next command results in proper output cat /tmp/foo | sort -m - # Also works: sort -m /tmp/foo Some const'ification was done to simplify the actual solution of adding "-" explicitly to the file list if we didn't have any file arguments left over. PR: 190099 MFC after: 1 week Notes: svn path=/head/; revision=335404
* sort(1): Add bits to allow easy checking against NetBSD testsKyle Evans2018-06-202-0/+17
| | | | | | | I'm looking at sort(1) failures, for better or worse. Notes: svn path=/head/; revision=335403