History log of /openbsd-current/bin/pax/ar_subs.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.52 18-May-2024 guenther

When comparing mtimes for the -u and -Z options and the target is
'too old', use pathconfat(_PC_TIMESTAMP_RESOLUTION, AT_SYMLINK_NOFOLLOW)
to get the timestamp resolution to which the _source_ timestamp
should be truncated for a stable comparison.

Problem reported by Walter Alejandro Iglesias (wai(at)roquesor.com)
ok millert@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.51 10-Jul-2023 jeremy

Don't open files that will be skipped

Previously, when creating an archive file with pax(1), pax will attempt
to open a file even if the file will be skipped due to an -s replacement
with the empty string. With this change, pax will not attempt to open
files that it knows will be skipped.

When doing direct copies to a directory (-rw), pax already skips
the file before attempting to open it. So this makes the behavior
more consistent.

This can measurably speed up pax when skipping a large number of files.

OK tb@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.50 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.49 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.48 26-Aug-2016 guenther

Need <time.h> for time() and others. Pulled in by coincidence previously

noted by tb@


# 1.47 26-Aug-2016 guenther

reduce and sort #includes


# 1.46 25-Aug-2016 guenther

Replace name_{uid,gid}() with the libc routines user_from_uid() and
group_from_gid(). Eliminate some superfluous strncpy() calls.

ok millert@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.45 19-Mar-2015 guenther

Use struct timespec internally. This gives nanosecond precision to pax -rw
and a basis for support of mtime and atime values in pax-format extended
header records.

ok millert@


# 1.44 17-Mar-2015 guenther

Add PAX_IS_{REG,HARDLINK,LINK} macros to simply many file type tests

ok millert@


# 1.43 12-Mar-2015 guenther

If an archive isn't a recognized type, then check whether it looks
like compress, gzip, bzip2, or xz output. If so then error out with
a useful message directing the user to the correct option and error
out instead of scanning forward for an embedded tar/cpio header.

wording help from sobrado@
ok millert@ deraadt@


# 1.42 09-Mar-2015 guenther

Unrevert post-unlock:
* Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if it's still that zero-length placeholder).

* For tar without -P, if a path in the archive has any ".." components
then strip everything up to and including the last of them (if
it ends in ".." then it becomes ".")
This mostly follows GNU tar's behavior, except for 'tar tf' and
'tar xvf' we report the modified path that would be/was actually
created instead of the raw path from the archive

Above two fixes prompted by a report from Daniel Cegielka
(daniel.cegielka (at) gmail.com)

* For directories whose times or mode will be fixed up in the
clean-up pass, record their dev+ino and then use
open(O_DIRECTORY)+fstat() to verify that we're updating the correct
directory before using futimens() and fchmod().

* Correct buffer overflow in handling of pax extension headers,
caught by the memcpy() overlap check.


previously ok millert@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.41 21-Feb-2015 guenther

branches: 1.41.2;
Recent changes haven't been completely stable, so revert for the 5.7 release

requested by deraadt@


# 1.40 12-Feb-2015 guenther

Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if its still that zero-length placeholder).

This and previous symlink and ".." path fixes prompted by a report
from Daniel Cegielka (daniel.cegielka (at) gmail.com)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.39 23-May-2014 guenther

branches: 1.39.4;
Make the signal handler safe: block signals when updating data-structures
that are walked by routines called from the signal handler and use
dprintf() instead fprintf() in ar_close().

ok millert@


Revision tags: OPENBSD_5_5_BASE
# 1.38 05-Feb-2014 halex

make pax cope with a stripped down format list, e.g. when compiled
with -DNOCPIO
- ignore empty entries (millert@, halex@)
- replace bsort with linear scan (guenther@)

ok millert@ guenther@


# 1.37 30-Jan-2014 espie

abstraction for the sake of abstraction is distracting.

zap extra func pointer going to the same routines for all formats.
okay millert@


# 1.36 08-Jan-2014 guenther

Zap trailing whitespace


# 1.35 08-Jan-2014 guenther

Use size_t where appropriate

ok fgsch@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 04-Dec-2012 deraadt

remove some unnecessary sys/param.h inclusions


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 06-May-2008 henning

when pax is running in -u mode, and no files are beeing updated because
not one changed, we should not exit with an error but zero to indicate
success (matches solaris behaviour).
need to track wether files were skipped because of the -u checks for that
and take that into account later when taking the exit code decision.
ok theo, comments from otto and miod


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 17-Nov-2006 otto

Fix extracting and setting permissions for tar archives when
(multiple) -C options are present and/or (multiple) file selections
args are used. Based on a diff in NetBSD PR 22995. Tested by ckuethe@
and jaredy@; ok jaredy@


Revision tags: OPENBSD_4_0_BASE
# 1.30 21-Jul-2006 ray

