Commit Graph

35 Commits

Author SHA1 Message Date
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
sin
84924d050e Add info about NetBSD to config.mk 2015-02-20 16:24:17 +00:00
Roberto E. Vargas Caballero
19fb7f115d Add -lrt switch
find(1) uses clock_gettime which in some systems needs -lrt.
2015-02-20 13:46:49 +00:00
sin
ce86a05f36 Import strcasestr() from musl and remove -D_GNU_SOURCE 2014-11-20 23:46:06 +00:00
sin
74ac827587 Require GNU make to build sbase
We seem to have problems building individual tools across various
make implementations.  If anyone can step up and fix this we will
remove the dependency on GNU make.
2014-11-17 13:54:24 +00:00
sin
0d0624b855 Use $(RANLIB) in Makefile 2014-11-17 12:24:03 +00:00
sin
e1c044e298 Do not append CPPFLAGS to CFLAGS 2014-11-17 10:38:37 +00:00
sin
9a9d6bb0dc Make build process more verbose 2014-11-17 10:36:39 +00:00
Evan Gates
0810c61154 add -D_DEFAULT_SOURCE to placate gcc 2014-11-14 10:37:52 +00:00
sin
a8c31586c5 Revert "config.mk: make cc the default $CC"
This reverts commit d2b527e369685606f812233a24dab12188d8930c.
2014-11-11 18:17:26 +00:00
Hiltjo Posthuma
603d86f276 config.mk: make cc the default $CC 2014-11-10 23:56:10 +00:00
sin
07dd658f0d Use -std=c99 by default
Note, the code is largely c89 clean.  This is to avoid certain
warnings on some systems (OSX).
2014-05-31 17:56:34 +01:00
sin
f8a216a18c Add -D_GNU_SOURCE to config.mk for tcc 2014-04-29 22:31:16 +01:00
sin
71cbd12ede Revert "Fix relocation error on OpenBSD (amd64) when compiling with pcc"
This reverts commit 06d43e4832.

Let's stick to the most basic and common options for the default
case.
2013-12-21 13:39:29 +00:00
sin
06d43e4832 Fix relocation error on OpenBSD (amd64) when compiling with pcc
ld: util.a(eprintf.o): relocation R_X86_64_32S can not be used when making a shared object; recompile with -fPIC
util.a: could not read symbols: Bad value
*** Error 1 in . (Makefile:114 'basename': @pcc -o basename basename.o util.a -g)
*** Error 1 in /home/sin/repos/sbase (Makefile:104 'binlib')
2013-10-28 10:45:11 +00:00
sin
9e5718282a Add sha512sum(1) 2013-08-04 11:00:34 -04:00
Christoph Lohmann
f8dc6883a3 Style inquistion for util and some tools. 2013-03-05 21:46:48 +01:00
Connor Lane Smith
146cca114e new ARGBEGIN & usage() function 2012-05-14 21:28:41 +01:00
William Haddon
cec53d14b1 implement cp and mv and improve rm 2012-01-30 22:41:33 +00:00
Connor Lane Smith
cb291cc394 add test.c (thanks Random832) 2011-11-08 19:35:38 +01:00
Connor Lane Smith
d7f9bda740 cc -Wextra 2011-06-21 05:05:37 +01:00
Connor Lane Smith
2404eb5b6b add todo 2011-06-08 17:54:55 +01:00
Connor Lane Smith
1e4a4e460d make (un)install 2011-06-08 11:37:00 +01:00
Connor Lane Smith
b5ff71655d recurse: ignore links 2011-06-04 14:30:54 +01:00
Connor Lane Smith
726973dcd5 glibc hates stripping 2011-06-01 21:31:22 +01:00
Connor Lane Smith
430b453c4d add nl 2011-05-29 21:30:44 +01:00
Connor Lane Smith
a9c970b973 add mkfifo 2011-05-25 11:00:15 +01:00
Connor Lane Smith
4fc1ad22ad posix 2 hates symlinks 2011-05-24 19:22:28 +01:00
Connor Lane Smith
a07ea108ad c99 2011-05-24 19:14:46 +01:00
Connor Lane Smith
5e6e00121e no bsd macro 2011-05-24 19:09:50 +01:00
Connor Lane Smith
f458397d5a no, getopt.h is gnu specific 2011-05-24 18:58:36 +01:00
pancake
da547fb294 add missing #include <getopt.h>
do not override CC in config.mk
2011-05-24 14:34:26 +02:00
Connor Lane Smith
fbb80983ce add ln, util.a 2011-05-24 13:00:30 +01:00
Connor Lane Smith
474ee643ed add sleep & date, thanks kamil 2011-05-23 19:00:31 +01:00
Connor Lane Smith
8e26716a5a initial commit 2011-05-23 02:36:34 +01:00