1842 Commits (1d885159f2f7ff68ed75d92af584174a1208ca01)
 

Author SHA1 Message Date
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>
5 years ago
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.
5 years ago
Roberto E. Vargas Caballero 18f6c5e014 Add TODO 5 years ago
Roberto E. Vargas Caballero ece6569297 Fix undo
Avoid incorrect values in the number of undo elements and restore lastln
value after an undo operation.
5 years ago
Roberto E. Vargas Caballero cd9b149c8f Use nextln() in scroll() 5 years ago
Roberto E. Vargas Caballero ebf740f962 Improve doglobal()
Don't use directly the line numbers and call to getlst()
when a line is matched.
5 years ago
Roberto E. Vargas Caballero 9781959581 Fix copy()
Copy was using directly the line numbers and incrementing them
without calling nextln(). It also didn't worry about how
line numbers are modified when we insert new lines.
5 years ago
Roberto E. Vargas Caballero 504dde1373 Allow overlapping transfer 5 years ago
Roberto E. Vargas Caballero d849e6d4aa Rename addchar_() to addchar()
All the ocurrences of addchar() were moved to addchar_(),
so we can rename addchar_() and remove the old definition.
5 years ago
Roberto E. Vargas Caballero 3ce26f33c6 Move subline() to use String type 5 years ago
Roberto E. Vargas Caballero 77fe371fe4 Fix type of c in getrhs()
C is compared against EOF, so it cannot be char.
5 years ago
Roberto E. Vargas Caballero 0732529fef Fix type of c in execsh()
C is compared against EOF, so it cannot be char.
5 years ago
Roberto E. Vargas Caballero a5d268c409 Move execsh() to use String type 5 years ago
Roberto E. Vargas Caballero 8d59405ae0 Move join() to use String type 5 years ago
Roberto E. Vargas Caballero 7c2eec7bd1 Move lastre to String type 5 years ago
Roberto E. Vargas Caballero 35cf3c79f2 Move text to String type 5 years ago
Roberto E. Vargas Caballero f5cb020f06 Move cmdline to String type 5 years ago
Roberto E. Vargas Caballero 20794b570e Define new String type
Current handling of strings is a bit messy. This type is copied
from the sed implementation. Addchar_ is added to be able to live
with String and old style chars based in 3 different variables.
5 years ago
Roberto E. Vargas Caballero 651e2b0ee2 Set restore point before setting signal handlers 5 years ago
Michael Forney d098ac4abc od: For the 'c' type, format non-printable charecters as octal
This is the behavior specified by POSIX.
5 years ago
Michael Forney f83c468b55 od: Don't modify bytes in the line for the 'a' type
Subsequent types should still print the full 8-bit value.
5 years ago
Michael Forney 1ff2a54e8f ed: Write "?\n" and explanatory messages to stdout
This is the behavior specified by POSIX.
5 years ago
Samadi van Koten 44ccadcde3 Fix line buffering issue with ed prompt
This fixes an issue whereby ed would not output the prompt (when
enabled) until after exitting due to stdout being line-buffered.
5 years ago
Pieter Kockx 4b9c6645f5 sed: Fix parsing bug in find_delim
's/[[x=]//' was parsed as 's/[[=x]//' which (correctly)
raises an error because the "second delimiter is missing", here =].

The two got mixed up because the parser didn't return to
the "inside bracket"-state after encountering an opening bracket
while inside the bracket expression.
6 years ago
Pieter Kockx a0a8791704 sed: Add usage 6 years ago
Michael Forney 38cc01b887 which: Minor simplification 6 years ago
Michael Forney 3b604b179c which: Don't look for paths with slashes in $PATH 6 years ago
Michael Forney 44265b29ce which: Move executable check to helper function 6 years ago
Pieter Kockx 5b66e55a83 which: handle relative/absolute pathnames 6 years ago
Pieter Kockx d15f49e715 which: fix whitespace 6 years ago
Pieter Kockx 6eec2eb3b4 tr: Fix infinite loop
When `makeset` got a string containing square brackets
followed by at least one extra character, e.g. "[abc]d",
it entered an infinite loop because it was assumed
`j` could not exceed `len` without having been equal to `len`.
It can, however, when `m == len` and subsequently `j = m + 1`.
6 years ago
David Phillips e1c56a6321 chmod: Use DIRFIRST
Previously, running `chmod 777` on a directory that had no read or
execute access (e.g. 111 or 000) would cause chmod to throw its
toys since it was trying to opendir before having added read permission
to the directory.
6 years ago
David Phillips 69b9c2444b libutil/recurse: only opendir if recursing
Previous behaviour was to call opendir regardless of if we are actually going
to be recursing into the directory. Additionally, some utilities that use
DIRFIRST benefit from running the function pointed to by fn before the call
to opendir. One such example is `chmod [-R] 777 dir` on a directory with mode
000, where it will be expected for chmod to first give itself rwx before
optionally listing the directory to traverse it.
6 years ago
Michael Forney e6d3032131 tar: Fix a few weprintf/eprintf format strings
Thanks to Jim Beveridge for spotting the incorrect utimensat error.

