Commit Graph

1918 Commits

Author SHA1 Message Date
Wolfgang Corcoran-Mathe
cd0b771cbb Add join(1) 2015-04-20 11:24:12 +01:00
FRIGN
f83d7bc647 Add SILENT flag to recurse()
recurse() is getting smarter every day. I expect it to pass the Turing
test in a few months.
Along the way, it was reported that "rm -f" on nonexistant files reports
their missing as an internal recurse()-error.
So recurse() knows when to shut up, I added the SILENT flag to fix all
these things.
2015-04-20 11:12:40 +01:00
FRIGN
7b2465c101 Add maxdepth to recurse()
This also makes more sense.
2015-04-20 11:12:40 +01:00
FRIGN
e14d9412f8 Properly handle recursion in recurse()
The restructuring of recurse() in the last few weeks actually broke
the recursion-flags in different tools.
As a long-term goal, the recursor should have a field "maxdepth"
which should be "1" for the non-Rflag-case. "0" stands for unlimited.
2015-04-20 11:12:40 +01:00
Hiltjo Posthuma
e2edbdcb87 sed: use reallocarray (non-issue) 2015-04-17 19:01:02 +01:00
Evan Gates
1dbb848037 intptr_t is an optional type, use intmax_t 2015-04-14 16:42:43 +01:00
sin
ea819714c2 Don't close stdin early in sed(1)
Fix by emg.
2015-04-09 15:33:57 +01:00
Hiltjo Posthuma
dd395693d4 sed: remove unused strnacpy() 2015-04-08 15:32:56 +01:00
Jakob Kramer
403b047a30 sort: allow keys where start_col > end_col
Useful in (rare) cases like:

	$ printf 'aaaa c\nx a\n0 b\n' | sort -k 2,1.3

And this is how POSIX wants it.
2015-04-06 17:15:54 +01:00
Jakob Kramer
061932a31b sort: allow 0 as key's end_char 2015-04-06 17:15:54 +01:00
Jakob Kramer
bddb7200b8 sort: apply -b only to "custom" keys 2015-04-06 17:15:54 +01:00
Jakob Kramer
2d9d224a1b sort: add support for delimiter strings
Instead of just single characters.  This also fixes
some bugs in columns().  Example bug:

	$ printf "a b\nc b x\n" | sort -k 2,2 -k 1,1
2015-04-06 17:15:54 +01:00
Dionysis Grigoropoulos
ada69106b7 du: Reset size counter for each file read 2015-04-06 08:57:46 +01:00
FRIGN
d8e829a88d Solve little output issue in du(1)
Don't run the size throug nblks() twice.
2015-04-06 08:57:46 +01:00
sin
bb2c0cff45 Fix function definition style for fshut.c 2015-04-05 09:16:50 +01:00
FRIGN
343923b1cc Add Dionysis Grigoropoulos alias erethon to LICENSE 2015-04-05 09:16:50 +01:00
Dionysis Grigoropoulos
feb77a3b8d wc: Print number of bytes by default
According to POSIX, wc should by default print the number of bytes and
not the number of chars
2015-04-05 09:13:56 +01:00
FRIGN
3eee8e1509 Remove DEBUG-define for eprintf.c
Prepend program name only when fmt doesn't begin with "usage".
2015-04-05 09:13:56 +01:00
FRIGN
0c470f5563 Remove fflush-check from fshut()
Basically, it's a conflict between POSIX and ISO C what do to when
input streams are passed to fflush().
POSIX mandates that the seeking-position should be synced, but ISO C
says it's undefined behaviour.
We love POSIX, but the standard-documents specify that in all conflict
cases, ISO C wins, so this breaks with EBADF on BSD's.

musl and glibc follow POSIX behaviour, which makes sense, but involves
numerous portability concerns.

To get around this, we just don't check fflush() and rely on the fact
that no implementation sets ferror on the file-stream in fflush if it
is an input stream, so every issue caught in fflush() is caught later
with ferror() and fclose().

Add a comment to fshut() because this stuff is so complicated, it
took us a day to figure out.
2015-04-05 09:13:56 +01:00
FRIGN
28c5d560fb Fix small issue in nl(1)
If fp == NULL we don't want to close it.
2015-04-05 09:13:56 +01:00
FRIGN
11e2d472bf Add *fshut() functions to properly flush file streams
This has been a known issue for a long time. Example:

printf "word" > /dev/full

wouldn't report there's not enough space on the device.
This is due to the fact that every libc has internal buffers
for stdout which store fragments of written data until they reach
a certain size or on some callback to flush them all at once to the
kernel.
You can force the libc to flush them with fflush(). In case flushing
fails, you can check the return value of fflush() and report an error.

However, previously, sbase didn't have such checks and without fflush(),
the libc silently flushes the buffers on exit without checking the errors.
No offense, but there's no way for the libc to report errors in the exit-
condition.

GNU coreutils solve this by having onexit-callbacks to handle the flushing
and report issues, but they have obvious deficiencies.
After long discussions on IRC, we came to the conclusion that checking the
return value of every io-function would be a bit too much, and having a
general-purpose fclose-wrapper would be the best way to go.

It turned out that fclose() alone is not enough to detect errors. The right
way to do it is to fflush() + check ferror on the fp and then to a fclose().
This is what fshut does and that's how it's done before each return.
The return value is obviously affected, reporting an error in case a flush
or close failed, but also when reading failed for some reason, the error-
state is caught.

