Commit Graph

1855 Commits

Author SHA1 Message Date
FRIGN
e8a4f37884 Fix tail(1) -n 0 handling and unglobalize some variables
Don't terminate too early. If the given file doesn't exist,
we need the error-message.

Additionally, some variables were globals for no good reason.
2015-05-21 15:43:38 +01:00
Hiltjo Posthuma
fbd128b564 fold: check -N form properly 2015-05-21 15:43:38 +01:00
Hiltjo Posthuma
bc9205cab5 fold: check form -n aswell, > 0 2015-05-21 15:43:38 +01:00
FRIGN
9304b84c92 Use a function pointer in uuencode(1)
This simplifies the code a lot.
2015-05-21 15:43:38 +01:00
FRIGN
9a074144c9 Remove handrolled strcmp()'s
Favor readability over bare-metal.
2015-05-21 15:43:38 +01:00
FRIGN
1797df01e7 Fix uniq(1)
The argument handling was quite garbled up. So I fixed it.
In the process, it drops a lot of locs.

Previously, it would lead to an off-by-one in an edge case, so
stop messing around with argv and use an idiomatic fp- and fname-
array.

Now this works fine and is much easier to read.

This is also the first step towards going back to strcmp() instead
of handrolling the "-"-checks.
2015-05-19 16:51:19 +01:00
Michael Forney
b4adb4bb87 touch: Use both atime and mtime of reference file 2015-05-16 13:34:00 +01:00
Michael Forney
4132561c17 touch: Handle nanosecond timestamps 2015-05-16 13:34:00 +01:00
Michael Forney
1d28fbd6cf mv, cp: Preserve nanosecond timestamps
Otherwise, we run into problems in a typical autoconf-based build
system:

  - config.status is created at some point between two seconds.
  - config.status is run, generating Makefile by first writing to a file
    in /tmp, and then mv-ing it to Makefile.
  - If this mv happens before the beginning of the next second, Makefile
    will be created with the same tv_sec as config.status, but with
    tv_nsec = 0.
  - When make runs, it sees that Makefile is older than config.status,
    and re-runs config.status to generate Makefile.
2015-05-16 13:34:00 +01:00
sin
0ba81a0f84 grep: Remove unused variable 2015-05-16 13:34:00 +01:00
FRIGN
0545d32ce9 Handle '-' consistently
In general, POSIX does not define /dev/std{in, out, err} because it
does not want to depend on the dev-filesystem.
For utilities, it thus introduced the '-'-keyword to denote standard
input (and output in some cases) and the programs have to deal with
it accordingly.

Sadly, the design of many tools doesn't allow strict shell-redirections
and many scripts don't even use this feature when possible.

Thus, we made the decision to implement it consistently across all
tools where it makes sense (namely those which read files).

Along the way, I spotted some behavioural bugs in libutil/crypt.c and
others where it was forgotten to fshut the files after use.
2015-05-16 13:34:00 +01:00
Alexandre Niveau
6be7eaff1b ls: fix option -S for it to work without -lnpFi 2015-05-15 12:07:43 +01:00
sin
f90354bfc9 find: Allow using multiple paths 2015-05-15 12:07:43 +01:00
Evan Gates
86f9ce55a8 need implicit -a between ) and ! 2015-05-13 23:43:33 +01:00
Hiltjo Posthuma
347f0828f3 mktemp improvements
- add -p dir, -t and -u.
- fix dirname(tmp) check (did not check null terminator).

the semantics of mktemp is now the same as OpenBSD mktemp.
2015-05-10 12:58:38 +01:00
Hiltjo Posthuma
590f34c4a9 tar: compatibility, treat reserved type as regular file
References:
- http://www.gnu.org/software/tar/manual/html_node/Standard.html
- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/tar.h.html
2015-05-10 12:58:38 +01:00
Hiltjo Posthuma
9d95321f0b tar: compatibility, allow empty magic aswell 2015-05-10 12:58:38 +01:00
Wolfgang Corcoran-Mathe
00883efc16 join: fix typo 2015-05-09 20:29:52 +01:00
Hiltjo Posthuma
d41095299a tar: ignore more crazy GNU PAX header crap
don't fail, but maybe we should give a warning for this?
2015-05-08 21:36:40 +01:00
Hiltjo Posthuma
deb8a16527 tar: fix checksum calculation (signed/unsigned issue)
some archives gave the error: "malformed tar archive"

test file where this occurred:
   http://nl.alpinelinux.org/alpine/v3.1/main/x86_64/apk-tools-static-2.5.0_rc1-r0.apk
2015-05-08 21:36:40 +01:00
Hiltjo Posthuma
29649762b3 libutil/getlines: fix potential crash
linelen was uninitialized if for example:

$ > empty
$ sort ls.c empty
2015-05-08 16:38:06 +01:00
sin
e3cdcce2ec Clarify that compression is now supported in tar.1 2015-05-08 15:56:21 +01:00
sin
198238bd5d Bump date in tar.1 2015-05-08 15:56:21 +01:00
Hiltjo Posthuma
1d9d17eba2 tar: add support for compressing with an external tool
... and add xz, compress and lzma as options
2015-05-08 15:56:20 +01:00
Hiltjo Posthuma
7dff7d4c83 tar: add verbose flag (-v) 2015-05-08 15:56:20 +01:00
Eivind Uggedal
f5f43dbd5b ln: exit non-zero when errors accured 2015-05-08 10:06:58 +01:00
Eivind Uggedal
8f4b2e8689 ln: only check existence of src/to for hardlinks
This allows for creating dangling symlinks with force applied:

    # Before:
    $ ln -sf non-existant target
    ln: stat non-existent: No such file or directory
    $ ls -l target
    ls: lstat target: No such file or directory

    # After:
    $ ln -sf non-existant target
    $ ls -l target
    lrwxrwxrwx    1 eu    users   12 May 08 07:50 target -> non-existent