Turns out there are a few other instances of this in the vicinity.
6 years ago
Pieter Kockx d90ba15f29 Fix segmentation fault in paste(1)
libutil/unescape received a pointer to a a string in
read-only memory.
6 years ago
Eric Pruitt fb936d5ba5 Add missing getconf.h dependency to sbase-box 6 years ago
Michael Forney b524eb6f3d getconf: Ensure output was written successfully 6 years ago
Michael Forney c225d88d49 getconf: Report invalid variables as errors
Printing `undefined` to stdout means that the variable is valid but not
set. Instead, report an error in this case.

linux 4.13 appends the result of `getconf LFS_CFLAGS` to HOSTCFLAGS,
even if it prints `undefined`. This is arguably a bug in the Makefile,
but even so, getconf shouldn't report that unsupported variables are
valid.
6 years ago
John Vogel ed78aef5b1 date: add date/time setting capability
[Michael Forney: Moved functionality to setdate, other minor tweaks]
6 years ago
Michael Forney 1b41610a82 date: Just set TZ to handle -u flag
This simplifies things a tiny bit, and is also necessary for setting the
date since mktime operates based on the value of TZ.
6 years ago
Michael Forney 772a40188b tar: Explain reason for malformed header 6 years ago
David Phillips 46495ea902 ls: abort a directory if we cannot opendir it
We should not try and perform operations on an invalid DIR* stream.
Instead, we shall let the error message be printed, and the return
code set (existing behaviour) and abort afterwards.
6 years ago
Laslo Hunhold e92a1aef54 Handle { NULL } argv[] properly in manual arg-reduction
Thanks izabera for reporting this!
6 years ago
Michael Forney ea8622a4ce tail: Process bytes with -c option, and add -m option for runes
POSIX says that -c specifies a number of bytes, not characters. This
flag is commonly used by scripts that operate on binary files to things
like extract a header. Treating the offsets as character offsets will
break things in mysterious ways.

Instead, add a -m option (chosen to match `wc -m`, which also operates
on characters) to handle character offsets.
6 years ago
Michael Forney 1ab4ac60ff tail: Use fstat in case file is removed 6 years ago
Michael Forney 51e432cc44 cp: Only call chmod with -p or -a
Previously, when the destination file was created with fopen, we needed
to use fchmod to set its permissions.

Now that we pass in the mode to creat, we already get the desired
behavior of creating the file with the same mode as the source file
modified by the user's file creation mask.

This fixes the issue where a directory or special file created with
mkdir/mknod does not end up with the appropriate mode with -p or -a
(since it may have been narrowed by the umask).

This also allows us to clear the SUID and SGID bits from the mode if the
chown fails, as specified by POSIX.
6 years ago
Michael Forney 3276fbea1c concat: Use plain read/write instead of buffered stdio
If we are just copying data from one file to another, we don't need to
fill a complete buffer, just read a chunk at a time, and write it to the
output.
6 years ago
Michael Forney 9a3b12525b Don't use buffered IO (fread) when not appropriate
fread reads the entire requested size (BUFSIZ), which causes tools to
block if only small amounts of data are available at a time. At best,
this causes unnecessary copies and inefficiency, at worst, tools like
tee and cat are almost unusable in some cases since they only display
large chunks of data at a time.
6 years ago
Michael Forney 5cb3a1eba1 libutil: Add writeall utility function
writeall makes successive write calls to write an entire buffer to the
output file descriptor. It returns the number of bytes written, or -1 on
the first error.
6 years ago
Michael Forney 529e50a7ad mkdir: Fix created directory permissions
Previously, with -p, the specified directory and all of its parents
would be 0777&~filemask (regardless of the -m flag). POSIX says parent
directories must created as (0300|~filemask)&0777, and of course if -m
is set, the specified directory should be created with those
permissions.

Additionally, POSIX says that for symbolic_mode strings, + and - should
be interpretted relative to a default mode of 0777 (not 0).

Without -p, previously the directory would be created first with
0777&~filemask (before a chmod), but POSIX says that the directory shall
at no point in time have permissions less restrictive than the -m mode
argument.

Rather than dealing with mkdir removing the filemask bits by calling
chmod afterward, just clear the umask and remove the bits manually.
6 years ago