sbase/libutil
FRIGN 3111908b03 Refactor recurse() again
Okay, why yet another recurse()-refactor?
The last one added the recursor-struct, which simplified things
on the user-end, but there was still one thing that bugged me a lot:
Previously, all fn()'s were forced to (l)stat the paths themselves.
This does not work well when you try to keep up with H-, L- and P-
flags at the same time, as each utility-function would have to set
the right function-pointer for (l)stat every single time.

This is not desirable. Furthermore, recurse should be easy to use
and not involve trouble finding the right (l)stat-function to do it
right.
So, what we needed was a stat-argument for each fn(), so it is
directly accessible. This was impossible to do though when the
fn()'s are still directly called by the programs to "start" the
recurse.
Thus, the fundamental change is to make recurse() the function to
go, while designing the fn()'s in a way they can "live" with st
being NULL (we don't want a null-pointer-deref).

What you can see in this commit is the result of this work. Why
all this trouble instead of using nftw?
The special thing about recurse() is that you tell the function
when to recurse() in your fn(). You don't need special flags to
tell nftw() to skip the subtree, just to give an example.

The only single downside to this is that now, you are not allowed
to unconditionally call recurse() from your fn(). It has to be
a directory.
However, that is a cost I think is easily weighed up by the
advantages.

Another thing is the history: I added a procedure at the end of
the outmost recurse to free the history. This way we don't leak
memory.

A simple optimization on the side:

-		if (h->dev == st.st_dev && h->ino == st.st_ino)
+		if (h->ino == st.st_ino && h->dev == st.st_dev)

First compare the likely difference in inode-numbers instead of
checking the unlikely condition that the device-numbers are
different.
2015-03-19 01:08:19 +01:00
..
concat.c Audit concat() in libutil 2015-03-18 22:58:42 +01:00
cp.c Remove apathmax() and implicitly agetcwd() 2015-03-18 15:20:35 +01:00
crypt.c Make already audited tools argv-centric instead of argc-centric 2015-03-02 14:19:26 +01:00
ealloc.c add estrndup 2015-02-11 01:17:21 +00:00
enmasse.c Remove apathmax() and implicitly agetcwd() 2015-03-18 15:20:35 +01:00
eprintf.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
eregcomp.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
estrtod.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
fnck.c Refactor enmasse() and recurse() to reflect depth 2015-03-02 22:50:38 +01:00
getlines.c Make getlines() less verbose 2015-02-12 14:34:07 +00:00
human.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
md5.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
mode.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
putword.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
reallocarray.c Implement mallocarray() 2015-03-10 22:19:19 +01:00
recurse.c Refactor recurse() again 2015-03-19 01:08:19 +01:00
rm.c Refactor recurse() again 2015-03-19 01:08:19 +01:00
sha1.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
sha256.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
sha512.c Rename util/ to libutil/ 2014-11-17 16:48:34 +00:00
strcasestr.c Argh - include strings.h 2014-11-21 00:03:30 +00:00
strlcat.c Add estrlcat() and estrlcpy() 2015-03-17 11:24:49 +01:00
strlcpy.c Add estrlcat() and estrlcpy() 2015-03-17 11:24:49 +01:00
strsep.c Import strsep() from musl libc 2015-01-25 17:48:11 +00:00
strtonum.c Use strtonum and libutf in test(1), refactor code and manpage 2015-02-09 22:21:23 +01:00
unescape.c Add \e, \", \' and hex-escapes (\xH[H]) to unescape() 2015-02-14 22:55:37 +01:00