Mirror of Suckless' sbase (git://git.suckless.org/sbase)
Go to file
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
libutf Add mkrunetype.awk 2015-02-23 20:36:47 +01:00
libutil Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
arg.h ARGNUMF() only works on base 10 as it uses strtonum underneath 2015-01-30 16:45:44 +00:00
basename.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
basename.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
cal.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
cal.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
cat.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
cat.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
chgrp.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
chgrp.c Refactor recurse() again 2015-03-19 01:08:19 +01:00
chmod.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
chmod.c Refactor recurse() again 2015-03-19 01:08:19 +01:00
chown.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
chown.c Refactor recurse() again 2015-03-19 01:08:19 +01:00
chroot.1 Finish up chroot(1) and md5sum(1) 2015-01-31 23:54:51 +01:00
chroot.c Don't return but _exit after failed exec*() and fork() 2015-03-09 01:12:59 +01:00
cksum.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
cksum.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
cmp.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
cmp.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
col.1 col: buffer 128 lines by default 2015-03-30 21:48:26 +02:00
col.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
cols.1 Audit cols(1) 2015-03-08 19:49:59 +01:00
cols.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
comm.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
comm.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
compat.h Add compat.h 2014-11-17 15:46:28 +00:00
config.mk Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
cp.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
cp.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
cron.1 cron.1: path macro for /etc/crontab 2015-02-06 15:43:23 +01:00
cron.c Check getline()-return-values properly 2015-03-27 14:49:48 +01:00
crypt.h Refactor cryptcheck() to allow multiple list-files and stdin 2015-03-01 22:51:52 +01:00
cut.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
cut.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
date.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
date.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
dirname.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
dirname.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
du.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
du.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
echo.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
echo.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
env.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
env.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
expand.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
expand.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
expr.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
expr.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
false.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
false.c Simplify true(1) and false(1) 2014-10-03 00:03:08 +01:00
find.1 add find.1, sed.1, time.1 stubs 2015-02-28 13:46:20 +01:00
find.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
fold.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
fold.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
fs.h Audit tar(1), add DIRFIRST-flag to recurse() 2015-03-21 01:30:47 +01:00
grep.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
grep.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
head.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
head.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
hostname.1 Audit hostname(1) 2015-02-28 21:22:55 +01:00
hostname.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
kill.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
kill.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
LICENSE nl: add -d -p -f -h options 2015-03-19 10:10:55 +00:00
link.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
link.c Audit unlink(1) 2015-02-28 20:05:22 +01:00
ln.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
ln.c Audit ln(1) 2015-03-05 21:14:43 +01:00
logger.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
logger.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
logname.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
logname.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
ls.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
ls.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
Makefile Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
md5.h Add crypt.[ch] and update md5sum and sha1sum 2013-07-18 09:51:17 -04:00
md5sum.1 Update *sum(1)-manpages and mark them as finished and audited 2015-03-01 22:59:20 +01:00
md5sum.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
mkdir.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
mkdir.c Three bugfixes in mkdir(1) 2015-03-13 12:23:22 +01:00
mkfifo.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
mkfifo.c Audit mkfifo(1) 2015-03-02 17:25:29 +01:00
mktemp.1 Finish up printenv(1) 2015-02-01 00:23:38 +01:00
mktemp.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
mv.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
mv.c Audit cp() in libutil 2015-03-19 17:57:12 +01:00
nice.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
nice.c Don't return but _exit after failed exec*() and fork() 2015-03-09 01:12:59 +01:00
nl.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
nl.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
nohup.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
nohup.c Don't return but _exit after failed exec*() and fork() 2015-03-09 01:12:59 +01:00
paste.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
paste.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
printenv.1 Finish up printenv(1) 2015-02-01 00:23:38 +01:00
printenv.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
printf.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
printf.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
pwd.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
pwd.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
queue.h Use queue.h in grep(1) 2014-11-16 12:39:15 +00:00
readlink.1 Audit readlink(1) 2015-03-20 22:14:31 +01:00
readlink.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
README POSIX 2013 audit 2015-03-27 17:25:22 +01:00
renice.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
renice.c Audit renice(1) 2015-03-17 22:15:09 +01:00
rm.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
rm.c Refactor recurse() again 2015-03-19 01:08:19 +01:00
rmdir.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
rmdir.c Add argv0 to usage() in rmdir.c 2015-03-02 16:24:08 +01:00
sed.1 add find.1, sed.1, time.1 stubs 2015-02-28 13:46:20 +01:00
sed.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
seq.1 Audit seq(1) 2015-03-20 16:05:31 +01:00
seq.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
setsid.1 Finish up setsid(1) 2015-02-01 00:47:32 +01:00
setsid.c fork: no need to _exit() on the error case 2015-03-10 20:05:18 +01:00
sha1.h Add crypt.[ch] and update md5sum and sha1sum 2013-07-18 09:51:17 -04:00
sha1sum.1 Update *sum(1)-manpages and mark them as finished and audited 2015-03-01 22:59:20 +01:00
sha1sum.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
sha256.h Add sha256sum(1) 2013-07-20 13:20:16 -04:00
sha256sum.1 Update *sum(1)-manpages and mark them as finished and audited 2015-03-01 22:59:20 +01:00
sha256sum.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
sha512.h Add sha512sum(1) 2013-08-04 11:00:34 -04:00
sha512sum.1 Update *sum(1)-manpages and mark them as finished and audited 2015-03-01 22:59:20 +01:00
sha512sum.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
sleep.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
sleep.c Audit sleep(1) 2015-02-28 20:10:25 +01:00
sort.1 Add -m and -o flags to sort(1) 2015-03-22 23:39:48 +01:00
sort.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
split.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
split.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
sponge.1 Refactor sponge(1) code and manpage 2015-02-08 22:17:21 +01:00
sponge.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
strings.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
strings.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
sync.1 Refactor sync(1) code and manpage 2015-02-08 22:08:14 +01:00
sync.c fix some signed/unsigned warnings and style fixes 2015-03-27 22:48:05 +01:00
tail.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
tail.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
tar.1 Audit tar(1), add DIRFIRST-flag to recurse() 2015-03-21 01:30:47 +01:00
tar.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
tee.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
tee.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
test.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
test.c Audit test(1) 2015-03-17 23:35:11 +01:00
text.h Use size_t for number of lines in linebuf 2015-01-31 22:49:43 +00:00
time.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
time.c fork: no need to _exit() on the error case 2015-03-10 20:05:18 +01:00
TODO Revert "Add command(1) to TODO" 2015-04-03 19:37:07 +01:00
touch.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
touch.c Audit touch(1) 2015-03-17 23:38:09 +01:00
tr.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
tr.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
true.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
true.c Simplify true(1) and false(1) 2014-10-03 00:03:08 +01:00
tty.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
tty.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
uname.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
uname.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
unexpand.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
unexpand.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
uniq.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
uniq.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
unlink.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
unlink.c Audit unlink(1) 2015-02-28 20:05:22 +01:00
utf.h Scrap chartorunearr(), introducing utftorunestr() 2015-02-11 21:32:09 +01:00
util.h Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
uudecode.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
uudecode.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
uuencode.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
uuencode.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
wc.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
wc.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
xargs.1 POSIX 2013 audit 2015-03-27 17:25:22 +01:00
xargs.c Add *fshut() functions to properly flush file streams 2015-04-05 09:13:56 +01:00
yes.1 Finish up yes(1) by adding multiple string support 2015-02-01 02:13:47 +01:00
yes.c Make already audited tools argv-centric instead of argc-centric 2015-03-02 14:19:26 +01:00