Prevent segfault when "cpio -o" is called with no input.

Found and fix provided by Alf Schlichting <a dot schlichting at
lemarit dot com>.

OK millert@ and markus@.


Revision tags: OPENBSD_3_9_BASE
# 1.29 25-Jan-2006 markus

append without a file list should not corrupt a tar file;
report Rainer Giedat; ok millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.28 16-Apr-2004 deraadt

spacing


# 1.27 30-Mar-2004 millert

Add support for expanding GNU long links from NetBSD. I've had this
in my tree for ages but didn't have a proper test case. Thanks to
otto@ for providing one.


Revision tags: OPENBSD_3_5_BASE
# 1.26 15-Mar-2004 djm

more "if (foo);" ok millert@


Revision tags: OPENBSD_3_4_BASE
# 1.25 26-Jun-2003 deraadt

protos. this requires changing the api for the *trail() functions a bit


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.23 03-Feb-2003 jmc

typos;
from netbsd(svs+pr@grep.ru)
suggested by deraadt@


# 1.22 18-Oct-2002 millert

Pull in some changes from NetBSD
o When extracting GNU tar archives, honor @LongLink long links/files
o Add an option to prevent pax from prompting for the next volume
upon premature end of archive.


# 1.21 16-Oct-2002 millert

sprinkle const; mostly from NetBSD


# 1.20 16-Oct-2002 millert

Fix comment typos; most from NetBSD and FreeBSD


# 1.19 16-Oct-2002 millert

kill register


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.18 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.17 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.16 17-Jul-2001 millert

Add a safe_print() function that uses vis(3) if output is a tty.
Uses the vis C-style mode which is consistent with what GNU tar
does (though GNU tar does vis(3) regardless of whether output is a tty).

It may make sense to add a flag to force vis(3)ification like ls does
but I have not done that here as I'm reticent to add more flags.


# 1.15 16-May-2001 mickey

use proper str*cpy functions instead of home grown one, spaces; millert@ ok


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 20-Sep-1998 millert

When invoked as tar, print verbose output to stdout, not stderr. If in list mode or in create mode where create output is to stdout print to stderr


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 16-Sep-1997 niklas

Do not error out on archives without the
customary block of zeroes at the end.


# 1.12 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.11 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.10 24-Jul-1997 millert

Stash fd of cwd instead of using getcwd() to stash path.
This works in cases where the parent dir is not readable.


# 1.9 23-Jul-1997 kstailey

tabify


# 1.8 18-Jun-1997 kstailey

(foo *)NULL -> NULL


# 1.7 04-Jun-1997 millert

Fix usage of l_strncpy() (noticed by Theo) and make l_strncpy()
pad with NULL's like strncpy(3). This eliminates the need for
zf_strncpy(); ocurrences of zf_strncpy() have been changed to l_strncpy().


Revision tags: OPENBSD_2_1_BASE
# 1.6 27-Feb-1997 michaels

fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl).


# 1.5 24-Jan-1997 millert

Support multiple -v options like GNU tar (> 1 -v means do ls-like output).


# 1.4 27-Oct-1996 downsj

Initial cut -C support in paxtar. Exceeds GNU tar by quite a bit.
General pax still seems to work ok.


Revision tags: OPENBSD_2_0_BASE
# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 11-Jun-1996 tholo

Correct compile warnings
Rename warn() to paxwarn() so <err.h> can be included

Remove #include <ctype.h> when not needed; from FreeBSD


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.51 10-Jul-2023 jeremy

Don't open files that will be skipped

Previously, when creating an archive file with pax(1), pax will attempt
to open a file even if the file will be skipped due to an -s replacement
with the empty string. With this change, pax will not attempt to open
files that it knows will be skipped.

When doing direct copies to a directory (-rw), pax already skips
the file before attempting to open it. So this makes the behavior
more consistent.

This can measurably speed up pax when skipping a large number of files.

OK tb@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.50 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.49 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.48 26-Aug-2016 guenther

Need <time.h> for time() and others. Pulled in by coincidence previously

noted by tb@


# 1.47 26-Aug-2016 guenther

reduce and sort #includes


# 1.46 25-Aug-2016 guenther

Replace name_{uid,gid}() with the libc routines user_from_uid() and
group_from_gid(). Eliminate some superfluous strncpy() calls.

ok millert@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.45 19-Mar-2015 guenther

Use struct timespec internally. This gives nanosecond precision to pax -rw
and a basis for support of mtime and atime values in pax-format extended
header records.

ok millert@


# 1.44 17-Mar-2015 guenther

Add PAX_IS_{REG,HARDLINK,LINK} macros to simply many file type tests

ok millert@


# 1.43 12-Mar-2015 guenther