This also allows creating relative non-dangling symlinks with force applied:

    touch existant; mkdir dir

    # Before
    $ ln -sf ../existant dir
    ln: stat ../existant: No such file or directory
    $ ls -l dir

    # After
    $ ln -sf ../existant dir
    $ ls -l dir
    lrwxrwxrwx    1 eu    users   11 May 08 07:53 existant -> ../existant

The check for whether each src and to pairs are on the same device with the
same inode are only needed for hardlinks so that a forcefull link does
not remove the underlying file:

    touch f; mkdir dir

    # Before:
    $ ln -f f f dir
    ln: f and f are the same file
    $ ls -i f dir/f
    3670611 dir/f
    3670611 f

    # After:
    $ ln -f f f dir
    ln: f and f are the same file
    $ ls -i f dir/f
    4332236 dir/f
    4332236 f
2015-05-08 10:06:58 +01:00
Hiltjo Posthuma
3f01706837 libutil/getlines: use known line length
also style: linelen = length of getline(), this was slightly confusing.
2015-05-07 18:18:36 +01:00
Hiltjo Posthuma
adf9f47525 Revert "libutil/getlines: use known line length"
This reverts commit c69a70ddfd5c2b1514d9efd1c7a0fcbee5b0d2e7.
2015-05-07 18:18:36 +01:00
Hiltjo Posthuma
bd67e7d92d libutil/getlines: use known line length 2015-05-07 18:18:35 +01:00
Hiltjo Posthuma
72250324b1 sort: reuse buffer in columns()
speeds up sorting for huge input aswell.
2015-05-07 18:18:35 +01:00
Wolfgang Corcoran-Mathe
0b85532616 join manpage: Fix spelling
'-eth' might sound good to a native English speaker but will
probably confuse everyone else.
2015-05-05 10:53:42 +01:00
Wolfgang Corcoran-Mathe
dcfa94cdbd join: Add LICENSE header 2015-05-05 10:53:41 +01:00
Evan Gates
72d6553b12 include stdint.h for SIZE_MAX 2015-04-29 22:25:03 +01:00
sin
50c8785497 kill: Include strings.h for strcasecmp() 2015-04-29 16:42:49 +01:00
sin
63d863ae53 du: Use off_t instead of uintmax_t 2015-04-29 16:42:49 +01:00
sin
2deb40290e Use off_t in humansize() as it is more descriptive and applicable 2015-04-29 16:42:49 +01:00
sin
42326f7684 Include stdint.h in util.h for uintmax_t 2015-04-28 11:36:58 +01:00
Dionysis Grigoropoulos
a04da01160 du: Use uintmax_t instead of size_t
Fixes wraparound for files greater than 4G on 32-bit systems.
2015-04-28 11:36:58 +01:00
Dionysis Grigoropoulos
2d6cde1862 humansize: Use uintmax_t for size
du(1) breaks on 32-bit size_t for files greater than 4G.
2015-04-28 11:36:58 +01:00
sin
68fb6754ba which: Add LICENSE header 2015-04-27 19:33:57 +01:00
FRIGN
0b76449414 Add flag support to printf(1)
We skipped flags before, so no real bug, but it's trivial to add
now, so there's no reason not to do it.
2015-04-27 19:33:57 +01:00
FRIGN
b333176b8c Refactor and audit which(1)
Use the *at functions instead of building paths manually. We do
still have path-building in recurse() and other areas, but the
long-term goal is to rid most interfaces of that for practical
and security reasons.
In this case, it's more or less trivial.

Also, refactor the manpage to be more consistent with the others.

BUGFIX: Return exit status 3 on error.
2015-04-27 19:33:57 +01:00
Michael Forney
035e14c516 tr: Fix -c option when translating 2015-04-27 17:16:37 +01:00
Hiltjo Posthuma
e34bcca3e3 join: remove argv0, it is in arg.h 2015-04-27 16:58:42 +01:00
Hiltjo Posthuma
58cb564bbd add which 2015-04-27 16:58:42 +01:00
FRIGN
5595af5742 Convert humansize() to accept a size_t instead of a double
General convention is to use size_t to store sizes of all kinds.
Internally, the function uses double anyway, but at least this
doesn't clobber up the API any more and there's a chance in the
future to make this function a bit cleaner and not use this dirty
static buffer hack any more.
2015-04-25 11:43:14 +01:00
FRIGN
9016d288f1 Do not use arg.h for tools which take no flags
We've already seen the issue with echo(1): Before we changed it to
ignore "--", the command

$ echo --

did not work as expected. Given POSIX mandated this and makes most
sense, in the interest of consistency the other tools need to be
streamlined for that as well.
Looking at yes(1) for instance, there's no reason to skip "--" in
the argument list.
We do not have long options like GNU does and there's no reason to
tinker with that here.

The majority of tools changed are ones taking lists of arguments
or only a single one. There's no reason why dirname should "fail"
on "--". In the end, this is a valid name.

The practice of hand-holding the user was established with the GNU
coreutils. "--help" and "--version" long-options are a disgrace to
what could've been done properly with manpages.
2015-04-25 11:43:14 +01:00
Hiltjo Posthuma
e73f58937d du: staticize du 2015-04-25 11:43:14 +01:00
FRIGN
5a52154a47 tar: Fix remove(3)-error-message 2015-04-24 10:09:26 +01:00