Commit Graph

31 Commits

Author SHA1 Message Date
sin bb7427f6c1 Fix type mismatch in split(1)
Adapted from a patch sent by Random832.
2015-11-26 10:35:46 +00:00
sin 2366164de7 No need for semicolon after ARGEND
This is also the style used in Plan 9.
2015-11-01 10:18:55 +00:00
FRIGN c514c580ec Print error message when size == 0 in split(1)
instead of just exiting with code 1. This could be confusing.
2015-09-30 19:44:10 +01:00
FRIGN fe84305649 Check for size == 0 in split(1) 2015-09-30 19:44:10 +01:00
FRIGN 8125e8829d Convert split(1) to parseoffset()
This drops a lot of duplicate code. Also simplify it in other
parts of the main arg-handler.
2015-09-30 19:44:10 +01:00
FRIGN d23cc72490 Simplify return & fshut() logic
Get rid of the !!()-constructs and use ret where available (or introduce it).

In some cases, there would be an "abort" on the first fshut-error, but we want
to close all files and report all warnings and then quit, not just the warning
for the first file.
2015-05-26 16:41:43 +01:00
FRIGN 11e2d472bf Add *fshut() functions to properly flush file streams
This has been a known issue for a long time. Example:

printf "word" > /dev/full

wouldn't report there's not enough space on the device.
This is due to the fact that every libc has internal buffers
for stdout which store fragments of written data until they reach
a certain size or on some callback to flush them all at once to the
kernel.
You can force the libc to flush them with fflush(). In case flushing
fails, you can check the return value of fflush() and report an error.

However, previously, sbase didn't have such checks and without fflush(),
the libc silently flushes the buffers on exit without checking the errors.
No offense, but there's no way for the libc to report errors in the exit-
condition.

GNU coreutils solve this by having onexit-callbacks to handle the flushing
and report issues, but they have obvious deficiencies.
After long discussions on IRC, we came to the conclusion that checking the
return value of every io-function would be a bit too much, and having a
general-purpose fclose-wrapper would be the best way to go.

It turned out that fclose() alone is not enough to detect errors. The right
way to do it is to fflush() + check ferror on the fp and then to a fclose().
This is what fshut does and that's how it's done before each return.
The return value is obviously affected, reporting an error in case a flush
or close failed, but also when reading failed for some reason, the error-
state is caught.

the !!( ... + ...) construction is used to call all functions inside the
brackets and not "terminating" on the first.
We want errors to be reported, but there's no reason to stop flushing buffers
when one other file buffer has issues.
Obviously, functionales come before the flush and ret-logic comes after to
prevent early exits as well without reporting warnings if there are any.

One more advantage of fshut() is that it is even able to report errors
on obscure NFS-setups which the other coreutils are unable to detect,
because they only check the return-value of fflush() and fclose(),
not ferror() as well.
2015-04-05 09:13:56 +01:00
FRIGN 3725d501b3 Audit split(1)
1) Refactor manpage, add STANDARDS section.
2) Boolean-style-changes.
3) Update usage, reflecting num-idiom also changed in the manpage.
4) Refactor error messages.
5) Also fclose stdin.
6) Empty line before return.
2015-03-17 22:59:48 +01:00
FRIGN 93fd817536 Add estrlcat() and estrlcpy()
It has become a common idiom in sbase to check strlcat() and strlcpy()
using

if (strl{cat, cpy}(dst, src, siz) >= siz)
        eprintf("path too long\n");

However, this was not carried out consistently and to this very day,
some tools employed unchecked calls to these functions, effectively
allowing silent truncations to happen, which in turn may lead to
security issues.
To finally put an end to this, the e*-functions detect truncation
automatically and the caller can lean back and enjoy coding without
trouble. :)
2015-03-17 11:24:49 +01:00
Hiltjo Posthuma 0c17cd0fb3 staticize some functions 2015-03-07 13:33:39 +01:00
FRIGN 31572c8b0e Clean up #includes 2015-02-14 21:12:23 +01:00
Hiltjo Posthuma 949f930280 split: fixes
- -b argument required, don't allow -b <= 0.
- -l argument required, don't allow -l <= 0.
- usage() and argument parsing: sort flags.
- don't write 0 size file, get rid of goto reproducable with:
  printf 'a' | split -b 1.
- close FILE *in if != stdin.
- mark split as finished in README.
- codestyle fixes.
2015-02-01 16:30:12 +01:00
FRIGN 27b770c02c Adjust some limits to more flexibility for strtonum 2015-02-01 01:24:03 +01:00
FRIGN fd562481f3 Convert estrto{l, ul} to estrtonum
Enough with this insanity!
2015-01-30 16:52:44 +01:00
FRIGN 1436518f9d Use < 0 instead of == -1 2014-11-19 20:09:29 +00:00
FRIGN 7fc5856e64 Tweak NULL-pointer checks
Use !p and p when comparing pointers as opposed to explicit
checks against NULL.  This is generally easier to read.
2014-11-14 10:54:30 +00:00
FRIGN 7d2683ddf2 Sort includes and more cleanup and fixes in util/ 2014-11-14 10:54:10 +00:00
FRIGN eee98ed3a4 Fix coding style
It was about damn time. Consistency is very important in such a
big codebase.
2014-11-13 18:08:43 +00:00
sin 0c5b7b9155 Stop using EXIT_{SUCCESS,FAILURE} 2014-10-02 23:46:59 +01:00
sin b712ef44ad Fix warning 'array subscript of type char' 2014-09-02 13:32:32 +01:00
Hiltjo Posthuma 5b3a0a9382 build warnings: initialise values...
... to make fix gcc warnings with -Wall.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-05-12 12:06:14 +01:00
dwts 575b38391c keep usage definition above main 2014-04-22 13:46:33 +01:00
sin 02d91696b4 Fix char **argv to char *argv[] 2014-04-18 11:54:44 +01:00
Hiltjo Posthuma bd9a81951f split: dont use table lookup for size
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-04-01 16:20:52 +01:00
Hiltjo Posthuma f7403ce6c6 style: whitespace fixes
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-04-01 16:20:43 +01:00
sin a6ef67cd3d Use strlcpy() 2014-03-23 18:33:45 +00:00
sin b1b225c9ee No need to print the name of the program
The name is printed automatically.  Add some missing newlines
as well.
2014-01-30 14:55:18 +00:00
sin 5b5f062184 Add license file details at top of files 2013-10-07 17:03:34 +01:00
sin b5a511dacf Exit with EXIT_SUCCESS/EXIT_FAILURE instead of 0 and 1
Fixed for consistency purposes.
2013-10-07 16:44:22 +01:00
David Galos 9f8deb4b23 Tar compiles on BSD, thanks Roberto E. Vargas Caballero. Also remove tons of trailing whitespace. 2013-07-20 01:27:42 -04:00
Christoph Lohmann 9df408f8c6 Adding who, chroot, env and split.
Thanks "Galos, David" <galosd83@students.rowan.edu>!
2013-06-14 18:55:25 +02:00