If an archive isn't a recognized type, then check whether it looks
like compress, gzip, bzip2, or xz output. If so then error out with
a useful message directing the user to the correct option and error
out instead of scanning forward for an embedded tar/cpio header.

wording help from sobrado@
ok millert@ deraadt@


# 1.42 09-Mar-2015 guenther

Unrevert post-unlock:
* Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if it's still that zero-length placeholder).

* For tar without -P, if a path in the archive has any ".." components
then strip everything up to and including the last of them (if
it ends in ".." then it becomes ".")
This mostly follows GNU tar's behavior, except for 'tar tf' and
'tar xvf' we report the modified path that would be/was actually
created instead of the raw path from the archive

Above two fixes prompted by a report from Daniel Cegielka
(daniel.cegielka (at) gmail.com)

* For directories whose times or mode will be fixed up in the
clean-up pass, record their dev+ino and then use
open(O_DIRECTORY)+fstat() to verify that we're updating the correct
directory before using futimens() and fchmod().

* Correct buffer overflow in handling of pax extension headers,
caught by the memcpy() overlap check.


previously ok millert@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.41 21-Feb-2015 guenther

branches: 1.41.2;
Recent changes haven't been completely stable, so revert for the 5.7 release

requested by deraadt@


# 1.40 12-Feb-2015 guenther

Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if its still that zero-length placeholder).

This and previous symlink and ".." path fixes prompted by a report
from Daniel Cegielka (daniel.cegielka (at) gmail.com)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.39 23-May-2014 guenther

branches: 1.39.4;
Make the signal handler safe: block signals when updating data-structures
that are walked by routines called from the signal handler and use
dprintf() instead fprintf() in ar_close().

ok millert@


Revision tags: OPENBSD_5_5_BASE
# 1.38 05-Feb-2014 halex

make pax cope with a stripped down format list, e.g. when compiled
with -DNOCPIO
- ignore empty entries (millert@, halex@)
- replace bsort with linear scan (guenther@)

ok millert@ guenther@


# 1.37 30-Jan-2014 espie

abstraction for the sake of abstraction is distracting.

zap extra func pointer going to the same routines for all formats.
okay millert@


# 1.36 08-Jan-2014 guenther

Zap trailing whitespace


# 1.35 08-Jan-2014 guenther

Use size_t where appropriate

ok fgsch@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 04-Dec-2012 deraadt

remove some unnecessary sys/param.h inclusions


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 06-May-2008 henning

when pax is running in -u mode, and no files are beeing updated because
not one changed, we should not exit with an error but zero to indicate
success (matches solaris behaviour).
need to track wether files were skipped because of the -u checks for that
and take that into account later when taking the exit code decision.
ok theo, comments from otto and miod


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 17-Nov-2006 otto

Fix extracting and setting permissions for tar archives when
(multiple) -C options are present and/or (multiple) file selections
args are used. Based on a diff in NetBSD PR 22995. Tested by ckuethe@
and jaredy@; ok jaredy@


Revision tags: OPENBSD_4_0_BASE
# 1.30 21-Jul-2006 ray

Prevent segfault when "cpio -o" is called with no input.

Found and fix provided by Alf Schlichting <a dot schlichting at
lemarit dot com>.

OK millert@ and markus@.


Revision tags: OPENBSD_3_9_BASE
# 1.29 25-Jan-2006 markus

append without a file list should not corrupt a tar file;
report Rainer Giedat; ok millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.28 16-Apr-2004 deraadt

spacing


# 1.27 30-Mar-2004 millert

Add support for expanding GNU long links from NetBSD. I've had this
in my tree for ages but didn't have a proper test case. Thanks to
otto@ for providing one.


Revision tags: OPENBSD_3_5_BASE
# 1.26 15-Mar-2004 djm

more "if (foo);" ok millert@


Revision tags: OPENBSD_3_4_BASE
# 1.25 26-Jun-2003 deraadt

protos. this requires changing the api for the *trail() functions a bit


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.23 03-Feb-2003 jmc

typos;
from netbsd(svs+pr@grep.ru)
suggested by deraadt@


# 1.22 18-Oct-2002 millert

Pull in some changes from NetBSD
o When extracting GNU tar archives, honor @LongLink long links/files
o Add an option to prevent pax from prompting for the next volume
upon premature end of archive.


# 1.21 16-Oct-2002 millert

sprinkle const; mostly from NetBSD


# 1.20 16-Oct-2002 millert

Fix comment typos; most from NetBSD and FreeBSD


# 1.19 16-Oct-2002 millert

kill register


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.18 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.17 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.16 17-Jul-2001 millert

Add a safe_print() function that uses vis(3) if output is a tty.
Uses the vis C-style mode which is consistent with what GNU tar
does (though GNU tar does vis(3) regardless of whether output is a tty).

