aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/split/split.c
Commit message (Collapse)AuthorAgeFilesLines
* Tighten boundary check in split(1) to prevent a potential buffer overflow.Shawn Bayern2024-05-061-0/+4
| | | | (cherry picked from commit 95032b58a1ad0fde57518f17805ca721bb4563ad)
* split: Further option parsing improvements.Dag-Erling Smørgrav2023-10-051-38/+51
| | | | | | | | | | | | | | | | | | | | | | | | * Whenever possible, use strtonum() to parse numeric arguments. * Improve usefulness and consistency of error messages. * While here, fix some type and style issues. Sponsored by: Klara, Inc. Reviewed by: christos, kevans Differential Revision: https://reviews.freebsd.org/D42010 (cherry picked from commit d7399551b02861b910b15c7b7a78a2835644aa45) split: Improve GNU compatibility. * Like GNU split, turn autoextend back on if given -a0. * Add a test case that verifies that -a<non-zero> turns autoextend off. * Add a test case that verifies that -a0 turns autoextend back on. Sponsored by: Klara, Inc. Reviewed by: christos, kevans Differential Revision: https://reviews.freebsd.org/D42011 (cherry picked from commit d9d69a6f6fc1f8d80df9ce6493e8ab9388781615)
* split: Add missing test cases.Dag-Erling Smørgrav2023-09-141-22/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds test cases for c4f7198f47c1 and ac17fc816e67. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41755 (cherry picked from commit cbea5eddb1b6ae2a101beacf00bf165517f4f2b1) split: Code cleanup. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41756 (cherry picked from commit 851bf856d1a7ad5427ea9c22639ab6f6c4a3f503) split: Fix linecount parsing. The “undocumented kludge” which unfortunately can't be dropped for backward compatibility reasons was prone to segfaulting and would improperly allow a new linecount when one was already set. Fix these issues and add regression tests. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41757 (cherry picked from commit 117c54a78ccd214c236806721f21da750e512d3e)
* Mark usage function as __dead2 in programs where it does not returnAlfonso Gregory2023-09-141-1/+1
| | | | | | | | | | In most cases, usage does not return, so mark them as __dead2. For the cases where they do return, they have not been marked __dead2. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/735 (cherry picked from commit cccdaf507eee8fb34494b4624eb85bb951e323c8)
* split(1): auto-extend suffix length if requiredJan Schaumann2023-09-141-8/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the input cannot be split into the number of files resulting from the default suffix length, automatically extend the suffix length rather than bailing out with 'too many files'. Suffixes are extended such that the resulting files continue to sort lexically and "cat *" would reproduce the input. For example, splitting a 1M lines file into (default) 1000 lines per file would yield files named 'xaa', 'xab', ..., 'xyy', 'xyz', 'xzaaa', 'xzaab', ..., 'xzanl'. If '-a' is specified, the suffix length is not auto-extended. This behavior matches GNU sort(1) since around version 8.16. Reviewed by: christos Approved by: kevans Different Revision: https://reviews.freebsd.org/D38279 (cherry picked from commit c4f7198f47c15eece849d06e8fdd1fb46ed43bba) split(1): add '-c' to continue creating files Currently, split(1) will clobber any existing output files: $ split file; ls xaa xab xac xad $ split second-file; ls xaa xab xac xad xae xaf This patch adds a flag "-c" (mnemonic "create, don't overwrite" or "continue where you left off"): $ split file; ls xaa xab xac xad $ split -c second-file; ls xaa xab xac xad xae xaf xag xah xai xaj Reviewed by: christos Approved by: kevans Different Revision: https://reviews.freebsd.org/D38553 (cherry picked from commit ac17fc816e67a4e5e2e481b5001577a8d589f8b6)
* split: Update synopsis and usage; fix examplesMateusz Piotrowski2023-09-141-4/+4
| | | | | | | | | | - Mark -d as an optional flag - Add a prompt to one of the examples for consistency - Add -d to the usage message Sponsored by: Klara Inc. (cherry picked from commit fb499259997c0bfd724b7b67578035cd977ef60f)
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-231-2/+0
| | | | | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/ Similar commit in main: (cherry picked from commit 1d386b48a555)
* split: reset errno prior to getline()Math Ieu2022-11-111-1/+1
| | | | | | | | | | Something else may have set errno, breaking the post-getline() logic that tries to detect the getline() error. This was initially noted in a jail on a system that has HPET, in a jail that does not expose /dev/hpet0 -- we see an earlier error in libc's vdso bits. Fixes: 5c053aa3c5e90 ("split: switch to getline() [...]") (cherry picked from commit 172be8642d93851b0c083d0db240cf35fd56ab0e)
* split: switch to getline() for line/pattern matchingKyle Evans2022-11-111-13/+12
| | | | | | | | | | | | Get rid of split's home-grown logic for growing the buffer; arbitrarily breaking at LONG_MAX bytes instead of 65536 bytes gives us much more wiggle room. Additionally, we'll actually fail out entirely if we can't fit a line, which makes noticing this class of problem much easier. Reviewed by: bapt, emaste, pauamma Sponsored by: Klara, Inc. (cherry picked from commit 5c053aa3c5e907bdd1ac466ce9b58611781c2c20)
* Revert r352953: Convert pnmatch to single element array in regexec callsAlexander Kabaev2019-10-021-4/+4
| | | | | | | Requested by: cem Notes: svn path=/head/; revision=353011
* Convert pnmatch to single element array in regexec callsAlexander Kabaev2019-10-021-4/+4
| | | | | | | | | | | | | | The regexec function is declared as taking an array of regmatch_t elements, and passing in the pointer to singleton element, while correct, triggers a Coverity warning. Convert the singleton into an array of one to silence the warning. Reported by: Coverity Coverity CID: 1009732, 1009733 MFC after: 2 weeks Notes: svn path=/head/; revision=352953
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-1/+3
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Change manual string conversion to expand_numberEitan Adler2013-11-091-16/+4
| | | | | | | Reviewed by: adrian Notes: svn path=/head/; revision=257884
* Avoid signed overflow in error handling code.Eitan Adler2013-05-211-1/+3
| | | | | | | Reviewed by: cperciva, bjk Notes: svn path=/head/; revision=250882
* Implement 'split -d' which allows a numeric suffix instead of anEitan Adler2013-05-101-5/+23
| | | | | | | | | | | | alphabetic one. PR: bin/116209 Submitted by: Marcin Gryszkalis <mg@fork.pl> (adapted from) Reviewed by: will MFC after: 1 week Notes: svn path=/head/; revision=250432
* Fix warning when compiling with gcc46:Eitan Adler2012-01-101-3/+0
| | | | | | | | | | error: variable 'defname' set but not use Approved by: dim MFC after: 3 day Notes: svn path=/head/; revision=229905
* Add missing static keywords to split(1)Ed Schouten2011-11-061-10/+10
| | | | Notes: svn path=/head/; revision=227183
* Remove the advertising clause from UCB copyrighted files in usr.bin. ThisJoel Dahl2010-12-111-4/+0
| | | | | | | | | | | | is in accordance with the information provided at ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change Also add $FreeBSD$ to a few files to keep svn happy. Discussed with: imp, rwatson Notes: svn path=/head/; revision=216370
* Add a -n option to split(1) to split files into N chunks rather thanDavid Schultz2008-03-161-11/+69
| | | | | | | | | | | having to specify the right number of bytes. Obtained from: NetBSD Submitted by: Jan Schaumann <jschauma@netmeister.org> PR: 113175 Notes: svn path=/head/; revision=177256
* Add support for splitting at gigabyte boundaries. [1]Giorgos Keramidas2006-08-101-5/+6
| | | | | | | | | | | | | | | | | Also make both lowercase and uppercase suffix letters work as byte-count suffixes, i.e. the following two commands are equivalent now: % split -b 4m foo % split -b 4M foo Submitted by: Roman Divacky [1] Lots of help by: cperciva Reviewed by: cperciva MFC after: 1 week Notes: svn path=/head/; revision=161172
* Update usage & SYNOPSIS and clarify that input files are not removed.Giorgos Keramidas2006-08-081-8/+8
| | | | | | | | | | | | | | Sort getopt option handling of -p too, while here. The changes are adapted from a patch by Ruslan Ermilov, posted as followup to docs/33852. PR: docs/33852 Submitted by: Gary W. Swearingen <swear@blarg.net> MFC after: 1 week Notes: svn path=/head/; revision=161106
* Remove undocumented historic support for treating "-" as an optionTim J. Robbins2005-08-301-14/+8
| | | | | | | instead of a file operand; this is not compatible with POSIX. Notes: svn path=/head/; revision=149616
* Remove the hack that varied the first character of the output file nameTim J. Robbins2005-08-211-10/+2
| | | | | | | | | | | if none was specified on the command line. This is not permitted by POSIX, and no longer needed now that we have the -a option. PR: 85099 Submitted by: Toby Peterson (Apple Computer) Notes: svn path=/head/; revision=149345
* Respect locale settings from the environment.Tim J. Robbins2004-07-111-0/+3
| | | | Notes: svn path=/head/; revision=131978
* Support larger files (at least 64-bit offsets) by using off_t instead ofTim J. Robbins2002-07-151-8/+21
| | | | | | | int to store offsets. Notes: svn path=/head/; revision=100024
* Remove <sys/types> where we use <sys/param> already.Juli Mallett2002-06-151-8/+5
| | | | | | | protoize. Notes: svn path=/head/; revision=98253
* Allow "-" to be specified as an operand as well as an option.Tim J. Robbins2002-05-271-1/+3
| | | | | | | SUSV3 requires something like "split -- -" to work. Document the "-" operand. Notes: svn path=/head/; revision=97334
* Avoid overflowing `fname' if the file name prefix given on the commandTim J. Robbins2002-05-271-1/+2
| | | | | | | | | line is too long. Obtained from: OpenBSD Notes: svn path=/head/; revision=97332
* remove __PWarner Losh2002-03-221-4/+4
| | | | Notes: svn path=/head/; revision=92922
* Add -a option (SUSv3) to split(1).Mike Barcroft2002-02-011-7/+31
| | | | | | | | Submitted by: Tim J. Robbins <tim@robbins.dropbear.id.au> MFC after: 1 month Notes: svn path=/head/; revision=90048
* WARNS=2 fixes, use __FBSDID, remove GCC-specific flags.Mark Murray2001-12-121-11/+10
| | | | Notes: svn path=/head/; revision=87765
* Add/fix the ability to split a file larger than 2 gigabytes.John W. De Boskey2000-11-191-4/+6
| | | | | | | | | | | Added $FreeBSD tag (in the way the already present sccsid is done). I've been told the rcsid stuff may be of dubious value so I'm curious to know if folks (still) use it. Submitted by: Brad Chisholm <blc@bsdwins.com> Notes: svn path=/head/; revision=68887
* Print usage via fprintf(stderr, ..) instead of errx() to avoid progname prefix.Archie Cobbs1999-02-051-2/+3
| | | | | | | Submitted by: Philippe Charnier <charnier@xp11.frmug.org> Notes: svn path=/head/; revision=43625
* Add new option '-p pattern' for splitting files based on matching lines inArchie Cobbs1999-02-011-52/+77
| | | | | | | | | the file with a regular expression. Useful for e.g. 'cvs diff' output. Also compile cleanly with -Wall and fix a few style bugs. PR: bin/9405 Notes: svn path=/head/; revision=43513
* Cosmetic in err() string.Philippe Charnier1997-08-111-9/+10
| | | | Notes: svn path=/head/; revision=28071
* compare return value from getopt against -1 rather than EOF, per the finalWarner Losh1997-03-291-1/+1
| | | | | | | posix standard on the topic. Notes: svn path=/head/; revision=24360
* This fixes 'split -l NNN foo'. As it stands split willRodney W. Grimes1995-07-071-1/+1
| | | | | | | | | | | | | complain about an 'illegal line count' becuase it's looking at the wrong end pointer (ep) to detect any extra characters after the NNN. Submitted by: Rich Murphey <rich@freebsd.org> This should probably get pulled into 2.0.6 and 2.1.0 Notes: svn path=/head/; revision=9427
* BSD 4.4 Lite Usr.bin SourcesRodney W. Grimes1994-05-271-0/+288
Notes: svn path=/cvs2svn/branches/CHRISTOS/; revision=1590