1952 Commits (master)

Author SHA1 Message Date
Richard Ipsum 53040766d1 cmp: Make output of error message POSIX compliant

in the POSIX locale the following diagnostic message shall be written:

    "cmp: EOF on %s%s\n", <name of shorter file>, <additional info>

Amended by mcf: kept weprintf for consistency with other diagnostic
messages, but dropped the doubled prefix.
2 months ago
David Demelier 446903d688 libutf: add some const's 2 months ago
Michael Forney 7fc2f68aec libutf: Update to unicode 15.0.0 2 months ago
Greg Reagle df50727a08 refer to re_format(7) for BSDs 2 months ago
Arthur Williams 8dfcbf23b0 cp: don't abort when src and dest file are the same
The POSIX spec gives many options on how to handle this case, but it
also states that cp (and mv) should continue with remaining operands
regardless. We used to exit immediately, which violates the spec.

This change makes cp/mv not exit immediately in this case and
also won't cause the return value to be non-zero.

From `man 1p cp`:
   If source_file references the same file as dest_file, cp may write
   a diagnostic message to standard error; it shall do nothing more
   with source_file and shall go on to any remaining files.
2 months ago
Andrea Calligaris 499c3b1227 sort.1: fix typo 2 months ago
Andrea Calligaris 93f34c1840 ed: Fix 'w' command not respecting '-s' option 2 months ago
Michael Forney fb16e7c6ad dd: Consider block count in inner read loop
When ibs is smaller than obs, checking the block count in the outer
loop is not sufficient; we need to break out of the inner read loop
once we've read the specified number of blocks.

Thanks to phoebos for reporting this issue.
2 months ago
Michael Forney 00995639fe dd: Fix backwards comparison when handling short writes
ipos is always ahead of opos, so the left side of this condition
was never true. This only mattered when we get short writes, since
on EOF we always have less than a full output block, so it takes
only one normal write.
2 months ago
Michael Forney 191f7e693b find: insert -a in before open parens as well
This fixes expressions like -type f '(' -name foo -o -name bar ')'.
8 months ago
Hiltjo Posthuma 63271b47f7 setsid: fix usage information for -f flag 12 months ago
Michael Forney c3e47c1f44 Fix LICENSE name
The license text matches (and has always matched) what is known as
the MIT license[0]. The MIT/X Consortium license, also called the
X11 license, is slightly different and has an additional clause
prohibiting various uses of the X Consortium name.

[0] https://opensource.org/licenses/MIT
1 year ago
Arthur Williams 2c2a7f54ab nohup: Open nohup.out WRONLY
Open nohup.out write-only instead of not specifying the access permissions
instead of getting undefined behavior (which probably results in stdout
not being writable).
2 years ago
Michael Forney 371f3cb5ec find: Flush stdout before executing commands
The commands may produce output themselves, so this is required to
ensure that our -print output is actually written before a command's
output, and also that we don't end up with partially written lines
due to stdout buffering intermixed with the output of other commands.

Other implementations of find(1) do the same.
2 years ago
Michael Forney c331811c91 find: Add spawn helper function 2 years ago
Michael Forney 7d60e2cabb mv: Move on to other files if rename fails with something other than EXDEV 2 years ago
Michael Forney df6599ef78 mv: Only remove source if copy succeeded 2 years ago
Michael Forney 688384568c mv: Prevent successful rename from forgetting past failure 2 years ago
Hiltjo Posthuma 1cc5a57fd7 printf: allow flags for the %s format string aswell
This is useful for example to left-align strings and pad them with spaces.

printf '%-12.12s: %s\n' 'user' "$USER"
2 years ago
Hiltjo Posthuma 61be841f5c tar: check if allocation failed 2 years ago
Michael Forney 3d8481f01d README: Add dd(1) to tool list 2 years ago
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.
2 years ago
Michael Forney 7ef4038fb5 strings: Rename `len` to `min` 2 years ago
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.
2 years ago
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.
3 years ago
Richard Ipsum 172cdd98c3 fold: fix handling of -s 3 years ago
Richard Ipsum cd9f55f5e1 fold: fix handling of multibyte characters 3 years ago
Richard Ipsum db1dc984c3 fold: don't putchar('\n') if last byte is '\n' 3 years ago
Richard Ipsum 0d42b4f3d1 fold: fix handling of \b,\r 3 years ago
Richard Ipsum 75b5499a3a fold: fix tabstop column count 3 years ago
Michael Forney ab53d99375 TODO: sbase-box does not list `install` in command list
Reported by Ethan Sommer
3 years ago
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.
3 years ago
Tait Hoyem 714601b29d ed: Add bytecount print to 'w' command 3 years ago
Hiltjo Posthuma 0df09d5ba0 setsid: add optional -f to force fork() 3 years ago
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).
3 years ago
Michael Forney f1c3fd4e44 Remove unnecessary initializers of recursor members 3 years ago
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.
3 years ago
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

% 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
3 years ago
Michael Forney 9e985c2bb2 install: Unlink destination file on failure 3 years ago
Michael Forney 8ef9b38e56 install: Use fchown to change owner 3 years ago
Richard Ipsum 8c02cf675c nl.1: document pages 3 years ago
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.
3 years ago
Michael Forney 6ff6bb57ce Add implementation of dd(1) 3 years ago
Michael Forney 92f17ad648 paste: Minor style tweaks
Convert for-loop with no initial or continue expression into a

Drop unnecessary parentheses.
3 years ago
Richard Ipsum 2f0b15201d paste: Support -d '\0'
POSIX specifies that -d '\0' sets the delimiter to an empty string.
3 years ago
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.
3 years ago
Michael Forney 6902aad435 Add a bugs section to TODO 3 years ago
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.
3 years ago
Michael Forney fa2f0e09c3 *sum: Ignore -b and -t flags 3 years ago
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.
3 years ago