It may make sense to add a flag to force vis(3)ification like ls does
but I have not done that here as I'm reticent to add more flags.


# 1.15 16-May-2001 mickey

use proper str*cpy functions instead of home grown one, spaces; millert@ ok


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 20-Sep-1998 millert

When invoked as tar, print verbose output to stdout, not stderr. If in list mode or in create mode where create output is to stdout print to stderr


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 16-Sep-1997 niklas

Do not error out on archives without the
customary block of zeroes at the end.


# 1.12 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.11 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.10 24-Jul-1997 millert

Stash fd of cwd instead of using getcwd() to stash path.
This works in cases where the parent dir is not readable.


# 1.9 23-Jul-1997 kstailey

tabify


# 1.8 18-Jun-1997 kstailey

(foo *)NULL -> NULL


# 1.7 04-Jun-1997 millert

Fix usage of l_strncpy() (noticed by Theo) and make l_strncpy()
pad with NULL's like strncpy(3). This eliminates the need for
zf_strncpy(); ocurrences of zf_strncpy() have been changed to l_strncpy().


Revision tags: OPENBSD_2_1_BASE
# 1.6 27-Feb-1997 michaels

fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl).


# 1.5 24-Jan-1997 millert

Support multiple -v options like GNU tar (> 1 -v means do ls-like output).


# 1.4 27-Oct-1996 downsj

Initial cut -C support in paxtar. Exceeds GNU tar by quite a bit.
General pax still seems to work ok.


Revision tags: OPENBSD_2_0_BASE
# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 11-Jun-1996 tholo

Correct compile warnings
Rename warn() to paxwarn() so <err.h> can be included

Remove #include <ctype.h> when not needed; from FreeBSD


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.50 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.49 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.48 26-Aug-2016 guenther

Need <time.h> for time() and others. Pulled in by coincidence previously

noted by tb@


# 1.47 26-Aug-2016 guenther

reduce and sort #includes


# 1.46 25-Aug-2016 guenther

Replace name_{uid,gid}() with the libc routines user_from_uid() and
group_from_gid(). Eliminate some superfluous strncpy() calls.

ok millert@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.45 19-Mar-2015 guenther

Use struct timespec internally. This gives nanosecond precision to pax -rw
and a basis for support of mtime and atime values in pax-format extended
header records.

ok millert@


# 1.44 17-Mar-2015 guenther

Add PAX_IS_{REG,HARDLINK,LINK} macros to simply many file type tests

ok millert@


# 1.43 12-Mar-2015 guenther

If an archive isn't a recognized type, then check whether it looks
like compress, gzip, bzip2, or xz output. If so then error out with
a useful message directing the user to the correct option and error
out instead of scanning forward for an embedded tar/cpio header.

wording help from sobrado@
ok millert@ deraadt@


# 1.42 09-Mar-2015 guenther

Unrevert post-unlock:
* Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if it's still that zero-length placeholder).

* For tar without -P, if a path in the archive has any ".." components
then strip everything up to and including the last of them (if
it ends in ".." then it becomes ".")
This mostly follows GNU tar's behavior, except for 'tar tf' and
'tar xvf' we report the modified path that would be/was actually
created instead of the raw path from the archive

Above two fixes prompted by a report from Daniel Cegielka
(daniel.cegielka (at) gmail.com)

* For directories whose times or mode will be fixed up in the
clean-up pass, record their dev+ino and then use
open(O_DIRECTORY)+fstat() to verify that we're updating the correct
directory before using futimens() and fchmod().

* Correct buffer overflow in handling of pax extension headers,
caught by the memcpy() overlap check.


previously ok millert@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.41 21-Feb-2015 guenther

branches: 1.41.2;
Recent changes haven't been completely stable, so revert for the 5.7 release

requested by deraadt@


# 1.40 12-Feb-2015 guenther

Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if its still that zero-length placeholder).

This and previous symlink and ".." path fixes prompted by a report
from Daniel Cegielka (daniel.cegielka (at) gmail.com)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.39 23-May-2014 guenther

branches: 1.39.4;
Make the signal handler safe: block signals when updating data-structures
that are walked by routines called from the signal handler and use
dprintf() instead fprintf() in ar_close().

ok millert@


Revision tags: OPENBSD_5_5_BASE
# 1.38 05-Feb-2014 halex

make pax cope with a stripped down format list, e.g. when compiled
with -DNOCPIO
- ignore empty entries (millert@, halex@)
- replace bsort with linear scan (guenther@)

ok millert@ guenther@


# 1.37 30-Jan-2014 espie

abstraction for the sake of abstraction is distracting.

zap extra func pointer going to the same routines for all formats.
okay millert@


# 1.36 08-Jan-2014 guenther

Zap trailing whitespace


# 1.35 08-Jan-2014 guenther

Use size_t where appropriate

