Commit Graph

1914 Commits

Author SHA1 Message Date
Michael Forney
9e985c2bb2 install: Unlink destination file on failure 2020-05-24 20:58:36 -07:00
Michael Forney
8ef9b38e56 install: Use fchown to change owner 2020-05-24 20:56:50 -07:00
Richard Ipsum
8c02cf675c nl.1: document pages 2020-05-15 02:52:26 -07:00
Michael Forney
e6b6f34506 find: Fix buffer overflow in token stack
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.
2020-05-12 20:01:43 -07:00
Michael Forney
6ff6bb57ce Add implementation of dd(1) 2020-05-12 19:58:21 -07:00
Michael Forney
92f17ad648 paste: Minor style tweaks
Convert for-loop with no initial or continue expression into a
while-loop.

Drop unnecessary parentheses.
2020-04-15 16:13:22 -07:00
Richard Ipsum
2f0b15201d paste: Support -d '\0'
POSIX specifies that -d '\0' sets the delimiter to an empty string.
2020-04-15 16:11:12 -07:00
Michael Forney
28063c02f4 libutf: Change return type of utftorunestr to size_t
It returns the size of the rune array, so size_t is the right type
to use here.
2020-04-07 01:25:22 -07:00
Michael Forney
6902aad435 Add a bugs section to TODO 2020-04-05 20:02:15 -07:00
Michael Forney
2b8f1ee3a6 install: Remove special handling for non-regular files
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.
2020-03-21 12:27:00 -07:00
Michael Forney
fa2f0e09c3 *sum: Ignore -b and -t flags 2020-03-05 00:45:53 -08:00
Michael Forney
edbcc223ea libutil/recurse: Use a single path buffer, and directory fd
This way, we don't use PATH_MAX bytes on the stack per path component,
and don't have to keep copying the complete path around.
2020-03-05 00:45:53 -08:00
Michael Forney
039b54aa51 Use *at functions with appropriate flags instead of lstat/lchown 2020-03-05 00:45:53 -08:00
Michael Forney
3e160b616a chmod: Remove -HLP flags, and ignore symlinks during traversal
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.
2020-03-05 00:45:44 -08:00
Michael Forney
4fcb31c6e0 TODO: ed(1) has a man page since 370e0ae675 2020-03-01 16:55:13 -08:00
Ethan Sommer
39ae2ae60f getconf.sh: remove unnecessary use of cat(1) 2020-03-01 16:47:15 -08:00
Michael Forney
eb74f374f2 getconf: Add an explicit return at the end of main
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.
2020-03-01 16:40:01 -08:00
Michael Forney
4542db4e40 mknod: Add support for making FIFOs 2020-03-01 16:33:18 -08:00
Michael Forney
ba2f04f391 mknod: Use a switch statement for the node type 2020-03-01 16:33:18 -08:00
Michael Forney
e5d8efb32f Import mknod from ubase
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.
2020-03-01 16:33:11 -08:00
Michael Forney
22921a859f Fix various lint warnings in manuals
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.
2020-03-01 15:32:11 -08:00
Michael Forney
dbbac61fc4 sed: Include filename in error message 2020-02-20 21:49:11 -08:00
Michael Forney
71154d42aa sed: Simplify next_file slightly 2020-02-20 21:47:26 -08:00
Michael Forney
5cf4544f2c sed: Exit with failure if open failed 2020-02-20 21:26:38 -08:00
Michael Forney
971c573e87 sed: Fix typo 2020-01-13 01:42:06 -08:00
Michael Forney
5c63ffad33 install: Fix -d with more than two directories
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.
2020-01-11 02:19:26 -08:00
Michael Forney
f3d05ffd0a chmod: Implement X perm symbol
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.
2020-01-06 13:47:26 -08:00
Michael Forney
e5284b1537 sort: Don't do fallback top-level sort in check mode
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.
2020-01-03 15:42:33 -08:00
Michael Forney
e9bfb97808 sort: Consider end field in keydef when additional fields are present
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.
2020-01-01 12:23:48 -08:00
Michael Forney
a8dc42e6b5 ed: Use reallocarray 2019-12-31 13:41:38 -08:00
Michael Forney
d4634f6740 libutil/getlines: Use reallocarray 2019-12-31 13:39:08 -08:00
Richard Ipsum
57c9cab849 sort: Fix string length update math 2019-12-31 13:32:25 -08:00
Michael Forney
60895834f0 libutil/recurse: Use while-loop instead of for-loop with only condition 2019-12-28 22:38:17 -08:00
Michael Forney
f4b9b966cf cp: Default to -P when -R is specified
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.
2019-12-21 21:26:19 -08:00
Michael Forney
61f5d4887a wc: Removing output padding
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.
2019-12-21 20:19:08 -08:00
Michael Forney
27f3ca6063 wc: Remove unnecessary precision specifier in format strings
The default precision for 'u' conversions is 1, so we don't need to
specify it in the format string.
2019-11-02 14:03:10 -07:00
Michael Forney
abf068492e wc: Set flag defaults if none were specified 2019-11-02 14:03:10 -07:00
Michael Forney
45b9b26cae libutil/recurse: Remove some unnecessary parentheses 2019-11-02 14:03:10 -07:00
Michael Forney
c5c8c7ff86 libutil/mode: Remove unnecessary octal-to-mode conversion
The values of the file mode macros are specified explicitly by POSIX,
so we can just use the octal value directly.
2019-11-01 19:07:10 -07:00
Michael Forney
b29fc0b05f chgrp: Pass -1 as the owner ID to chown(3)
Otherwise, if the owner ID changes between stat() and chown(), we will
revert to the previous owner while changing the group.
2019-11-01 19:03:00 -07:00
Michael Forney
71ba97c175 chmod: Clear the S_IFMT bits before calling chmod 2019-11-01 01:58:54 -07:00
Michael Forney
4f1d0df755 yes: Simplify, only support one argument
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.
2019-10-31 18:14:18 -07:00
Michael Forney
39f92650d3 ls, tar: Guard inclusion of sys/sysmacros.h by absence of major definition
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.
2019-08-05 14:38:32 -07:00
Mattias Andrée
7315b8686f which: check AT_EACCESS
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>
2019-07-30 07:40:35 -07:00
Mattias Andrée
be34c4a24d which: remove unnecessary third parameter in O_RDONLY call to open(3)
Signed-off-by: Mattias Andrée <maandree@kth.se>
2019-07-29 18:49:14 -07:00
Richard Ipsum
9719a7e3d2 chgrp: parse gid if operand is not group name
[Michael Forney: Removed unnecessary `gid == -1` check, changed *argv
 to argv[0] to match existing code]
2019-07-08 14:07:08 -07:00
Richard Ipsum
dc77c5968b chown/chgrp: chown target not symlink by default
chown on a symlink should only chown the symlink itself when -h
is specified, when no options are provided the target should be chown'd.
2019-07-03 22:33:06 -07:00
Michael Forney
a0fae71977 Don't justify text in README 2019-06-30 13:17:17 -07:00
Michael Forney
adcdc1b308 Move utility status to its own section at the end of README
This way the important information can be found easily at the top.
2019-06-30 13:13:07 -07:00
Michael Forney
d7714c84b5 Remove unnecessary ';' after ARGEND 2019-06-29 18:39:07 -07:00