Commit Graph

1900 Commits

Author SHA1 Message Date
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
Michael Forney
d2824f5294 Revert "Do not use arg.h for tools which take no flags"
This reverts commit 9016d288f1.

Tools that have no options are required by POSIX to support "--" so
that conforming applications have a way to shield their operands from
implementations that provide options as an extension.

echo(1) is just an exception, so it is handled specially.

See OPTIONS in https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/V3_chap01.html#tag_17_04
2019-06-29 18:33:48 -07:00
Michael Forney
9ae6c45097 Add .gitignore
Also, add rule to regenerate in case executable list changes.
2019-06-28 00:10:10 -07:00
Michael Forney
01b5105e0c mkfifo: Simplify -m handling
Rather than create the FIFO with incorrect permissions at first, then
restore with chmod(2), just clear the umask when -m is specified, and
pass the parsed mode to mkfifo(2).
2019-06-13 13:45:37 -07:00
Michael Forney
9a17de569a sed: Print better error message when open fails 2019-06-13 13:08:16 -07:00
Richard Ipsum
2ee4c13433 mkfifo: Set initial mode
From POSIX:

In the symbolic_mode strings, the op characters '+' and '-'
shall be interpreted relative to an assumed initial mode of
a=rw.
2019-06-13 13:07:20 -07:00
Michael Forney
eeedfd87e5 libutil: Rename functions in reserved namespace to prevent potential conflict
libc may define functions with the same names, but differing in prototype.
2019-05-20 16:56:07 -07:00
Richard Ipsum
036449cdf1 grep: Fix exit status on use of -l 2019-05-20 12:38:54 -07:00
Richard Ipsum
5b92551057 cal: Centre month and year above calendar 2019-04-28 14:10:38 -07:00
Richard Ipsum
aae808fe5b cal: Fix grid alignment for years < 1000 2019-04-22 19:08:17 -07:00
Michael Forney
ef9f6f359a expr: Allocate arrays with reallocarray instead of VLA
The length of these arrays is user input, and this is the only use of
VLAs in sbase.
2019-04-16 17:44:08 -07:00
Michael Forney
3fec3e2f4c libutil: Add enreallocarray 2019-04-16 17:41:39 -07:00
Michael Forney
5d49332d4f libutf: Adjust runelen prototype to match definition
The `const` isn't useful here.
2019-04-16 17:27:38 -07:00
Richard Ipsum
09c2311b3a date: Fix default format string
From POSIX:

When no formatting operand is specified, the output in the POSIX
locale shall be equivalent to specifying:

           date "+%a %b %e %H:%M:%S %Z %Y"
2019-04-12 19:40:34 -07:00
Michael Forney
6b950e436b sort: Use regular double for -n
`long double` may require software emulation and the (possible) extra
precision is unnecessary here.
2019-03-13 11:59:33 -07:00