ok fgsch@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 04-Dec-2012 deraadt

remove some unnecessary sys/param.h inclusions


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 06-May-2008 henning

when pax is running in -u mode, and no files are beeing updated because
not one changed, we should not exit with an error but zero to indicate
success (matches solaris behaviour).
need to track wether files were skipped because of the -u checks for that
and take that into account later when taking the exit code decision.
ok theo, comments from otto and miod


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 17-Nov-2006 otto

Fix extracting and setting permissions for tar archives when
(multiple) -C options are present and/or (multiple) file selections
args are used. Based on a diff in NetBSD PR 22995. Tested by ckuethe@
and jaredy@; ok jaredy@


Revision tags: OPENBSD_4_0_BASE
# 1.30 21-Jul-2006 ray

Prevent segfault when "cpio -o" is called with no input.

Found and fix provided by Alf Schlichting <a dot schlichting at
lemarit dot com>.

OK millert@ and markus@.


Revision tags: OPENBSD_3_9_BASE
# 1.29 25-Jan-2006 markus

append without a file list should not corrupt a tar file;
report Rainer Giedat; ok millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.28 16-Apr-2004 deraadt

spacing


# 1.27 30-Mar-2004 millert

Add support for expanding GNU long links from NetBSD. I've had this
in my tree for ages but didn't have a proper test case. Thanks to
otto@ for providing one.


Revision tags: OPENBSD_3_5_BASE
# 1.26 15-Mar-2004 djm

more "if (foo);" ok millert@


Revision tags: OPENBSD_3_4_BASE
# 1.25 26-Jun-2003 deraadt

protos. this requires changing the api for the *trail() functions a bit


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.23 03-Feb-2003 jmc

typos;
from netbsd(svs+pr@grep.ru)
suggested by deraadt@


# 1.22 18-Oct-2002 millert

Pull in some changes from NetBSD
o When extracting GNU tar archives, honor @LongLink long links/files
o Add an option to prevent pax from prompting for the next volume
upon premature end of archive.


# 1.21 16-Oct-2002 millert

sprinkle const; mostly from NetBSD


# 1.20 16-Oct-2002 millert

Fix comment typos; most from NetBSD and FreeBSD


# 1.19 16-Oct-2002 millert

kill register


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.18 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.17 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.16 17-Jul-2001 millert

Add a safe_print() function that uses vis(3) if output is a tty.
Uses the vis C-style mode which is consistent with what GNU tar
does (though GNU tar does vis(3) regardless of whether output is a tty).

It may make sense to add a flag to force vis(3)ification like ls does
but I have not done that here as I'm reticent to add more flags.


# 1.15 16-May-2001 mickey

use proper str*cpy functions instead of home grown one, spaces; millert@ ok


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 20-Sep-1998 millert

When invoked as tar, print verbose output to stdout, not stderr. If in list mode or in create mode where create output is to stdout print to stderr


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 16-Sep-1997 niklas

Do not error out on archives without the
customary block of zeroes at the end.


# 1.12 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.11 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.10 24-Jul-1997 millert

Stash fd of cwd instead of using getcwd() to stash path.
This works in cases where the parent dir is not readable.


# 1.9 23-Jul-1997 kstailey

tabify


# 1.8 18-Jun-1997 kstailey

(foo *)NULL -> NULL


# 1.7 04-Jun-1997 millert

Fix usage of l_strncpy() (noticed by Theo) and make l_strncpy()
pad with NULL's like strncpy(3). This eliminates the need for
zf_strncpy(); ocurrences of zf_strncpy() have been changed to l_strncpy().


Revision tags: OPENBSD_2_1_BASE
# 1.6 27-Feb-1997 michaels

fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl).


# 1.5 24-Jan-1997 millert

Support multiple -v options like GNU tar (> 1 -v means do ls-like output).


# 1.4 27-Oct-1996 downsj

Initial cut -C support in paxtar. Exceeds GNU tar by quite a bit.
General pax still seems to work ok.


Revision tags: OPENBSD_2_0_BASE
# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 11-Jun-1996 tholo

Correct compile warnings
Rename warn() to paxwarn() so <err.h> can be included

Remove #include <ctype.h> when not needed; from FreeBSD


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.49 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.48 26-Aug-2016 guenther

Need <time.h> for time() and others. Pulled in by coincidence previously

noted by tb@


# 1.47 26-Aug-2016 guenther

reduce and sort #includes


# 1.46 25-Aug-2016 guenther

Replace name_{uid,gid}() with the libc routines user_from_uid() and
group_from_gid(). Eliminate some superfluous strncpy() calls.

ok millert@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.45 19-Mar-2015 guenther

Use struct timespec internally. This gives nanosecond precision to pax -rw
and a basis for support of mtime and atime values in pax-format extended
header records.

ok millert@


