Commit Graph

1940 Commits

Author SHA1 Message Date
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
Stephen Gregoratto c30255e50a Fix typo 2018-11-21 10:45:43 -08:00
David Phillips 99c7876310 On glibc, include sysmacros.h directly
On glibc, major, minor, and makedev are all defined in
sys/sysmacros.h with types.h only including this for historical
reasons. A future release of glibc will remove this behaviour,
meaning that major, minor, and makedev will no longer be defined
for us without including sysmacros.h.
2018-09-25 19:31:01 -07:00
Michael Forney 48d04ae446 find: Make -H and -L flag handling clearer 2018-09-25 19:16:19 -07:00
Mattias Andrée d8656b0189 uname: check that no operands are specified
Signed-off-by: Mattias Andrée <maandree@kth.se>
2018-09-24 13:04:06 -07:00
Firas Khalil Khana a1627b9419 ed: Changed delimiter to fix unterminated TODO comment 2018-09-23 11:02:31 +02:00
Roberto E. Vargas Caballero 6d3f18c821 ed: Add more bugs to TODO 2018-09-20 10:54:21 +02:00
Mattias Andrée 7441770cfd tty: fix exit value on error from 1 to 2
Signed-off-by: Mattias Andrée <maandree@kth.se>
2018-07-07 12:18:50 +01:00
Mattias Andrée 084b46ac51 dirname: support --
POSIX-2017 clarifies that -- and normal option parsing must be supported.
See EXAMPLES in basename(1p)

Signed-off-by: Mattias Andrée <maandree@kth.se>
2018-07-07 12:16:15 +01:00
Mattias Andrée 1d885159f2 basename: support --
POSIX-2017 clarifies that -- and normal option parsing must be supported.
See EXAMPLES in basename(1p).

Signed-off-by: Mattias Andrée <maandree@kth.se>
2018-07-07 12:16:11 +01:00
Roberto E. Vargas Caballero f45156d5b4 Simplify expression in makeline()
This expression was wrong, but it was causing a false positive
in some compilers that couldn't see that error() cannot return.
The actual problem of the line is that it was too complex and it is better
to split it in simplex expressions.
2018-07-03 09:31:46 +01:00