path is not fixed up on exit from recursive step, this leads to
incorrect paths in du's output.
% find D
D
D/E
D/E/F
D/E/F/a2
D/E/F/b2
D/E/a1
D/E/b1
D/a
D/b
% du D
4 D/E/F
8 D/E
12 D
% ~/sbase/du D
4 D/E/F/b2
8 D/E/b1
12 D
The stack is used for two purposes: storing operators for the
shunting yard algorithm, and storing primitives when arranging the
operators into a tree. The number of operators is bounded by the
number of arguments, since we only insert at most one extra operator
per primitive. However, the number of primitives may be as high as
argc + 1, since -print may have been added implicitly.
This can triggered with an empty expression, `find .`, since in
this case argc is 0, but we still try to store -print in the stack.
Detected with musl's WIP allocator, mallocng-draft.
All install(1) implementations I'm aware of don't try to replicate
the source file node like this. Additionally, this reportedly breaks
some scripts that use install(1) in a pipeline.
These flags are non-POSIX and not useful since the mode of symlinks
is not used for anything.
This prevents a failure when a dangling symlink is encountered
during a recursive chmod.
ISO C does not require that main() have an explicit return value
(if the end of the main function is reached, it is as if it returned
0). However, when built as sbase-box, the main function is turned
into getconf_main, which does not have the same special treatment.
Although mknod is not a POSIX tool, it is widely available on nearly
all UNIX-like systems. It also can be implemented portably apart
from use of the makedev macros, which is already a requirement of
a couple other tools in sbase.
While we're at it, fix a few bugs:
- Include sys/sysmacros.h if makedev was not defined by sys/types.h
- The default mode should respect the user's umask, rather than
assuming it is 022.
- Clear the umask when -m is specified explicitly so that nodes can
be created with permissions wider than the user's umask.
- Utilize parsemode from libutil to support symbolic mode strings.
Fix "new sentence, new line" warnings throughout so that formatters
can produce correct spacing between sentences.
join.1
Remove unnecessary Ns macros. These are not necessary for delimeters,
which get special treatment.
xinstall.1
Fix date in manual. The contents were last modified on 2016-12-03,
so use that instead of the invalid date.
grep.1
Fix escape sequence for `\<` and `\>`.
ed.1
Remove spurious `\\n` escape for the null-command.
The `tflag || argc > 2` if-statement should only apply when not
creating directories (-d). Otherwise, if we are creating more than
two directories, we get an error if the last argument does not
already exist.
To fix this, move the -d case above and return early.
Instead of clearing the format bits before calling parsemode, leave
them in so we can differentiate between directories and other files,
then clear the format bits in the result.
The fallback useful to provide a consistent order of tied lines, but
in check mode, we don't want it to report disorder for equal lines
(according to the passed flags).
Thanks to Richard Ipsum for the bug report and proposed patch.
Currently, if the delimiter is found after the last field of a keydef,
only up to the beginning of the field is considered. This breaks `sort
-k N,N`, as well as whenever the sorted order comes down to that last
field.
Thanks to Richard Ipsum for the bug report and proposed patch.
POSIX only specifies the -H, -L, and -P options for use with -R, and
the default is left to the implementation. Without -R, symlinks must
be followed.
Most implementations use -P as the default with -R, which makes sense
to me as default behavior (the source and destination trees are the same).
Since we use the same code for -R and without it, and we allow -H, -L,
and -P without -R, set the default based on the presence of -R. Without
it, use -L as before, as required by POSIX, and with it, use -P to match
the behavior of other implementations.
Since the first column is not padded on the left, all the others will
not be aligned, so the padding isn't very useful.
POSIX says thet output should have the form
"%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
so just do that.
The previous code was too difficult to decipher for such a simple tool.
Since yes(1) is not specified in any standard and several well-known
implementations only support a single argument, do the same here.
Thanks to everyone who offered implementation suggestions in the
hackers@suckless.org email thread.
Since musl 1.1.23, it too does not provide `major` and `minor` through
sys/types.h, so instead include sys/sysmacros.h based on the absence of
`major` rather than only on glibc.
Thanks to Rich Felker for the suggestion.
A file is executable only if the effective user
have permission to execute it. The real user's
permissions do not matter.
Signed-off-by: Mattias Andrée <maandree@kth.se>