2033 Commits

Author SHA1 Message Date
Roberto E. Vargas Caballero
d4dfd42d35 rm.1: swap .St mdoc macro with text 2025-04-24 23:20:13 +02:00
THIBAUT AUBIN
a0844fc863 cp.1: swap .St mdoc macro with text 2025-04-24 23:16:42 +02:00
Roberto E. Vargas Caballero
3f7c7c2497 rm: Don't attempt to remove . or ..
POSIX explicitely mandates to ignore . or .. to avoid
pitfals like rm -r .* and no having files that begin
with a dot.
2025-04-24 09:28:05 +02:00
Roberto E. Vargas Caballero
0df8cdc12d rm: Add -i and cleanup rm()
POSIX mandates that if the input of rm is a tty and it does not have
write rights over a file/dir then it should ask for confirmation, in
the same way that is done with the -i flag. To accomodate both things
the code has been rearrenged a bit to have only one case instead of
having two. Also, this rework adds the error message when a directory
is removed without a -r flag.
2025-04-24 09:27:59 +02:00
Michael Forney
948e516190 libutil/unescape: Stop octal escape at 3 digits
unescape() is used by several tools, in particular printf(1) and
tr(1), which should stop the octal escape at a maximum of 3 digits:

printf(1)
> In addition to the escape sequences shown in XBD 5. File Format
> Notation ('\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v'), "\ddd",
> where ddd is a one, two, or three-digit octal number, shall be
> written as a byte with the numeric value specified by the octal
> number.

tr(1)
> An octal sequence shall consist of a <backslash> followed by the
> longest sequence of one, two, or three-octal-digit characters.

Previously, the maximum was set to 4 (possibly a typo?), which meant
that printf '\0123' printed `S` instead of `<newline>3`.

To check that this doesn't break any other tools using unescape:

- cut: used for -d parameter, escapes are non-standard
- join: used for -t parameter, escapes are non-standard
- nl: used for -s parameter, escapes are non-standard
- paste: used for -d parameter, POSIX specifies \n, \t, \\, and \0,
  \0 followed by a digit is unspecified
- sort: used for -t parameter, escapes are non-standard
2025-04-23 21:10:51 +02:00
Roberto E. Vargas Caballero
f3bf46b44b rm: Remove unneeded declarations
Rm uses flags from a data object passed to the recursion callback and
the old global variables are not defined anymore.
2025-04-22 18:18:31 +02:00
Roberto E. Vargas Caballero
11492947de cp: Don't modify status for -i
Quoting POSIX:

        The following exit values shall be returned:                                                                            0    All requested files (excluding files where a                                                                 non-affirmative response was given to a request for                                                                  confirmation) were successfully copied.                                                                                >0    An error occurred.
2025-04-22 13:57:36 +02:00
Thibaut Aubin
9e8b431075 cp: add -i flag 2025-04-20 09:20:11 +02:00
Thibaut Aubin
8d07e5e8f6 libutil: add confirm() prompt 2025-04-20 09:20:02 +02:00
Tavian Barnes
8e18687849 find: Fix -exec return value 2025-03-26 20:08:20 +01:00
Elie Le Vaillant
3de61ef1aa rev, tail: replace hardcoded code by UTF8_POINT macro 2025-03-21 08:44:35 +01:00
Sebastien Peterson-Boudreau
2a29857fe9 Add sbase-box to gitignore 2025-03-20 09:55:29 +01:00
remph
e8fe04c543 du: Dedup hardlinks
Conform to POSIX, which says `Files with multiple links shall be counted
and written for only one entry,' in the 2008[1] and 2013[2] editions, and
uses more words to say the same thing in the 2017[3] and 2024[4] editions.
This patch also keeps inodes between operands and dedups symlinks if
applicable, which are implementation-defined in 2017 and required in 2024.
See also the `RATIONALE' section in the 2024 edition.

[1] https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/du.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/utilities/du.html
[3] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/du.html
[4] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/du.html
2025-03-19 21:51:05 +01:00
Andrea Calligaris
39a4c55378 tar: archive: improve fix for long names crashing
As requested, I resend my old patch for fixing the crashing while
archiving with names longer than 100 characters.

Last patch dealing with the issue was [1], and the old patch was [2]. The
code before this commit was not dealing correctly with multiple slashes,
but use of basename(3) and dirname(3) needed a temporary buffer because
otherwise we destroyed the path that was used later in several places.
This solution does not modifies the path and use pointer arithmetic to
solve the problem.

[1] https://lists.suckless.org/hackers/2412/19213.html
[2] https://lists.suckless.org/hackers/2402/19071.html