the !!( ... + ...) construction is used to call all functions inside the
brackets and not "terminating" on the first.
We want errors to be reported, but there's no reason to stop flushing buffers
when one other file buffer has issues.
Obviously, functionales come before the flush and ret-logic comes after to
prevent early exits as well without reporting warnings if there are any.

One more advantage of fshut() is that it is even able to report errors
on obscure NFS-setups which the other coreutils are unable to detect,
because they only check the return-value of fflush() and fclose(),
not ferror() as well.
2015-04-05 09:13:56 +01:00
Ypnose
11d59a78c8 Makefile: missing sbase-box-install in PHONY 2015-04-03 23:08:04 +01:00
sin
ef08e52e9b Revert "Add command(1) to TODO"
It must be a shell builtin.  Thanks emg.
2015-04-03 19:37:07 +01:00
sin
2ef65fe317 Add command(1) to TODO
Potentially useful in certain situations, not for the 0.1 release
though.
2015-04-03 16:54:46 +01:00
sin
ccf0fbcd7b Fix usage for printf(1) 2015-04-03 10:41:38 +01:00
sin
9611e92303 Do not interpret -- in echo(1)
Retain -n as it is marginally useful and common.
2015-04-03 10:29:11 +01:00
Dionysis Grigoropoulos
bbd2b4d243 wc: Show line/char/word count even if it's zero
Fix a bug where if a line, character or word count is zero, it's not
printed
2015-04-01 11:06:47 +01:00
Hiltjo Posthuma
bf90e85f18 col: dont allow col -l 0 2015-03-30 21:49:33 +02:00
Hiltjo Posthuma
b1fcce32e2 col: exit status 1 on usage 2015-03-30 21:49:04 +02:00
Hiltjo Posthuma
24c6df3d73 col: buffer 128 lines by default 2015-03-30 21:48:26 +02:00
Hiltjo Posthuma
398598dbbe paste: fix crash with empty delimiter
reproduce:
	paste -d '' /dev/null
or
	paste -d '\0' /dev/null

show usage() in these cases.
2015-03-30 21:25:23 +02:00
Hiltjo Posthuma
d6aff89bbb tail: allow tail -n 0 or tail -0
fix a crash, but allow this option.
2015-03-30 21:24:46 +02:00
Hiltjo Posthuma
d583d12300 du: fix possible division by zero if $BLOCKSIZE is 0
these kind of $BLOCKSIZE dont make sense, but dont crash atleast.
2015-03-30 19:58:06 +02:00
Hiltjo Posthuma
27f258dd34 libutil/getlines: style fix 2015-03-29 21:55:34 +02:00
Hiltjo Posthuma
9f97430143 libutil/getlines: fix crash with no lines
because b->lines and b->nlines would be 0 with no lines read.

reproduce: printf '' | sort or cols

bug was introduced by commit: 66a5ea722d
2015-03-29 21:48:49 +02:00
Hiltjo Posthuma
1e0c3a0ba6 whitespace fixes 2015-03-27 22:48:05 +01:00
Hiltjo Posthuma
8e486d5282 xargs: minor optimizations 2015-03-27 22:48:05 +01:00
Hiltjo Posthuma
67ca2428d5 xargs: fix sysconf(_SC_ARG_MAX)
the minimum space required by environment variables isn't clearly defined by
POSIX afaik.
2015-03-27 22:48:05 +01:00
Hiltjo Posthuma
7ebf02d749 find: fgetc() returns int 2015-03-27 22:48:05 +01:00
Hiltjo Posthuma
a9bedca038 fix some signed/unsigned warnings and style fixes 2015-03-27 22:48:05 +01:00
FRIGN
57dc7b94b0 POSIX 2013 audit
Mostly manpage-shuffling according to the changes in the corrigendum,
wording changes and more idiomatic expressions.
All this is finished up by marking the POSIX 2013 conformant tools
with
.St -p1003.1-2013
which is not available in older mandoc builds or nroff, but which
reflects what we actually did, so who cares?

This is a huge step and it's not far until we can release sbase 0.1.
2015-03-27 17:25:22 +01:00
Hiltjo Posthuma
06b663234f sed: declare functions and global vars static (some still missing) 2015-03-27 16:20:50 +01:00
Hiltjo Posthuma
244539e473 sed: style improvements
- declare variables at the top of a function.
- free(NULL) is valid.
- avoid VLA.
2015-03-27 16:01:55 +01:00
Hiltjo Posthuma
0547e72441 sed: show specific error strings (strerror) and minor style fixes 2015-03-27 15:59:09 +01:00
Hiltjo Posthuma
fea0a34e13 grep: use len returned from getline and check fmemopen() 2015-03-27 15:54:41 +01:00
Hiltjo Posthuma
44298e54e6 comm: minor optimization 2015-03-27 15:53:46 +01:00
FRIGN
9144d51594 Check getline()-return-values properly
It's not useful when 0 is returned anyway, so be sure that we have a
string with length > 0, this also solves some indexing-gotchas like
"len - 1" and so on.
Also, add checked getline()'s whenever it has been forgotten and
clean up the error-messages.
2015-03-27 14:49:48 +01:00
Hiltjo Posthuma
a516338581 nl.1: fix mandoc warning 2015-03-27 12:21:28 +01:00
Hiltjo Posthuma
c5a51123b1 printf: no need to nul-terminate after strndup 2015-03-27 12:21:13 +01:00
FRIGN
096da1297b Properly handle width and precision in printf(1) 2015-03-26 23:01:26 +01:00