# 1.44 17-Mar-2015 guenther

Add PAX_IS_{REG,HARDLINK,LINK} macros to simply many file type tests

ok millert@


# 1.43 12-Mar-2015 guenther

If an archive isn't a recognized type, then check whether it looks
like compress, gzip, bzip2, or xz output. If so then error out with
a useful message directing the user to the correct option and error
out instead of scanning forward for an embedded tar/cpio header.

wording help from sobrado@
ok millert@ deraadt@


# 1.42 09-Mar-2015 guenther

Unrevert post-unlock:
* Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if it's still that zero-length placeholder).

* For tar without -P, if a path in the archive has any ".." components
then strip everything up to and including the last of them (if
it ends in ".." then it becomes ".")
This mostly follows GNU tar's behavior, except for 'tar tf' and
'tar xvf' we report the modified path that would be/was actually
created instead of the raw path from the archive

Above two fixes prompted by a report from Daniel Cegielka
(daniel.cegielka (at) gmail.com)

* For directories whose times or mode will be fixed up in the
clean-up pass, record their dev+ino and then use
open(O_DIRECTORY)+fstat() to verify that we're updating the correct
directory before using futimens() and fchmod().

* Correct buffer overflow in handling of pax extension headers,
caught by the memcpy() overlap check.


previously ok millert@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.41 21-Feb-2015 guenther

branches: 1.41.2;
Recent changes haven't been completely stable, so revert for the 5.7 release

requested by deraadt@


# 1.40 12-Feb-2015 guenther

Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if its still that zero-length placeholder).

This and previous symlink and ".." path fixes prompted by a report
from Daniel Cegielka (daniel.cegielka (at) gmail.com)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.39 23-May-2014 guenther

branches: 1.39.4;
Make the signal handler safe: block signals when updating data-structures
that are walked by routines called from the signal handler and use
dprintf() instead fprintf() in ar_close().

ok millert@


Revision tags: OPENBSD_5_5_BASE
# 1.38 05-Feb-2014 halex

make pax cope with a stripped down format list, e.g. when compiled
with -DNOCPIO
- ignore empty entries (millert@, halex@)
- replace bsort with linear scan (guenther@)

ok millert@ guenther@


# 1.37 30-Jan-2014 espie

abstraction for the sake of abstraction is distracting.

zap extra func pointer going to the same routines for all formats.
okay millert@


# 1.36 08-Jan-2014 guenther

Zap trailing whitespace


# 1.35 08-Jan-2014 guenther

Use size_t where appropriate

ok fgsch@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 04-Dec-2012 deraadt

remove some unnecessary sys/param.h inclusions


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 06-May-2008 henning

when pax is running in -u mode, and no files are beeing updated because
not one changed, we should not exit with an error but zero to indicate
success (matches solaris behaviour).
need to track wether files were skipped because of the -u checks for that
and take that into account later when taking the exit code decision.
ok theo, comments from otto and miod


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 17-Nov-2006 otto

Fix extracting and setting permissions for tar archives when
(multiple) -C options are present and/or (multiple) file selections
args are used. Based on a diff in NetBSD PR 22995. Tested by ckuethe@
and jaredy@; ok jaredy@


Revision tags: OPENBSD_4_0_BASE
# 1.30 21-Jul-2006 ray

Prevent segfault when "cpio -o" is called with no input.

Found and fix provided by Alf Schlichting <a dot schlichting at
lemarit dot com>.

OK millert@ and markus@.


Revision tags: OPENBSD_3_9_BASE
# 1.29 25-Jan-2006 markus

append without a file list should not corrupt a tar file;
report Rainer Giedat; ok millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.28 16-Apr-2004 deraadt

spacing


# 1.27 30-Mar-2004 millert

Add support for expanding GNU long links from NetBSD. I've had this
in my tree for ages but didn't have a proper test case. Thanks to
otto@ for providing one.


Revision tags: OPENBSD_3_5_BASE
# 1.26 15-Mar-2004 djm

more "if (foo);" ok millert@


Revision tags: OPENBSD_3_4_BASE
# 1.25 26-Jun-2003 deraadt

protos. this requires changing the api for the *trail() functions a bit


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.23 03-Feb-2003 jmc

typos;
from netbsd(svs+pr@grep.ru)
suggested by deraadt@


# 1.22 18-Oct-2002 millert

Pull in some changes from NetBSD
o When extracting GNU tar archives, honor @LongLink long links/files
o Add an option to prevent pax from prompting for the next volume
upon premature end of archive.


# 1.21 16-Oct-2002 millert

sprinkle const; mostly from NetBSD


# 1.20 16-Oct-2002 millert

Fix comment typos; most from NetBSD and FreeBSD


# 1.19 16-Oct-2002 millert

