Commit Graph

40 Commits

Author SHA1 Message Date
sin ea0d16e928 Revert "fix length after '\' getline string termination"
Caused a regression in sed, revert until we investigate further.
2016-03-01 15:24:32 +00:00
Hiltjo Posthuma a51b01ff90 uudecode: dont return pointer to local variable 2016-03-01 15:24:32 +00:00
Hiltjo Posthuma e8eeb19fcd fix length after '\' getline string termination 2016-02-26 09:54: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 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 9a074144c9 Remove handrolled strcmp()'s
Favor readability over bare-metal.
2015-05-21 15:43:38 +01:00
FRIGN 0545d32ce9 Handle '-' consistently
In general, POSIX does not define /dev/std{in, out, err} because it
does not want to depend on the dev-filesystem.
For utilities, it thus introduced the '-'-keyword to denote standard
input (and output in some cases) and the programs have to deal with
it accordingly.

Sadly, the design of many tools doesn't allow strict shell-redirections
and many scripts don't even use this feature when possible.

Thus, we made the decision to implement it consistently across all
tools where it makes sense (namely those which read files).

Along the way, I spotted some behavioural bugs in libutil/crypt.c and
others where it was forgotten to fshut the files after use.
2015-05-16 13:34:00 +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
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-

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 9144d51594 Check getline()-return-values properly
It's not useful when 0 is returned anyway, so be sure that we have a
string with length > 0, this also solves some indexing-gotchas like
"len - 1" and so on.
Also, add checked getline()'s whenever it has been forgotten and
clean up the error-messages.
2015-03-27 14:49:48 +01:00
FRIGN 1b71559431 Audit uudecode(1)
Style cleanup, Manpage refactoring.
2015-03-18 00:10:36 +01:00
Hiltjo Posthuma bb79b5c7eb uudecode: fix no newline before EOF 2015-02-20 14:36:50 +01:00
Hiltjo Posthuma ddeb4c0e35 uudecode: add newline to out-of-range error 2015-02-20 14:36:50 +01:00
Hiltjo Posthuma 6c7ff5fda5 code-style: unindent one level of switch 2015-02-20 13:29:38 +01:00
Tai Chi Minh Ralph Eastwood 26168d5c37 uudecode: fix error msgs (newlines, no output name) 2015-02-15 19:37:17 +00:00
FRIGN 31572c8b0e Clean up #includes 2015-02-14 21:12:23 +01:00
sin 7768918d6a uudecode: Style fix 2015-02-13 11:20:23 +00:00
Tai Chi Minh Ralph Eastwood b64b51dc91 uudecode: fix flushing (again) through rewrite 2015-02-13 11:20:22 +00:00
Tai Chi Minh Ralph Eastwood 6d2cbf7a3f uudecode: fix flushing in corner case 2015-02-13 11:20:21 +00:00
Tai Chi Minh Ralph Eastwood ec02816d3e uuencode: add support for base64 and -o to stdout 2015-02-13 11:20:21 +00:00
Evan Gates 84b08427a1 remove agetline 2014-11-18 21:05:28 +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
Hiltjo Posthuma fab4b384e7 use agetline instead of agets
also use agetline where fgets with a static buffer was used previously.

Signed-off-by: Hiltjo Posthuma <>
2014-06-01 18:03:10 +01:00
Hiltjo Posthuma daad071b31 cut, uudecode: free buf after use
Signed-off-by: Hiltjo Posthuma <>
2014-06-01 18:01:31 +01:00
Hiltjo Posthuma bd99b92e91 parsemode: rework
- for octal input: reset mode to 0.
- take umask into account.
- make '=rwx' etc work.
- we wont support crazy but valid modes like "a+rw,g=x,o=g"
- uudecode: use parsemode, mask is 0.

Signed-off-by: Hiltjo Posthuma <>
2014-04-24 11:51:33 +01:00
Hiltjo Posthuma 560340341f make parsemode() generic
use for uudecode and chmod

Signed-off-by: Hiltjo Posthuma <>
2014-04-09 15:40:32 +01:00
Hiltjo Posthuma f7403ce6c6 style: whitespace fixes
Signed-off-by: Hiltjo Posthuma <>
2014-04-01 16:20:43 +01:00
sin b0e4b45e3b No need to use do { } while (0) construct 2014-02-04 16:51:34 +00:00
sin 136f2f3b60 Correct error message in uudecode(1) 2014-02-04 15:20:41 +00:00
sin 71461978f2 Error out on invalid mode in uudecode(1) 2014-02-04 15:19:23 +00:00
sin df035a6a2c Break out fclose() 2014-02-04 15:16:16 +00:00
sin 6da5fb7153 Rename check*() to parse*() to be consistent with the rest of sbase 2014-02-04 15:08:08 +00:00
sin d7383490dc Use chmod() directly 2014-02-04 15:08:02 +00:00
sin bf2b270946 A couple more stylistic changes to uudecode(1) 2014-02-04 14:46:34 +00:00
sin ed9985205b Explicitly check for '\0' at the start and exit early 2014-02-04 14:38:43 +00:00
sin c2db1b9ec6 Remember to fclose(nfp) as well 2014-02-04 14:35:13 +00:00
sin 4d8c3d4dc2 Simplify uudecode(1) and fix some bugs 2014-02-04 14:32:36 +00:00
dsp 7008d751b2 Initial commit of the uudecode tool and man page
Currently it operates only on regular files and does not
support Base64.
2014-02-02 20:50:31 +00:00