Commit Graph

1763 Commits

Author SHA1 Message Date
Evan Gates
4b5a948cee targets must be prerequisites to .PHONY not commands 2016-12-27 13:15:10 +01:00
Laslo Hunhold
e2f886c7e2 ed: Use strlcpy() instead of strcpy() and other minor things
Based on contribution by Ali H. Fardan, thanks!
2016-12-27 13:07:02 +01:00
Thomas Mannay
370e0ae675 ed: add manpage
Laslo: Fix some things pointed out by mandoc -Tlint:
	1) replace empty lines with .Pp, we want to start a new
	   paragraph
	2) Add a comma before the second item in SEE ALSO
	3) Place SEE ALSO before STANDARDS, as is the convention
	4) Update the man-date
2016-12-27 12:53:30 +01:00
Thomas Mannay
30da327fbd ed: remove double free in join() 2016-12-27 12:50:25 +01:00
Thomas Mannay
2304df908c ed: place newly joined lines correctly 2016-12-27 12:50:20 +01:00
Thomas Mannay
696520714b ed: giving j only one address does nothing 2016-12-27 12:50:09 +01:00
Thomas Mannay
61e06396bd ed: remove infinite loops in join() and getindex() 2016-12-27 12:50:03 +01:00
Evan Gates
d2bd40a589 find: remove VLAs
Laslo: Use ereallocarray and fix the style a bit
2016-12-27 12:46:06 +01:00
Evan Gates
0b27c0c9a0 find: estrdup before basename
"The basename() function may modify the string pointed to by path..."
Thanks POSIX

Laslo: Changed the style a bit
2016-12-27 12:37:57 +01:00
Wolfgang Corcoran-Mathe
b7c73e2392 ed: Fix backslash expressions in RHS
By stripping backslashes this code caused a number of bugs.
'\<digit>' expressions caused literal <digit>s to be subbed-in,
'\&' was treated identically to '&', and other escaped characters
added garbage to the string.
2016-12-27 12:29:52 +01:00
Wolfgang Corcoran-Mathe
f5baf2630a ed: Don't match against line 0 in search()
regexec(3) happily matches /^$/ against the text of line
zero (the null string), causing an error.

Also update email address for Wolfgang Corcoran-Mathe
2016-12-27 12:28:36 +01:00
Mattias Andrée
28129a87c4 Add rev(1)
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-12-27 11:35:27 +01:00
Laslo Hunhold
fb11173926 tr: Fix multiple ranges with different lengths (Michael Forney)
See his description below. Thanks Michael!

---
A bug was introduced in bc4c293fe5 causing the
range length for the next set to be used instead of the first one. This causes
issues when choosing the replacement rune when the ranges are of different
lengths.

Current behavior:

$ echo 1234 | tr 'a-f1-4' '1-6a-d'
56ab

Correct behavior:

$ echo 1234 | tr 'a-f1-4' '1-6a-d'
abcd

This also fixes range expressions in the form [a-z], which get encoded as four
ranges '[', 'a'..'z', ']', causing all a-z characters to get mapped to ']'. This
form is occasionally used in shell scripts, including the syscalltbl.sh script
used to build linux.
---
2016-11-18 12:45:59 +01:00
Evan Gates
d24ef864cb ls: respect -q when printing directory names with -R
break out the non printable character to ? code into a makeprint()
function so it can be used both in output() and lsdir()
2016-10-06 10:21:12 +02:00
Evan Gates
071dcc4d6b ls: fix ls -lq to respect -q flag 2016-10-06 10:21:12 +02:00
Laslo Hunhold
b5ebd49dd3 tr: Provide a fallthrough case for single-arg -s
Previously, this would not work properly and not be let through the
sanity check.

This is a dirty hack until the next iteration where I'll clean up the
data structures and make this saner.
2016-10-06 02:00:25 +02:00
Laslo Hunhold
c154ef7a03 tr(1): Properly handle the -dc case for character classes
I actually did that properly in the set-case but forgot to add the same
logic to the character classes. Now it should work fine.
2016-10-06 00:16:30 +02:00
Laslo Hunhold
096c504d82 tr(1): Properly jump to output when inside set complement 2016-10-05 21:54:51 +02:00
Laslo Hunhold
456f3c4211 tr.1: Make note of some changes in the utility 2016-10-05 21:42:24 +02:00
FRIGN
bc4c293fe5 Revamp tr(1) set parsing and handling
If you look at GNU coreutils, they do not support the mappings

	$ echo "1234abc" | tr "[:alnum:]" "[:upper:]"

	$ echo "ABCabc" | tr -c "[:upper:]" "[l*]"