kill register


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.18 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.17 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.16 17-Jul-2001 millert

Add a safe_print() function that uses vis(3) if output is a tty.
Uses the vis C-style mode which is consistent with what GNU tar
does (though GNU tar does vis(3) regardless of whether output is a tty).

It may make sense to add a flag to force vis(3)ification like ls does
but I have not done that here as I'm reticent to add more flags.


# 1.15 16-May-2001 mickey

use proper str*cpy functions instead of home grown one, spaces; millert@ ok


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 20-Sep-1998 millert

When invoked as tar, print verbose output to stdout, not stderr. If in list mode or in create mode where create output is to stdout print to stderr


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 16-Sep-1997 niklas

Do not error out on archives without the
customary block of zeroes at the end.


# 1.12 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.11 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.10 24-Jul-1997 millert

Stash fd of cwd instead of using getcwd() to stash path.
This works in cases where the parent dir is not readable.


# 1.9 23-Jul-1997 kstailey

tabify


# 1.8 18-Jun-1997 kstailey

(foo *)NULL -> NULL


# 1.7 04-Jun-1997 millert

Fix usage of l_strncpy() (noticed by Theo) and make l_strncpy()
pad with NULL's like strncpy(3). This eliminates the need for
zf_strncpy(); ocurrences of zf_strncpy() have been changed to l_strncpy().


Revision tags: OPENBSD_2_1_BASE
# 1.6 27-Feb-1997 michaels

fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl).


# 1.5 24-Jan-1997 millert

Support multiple -v options like GNU tar (> 1 -v means do ls-like output).


# 1.4 27-Oct-1996 downsj

Initial cut -C support in paxtar. Exceeds GNU tar by quite a bit.
General pax still seems to work ok.


Revision tags: OPENBSD_2_0_BASE
# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 11-Jun-1996 tholo

Correct compile warnings
Rename warn() to paxwarn() so <err.h> can be included

Remove #include <ctype.h> when not needed; from FreeBSD


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.48 26-Aug-2016 guenther

Need <time.h> for time() and others. Pulled in by coincidence previously

noted by tb@


# 1.47 26-Aug-2016 guenther

reduce and sort #includes


# 1.46 25-Aug-2016 guenther

Replace name_{uid,gid}() with the libc routines user_from_uid() and
group_from_gid(). Eliminate some superfluous strncpy() calls.

ok millert@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.45 19-Mar-2015 guenther

Use struct timespec internally. This gives nanosecond precision to pax -rw
and a basis for support of mtime and atime values in pax-format extended
header records.

ok millert@


# 1.44 17-Mar-2015 guenther

Add PAX_IS_{REG,HARDLINK,LINK} macros to simply many file type tests

ok millert@


# 1.43 12-Mar-2015 guenther

If an archive isn't a recognized type, then check whether it looks
like compress, gzip, bzip2, or xz output. If so then error out with
a useful message directing the user to the correct option and error
out instead of scanning forward for an embedded tar/cpio header.

wording help from sobrado@
ok millert@ deraadt@


# 1.42 09-Mar-2015 guenther

Unrevert post-unlock:
* Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if it's still that zero-length placeholder).

* For tar without -P, if a path in the archive has any ".." components
then strip everything up to and including the last of them (if
it ends in ".." then it becomes ".")
This mostly follows GNU tar's behavior, except for 'tar tf' and
'tar xvf' we report the modified path that would be/was actually
created instead of the raw path from the archive

Above two fixes prompted by a report from Daniel Cegielka
(daniel.cegielka (at) gmail.com)

* For directories whose times or mode will be fixed up in the
clean-up pass, record their dev+ino and then use
open(O_DIRECTORY)+fstat() to verify that we're updating the correct
directory before using futimens() and fchmod().

* Correct buffer overflow in handling of pax extension headers,
caught by the memcpy() overlap check.


previously ok millert@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.41 21-Feb-2015 guenther

branches: 1.41.2;
Recent changes haven't been completely stable, so revert for the 5.7 release

requested by deraadt@


# 1.40 12-Feb-2015 guenther

Prevent an archive from esacaping the current directory by itself:
when extracting a symlink whose value is absolute or contains ".."
components, just create a zero-length normal file (with additional
tracking of the mode and hardlinks to the symlink) until everything
else is extracted, then go back and replace it with the requested
link (if its still that zero-length placeholder).

This and previous symlink and ".." path fixes prompted by a report
from Daniel Cegielka (daniel.cegielka (at) gmail.com)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.39 23-May-2014 guenther

branches: 1.39.4;
Make the signal handler safe: block signals when updating data-structures
that are walked by routines called from the signal handler and use
dprintf() instead fprintf() in ar_close().

ok millert@


Revision tags: OPENBSD_5_5_BASE
# 1.38 05-Feb-2014 halex

