Commit Graph

22 Commits

Author SHA1 Message Date
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
Eivind Uggedal
93043beec9 readlink: simplify -f
Use output from realpath(3) directly. This makes usage
with . more consistent with other implementations.
2015-06-04 23:54:09 +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
a531865fe5 Audit readlink(1)
1) Properly document e, f and m-flags in the manpage.
2) Clear up the code for the m-flag-handling. Add idiomatic
   '/'-path-traversal as already seen in mkdir(1).
3) Unwrap the SWAP_BUF()-macro.
4) BUGFIX: Actually handle the f-flag properly. Only resolve
   the dirname and append the basename later.
5) Use fputs() instead of printf("%s", ...).
2015-03-20 22:14:31 +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
8f436abde6 style: document intentional fallthrough 2015-03-09 00:33:13 +01:00
Hiltjo Posthuma
6c7ff5fda5 code-style: unindent one level of switch 2015-02-20 13:29:38 +01:00
FRIGN
31572c8b0e Clean up #includes 2015-02-14 21:12:23 +01:00
sin
6d4a7989cd readlink: Use eprintf() to report errors 2015-02-11 11:58:13 +00:00
sin
3f3e15b314 readlink: Use strlcat() instead of strncat() 2015-02-11 11:51:57 +00:00
Tai Chi Minh Ralph Eastwood
28e26bc688 readlink: add -m and -f flags 2015-02-11 10:56:58 +00:00
FRIGN
7faf732d0b Edit readlink.1 and document missing flags 2015-02-01 00:43:43 +01:00
sin
88a6d6f97e State the reason for failure in readlink(1) 2014-12-04 12:14:59 +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
ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +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
b5a511dacf Exit with EXIT_SUCCESS/EXIT_FAILURE instead of 0 and 1
Fixed for consistency purposes.
2013-10-07 16:44:22 +01:00
sin
83c2c3d1f5 Add 'not implemented' errors for unimplemented flags
These used to live in TODO but we got rid off them.  Make sure
we keep track of what we want to support by printing a message
when those flags are unimplemented.
2013-10-05 13:51:45 +01:00
David Galos
7adf4f380a Fixing zero-bye append in readlink. Thanks, Willem van de Krol 2013-07-09 19:40:28 -04:00
stateless
7216a53a7e Remove unnecessary exit(1) in usage()
Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-06-19 19:58:19 +02:00
stateless
f66b47bc6f Add readlink
Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-06-16 07:46:01 +02:00