to only give a few examples. This commit broadens the scope of tr(1)
as far as humanly possible to map between classes and non-classes,
making tr a usable tool and actually fulfilling user expectations.
Posix really is of no help here as it still kind of assumes the
fixed ASCII table instead of complex Unicode code points or even
Grapheme clusters.
2016-10-05 21:18:24 +02:00
FRIGN
9de401a495 Fix tr(1) squeezing
Okay, it took me a while and another look at the Posix spec to see that
I have been dealing with squeezing in a way too complicated way.
What just needed to be done is before doing the final write to deploy
the squeeze-check. We actually do not need this atomically complicated
squeeze check in every single edge-case. Now it should work properly.
2016-10-05 19:31:50 +02:00
FRIGN
fac091b7cc getconf.sh: Be more explicit we are using a heredoc here 2016-10-05 18:48:10 +02:00
Evan Gates
de28c8bfa7 use only one getconf header
this simplifies the getconf.sh script and handling parallel make
2016-10-05 18:48:10 +02:00
Mattias Andrée
96ccf5172d find: check whether readdir failed, and properly check timestamps
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-10-05 18:48:10 +02:00
Mattias Andrée
e8a3a3ec37 test: -erwx test against effetive uid/gid, not real
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-10-05 18:48:10 +02:00
Mattias Andrée
da04e4cc2a pathchk: fixes and cleanup
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-10-05 18:48:10 +02:00
Evan Gates
e3f497e1f6 subtract 'a' from indices for marks
Given:

static int marks['z' - 'a'];
marks[c];

In this case c is the character read and index is out of bounds. We
need marks[c - 'a']

While playing around with optimization settings gcc caught caught this.

Also fix one check for c, change from isalpha to islower.

-emg

From 2cc36818283e9068576c1042690c016a81b709a3 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.gates@gmail.com>
Date: Fri, 15 Jul 2016 09:52:39 -0700
Subject: [PATCH] fix marks indexing
2016-08-03 15:35:36 +01:00
Michael Forney
3c12b287ec touch: Avoid unnecessary call to stat
Now, we first try a utimensat. If it succeeds, we are done, if not (and no -c
flag), create the file, then set the times with futimens.
2016-07-09 10:17:16 +01:00
Michael Forney
2e5f1281ed touch: Use special UTIME_NOW and UTIME_OMIT values
This allows users to touch files they have write access to, but aren't the
owner.

Also, remove utime.h include (not necessary since
4132561c17), and make sure to check the return
value of localtime (potentially preventing a NULL pointer derefence).
2016-07-09 10:17:16 +01:00
Michael Forney
36a0a6cd92 touch: Remove useless variable
The only possible return values of stat are 0 or -1, so it doesn't make sense to
store the return value in a variable to make sure it is not positive.
2016-07-09 10:17:16 +01:00
Michael Forney
0941c9ab2c touch: Respect caller's umask
Currently, if the caller has a umask of 002 or 000, the file gets created as 644
anyway.

Also, add O_WRONLY to the open call, since POSIX says that "Applications shall
specify exactly one of the first five values (file access modes) below in the
value of oflag".
2016-07-09 10:17:16 +01:00
Michael Forney
a211649cfd ln: Only fail if same inode without -f flag 2016-07-09 10:17:16 +01:00
Michael Forney
083d1451ac install: Handle -c flag as a no-op
This is required in order for autoconf's AC_PROG_INSTALL to use the sbase
install. Otherwise it will fall back to the slow and sucky install-sh script
from automake.
2016-07-09 10:17:16 +01:00
Michael Forney
49e1854600 od: Don't advance past end of type string
Currently, if you specify -t x, then s is advanced once in the switch statement
to determine the length, and then once again in the for loop, resulting in a
read past the end of the argument.

