Commit Graph

2627 Commits

Author SHA1 Message Date
Roberto E. Vargas Caballero 8ca12835a5 build: Remove .gitignore rule
It is not needed because it is just easier to maintain
the gitignore file.
2023-09-27 06:37:38 +02:00
Roberto E. Vargas Caballero d3780956a9 ed: Deal signals in a reliable way
The signal handlers were calling longjmp() but as the code was calling
non signal safe functions the behaviour was very unpredictable generating
segmentation faults and dead lock. This commit changes the signal handlers
to only set a variable that is checked in safe places where long loops
happen.
2023-09-26 11:33:45 +02:00
Rene Kita 95b9603975 Ensure commands are followed by a blank
POSIX.1-2017 demands in Shell & Utilities under 'Commands in ed':
The e, E, f, r, and w commands shall take an optional file parameter,
separated from the command letter by one or more <blank> characters.

Ensure at least one <blank> character (as defined for the POSIX locale)
is present or error out.

Signed-off-by: Rene Kita <mail@rkta.de>
2023-09-26 10:50:15 +02:00
Markus Rudy a015607af0 Explicitly include sys/sysmacros.h for makedev etc
This header used to be included by sys/types.h in glibc, and musl
adopted the behaviour. However, this dependency was never desired, so
glibc deprecated it in 2016 and finally removed it in 2019, and so did
musl. Explicitly including the header should be a no-op on older libc
versions and fixes the build on newer versions.

https://sourceware.org/bugzilla/show_bug.cgi?id=19239
https://git.musl-libc.org/cgit/musl/commit/?id=f552c79
2023-09-26 09:22:32 +02:00
Roberto E. Vargas Caballero 67a00c86f9 ed: Open output file for writing
Fopen() and Popen() were open as read streams, but we were writing
in both cases. In the same way, the FILE pointer returned by popen()
was close with fclose() that can lead to file descriptor leaks and
zombie processes.
2023-09-22 20:45:38 +02:00
Roberto E. Vargas Caballero feeb6e3279 ed: Don't discard full lines
Discard() was reading stdin until a new line was found, but in
case of having an empty line in the input buffer then it didn't
make sense because we were just discarding the full next line.
2023-09-22 20:44:17 +02:00
Roberto E. Vargas Caballero 2cbf61dff9 xargs: Read full lines is -I
POSIX specifies that when -I is used then arguments are delimited
only by newlines.
2023-09-22 14:19:36 +02:00
Roberto E. Vargas Caballero fc85dc819d xargs: Free argument before substitution
strnsubst() allocates a new array always, indepently of
the number of occurences of the replace string.
2023-09-22 14:18:14 +02:00
Roberto E. Vargas Caballero a1f0426699 xargs: Apply -I substitution to all the parameters
The substitution must happen in all the parameters that contain
the replacement string, but the code was soing the substitution
only once and in the parameter with an exact match.
Also, the argument length was not updated correctly, assuming
that the final argument had the size read from stdin.
2023-09-22 11:45:46 +02:00
Roberto E. Vargas Caballero 22f110db28 libutil: Remove free() from strnsub()
The free() was added in the wrong assumption that xargs was not
freeing the argument in the position replaced, but it actually
does it.

Also, removing the call to free() makes more general the function.
2023-09-22 11:44:58 +02:00
Roberto E. Vargas Caballero 4e8a096b1c xargs: Update the man page about -I 2023-09-22 10:54:08 +02:00
Roberto E. Vargas Caballero b3a8052634 xargs: Add -x when -I is used
POSIX mandates to use -x when -I is used.
2023-09-22 10:37:18 +02:00
sewn 8d97acc135 xargs: add replace string flag (-I) 2023-09-22 10:34:36 +02:00
noneofyourbusiness f14887c765 tr: fix behavior of cflag when using character classes
a simple test case:

printf ab3 | tr -c '[:alpha:]' '\n'

output should be ab<newline>, previously you would find just newlines.

Signed-off-by: noneofyourbusiness <noneofyourbusiness@danwin1210.de>
2023-09-21 15:27:01 +02:00
Heiko Berges 0b4c2ceb2f ed: Add support for ! in w command
When the file name begins with ! then the addressed buffer content is
piped to the name of the file that is considered a command that is
executed in a shell.
2023-09-21 15:14:16 +02:00
Richard Ipsum 53040766d1 cmp: Make output of error message POSIX compliant
From POSIX:

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.
2023-04-12 21:37:04 -07:00
David Demelier 446903d688 libutf: add some const's 2023-04-12 21:22:28 -07:00
Michael Forney 7fc2f68aec libutf: Update to unicode 15.0.0 2023-04-12 21:20:56 -07:00
Greg Reagle df50727a08 refer to re_format(7) for BSDs 2023-04-12 21:16:30 -07:00
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.
2023-04-12 21:09:12 -07:00
Andrea Calligaris 499c3b1227 sort.1: fix typo 2023-04-12 21:01:30 -07:00
Andrea Calligaris 93f34c1840 ed: Fix 'w' command not respecting '-s' option 2023-04-12 21:01:27 -07:00
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.
2023-04-12 20:47:34 -07:00
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.
2023-04-12 20:09:51 -07:00
Michael Forney 191f7e693b find: insert -a in before open parens as well
This fixes expressions like -type f '(' -name foo -o -name bar ')'.
2022-10-21 18:31:52 -07:00
Hiltjo Posthuma 63271b47f7 setsid: fix usage information for -f flag 2022-06-20 12:39:59 +02:00
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
2022-03-22 17:20:51 -07:00
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).
2021-10-23 16:17:20 -07:00
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.
2021-09-10 22:48:47 -07:00
Michael Forney c331811c91 find: Add spawn helper function 2021-09-10 22:43:54 -07:00
Michael Forney 7d60e2cabb mv: Move on to other files if rename fails with something other than EXDEV 2021-07-30 12:24:32 -07:00
Michael Forney df6599ef78 mv: Only remove source if copy succeeded 2021-07-30 12:09:34 -07:00
Michael Forney 688384568c mv: Prevent successful rename from forgetting past failure 2021-07-30 12:01:09 -07:00
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"
2021-07-26 20:10:09 +02:00
Hiltjo Posthuma 61be841f5c tar: check if allocation failed 2021-07-18 10:53:51 -07:00
Michael Forney 3d8481f01d README: Add dd(1) to tool list 2021-06-17 19:09:25 -07:00
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