make pax cope with a stripped down format list, e.g. when compiled
with -DNOCPIO
- ignore empty entries (millert@, halex@)
- replace bsort with linear scan (guenther@)

ok millert@ guenther@


# 1.37 30-Jan-2014 espie

abstraction for the sake of abstraction is distracting.

zap extra func pointer going to the same routines for all formats.
okay millert@


# 1.36 08-Jan-2014 guenther

Zap trailing whitespace


# 1.35 08-Jan-2014 guenther

Use size_t where appropriate

ok fgsch@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 04-Dec-2012 deraadt

remove some unnecessary sys/param.h inclusions


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 06-May-2008 henning

when pax is running in -u mode, and no files are beeing updated because
not one changed, we should not exit with an error but zero to indicate
success (matches solaris behaviour).
need to track wether files were skipped because of the -u checks for that
and take that into account later when taking the exit code decision.
ok theo, comments from otto and miod


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 17-Nov-2006 otto

Fix extracting and setting permissions for tar archives when
(multiple) -C options are present and/or (multiple) file selections
args are used. Based on a diff in NetBSD PR 22995. Tested by ckuethe@
and jaredy@; ok jaredy@


Revision tags: OPENBSD_4_0_BASE
# 1.30 21-Jul-2006 ray

Prevent segfault when "cpio -o" is called with no input.

Found and fix provided by Alf Schlichting <a dot schlichting at
lemarit dot com>.

OK millert@ and markus@.


Revision tags: OPENBSD_3_9_BASE
# 1.29 25-Jan-2006 markus

append without a file list should not corrupt a tar file;
report Rainer Giedat; ok millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.28 16-Apr-2004 deraadt

spacing


# 1.27 30-Mar-2004 millert

Add support for expanding GNU long links from NetBSD. I've had this
in my tree for ages but didn't have a proper test case. Thanks to
otto@ for providing one.


Revision tags: OPENBSD_3_5_BASE
# 1.26 15-Mar-2004 djm

more "if (foo);" ok millert@


Revision tags: OPENBSD_3_4_BASE
# 1.25 26-Jun-2003 deraadt

protos. this requires changing the api for the *trail() functions a bit


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.23 03-Feb-2003 jmc

typos;
from netbsd(svs+pr@grep.ru)
suggested by deraadt@


# 1.22 18-Oct-2002 millert

Pull in some changes from NetBSD
o When extracting GNU tar archives, honor @LongLink long links/files
o Add an option to prevent pax from prompting for the next volume
upon premature end of archive.


# 1.21 16-Oct-2002 millert

sprinkle const; mostly from NetBSD


# 1.20 16-Oct-2002 millert

Fix comment typos; most from NetBSD and FreeBSD


# 1.19 16-Oct-2002 millert

kill register


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.18 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.17 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.16 17-Jul-2001 millert

Add a safe_print() function that uses vis(3) if output is a tty.
Uses the vis C-style mode which is consistent with what GNU tar
does (though GNU tar does vis(3) regardless of whether output is a tty).

It may make sense to add a flag to force vis(3)ification like ls does
but I have not done that here as I'm reticent to add more flags.


# 1.15 16-May-2001 mickey

use proper str*cpy functions instead of home grown one, spaces; millert@ ok


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 20-Sep-1998 millert

When invoked as tar, print verbose output to stdout, not stderr. If in list mode or in create mode where create output is to stdout print to stderr


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.13 16-Sep-1997 niklas

Do not error out on archives without the
customary block of zeroes at the end.


# 1.12 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.11 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.10 24-Jul-1997 millert

Stash fd of cwd instead of using getcwd() to stash path.
This works in cases where the parent dir is not readable.


# 1.9 23-Jul-1997 kstailey

tabify


# 1.8 18-Jun-1997 kstailey

(foo *)NULL -> NULL


# 1.7 04-Jun-1997 millert

Fix usage of l_strncpy() (noticed by Theo) and make l_strncpy()
pad with NULL's like strncpy(3). This eliminates the need for
zf_strncpy(); ocurrences of zf_strncpy() have been changed to l_strncpy().


Revision tags: OPENBSD_2_1_BASE
# 1.6 27-Feb-1997 michaels

fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl).


# 1.5 24-Jan-1997 millert

Support multiple -v options like GNU tar (> 1 -v means do ls-like output).


# 1.4 27-Oct-1996 downsj

Initial cut -C support in paxtar. Exceeds GNU tar by quite a bit.
General pax still seems to work ok.


Revision tags: OPENBSD_2_0_BASE
# 1.3 23-Jun-1996 deraadt

update rcsid


# 1.2 11-Jun-1996 tholo

Correct compile warnings
Rename warn() to paxwarn() so <err.h> can be included

Remove #include <ctype.h> when not needed; from FreeBSD


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision