Commit Graph

1931 Commits

Author SHA1 Message Date
Michael Forney 4b76652eff dd: Always move excess to beginning of buffer after read/write loops
Otherwise, while we may have enough room for at least one input
block, we may not have enough room for an output block.
2021-05-21 12:16:41 -07:00
Michael Forney 7ef4038fb5 strings: Rename `len` to `min` 2021-01-14 21:46:30 -08:00
Michael Forney 5377a9c3d1 strings: Print strings that have the minimum length
Previously, there was an off-by-one error when determining whether
to print a strings, so when the string was exactly the minimum
length, it was not printed.

This fixes a bug with an x264 configure test, which expects to find
a string of length 4 (BIGE/EBIG) to detect system endianness.
2021-01-14 21:46:26 -08:00
Cág 3eb89c44aa ed: Fix double-free
After join() is called for the first time, s.str is left pointing
to a string that was just freed. Upon the second call to join(),
it is freed again at the start of the function.

Since the string is reset on every function call, there is no reason
for it to be static, so just replace the initial free with assignment
to NULL.
2020-10-19 14:50:47 -07:00
Richard Ipsum 172cdd98c3 fold: fix handling of -s 2020-10-14 15:03:20 -07:00
Richard Ipsum cd9f55f5e1 fold: fix handling of multibyte characters 2020-10-14 15:03:20 -07:00
Richard Ipsum db1dc984c3 fold: don't putchar('\n') if last byte is '\n' 2020-10-14 15:03:20 -07:00
Richard Ipsum 0d42b4f3d1 fold: fix handling of \b,\r 2020-10-14 15:03:20 -07:00
Richard Ipsum 75b5499a3a fold: fix tabstop column count 2020-10-14 15:03:20 -07:00
Michael Forney ab53d99375 TODO: sbase-box does not list `install` in command list
Reported by Ethan Sommer
2020-09-18 19:58:22 -07:00
Michael Forney a139474486 ed: Use fwrite to write lines instead of fputs
We already have the length of the line, so there is no point in
recalculating it before printing.
2020-09-18 19:58:22 -07:00
Tait Hoyem 714601b29d ed: Add bytecount print to 'w' command 2020-09-18 19:58:22 -07:00
Hiltjo Posthuma 0df09d5ba0 setsid: add optional -f to force fork() 2020-07-25 13:48:46 -07:00
Cem Keylan 991ff90064 remove sbase-box from PHONY
I have noticed this issue while I was trying to package sbase-box. Since
sbase-box was in the PHONY target, running sbase-box-install caused it to
be rebuilt when it was unnecessary. This also caused options passed to make
to be lost (such as LDFLAGS).
2020-07-03 13:18:23 -07:00
Michael Forney f1c3fd4e44 Remove unnecessary initializers of recursor members 2020-06-23 02:20:41 -07:00
Michael Forney fdb9084da9 libutil/recurse: Simplify adding trailing slash
We know that r->pathlen < sizeof(r->path) since r->path is
nul-terminated, so we can safely add a '/' here. If there is no
space left over for the rest of the path and nul-terminator, this
will be caught by the subsequent estrlcpy.
2020-06-20 18:48:14 -07:00
Richard Ipsum 5c76e79f41 du: recurse: fix path
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
2020-06-20 18:48:14 -07:00
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