Co-authored-by: Roberto E. Vargas Caballer <k0ga@shike2.net>
2025-03-19 21:47:01 +01:00
Roberto E. Vargas Caballero
97629ab386 build: Fix getconf generation
The Makefile was relaying in two extensions:

	1- Inference rule chaining: Based in getconf.c -> getconf.o -> getconf
	2- Inference rule .o: POSIX defines the .c rule, but not the .o rule
	(what makes sense because to be useful you need inference rule chaining).
2025-03-17 19:03:13 +01:00
Tavian Barnes
b1c6185a40 find: Implement -print0 2025-03-17 14:32:36 +01:00
Tavian Barnes
9d9afe00fb libutil/mode: Fix sticky bit parsing 2025-03-17 14:32:36 +01:00
Tavian Barnes
5567976329 find: Don't exit successfully after errors 2025-03-17 14:32:36 +01:00
Tavian Barnes
8f9824e34b find: Use the current umask to parse -perm
https://www.austingroupbugs.net/view.php?id=1392
2025-03-17 14:32:07 +01:00
Tavian Barnes
e861343db1 find: Fall back from stat() to lstat() on broken links 2025-03-17 14:30:38 +01:00
Roberto E. Vargas Caballero
eb749d1c88 Bump version to 0.1 0.1 2025-03-13 12:10:14 +01:00
Roberto E. Vargas Caballero
9b71b697fe build: Avoid using numbers in dist target directory
We are using a wildcard to copy things into the directory used to
build the distribution tar file, and this directory can contain
the .1 extension used in the *.1 wildcard used to copy the man
pages. Also, changed the cp command line from -r to -R because
-r is not specified in POSIX.
2025-03-13 12:10:07 +01:00
Randy Palamar
279cec8889 kill: handle TRAP signal
TRAP is a useful signal which when sent to a process currently
attached to a debugger causes the debugger to immediately break.
This is very helpful for programs running in some sort of run loop
where it may be difficult to set up a break point in an
appropriate location without modifying the source to include a
predicate condition.
2024-12-17 11:46:32 +01:00
Elie Le Vaillant
cafdc7c656 tar: force decompression
decomp() needs the force flag -f too.
2024-12-17 11:27:35 +01:00
Andrea Calligaris
782afdf8c6 sed.1: add some missing info
There are some features that are coded already, might as well document them.
2024-12-17 11:25:12 +01:00
TahaGTRC
20c27b1ad0 tar: fix problem with paths longer than 100 characters 2024-12-17 11:18:06 +01:00
Brandon Pribula
cf1e064339 README: Add usage instruction for sbase-box
It would be a good idea to add a usage instruction for sbase-box
in sbase's README similar to the one in ubase's README.

Also, There's no command named 'sha238sum' but there is one named
'sha384sum' and in the alphabetized list of commands 'paste' should
come before 'pathchk'.
2024-10-07 11:14:36 +02:00
Brandon Pribula
d458fa2c7b fix: update man pages to standard mdoc date format
When viewing sbase's man pages the date displayed at the bottom is
the current date rather than the date entered in the <program>.1
file.

According to this:

https://mandoc.bsd.lv/mdoc/details/date.html

The traditional man date format used by sbase (.Dd year-month-day)
is no longer recommended and no longer supported by GNU troff or
Heirloom Docs and as a result the current date is displayed instead.
Although this format is still accepted by mandoc for backward
compatibility.

For portability it states the standard mdoc date format should be
used instead: .Dd month day, year