sbase - suckless unix tools
===========================

sbase  is a  collection of  unix  tools that  are inherently  portable
across UNIX and UNIX-like systems.

The following tools are implemented:

'#'  -> UTF-8 support, '=' -> Implicit UTF-8 support, '*' -> Finished,
'|'  -> Audited,       'o' -> POSIX 2013 compliant,   'x' -> Non-POSIX,
'()' -> Petty flag

     UTILITY     MISSING FLAGS
     -------     -------------
=*|o basename    .
=*|o cal         .
=*|o cat         .
=*|o chgrp       .
=*|o chmod       .
=*|o chown       .
=*|x chroot      .
=*|o cksum       .
=*|o cmp         .
#*|x cols        .
#*|x col         .
=*|o comm        .
=*|o cp          (-i)
=*|x cron        .
#*|o cut         .
=*|o date        .
=*|o dirname     .
=*|o du          .
=*|o echo        .
=*|o env         .
#*|o expand      .
#*|o expr        .
=*|o false       .
=    find        .
#*|o fold        .
=* o grep        .
=*|o head        .
=*|x hostname    .
=*|o kill        .
=*|o link        .
=*|o ln          .
=*|o logger      .
=*|o logname     .
#* o ls          (-C, -k, -m, -p, -s, -x)
=*|x md5sum      .
=*|o mkdir       .
=*|o mkfifo      .
=*|x mktemp      .
=*|o mv          (-i)
=*|o nice        .
#*|o nl          .
=*|o nohup       .
#*|o paste       .
=*|x printenv    .
#*|o printf      .
=*|o pwd         .
=*|x readlink    .
=*|o renice      .
=*|o rm          (-i)
=*|o rmdir       .
#    sed         .
=*|x seq         .
=*|x setsid      .
=*|x sha1sum     .
=*|x sha256sum   .
=*|x sha512sum   .
=*|o sleep       .
     sort        -d, -f, -i
=*|o split       .
=*|x sponge      .
#*|o strings     .
=*|x sync        .
=*|o tail        .
=*|x tar         .
=*|o tee         .
=*|o test        .
=*|o time        .
=*|o touch       .
#*|o tr          .
=*|o true        .
=*|o tty         .
=*|o uname       .
#*|o unexpand    .
=*|o uniq        .
=*|o unlink      .
=*|o uudecode    .
=*|o uuencode    .
#*|o wc          .
=*|o xargs       (-p)
=*|x yes         .

The  complement of  sbase  is  ubase[1] which  is  Linux-specific  and
provides all  the non-portable tools.   Together they are  intended to
form a base system similar to busybox but much smaller and suckless.

Building
--------

To  build sbase,  simply  type  make.  You  may  have  to fiddle  with
config.mk depending on your system.

You  can  also  build  sbase-box,  which  generates  a  single  binary
containing  all  the  required  tools.    You  can  then  symlink  the
individual tools to sbase-box or run: make sbase-box-install

Ideally you will  want to statically link sbase.  If  you are on Linux
we recommend using musl-libc[2].

Portability
-----------

sbase has been  compiled on a variety of  different operating systems,
including Linux, *BSD, OSX, Haiku, Solaris, SCO OpenServer and others.

Various combinations of operating  systems and architectures have also
been built.

You can build sbase with gcc, clang, tcc, nwcc and pcc.

[1] http://git.suckless.org/ubase/
[2] http://www.musl-libc.org/