Also, use sizeof(int) when no length is specified, as specified by POSIX.
2016-07-09 10:17:16 +01:00
Michael Forney
5ae2793da6 od: Add some missing type flags 2016-07-09 10:17:16 +01:00
Michael Forney
8ca79a2993 linecmp: Handle NUL bytes properly
Test case:

if [ "$(printf 'a\na\0b' | ./sort -u)" = "$(printf 'a\na\0b')" ] ; then
	echo pass
else
	echo fail
fi
2016-07-09 10:09:50 +01:00
Michael Forney
a944b682a6 sort: Fix line comparison when col buffer contains data from longer line
I'm not sure if there are other implications of this or not, but
the issue is that columns() uses len to store the allocated buffer
size, but linecmp() compares up to len bytes. If those trailing
bytes do not match, the line is considered not matching, even though
the relevant parts of the buffer do match.

To resolve this, also keep track of column capacity. Additionally,
since there is no reason to keep the existing data when resizing,
just use free and emalloc rather than erealloc.

The simplest case I could reduce it to is this:

if [ "$(printf '%s\n' a a xxb xxc | ./sort -u)" = "$(printf '%s\n' a xxb xxc)" ] ; then
	echo pass
else
	echo fail
fi
2016-07-09 10:09:50 +01:00
Michael Forney
d827fcace2 ls: Simplify some logic
- After first iteration, set first to 0 instead of !first.
- If Hflag || Lflag, then mkent used stat instead of lstat, so the
  entity cannot be a symlink.
- Print path prefix along with directory name.
- In the 'if (Rflag)' block, just use 1 instead of Rflag.
2016-07-09 10:09:50 +01:00
Michael Forney
ea03da0bda ls: Don't show directory name with single directory operand
This fixes the issue b107489bf2 tried
to fix, but doesn't break -R (which
bb83eade39 tried to fix).
2016-07-09 10:09:50 +01:00
Michael Forney
e8e9b97baf Revert "ls: only display directory headers when more than one directory is specified"
This reverts commit b107489bf2.
2016-07-09 10:09:50 +01:00
Michael Forney
b91b9e79ec Revert "Fix showing directories when -R flag is set in ls(1)"
This reverts commit bb83eade39.

This commit causes the loop through dents at the end of main to
continue past the end of the dents array, causing a crash when
called with multiple directory arguments.
2016-07-09 10:09:50 +01:00
pranomostro
229d7cc89a printf: support escaping '%' with '%%'. See printf(1p) EXAMPLES section. 2016-06-27 11:21:47 +01:00
sin
11d8e91042 tee: Make sure we continue on error 2016-06-23 19:38:05 +01:00
Michael Forney
0ba879cdba grep: Fix -v output and exit status
Previously, it printed lines that didn't match some pattern. Instead,
it should print lines that don't match *any* pattern.

Test case:

out=$(echo foo | ./grep -v -e foo -e bar)
if [ "$?" = 1 ] && [ -z "$out" ] ; then
	echo pass
else
	echo fail
fi
2016-05-14 12:58:38 +01:00
Michael Forney
e6b3af07cf grep: Fix exit status with -F when last line doesn't match
Test case:

if printf '%s\n' foo bar | ./grep -F foo >/dev/null ; then
	echo pass
else
	echo fail
fi
2016-05-14 12:58:38 +01:00
Michael Forney
8636c956d9 grep: Reverse some if-else logic
This way, people don't have to do double negatives in their head.
2016-05-14 12:58:38 +01:00
FRIGN
c7ea20a9cb Update Kurt H. Maier's E-Mail address 2016-04-29 12:16:51 +01:00
FRIGN
afc944d9b8 Remove locale-cancer from grep(1)
What in the actual fuck? Check the ml history on why we won't use
locale() functions in this context.
2016-04-29 12:16:51 +01:00
Mattias Andrée
727f795e94 grep: fix UTF-8 support
Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-04-20 22:57:40 +01:00
Mattias Andrée
7250fb6968 printenv: exit status is 2 on failure
This provides a reliable and portable way to
test whether an environment variable is defined.

(Of course, if you are using glibc you may get
false positives if you include a = in the query.)

Signed-off-by: Mattias Andrée <maandree@kth.se>
2016-04-20 22:57:40 +01:00