I applied the following patch to sbase's last commit b30fb56 and
it fixes the issue.
2024-09-08 08:35:39 +02:00
Roberto E. Vargas Caballero
b30fb56804 ed: Add other pending bug
At this stage is clear that the match() function of ed has
serious problems that have to be solved.
2024-03-22 04:39:25 +01:00
Roberto E. Vargas Caballero
ac6d382515 build: Fix sbase-box-install target
The target tried to execute a non valid shell script
and there was a possibility to fatorize the creation
of the proto file instead of repeating it in all
the actions that required.
2024-03-12 17:11:35 +01:00
Elie Le Vaillant
13898fa7a9 tar: chktar: fix conditional typo 2024-03-06 16:00:10 +01:00
Elie Le Vaillant
bca3fcca91 tar: sanitize, chktar: leading spaces should be skipped over
Some tar archives (eg. ftp://ftp.gnu.org/gnu/shtool/shtool-2.0.8.tar.gz)
use leading spaces instead of leading zeroes for numeric fields.
Although it is not allowed by the ustar specification, most tar
implementations recognize it as correct.  But since 3ef6d4e4, we
replace all spaces by NULs here, not just trailing ones, which leads to
recognizing such archives as malformed.  This fixes it: we now skip
over leading spaces, allowing strtol(3) to read those numeric fields.
2024-03-05 13:25:44 +01:00
Randy Palamar
d335c366f7 expr: tonum: handle case where result was previously calculated
As pointed out in a mail to dev expr was segfaulting when multiple
math operations were specified on the command line: eg. 'expr 3 \*
2 + 1'. This happens because the tonum(), introduced in e50d533,
assumed that v->str was always non null. parse() guarantees this
for user input but this is not the case when doop() is called with
the result of a previous calculation. However in that case we know
that v->num is already valid so we can simply return.
2024-01-31 05:00:51 +01:00
Roberto E. Vargas Caballero
6b9da17eb4 build: Fix OBJ definition and remove MAN
The MAN macro was not used, and it and OBJ had the same problem
because they were defined using an empty string in the replace
pattern of the macro expansion, but as it is said by POSIX:

	The subst1 to be replaced shall be recognized when it is a suffix
	at the end of a word in string1

so, an empty string should not be used.

Also, a new inference rule is added to generate the binary
directly from the .c without generating the intermediate
object, removing the need of chaining different inference
rules which is not guaranteed to work in all the make
implementations.
2024-01-19 22:01:25 +01:00
Randy Palamar
270ca025ce expr: don't evaluate matched substr as a number
POSIX specifies that if the pattern contains a subexpression then
the first matched subexpression should be returned if it exists.

This fixes things like the following:

./expr 00003 : '\(.*\)'
Before: 3
After: 00003
2024-01-16 09:11:46 +01:00
Randy Palamar
e50d533d59 expr: treat expressions as strs until evaluation
Comparison operations (>, <, =, etc.) and matching operations must
operate originally provided string not one that has gone back and
forth through string formatting. This caused operations such as
the following to give incorrect results:

./expr 00003 : '.*'
Before: 1
After: 5

This commit fixes that issue.
2024-01-16 09:11:40 +01:00
Roberto E. Vargas Caballero
7d5b113423 ed: Add new TODO 2024-01-12 20:48:42 +01:00
Roberto E. Vargas Caballero
2732217a40 ed: Handle correctly lines in substitutions
The s command can apply a replace pattern with embedded newlines
which modifies the line/index assignament. Using a range in  the
address fail because afther the call to subline() the next  line
has to be searched based in the index because the replace  could
insert newlines.
2023-12-29 20:27:23 +01:00
Jules Maselbas
e24228e062 sbase-box: Fix segmentation fault when exe without args
when sbase-box is executed without argument, the check sbase-box
options doesn't verify the argument count leading to a segfault.

Add a check on the argc before parsing sbase-box options (currently
only `-i`)
2023-12-28 20:16:54 +01:00
Roberto E. Vargas Caballero
6a557314b9 ed: Don't undo commands in sigint
If newcmd is 0 then error() undo all the modifications
that happened since the last command, but this is  not
what POSIX mandates:

SIGINT	The ed utility shall interrupt its current activity, write the
	string "?\n" to standard output, and return to command mode
	(see the EXTENDED DESCRIPTION section).
2023-12-28 17:26:50 +01:00
Roberto E. Vargas Caballero
bbdd7bedc4 ed: Simplify sighup dealing
As we already have the dump() function we can move the
modification check inside the new dump() function.
2023-12-28 17:19:47 +01:00
Roberto E. Vargas Caballero
137f0917e4 ed: Print only last line in empty command 2023-12-28 17:19:17 +01:00
Roberto E. Vargas Caballero
2d4d7dc6d4 ed: Fix G and V commands 2023-12-28 17:16:34 +01:00
Roberto E. Vargas Caballero
516e7fec92 ed: Remove nothing comments
Several bugs happened in the past due to this kind of comments
and it is better to get rid of them.
2023-12-28 17:16:24 +01:00
Roberto E. Vargas Caballero
54a0fc3ecc ed: Fix makeline
Strings without newlines created problems in the function
and the global field was not updated, making that new lines
added were marked as global being processed in the current
global command.
2023-12-28 17:14:04 +01:00
Roberto E. Vargas Caballero
09dc00f995 ed: Update TODO
Remove the cases are tested to work correctly now.
2023-12-28 17:04:13 +01:00
Roberto E. Vargas Caballero
890f6c2c05 ed: Improve execsh 2023-12-28 17:02:44 +01:00
Roberto E. Vargas Caballero
aacfa18b79 ed: Avoid dangling pointer in getrhs()
If the string r.str is freed but error() is called then
next call will see a pointer that maybe it will try to free
because the call to error unwind the frame stack.
2023-12-28 17:02:19 +01:00
Roberto E. Vargas Caballero
b089261c3a ed: Read from input in append()
This enables using a and i commands in a global command
because the input is not anymore taken from stdin.
2023-12-28 17:01:58 +01:00
Roberto E. Vargas Caballero
1e10bf6069 ed: Add getinput() and setinput()
These functions allow to read from stdin the full next
line or seting as input a character array. These functions
avoid all the complexity about repeat commands that is very
fragile and depends on having multiple global variables with
weak relation between them.
2023-12-28 16:49:34 +01:00