Home | History | Annotate | only in /src/bin/pax
History log of /src/bin/pax
RevisionDateAuthorComments
 1.42 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.41 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.40 15-Aug-2019  uwe Install manual pages for tar and cpio only if ${MKBSDTAR} == "no"
PR bin/54468
 1.39 23-Apr-2010  joerg branches: 1.39.48; 1.39.50;
Add MKBSDTAR, defaulting to no. It switching cpio and tar to the
libarchive based frontends.
 1.38 03-Feb-2009  dbj do not require sys/mtio.h for a tools build of pax
 1.37 24-Feb-2008  joerg branches: 1.37.8; 1.37.10; 1.37.12;
Kill pre-4.4BSD compat code.
 1.36 16-Dec-2006  bouyer branches: 1.36.4; 1.36.8;
Don't depend on lubutil if we're building host tools. Fix tools build on
non-NetBSD hosts.
 1.35 14-Dec-2006  he Complete the move of string_to_flags() and flags_to_string() from the
bin/ls sources to libutil:
o Bump libutil minor version number
o Fix uses to include <util.h> to pick up the function definitions
o Fix most uses of flags_to_string() to release the now-malloc()ed result
 1.34 29-Jun-2005  christos Don't compile in cpio usage, if we are SMALL.
 1.33 26-Jun-2005  christos sprinkle a little const, and now everything compiles with WARNS=3
 1.32 01-May-2005  christos PR/29005: Jesse Off: nbpax requires sys/mtio.h which doesn't exist on Interix
I added an ifdef called HAVE_MTIO_H and fixed the code to use it. It is
always defined now, but you can change this for Interix.
 1.31 11-May-2004  christos Welcome to WARNS=3
 1.30 18-Jul-2003  lukem branches: 1.30.4;
doc2html works here now, so remove NOHTML=
(not that it worked here, because NOHTML= was provided *after* <bsd.own.mk>...)
 1.29 18-May-2003  lukem Now that <bsd.prog.mk> DTRT if HOSTPROG is defined (i.e, it is a no-op),
there's no need to special-case .include-ing it.
 1.28 09-May-2003  lukem #ifdef HOSTPROG then explicitly use {major,minor,makedev}_netbsd
macros from pack_dev.h instead of the native versions.
Fixes [toolchain/20051] by Valeriy E. Ushakov.
 1.27 30-Nov-2002  lukem don't need -lutil any more
 1.26 21-Oct-2002  lukem don't bother with cpio/tar links or compat symlinks for HOSTPROGs
 1.25 20-Oct-2002  thorpej Install compatibility symlinks for /usr/bin/tar (-> /bin/tar)
and /usr/bin/cpio (/bin/cpio). The pathname of tar(1) is hard-coded
into things like binary packages, and thus must be kept around
for backward compatibility.
 1.24 16-Oct-2002  christos Flip the pax switch
 1.23 14-Oct-2002  lukem fix previous: SMALLPROG w/o HOSTPROG still needs <bsd.prog.mk>. (hi christos)
 1.22 14-Oct-2002  christos don't support rmt for SMALLPROG
 1.21 12-Oct-2002  thorpej It doesn't help much to skip linking librmt if HOSTPROG but leave
all the librmt calls in the program. So, make librmt support conditional
on #ifdef SUPPORT_RMT, and define that when NOT building as a HOSTPROG.
 1.20 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.19 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path (etc).
 1.18 02-Feb-2002  lukem make smaller if SMALLPROG is defined, not CRUNCHEDPROG; it's feasible
that a crunchgen(3)ed version of pax wants -USMALL ...
 1.17 02-Feb-2002  lukem - don't compile in support for -M (mtree specfile input) or -N dbdir
(alternate directory for id info) if SMALL is defined
- enable -DSMALL and remove unused objects if CRUNCHEDPROG is defined
- minor cleanup in next_file() (preparation for future work)
 1.16 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.15 25-Jan-2002  martin Do not .include <bsd.prog.mk> if building as a host tool.
 1.14 24-Jan-2002  lukem Add '-N dbdir', to specify that user & group lookups (via pwcache(3)) are to
be done from dbdir/master.passwd and dbdir/group, using simple text file
parsing routines from ../../usr.sbin/mtree/getid.c.
This does not affect the -G and -U options, which always use the
system databases.
 1.13 28-Oct-2001  lukem s/u_longlong_t/unsigned long long/ to shut up the parc port
 1.12 25-Oct-2001  lukem Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.11 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.10 26-Sep-2000  phil Don't generate html yet. doc2html needs a fix.
 1.9 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.8 06-Mar-1998  mrg - implement -C and -l for pax-as-tar, as inspried by GNU tar.
- minor cleanups to the options parsing code.
- add a cpio frontend.

note: a few GNU/svr4 cpio options are not supported yet (#ifdef
notyet), however all x/open ones are.
 1.7 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.6 20-Jul-1997  christos Remove WARNS=1 from all the subdirectory Makefiles, and add it to Makefile.inc
now that all /bin has been cleaned.
 1.5 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  jtc Whoever wrote the tar command line argument parsing code didn't realize
that the order of arguments is different if the command flags are specified
without a `-'. I've integrated getoldopt.c from John Gilmore's pdtar which
handles argument parsing correctly.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.30.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.36.8.1 24-Mar-2008  keiichi sync with head.
 1.36.4.1 23-Mar-2008  matt sync with HEAD
 1.37.12.3 21-Apr-2010  matt sync to netbsd-5
 1.37.12.2 18-Dec-2009  matt Make this compile on snow leopard.
 1.37.12.1 15-Dec-2009  matt Allow tools to build on OSX 10.6 (Snow Leopard).
 1.37.10.1 03-Oct-2009  snj Pull up following revision(s) (requested by apb in ticket #1020):
bin/pax/Makefile: revision 1.38
bin/pax/ar_io.c: revision 1.49
tools/compat/configure: revision 1.69
tools/compat/configure.ac: revision 1.69
do not require sys/mtio.h for a tools build of pax
 1.37.8.1 03-Oct-2009  snj Pull up following revision(s) (requested by apb in ticket #1020):
bin/pax/Makefile: revision 1.38
bin/pax/ar_io.c: revision 1.49
tools/compat/configure: revision 1.69
tools/compat/configure.ac: revision 1.69
do not require sys/mtio.h for a tools build of pax
 1.39.50.1 13-Nov-2019  martin Pull up following revision(s) (requested by nakayama in ticket #421):

bin/pax/Makefile: revision 1.40

Install manual pages for tar and cpio only if ${MKBSDTAR} == "no"
PR bin/54468
 1.39.48.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.39.48.2 21-Apr-2020  martin Sync with HEAD
 1.39.48.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.60 20-Jul-2023  lukem pax: fix -Wformat for host tool
 1.59 04-Feb-2019  mrg - bump buffer sizes to avoid potential truncation issues
 1.58 02-Oct-2017  joerg branches: 1.58.4;
Include time.h for time(2). Sort.
 1.57 31-May-2016  dholland Don't use the length return from snprintf to write out the result
buffer. If snprintf truncated the output, the length returned will be
greater and we'll write trash. Just call strlen instead. (And since
what we're doing is writing progress messages to the user, checking
carefully for truncation isn't really worthwhile either.)

Spotted when attending to PR 50998 from David Binderman; the issue
there (computation of an unused value) popped up because one of the
prints was already calling strlen.
 1.56 09-Mar-2015  sevan From OpenBSD r1.49
Fix comment grammar
 1.55 08-Aug-2014  joerg Fix RCS ID.
 1.54 20-Mar-2012  matt branches: 1.54.2; 1.54.10;
Use C89 function definitions
 1.53 31-Aug-2011  plunky branches: 1.53.2;
NULL does not need a cast
 1.52 31-Aug-2010  enami Backout previous; it was wrong fix.
 1.51 31-Aug-2010  enami Fix build as tools.
 1.50 31-Aug-2010  enami - Raise an error rather than silently creating broken archive
if user don't specify --force-local but opened file is actually
a local file.
- Make cpio to accept -F option as described in manpage.
- Make pax to set forcelocal flag if requested to do so.
- Add missing break statement.
 1.49 03-Feb-2009  dbj do not require sys/mtio.h for a tools build of pax
 1.48 23-Apr-2007  christos branches: 1.48.18; 1.48.20; 1.48.22;
PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.47 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.46 01-May-2005  christos PR/29005: Jesse Off: nbpax requires sys/mtio.h which doesn't exist on Interix
I added an ifdef called HAVE_MTIO_H and fixed the code to use it. It is
always defined now, but you can change this for Interix.
 1.45 24-Apr-2005  christos PR/18759: FUKAUMI Naoki: pax/tar dot-dot handling broken
PR/18840: Frederick Bruckman: Fix for PR/18663 incomplete pax symlink handling

This patch makes ``--insecure'' do something. Now if ``--insecure''
is not set (the default) we do a realpath(3) in all the pathnames
that we are trying to create and if either realpath fails, or the
path is outside our working directory, we print a warning and die.
This maybe too strict and might fail on valid archives that create
symlinks and directories in the wrong order.
 1.44 02-Aug-2004  yamt indent fix for the previous (ar_io.c rev.1.43)
 1.43 18-Jul-2004  yamt for copy mode, show more meaningful infomation on SIGINFO.
 1.42 21-Jun-2004  christos don't keep going if -C failed to chdir(); from OpenBSD
 1.41 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.40 11-May-2004  christos Welcome to WARNS=3
 1.39 27-Oct-2003  lukem branches: 1.39.2;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.38 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.37 18-Sep-2003  grant wait for compression program to finish before exiting.

fix races condition resulting in a zero length archive after pax
exits.

patch from OpenBSD, provided by Joerg Sonnenberger in PR bin/22740.
 1.36 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.35 31-Mar-2003  christos Detect and report end of archive properly ala' gnu tar.
 1.34 31-Mar-2003  christos RP/8227: Peter Seeback: Emulate old gnu tar better.
 1.33 25-Feb-2003  wiz Add support for '-j' to create (and extract, but -z already did that)
bzip2 compressed tar files, for GNU tar compatibility.
Patch from Soren Jacobsen in PR 19467, okayed by christos.
Sync usage with options while here.
 1.32 09-Feb-2003  grant cosmetic error condition improvements.
- sprinkle some fflush() to print filenames correctly.
- print a \n to stdout to fix formatting.
- English, consistently use "Cannot" in error messages.

some whitespace cleanup.
 1.31 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.30 12-Dec-2002  christos fix horrible side effect introduced by changing the append mode into archive.
The append mode already did that, so we always ended up overwriting the archive.
 1.29 10-Dec-2002  christos PR/19339: Martin Weber: Tar fails to append on empty files and exits with
0. Revert previous change for PR/18689. We always want to exit with
an error if we could not determine the archive format. Instead,
treat empty files specially. On list/extract we turn into no/op.
On append, we turn into archive.
 1.28 05-Dec-2002  grant don't print archive summary twice.
 1.27 16-Oct-2002  christos Support gnu long filename extensions by default for tar on create, list, and
extract. We now generate GNU tar archives by default ("ustar ^@" instead of
"ustar^@00"). GNU extensions can be disabled with --strict.

XXX: long symlinks untested.
 1.26 13-Oct-2002  christos If the archive refers to stdin, the archive's name is null. Check for
null when we see if it refers to a remote file. From Eric Gillespie, thanks!
 1.25 12-Oct-2002  thorpej Only include <rmt.h> if SUPPORT_RMT.
 1.24 12-Oct-2002  thorpej It doesn't help much to skip linking librmt if HOSTPROG but leave
all the librmt calls in the program. So, make librmt support conditional
on #ifdef SUPPORT_RMT, and define that when NOT building as a HOSTPROG.
 1.23 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.22 31-Jan-2002  tv branches: 1.22.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.21 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.20 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.19 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.18 30-Mar-2000  thorpej Add a -O option: force one volume. This causes pax to not prompt for
a new volume upon premature end-of-volume (e.g. broken pipe). This is
especially useful in automated environments where error recovery cannot
be performed by a human.
 1.17 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.16 17-Feb-2000  itohy Use lseek(2) on devices if not tape drives.
This makes listing on raw disk device much faster.
Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.15 17-Feb-2000  itohy Fix SIGINFO botch (PR #8868).
Continue partial write(2) on signals (xwrite()).
Partial read(2) at a few places are also continued (xread()).

Add {read,write}_with_restart() hooks for porting on systems
which don't restart interrupted read()/write() calls.

Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.14 22-Oct-1999  is Implement positional -C argument to tar.
 1.13 03-Mar-1999  christos branches: 1.13.4;
Add SIGINFO support.
 1.12 04-Nov-1998  christos Fix problem compiling when NET2_STAT is defined.
 1.11 04-Nov-1998  christos make printf formats conservative
 1.10 10-Aug-1998  tv Transparently handle old-style GNU tar archives that may have garbage in
the trailing block and do not have an end-of-archive marker. (Does this
handling based on whether the ustar id is "ustar" or "ustar ".)
 1.9 27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.8 06-Mar-1998  mrg - implement -C and -l for pax-as-tar, as inspried by GNU tar.
- minor cleanups to the options parsing code.
- add a cpio frontend.

note: a few GNU/svr4 cpio options are not supported yet (#ifdef
notyet), however all x/open ones are.
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 26-Mar-1996  mrg impliment -z (gzip) in pax and tar, and -Z (compress) in tar.
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.13.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.22.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.22.2.1 07-Apr-2004  jmc Pullup rev 1.23-1.39 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.39.2.1 22-Jun-2004  tron branches: 1.39.2.1.2;
Pull up revision 1.41 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.39.2.1.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.48.22.2 18-Dec-2009  matt Make this compile on snow leopard.
 1.48.22.1 15-Dec-2009  matt Allow tools to build on OSX 10.6 (Snow Leopard).
 1.48.20.1 03-Oct-2009  snj Pull up following revision(s) (requested by apb in ticket #1020):
bin/pax/Makefile: revision 1.38
bin/pax/ar_io.c: revision 1.49
tools/compat/configure: revision 1.69
tools/compat/configure.ac: revision 1.69
do not require sys/mtio.h for a tools build of pax
 1.48.18.1 03-Oct-2009  snj Pull up following revision(s) (requested by apb in ticket #1020):
bin/pax/Makefile: revision 1.38
bin/pax/ar_io.c: revision 1.49
tools/compat/configure: revision 1.69
tools/compat/configure.ac: revision 1.69
do not require sys/mtio.h for a tools build of pax
 1.53.2.1 17-Apr-2012  yamt sync with head
 1.54.10.1 10-Aug-2014  tls Rebase.
 1.54.2.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.58.4.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.58.4.2 21-Apr-2020  martin Sync with HEAD
 1.58.4.1 10-Jun-2019  christos Sync with HEAD
 1.59 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.58 28-May-2023  lukem branches: 1.58.2;
pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.
The partial temporary file is removed. pax still exists non-zero.

Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.

Should fix PR misc/33753.
 1.57 05-Dec-2021  msaitoh branches: 1.57.2;
s/exisit/exist/ in comment.
 1.56 31-Aug-2011  plunky branches: 1.56.44; 1.56.46;
NULL does not need a cast
 1.55 14-Feb-2009  lukem fix -Wsign-compare issues
 1.54 04-May-2007  christos branches: 1.54.20;
PR/36275: john at iastate dot edu: tar -s modifies symlink targets
- This is explained in a comment in pat_rep.c inside mod_name(). I did not
want to change the default behavior, so I added another modifier "s" which
when set, the pattern will not modify the symlink destination.
- While here I fixed another bug that was introduced before by the fix in
PR/35257 where the renaming was happening twice since we called rep_name
twice.
- Finally if we are renaming hard of soft-link targets print the renames for
those too.
 1.53 23-Apr-2007  christos PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.52 08-Mar-2007  rillig EROFS is not a critical error in a "mkdir -p".
 1.51 14-Dec-2006  christos PR/35257: Andreas Gustafsson: tar(1) opens excluded files
Apply the file modification function in the input files so that we can
de-select matched patterns.
 1.50 07-Oct-2006  elad PR/34265: dieter roelants: pax truncates archive when appending fails.

Patch applied, thanks!
 1.49 11-Feb-2006  dsl Ensure we exit with an error if we don't actually do anything.
There are a lot of tty_warn(0,...) and syswarn(0,...) which probably ought
to be tty_warn/syswarn(1,...) to force an error exit. However some are
used in interactive parts (eg opening a continuation archive) where there
is a separate retry loop.
So we just pass a failure code out to main() - how quaint!
This should now cause the NetBSD build to fail when gzip tries to write
to a non-existant directory.
(I suspect there are still many errors that don't get reported correctly.)
 1.48 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.47 31-Jan-2006  christos Solaris mkdir on an automounted component returns ENOSYS. Go figure.
Good choices whould have been EROFS, EEXIST, EACCES, EISDIR...
 1.46 06-Dec-2005  christos If we get EACCES from mkdir, try to stat() it, and if it is ok, we keep going.
Fixes problem with IRIX.
 1.45 01-Nov-2005  christos PR/31923: Sergey Svishchev: pax-as-tar ignores -k, overwrites existing files
Fix from Onno van der Linden
 1.44 17-Sep-2005  christos mkdir(2) can return EISDIR for /
 1.43 16-Sep-2005  christos Another missing mkdir() race pointed out by chuq. Factor out the mkdir code.
 1.42 22-May-2005  christos Don't even declare fdochroot() if we are in tool mode.
 1.41 14-May-2005  christos Allow writing symlinks that point outside our tree, but not traversing
them to write other files.
 1.40 06-May-2005  jmc Wrap call to fchroot in CONFIG tests so this doesn't blow up on cross-tools
 1.39 05-May-2005  christos PR/30132: Juan RP: tar --chroot refuses to extract files.
fchroot() changes the effective path, so we need to call updatepath().
 1.38 24-Apr-2005  christos If we cannot resolve a path, that probably means that we have not created
directories for that path yet. So, do the check for each component recursively
and succeed if none of the components fall outside our current working
directory.
 1.37 24-Apr-2005  christos PR/18759: FUKAUMI Naoki: pax/tar dot-dot handling broken
PR/18840: Frederick Bruckman: Fix for PR/18663 incomplete pax symlink handling

This patch makes ``--insecure'' do something. Now if ``--insecure''
is not set (the default) we do a realpath(3) in all the pathnames
that we are trying to create and if either realpath fails, or the
path is outside our working directory, we print a warning and die.
This maybe too strict and might fail on valid archives that create
symlinks and directories in the wrong order.
 1.36 24-Apr-2005  christos For clarity instead of using -1 and -2 use the negative of the archive type.
 1.35 23-Jan-2005  jmc Apply user supplied patterns first before applying actions for -A. This way pax
behavior WRT to patterns lines up with the example in the documentation
and how other implementations do it as well since -A is a non-standard
option/behavior. Fixes items noted in PR#23776
 1.34 22-Oct-2004  jmc For HOSTTOOL builds, just exclude the chroot support as it's not needed and
avoids having to platform check for fchroot(). Fixes PR#27336
 1.33 17-Oct-2004  dsl Add an option --chroot to tar. Causes it to chroot(".") before doing
an extract. With -h this will cause existing absolute symlinks to be treated
as relative to the current directory.
Helps sysinst handle existing symlinks in the target system.
Remove 'L' from the usage (got spilt into 'h' and 'H' many moons ago)
Add 'S' to usage, and put into correct place in options list.
 1.32 10-Oct-2004  christos PR/27213: Greg A. Woods: pax doesn't honour SIGPIPE when listing
But always exit, not just on SIGPIPE.
 1.31 22-Aug-2004  tron Propery handle "cpio" archives where the last hardlink includes the
data of a file. This fixes PR bin/26514.
 1.30 16-Apr-2004  christos remove misplaced semi-colons.
 1.29 27-Oct-2003  lukem branches: 1.29.2;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.28 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.27 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.26 08-Jul-2003  simonb Add support for gnutar's -O "extract to stdout" option.
 1.25 23-Jun-2003  grant consistently use "cannot" instead of "can not".
 1.24 31-Mar-2003  christos RP/8227: Peter Seeback: Emulate old gnu tar better.
 1.23 09-Feb-2003  grant cosmetic error condition improvements.
- sprinkle some fflush() to print filenames correctly.
- print a \n to stdout to fix formatting.
- English, consistently use "Cannot" in error messages.

some whitespace cleanup.
 1.22 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.21 10-Dec-2002  christos PR/19339: Martin Weber: Tar fails to append on empty files and exits with
0. Revert previous change for PR/18689. We always want to exit with
an error if we could not determine the archive format. Instead,
treat empty files specially. On list/extract we turn into no/op.
On append, we turn into archive.
 1.20 18-Oct-2002  itojun exit with 0 if the input is empty of not a tar file. matches GNU tar behavior.
solves PR 18689.
 1.19 17-Oct-2002  christos Add proper longlink support. Previously we handled longname support, and
the longlink support was completely wrong.
 1.18 16-Oct-2002  christos Support gnu long filename extensions by default for tar on create, list, and
extract. We now generate GNU tar archives by default ("ustar ^@" instead of
"ustar^@00"). GNU extensions can be disabled with --strict.

XXX: long symlinks untested.
 1.17 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.16 31-Jan-2002  tv branches: 1.16.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.15 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.14 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.13 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.12 24-Aug-1999  tron branches: 1.12.2;
Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.11 03-Mar-1999  christos Add SIGINFO support.
 1.10 10-Aug-1998  tv Transparently handle old-style GNU tar archives that may have garbage in
the trailing block and do not have an end-of-archive marker. (Does this
handling based on whether the ustar id is "ustar" or "ustar ".)
 1.9 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.8 01-Apr-1998  kleink Need <time.h> for time() prototype.
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.12.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.16.2.3 25-Aug-2004  he Pull up revision 1.30 (requested by cube in ticket #1732):
Remove misplaced semi-colons.
 1.16.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.16.2.1 07-Apr-2004  jmc Pullup rev 1.17-1.29 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.29.2.2 25-Aug-2004  jmc branches: 1.29.2.2.2;
Pullup rev 1.31 (requested by tron in ticket #784)

Propery handle "cpio" archives where the last hardlink includes the
data of a file. PR#26514
 1.29.2.1 21-Apr-2004  jmc Pullup rev 1.30 (requested by christos in ticket #170)

Fixes for multiple pax pr's. PR#25200. PR#25207.
 1.29.2.2.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.54.20.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.56.46.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.56.44.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.56.44.1 21-Apr-2020  martin Sync with HEAD
 1.57.2.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.58.2.1 02-Aug-2025  perseant Sync with HEAD
 1.32 08-Sep-2024  rillig fix a/an grammar in obvious cases
 1.31 28-May-2023  lukem branches: 1.31.2;
pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.
The partial temporary file is removed. pax still exists non-zero.

Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.

Should fix PR misc/33753.
 1.30 28-May-2022  andvar branches: 1.30.2;
fix various typos, mainly in comments.
 1.29 19-Mar-2018  msaitoh branches: 1.29.2; 1.29.4;
s/copy copy/copy/ in comment.
 1.28 29-Apr-2007  msaitoh branches: 1.28.76;
fix typos
 1.27 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.26 24-Apr-2005  christos PR/20228: Simon Burge: pax has problems reading a particular cpio archive
The problem here is that the archive is too short (< 512 bytes). The
buffer routines, try to read at least 512 bytes, even when we try to determine
what format file we have, which is wrong.
 1.25 22-Sep-2004  christos fd can be -1 or -2 for the gnu long name/link hack. So check for >= 0
instead of -1 if we need to flush.
 1.24 15-Jun-2004  christos do the special symlink treatment with all negative fd's.
 1.23 27-Oct-2003  lukem branches: 1.23.2;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.22 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.21 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.20 21-Feb-2003  lukem When writing (-w) or copying (-rw), and using -M (stdin file list is
mtree(8) specfile), compare the "post write/copy" mtime against the
actual "pre write/copy" mtime instead of the mtime from the specfile.

This prevents warnings such as:
pax: File ./foo was modified during copy to archive
if the file's mtime in the file system is different to what's in the specfile.
(The resultant file will still get the specfile mtime ...)
 1.19 09-Feb-2003  grant cosmetic error condition improvements.
- sprinkle some fflush() to print filenames correctly.
- print a \n to stdout to fix formatting.
- English, consistently use "Cannot" in error messages.

some whitespace cleanup.
 1.18 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.17 31-Jan-2002  tv branches: 1.17.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.16 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.15 07-Oct-2001  wiz Fix typo.
 1.14 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.13 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.12 17-Feb-2000  itohy Fix SIGINFO botch (PR #8868).
Continue partial write(2) on signals (xwrite()).
Partial read(2) at a few places are also continued (xread()).

Add {read,write}_with_restart() hooks for porting on systems
which don't restart interrupted read()/write() calls.

Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.11 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.10 22-Oct-1999  mrg remove some old cruft.
 1.9 03-Feb-1998  mycroft branches: 1.9.4;
Deal with GCC warnings.
 1.8 25-Jul-1997  scottr #if __GNUC__, work around bogus initialization warning that occurs on
at least the m68k-based ports.
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.9.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.2.3 25-Aug-2004  he Pull up revision 1.24 (requested by cube in ticket #1733):
Do the special symlink treatment with all negative fd's.
 1.17.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.17.2.1 07-Apr-2004  jmc Pullup rev 1.18-1.23 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.23.2.2 12-Nov-2004  jmc branches: 1.23.2.2.2;
Pullup rev 1.25 (requested by christos in ticket #922)

fd can be -1 or -2 for the gnu long name/link hack. So check for >= 0
instead of -1 if we need to flush.
 1.23.2.1 18-Jun-2004  tron Pull up revision 1.24 (requested by dillo in ticket #507):
do the special symlink treatment with all negative fd's.
 1.23.2.2.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.28.76.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.29.4.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.29.2.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.29.2.1 21-Apr-2020  martin Sync with HEAD
 1.30.2.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.31.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.9 27-Jul-1998  mycroft Slight code reduction.
 1.8 27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.7 26-Jul-1998  mycroft const poisoning.
 1.6 20-Jul-1997  christos branches: 1.6.2;
- Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.5 11-Jan-1997  tls kill 'register'
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.6.2.1 20-Jan-1999  cgd patch to fix a memory leak (due to never actually adding items to the
hash table). The change corresponds with a change in -current, but the
file is now in libc (replacing a different version that was already in
libc). (mycroft)
 1.4 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.15 03-Jul-2017  wiz branches: 1.15.6;
Remove workaround for ancient HTML generation code.
 1.14 19-Dec-2015  wiz Use An in AUTHORS section.
 1.13 19-Jun-2011  wiz Use Fl Fl for long options.
 1.12 19-Jun-2011  christos document --xz
 1.11 02-Dec-2007  wiz branches: 1.11.26;
Minimally sort options; use Dq; new sentence, new line.
 1.10 23-Apr-2007  christos branches: 1.10.4;
bump date.
 1.9 11-Sep-2005  wiz Use better section header. From YOMURA Masanori in private mail.
 1.8 15-Sep-2004  hubertf Change copyright to 2-clause BSD-copyright.
Changed with explicit permission of Thorsten Lockert (tholo sigmasoft com)
 1.7 13-Feb-2004  snj branches: 1.7.2; 1.7.4;
s/nonmathing/nonmatching/
 1.6 10-Apr-2003  grant some mdoc fixes.
 1.5 25-Feb-2003  wiz New sentence, new line.
 1.4 16-Oct-2002  christos add commas between options. Suggested by wiz.
 1.3 16-Oct-2002  christos Document the long options.
 1.2 12-Oct-2002  wiz Miscellaneous fixes.
 1.1 12-Oct-2002  christos man pages from OpenBSD.
TODO: add long option documentation.
 1.7.4.2 07-Apr-2004  jmc Pullup rev 0-1.7 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.7.4.1 13-Feb-2004  jmc file cpio.1 was added on branch netbsd-1-6 on 2004-04-07 06:57:20 +0000
 1.7.2.1 16-Sep-2004  jmc Pullup rev 1.8 (requested by hubertf in ticket #850)

Change copyright to 2-clause BSD-copyright.
 1.10.4.1 09-Jan-2008  matt sync with HEAD
 1.11.26.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.15.6.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.15.6.1 21-Apr-2020  martin Sync with HEAD
 1.22 09-Aug-2012  christos branches: 1.22.34;
PR/46786: Simon Burge: After conversion to 64 bit time_t, tar/pax/cpio
erroneously think that negative time_t's never fit in 32 bits. Rework
conversion code to always use uintmax_t, and detect negative values.
XXX[1]: Perhaps we should do the same (use a signed conversion) for all
fields not just for time_t
XXX[2]: pullup for 6
 1.21 26-Mar-2011  martin branches: 1.21.4;
Fix bogus paranthesis, From Henning Peternse in PR bin/44773.
 1.20 14-Feb-2009  lukem fix -Wsign-compare issues
 1.19 11-Feb-2006  dsl branches: 1.19.28;
Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.18 04-Feb-2005  matt Don't write hardlinked file contents in sv4cpio mode.
 1.17 27-Oct-2003  lukem branches: 1.17.4;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.16 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.14 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.13 11-Feb-2002  wiz branches: 1.13.2;
achive is not a good word.
 1.12 31-Jan-2002  tv Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.11 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.10 04-Jan-2001  lukem use more standard %ll_ in favour of %q_
 1.9 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.8 28-Feb-1998  mrg rename variable to "cpio_swp_head"
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.13.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.13.2.1 07-Apr-2004  jmc Pullup rev 1.14-1.17 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.17.4.1 06-May-2005  riz Pull up revision 1.18 (requested by matt in ticket #1164):
Don't write hardlinked file contents in sv4cpio mode.
 1.19.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.4.1 30-Oct-2012  yamt sync with head
 1.22.34.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.22.34.1 21-Apr-2020  martin Sync with HEAD
 1.6 13-Oct-2003  agc branches: 1.6.98;
Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.4 17-Feb-2000  itohy branches: 1.4.6;
Cleanup and fix typos.
Partially from FreeBSD.
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.4.6.1 07-Apr-2004  jmc Pullup rev 1.5-1.6 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.6.98.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.6.98.1 21-Apr-2020  martin Sync with HEAD
 1.3 30-May-2016  dholland branches: 1.3.16;
Remove undefined behavior in buf(); use buf() as intended in intarg().
While here also add includes to fix the build. Retires PR 50999 from
David Binderman.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 16-Jun-2004  christos branches: 1.1.4; 1.1.26;
A small standalone program to dump ustar headers, used for debugging.
 1.1.26.1 18-May-2008  yamt sync with head.
 1.1.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.3.16.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.3.16.1 21-Apr-2020  martin Sync with HEAD
 1.61 28-May-2023  lukem pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.
The partial temporary file is removed. pax still exists non-zero.

Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.

Should fix PR misc/33753.
 1.60 03-Apr-2020  joerg branches: 1.60.6;
Move definition of chdname and do_chroot to options.c
 1.59 09-Aug-2012  christos branches: 1.59.26; 1.59.34; 1.59.36;
PR/46786: Simon Burge: After conversion to 64 bit time_t, tar/pax/cpio
erroneously think that negative time_t's never fit in 32 bits. Rework
conversion code to always use uintmax_t, and detect negative values.
XXX[1]: Perhaps we should do the same (use a signed conversion) for all
fields not just for time_t
XXX[2]: pullup for 6
 1.58 29-Aug-2011  joerg branches: 1.58.2;
static + __dead
 1.57 18-Jun-2011  christos add --xz
 1.56 07-Apr-2009  perry branches: 1.56.4;
Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.
 1.55 24-Feb-2008  joerg branches: 1.55.8; 1.55.10;
Kill pre-4.4BSD compat code.
 1.54 10-Jan-2008  tls branches: 1.54.2;
Teach set_ftime about symbolic links, because it has to know: on some
Linux systems, when we build as a tool we think we have lutimes but it
doesn't work on some filesystems at runtime. A bit ugly but effective
and without use of AC_TRY_RUN in the tool build. Tidier (than mine)
set_ftime reorganization from christos.
 1.53 04-May-2007  christos branches: 1.53.4;
PR/36275: john at iastate dot edu: tar -s modifies symlink targets
- This is explained in a comment in pat_rep.c inside mod_name(). I did not
want to change the default behavior, so I added another modifier "s" which
when set, the pattern will not modify the symlink destination.
- While here I fixed another bug that was introduced before by the fix in
PR/35257 where the renaming was happening twice since we called rep_name
twice.
- Finally if we are renaming hard of soft-link targets print the renames for
those too.
 1.52 23-Apr-2007  christos PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.51 16-Apr-2006  christos PR/22995: Sergey Svishchev: If we are cd'ing around and we have directories
with relative paths, convert the directories to absolute paths, so that
restoring timestamps does not fail.
 1.50 11-Feb-2006  dsl Ensure we exit with an error if we don't actually do anything.
There are a lot of tty_warn(0,...) and syswarn(0,...) which probably ought
to be tty_warn/syswarn(1,...) to force an error exit. However some are
used in interactive parts (eg opening a continuation archive) where there
is a separate retry loop.
So we just pass a failure code out to main() - how quaint!
This should now cause the NetBSD build to fail when gzip tries to write
to a non-existant directory.
(I suspect there are still many errors that don't get reported correctly.)
 1.49 16-Sep-2005  christos Another missing mkdir() race pointed out by chuq. Factor out the mkdir code.
 1.48 24-Apr-2005  christos PR/18759: FUKAUMI Naoki: pax/tar dot-dot handling broken
PR/18840: Frederick Bruckman: Fix for PR/18663 incomplete pax symlink handling

This patch makes ``--insecure'' do something. Now if ``--insecure''
is not set (the default) we do a realpath(3) in all the pathnames
that we are trying to create and if either realpath fails, or the
path is outside our working directory, we print a warning and die.
This maybe too strict and might fail on valid archives that create
symlinks and directories in the wrong order.
 1.47 22-Oct-2004  jmc For HOSTTOOL builds, just exclude the chroot support as it's not needed and
avoids having to platform check for fchroot(). Fixes PR#27336
 1.46 17-Oct-2004  dsl Add an option --chroot to tar. Causes it to chroot(".") before doing
an extract. With -h this will cause existing absolute symlinks to be treated
as relative to the current directory.
Helps sysinst handle existing symlinks in the target system.
Remove 'L' from the usage (got spilt into 'h' and 'H' many moons ago)
Add 'S' to usage, and put into correct place in options list.
 1.45 22-Sep-2004  christos Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.

The old code assumed that the buffer already contained the necessary
blocks to satisfy the read file request that contained the long
filename. This is not always the case, specially when we are dealing
with pipes which do shorter reads, thus having more probability
that a long file name will fall across a buffer boundary.

To reproduce, create a tar archive with a lot of gnu-long-names
(pkgsrc/devel/libsigc++2 is a good example), do a tar -tf to get
a list of filenames, compress it and do a tar -tzf to get another
list of the filenames. Notice that the two lists differ.
 1.44 22-Aug-2004  tron Propery handle "cpio" archives where the last hardlink includes the
data of a file. This fixes PR bin/26514.
 1.43 19-Jun-2004  christos add -0 argument to handle nul separated file lists.
 1.42 11-May-2004  christos Welcome to WARNS=3
 1.41 13-Feb-2004  matt branches: 1.41.2;
When pax catches a signal and cleans up, make sure to remove any temporary
file that was being extracted to. This will prevent pax from leaving
droppings when you hit ^C.
 1.40 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.39 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.38 08-Jul-2003  simonb Add support for gnutar's -O "extract to stdout" option.
 1.37 25-Feb-2003  wiz Add support for '-j' to create (and extract, but -z already did that)
bzip2 compressed tar files, for GNU tar compatibility.
Patch from Soren Jacobsen in PR 19467, okayed by christos.
Sync usage with options while here.
 1.36 08-Dec-2002  mrg add --exclude support.

XXX: --exclude & --exclude-from are still not 100% compatible, but since
rafal fixed --exclude-from's most annoying bug, they mostly work now.
 1.35 17-Oct-2002  christos Add proper longlink support. Previously we handled longname support, and
the longlink support was completely wrong.
 1.34 16-Oct-2002  christos Support gnu long filename extensions by default for tar on create, list, and
extract. We now generate GNU tar archives by default ("ustar ^@" instead of
"ustar^@00"). GNU extensions can be disabled with --strict.

XXX: long symlinks untested.
 1.33 15-Oct-2002  christos PR/18663: Jeremy Reed: pax/tar/cpio allows ".." in names.
We now disallow it by default on both archive creation and extraction.
Add --insecure option to override.
 1.32 13-Oct-2002  mrg make this build on LP64
 1.31 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.30 31-Jan-2002  tv branches: 1.30.2;
Roll in fixes to permit cross-compiling from non-NetBSD hosts. This
round has been tested on Solaris/x86 and Linux hosts.

* Add host tools cap_mkdb, ctags, m4, uudecode.
* Protect __RCSID() and __COPYRIGHT() better.
* Reduce the number of places that need to include "config.h", to keep
sources closer to their "vanilla" versions.
* Add more compat #defines and autoconf-checked functions.
 1.29 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.28 28-Oct-2001  lukem s/u_longlong_t/unsigned long long/ to shut up the parc port
 1.27 25-Oct-2001  lukem Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.26 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.25 22-Oct-2000  kleink LC_TIME holds a locale name, which isn't a strftime() format string.
 1.24 04-Jul-2000  thorpej Add GNU tar-style long options for pax's tar front-end. Still many
GNU options not implemented, but there is an #if 0'd out canonical
list.
 1.23 30-Mar-2000  thorpej branches: 1.23.4;
Add a -O option: force one volume. This causes pax to not prompt for
a new volume upon premature end-of-volume (e.g. broken pipe). This is
especially useful in automated environments where error recovery cannot
be performed by a human.
 1.22 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.21 17-Feb-2000  itohy Fix SIGINFO botch (PR #8868).
Continue partial write(2) on signals (xwrite()).
Partial read(2) at a few places are also continued (xread()).

Add {read,write}_with_restart() hooks for porting on systems
which don't restart interrupted read()/write() calls.

Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.20 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.19 22-Oct-1999  is Implement positional -C argument to tar.
 1.18 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.17 24-Aug-1999  tron branches: 1.17.2;
Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.16 03-Mar-1999  christos Add SIGINFO support.
 1.15 07-Feb-1999  tron Fix opt_add() prototype.
 1.14 20-Jan-1999  mrg implement the gnutar -X flag in terms of pax -s. fix some bugs in pax -s handling while i am here...
 1.13 10-Aug-1998  tv Transparently handle old-style GNU tar archives that may have garbage in
the trailing block and do not have an end-of-archive marker. (Does this
handling based on whether the ustar id is "ustar" or "ustar ".)
 1.12 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.11 27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.10 26-Jul-1998  mycroft const poisoning.
 1.9 06-Mar-1998  mrg - implement -C and -l for pax-as-tar, as inspried by GNU tar.
- minor cleanups to the options parsing code.
- add a cpio frontend.

note: a few GNU/svr4 cpio options are not supported yet (#ifdef
notyet), however all x/open ones are.
 1.8 28-Feb-1998  mrg rename variable to "cpio_swp_head"
 1.7 14-Sep-1997  lukem * cleanup manpage
* getopt returns -1 not EOF
* deprecate register
 1.6 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.5 26-Mar-1996  mrg impliment -z (gzip) in pax and tar, and -Z (compress) in tar.
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 04-Dec-1994  cgd from James Jegers <jimj@miller.cs.uwm.edu>: quiet -Wall, and squelch
some of the worst style errors.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.17.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.23.4.1 25-Oct-2000  tv Pullup 1.25 [kleink]:
Don't abuse LC_TIME for strftime(3) format strings.
 1.30.2.1 07-Apr-2004  jmc Pullup rev 1.31-1.41 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.41.2.2 12-Nov-2004  jmc branches: 1.41.2.2.2;
Pullup rev 1.45 (requested by christos in ticket #921)

Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.
 1.41.2.1 25-Aug-2004  jmc Pullup rev 1.44 (requested by tron in ticket #784)

Propery handle "cpio" archives where the last hardlink includes the
data of a file. PR#26514
 1.41.2.2.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.53.4.1 23-Mar-2008  matt sync with HEAD
 1.54.2.1 24-Mar-2008  keiichi sync with head.
 1.55.10.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.55.8.1 13-Apr-2009  snj Pull up following revision(s) (requested by christo in ticket #678):
bin/pax/extern.h: revision 1.56
bin/pax/file_subs.c: revision 1.62
bin/pax/options.c: revision 1.104
bin/pax/pat_rep.c: revision 1.29
bin/pax/pax.h: revision 1.30
Fixes from christos for pr-41167
XXX -X is still broken, but that wasn't part of this PR.
 1.56.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.58.2.1 30-Oct-2012  yamt sync with head
 1.59.36.2 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.59.36.1 30-Apr-2021  martin Pull up following revision(s) (requested by mrg in ticket #1263):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100

Avoid depending on common symbols.
 1.59.34.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.59.34.2 21-Apr-2020  martin Sync with HEAD
 1.59.34.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.59.26.1 07-May-2021  martin Pull up following revision(s) (requested by mrg in ticket #1678):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100
usr.sbin/installboot/Makefile: revisions 1.53,1.54 (patch)
usr.sbin/installboot/installboot.h: revision 1.41 (patch)
usr.sbin/installboot/machines.c: revisisons 1.41,1.42 (patch)

Avoid depending on common symbols.
 1.60.6.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.66 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.65 28-May-2023  lukem branches: 1.65.2;
pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.
The partial temporary file is removed. pax still exists non-zero.

Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.

Should fix PR misc/33753.
 1.64 20-Mar-2019  gutteridge branches: 1.64.2; 1.64.10;
pax: fix typos in comments in file_subs.c & tar.c

Stamp out "greengrocers' apostrophes" in various places (arguably there
are still more present, but style guides vary on that, and my energies
spent corralling wayward punctuation marks could be spent elsewhere).
 1.63 29-Jul-2013  christos branches: 1.63.26;
PR/48095: NAKAJIMA Yoshihiro: remove casts from time_t to long
 1.62 07-Apr-2009  perry branches: 1.62.6; 1.62.12;
Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.
 1.61 10-Jan-2008  tls branches: 1.61.10; 1.61.12;
Teach set_ftime about symbolic links, because it has to know: on some
Linux systems, when we build as a tool we think we have lutimes but it
doesn't work on some filesystems at runtime. A bit ugly but effective
and without use of AC_TRY_RUN in the tool build. Tidier (than mine)
set_ftime reorganization from christos.
 1.60 29-Apr-2007  msaitoh branches: 1.60.4;
fix typos
 1.59 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.58 04-Jan-2006  yamt obey umask as it used to be before the "mkstemp and then rename" change.
 1.57 18-Sep-2005  christos Check for another race reported by chuq.
 1.56 16-Sep-2005  christos Another missing mkdir() race pointed out by chuq. Factor out the mkdir code.
 1.55 13-Sep-2005  christos use stat and not lstat to detect if we have a directory. refactor the mkpath()
code.
 1.54 13-Sep-2005  christos when creating directories, check if the failure occured because someone
else created the directory before we did to avoid races. From chuq.
 1.53 24-Apr-2005  christos For clarity instead of using -1 and -2 use the negative of the archive type.
 1.52 22-Sep-2004  christos Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.

The old code assumed that the buffer already contained the necessary
blocks to satisfy the read file request that contained the long
filename. This is not always the case, specially when we are dealing
with pipes which do shorter reads, thus having more probability
that a long file name will fall across a buffer boundary.

To reproduce, create a tar archive with a lot of gnu-long-names
(pkgsrc/devel/libsigc++2 is a good example), do a tar -tf to get
a list of filenames, compress it and do a tar -tzf to get another
list of the filenames. Notice that the two lists differ.
 1.51 22-Aug-2004  tron Propery handle "cpio" archives where the last hardlink includes the
data of a file. This fixes PR bin/26514.
 1.50 02-Jul-2004  enami Salvage the `create parent directories and try again' path which is
removed by the previous commit.
 1.49 26-Jun-2004  grant break out of the loop and avoid the infinite loop if attempts to
create, unlink and create all fail.
 1.48 26-Jun-2004  grant don't attempt to remove the current directory.
 1.47 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.46 03-May-2004  christos Don't exit with 1 on broken archives that mark directories as files for
the benefit of pkgsrc. I would have prefered that people fixed their
archivers instead.
 1.45 30-Apr-2004  matt Set the chflags *after* the rename, not before.
 1.44 27-Apr-2004  christos PR/25350: Alan Barrett: Treat the sticky bit specially as non-superusers
cannot set it on non-directories (elvis-2.2_0 extraction failed)
 1.43 25-Apr-2004  christos PR/25188: Thomas Klausner: pax-as-tar problem with trailing slashes
The problem is with the program that generates the tar file:
-rwxrwxrwx 1 root wheel 0 Feb 8 16:46 faad2/aacDECdrop/
It creates directory nodes without the 'd' bit set, so that pax thinks
they are files and does the temporary name and dance with them. Added
code to detect this condition, warn about it, and work around it.
 1.42 20-Apr-2004  christos PR/25207: Hubert Feyrer: tar cores on certain archive contents
Don't forget to cleanup xtmp_name when we fail to create the temporary file.
 1.41 13-Feb-2004  matt branches: 1.41.2;
When pax catches a signal and cleans up, make sure to remove any temporary
file that was being extracted to. This will prevent pax from leaving
droppings when you hit ^C.
 1.40 13-Feb-2004  matt Nuke extra mkstemp. Use name, not tmp_name with chk_path.
 1.39 13-Feb-2004  matt Back out last change. Since the name is the entire path, prefixing it
with a '.' will not have the desired effect.
 1.38 13-Feb-2004  matt When creating the temporary file, prefix the name with a '.'
 1.37 12-Feb-2004  matt When restoring files from an archive, initially restore to a temp-file and
once it has been instantiated correctly, rename it to desired name. This
prevents the problem of partially created files being accessed before they
are complete. If said file is a shared library, that can cause ramdon core
dumps.
 1.36 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.35 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.34 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.33 23-Jun-2003  grant no need for HAVE_LCHOWN and HAVE_LCHMOD anymore.
 1.32 10-Feb-2003  grant add missing braces.

from HIRATSUKA Kouichirou in PR bin/20276.
 1.31 09-Feb-2003  grant cosmetic error condition improvements.
- sprinkle some fflush() to print filenames correctly.
- print a \n to stdout to fix formatting.
- English, consistently use "Cannot" in error messages.

some whitespace cleanup.
 1.30 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.29 20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.28 06-Jan-2003  wiz writable, not writeable.
 1.27 19-Dec-2002  grant Fix oops in last, chown() failure should be fatal.

Noted by Charles Hannum.
 1.26 19-Dec-2002  grant Don't attempt to chown files if euid != 0, and make chown() non-fatal
if it does fail.

This addresses my PR bin/18912 (running pkg_info as non-root user on a
binary package).
 1.25 17-Oct-2002  christos Add proper longlink support. Previously we handled longname support, and
the longlink support was completely wrong.
 1.24 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.23 11-Feb-2002  wiz branches: 1.23.2;
"doesn't" should have an 's'.
 1.22 31-Jan-2002  tv Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.21 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.20 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.19 17-Jun-2000  mrg minor KNF nits.
 1.18 13-Mar-2000  soren branches: 1.18.2;
Fix doubled 'the' in comment.
 1.17 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.16 17-Feb-2000  itohy Fix SIGINFO botch (PR #8868).
Continue partial write(2) on signals (xwrite()).
Partial read(2) at a few places are also continued (xread()).

Add {read,write}_with_restart() hooks for porting on systems
which don't restart interrupted read()/write() calls.

Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.15 07-Nov-1999  mycroft branches: 1.15.2;
Completely disable all the chflags(2) support for now. With this enabled, I
can't even get a build to finish over NFS. Not acceptable.
 1.14 07-Nov-1999  mycroft Don't try to set file flags for a symlink.
 1.13 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.12 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.11 22-Oct-1999  mrg remove some old cruft.
 1.10 28-Feb-1998  mrg branches: 1.10.4;
fix typo in a comment
 1.9 03-Feb-1998  mycroft Deal with GCC warnings.
 1.8 19-Oct-1997  mycroft When copying time stamps, copy the microseconds, too. Also nuke silly
static structure.
 1.7 08-Oct-1997  enami Restore owner/group/mode/atime/mtime of symbolic links.
 1.6 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.5 11-Jan-1997  tls kill 'register'
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.10.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.2.2 07-Nov-1999  mycroft Completely disable all the chflags(2) support for now. With this enabled, I
can't even get a build to finish over NFS. Not acceptable.
 1.15.2.1 07-Nov-1999  mycroft file file_subs.c was added on branch comdex-fall-1999 on 1999-11-07 15:48:25 +0000
 1.18.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.23.2.3 25-Aug-2004  he Pull up revisions 1.42-1.46,1.48-1.50 (requested by cube in ticket #1736):
Fix handling of certain archives, fixing core dump (PR#25207).
Fix problem with trailing slashes (PR#15188).
Treat sticky bit specially for non-superuser (PR#25350).
Set chflags after rename, not before.
Don't exit with 1 on broken archives that mark directories as files.
Don't attempt to remove current directory.
Break out of loop and avoid infinite loop in certain error situations.
Salvage the `create parent directories and try again' patch.
 1.23.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.23.2.1 07-Apr-2004  jmc Pullup rev 1.24-1.41 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.41.2.8 12-Nov-2004  jmc branches: 1.41.2.8.2;
Pullup rev 1.52 (requested by christos in ticket #921)

Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.
 1.41.2.7 25-Aug-2004  jmc Pullup rev 1.51 (requested by tron in ticket #784)

Propery handle "cpio" archives where the last hardlink includes the
data of a file. PR#26514
 1.41.2.6 12-Aug-2004  jmc Pullup rev 1.48-1.50 (requested by cube in ticket #754)

Fixes for pax breaking on some archives
 1.41.2.5 22-Jun-2004  tron Pull up revision 1.47 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.41.2.4 06-May-2004  jmc Pullup rev 1.45-1.46 (requested by snj in ticket #252)

Set the chflags *after* the rename, not before.
Don't exit with 1 on broken archives that mark directories as files for
the benefit of pkgsrc.
 1.41.2.3 28-Apr-2004  grant Pull up revision 1.44 (requested by snj in ticket #217):

PR/25350: Alan Barrett: Treat the sticky bit specially as non-superusers
cannot set it on non-directories (elvis-2.2_0 extraction failed)
 1.41.2.2 28-Apr-2004  grant Pull up revision 1.43 (requested by snj in ticket #217):

PR/25188: Thomas Klausner: pax-as-tar problem with trailing slashes
The problem is with the program that generates the tar file:
-rwxrwxrwx 1 root wheel 0 Feb 8 16:46 faad2/aacDECdrop/
It creates directory nodes without the 'd' bit set, so that pax thinks
they are files and does the temporary name and dance with them. Added
code to detect this condition, warn about it, and work around it.
 1.41.2.1 21-Apr-2004  jmc Pullup rev 1.42 (requested by christos in ticket #170)

Fixes for multiple pax pr's. PR#25200. PR#25207.
 1.41.2.8.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.60.4.1 23-Mar-2008  matt sync with HEAD
 1.61.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.61.10.1 13-Apr-2009  snj Pull up following revision(s) (requested by christo in ticket #678):
bin/pax/extern.h: revision 1.56
bin/pax/file_subs.c: revision 1.62
bin/pax/options.c: revision 1.104
bin/pax/pat_rep.c: revision 1.29
bin/pax/pax.h: revision 1.30
Fixes from christos for pr-41167
XXX -X is still broken, but that wasn't part of this PR.
 1.62.12.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.62.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.63.26.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.63.26.2 21-Apr-2020  martin Sync with HEAD
 1.63.26.1 10-Jun-2019  christos Sync with HEAD
 1.64.10.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.64.2.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.65.2.1 02-Aug-2025  perseant Sync with HEAD
 1.46 08-Sep-2024  rillig s/effect/affect/ in a few places
 1.45 08-Sep-2024  rillig fix a/an grammar in obvious cases
 1.44 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.43 28-May-2023  lukem branches: 1.43.2;
pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.
 1.42 27-Sep-2012  christos branches: 1.42.32; 1.42.34; 1.42.42;
deal properly with empty lines in spec file
 1.41 20-Mar-2012  matt branches: 1.41.2;
Use C89 function definitions
 1.40 14-Feb-2009  lukem branches: 1.40.6; 1.40.8;
fix -Wsign-compare issues
 1.39 28-Apr-2008  martin branches: 1.39.6; 1.39.8;
Remove clause 3 and 4 from TNF licenses
 1.38 24-Feb-2008  joerg branches: 1.38.2;
Kill pre-4.4BSD compat code.
 1.37 18-Feb-2008  simonb branches: 1.37.2;
Set "ftent" to NULL in in ftree_arg() after we call fts_close(), so that
it isn't used later on in ftree_sel() after it's been free'd.

OK christos@ (and for the interesting test case).
 1.36 10-Jan-2008  tls Teach set_ftime about symbolic links, because it has to know: on some
Linux systems, when we build as a tool we think we have lutimes but it
doesn't work on some filesystems at runtime. A bit ugly but effective
and without use of AC_TRY_RUN in the tool build. Tidier (than mine)
set_ftime reorganization from christos.
 1.35 29-Apr-2007  msaitoh branches: 1.35.4;
fix typos
 1.34 11-Feb-2006  dsl branches: 1.34.4;
Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.33 24-Sep-2005  dsl Don't leave arcn->org_name pointing to ftent->fts_path, if we being cpio
then ftent is freed just below. Take a copy of the name and point org_name
at the copy.
Should fix PR/30627 (the fix in the PR will break pax and tar!)
 1.32 02-Jul-2004  christos remove stray debugging left from last commit.
 1.31 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.30 19-Jun-2004  christos add -0 argument to handle nul separated file lists.
 1.29 27-Oct-2003  lukem branches: 1.29.2;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.28 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.27 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.26 23-Jun-2003  christos spelling
 1.25 09-May-2003  itojun use sizeof for safety
 1.24 21-Apr-2003  christos PR/21253: Manuel Bouyer: cpio should never descend on a directory; even on
the first one.
 1.23 19-Oct-2002  provos use readlink with bufsize - 1; approved thorpej.
 1.22 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.21 28-Jun-2002  lukem Change how "cd .." is handled in next_file() with -M, to ensure that curdir[]
isn't addressed with a negative offset when back at the top of the tree.
This caused pax -M on sparc64 to generate corrupt tar files.
Problem found by Tim Goodwin <tjg@star.le.ac.uk> in [bin/17412].
 1.20 20-Apr-2002  lukem branches: 1.20.2;
- Directories marked `optional' won't be stored, even though their
contents will be.
- Document that `optional' faked-up entries won't be created.
 1.19 12-Apr-2002  lukem If an entry is in the specfile but not in the underlying file system, and it's
marked "optional", don't add it.
 1.18 02-Feb-2002  lukem - don't compile in support for -M (mtree specfile input) or -N dbdir
(alternate directory for id info) if SMALL is defined
- enable -DSMALL and remove unused objects if CRUNCHEDPROG is defined
- minor cleanup in next_file() (preparation for future work)
 1.17 31-Jan-2002  tv Roll in fixes to permit cross-compiling from non-NetBSD hosts. This
round has been tested on Solaris/x86 and Linux hosts.

* Add host tools cap_mkdb, ctags, m4, uudecode.
* Protect __RCSID() and __COPYRIGHT() better.
* Reduce the number of places that need to include "config.h", to keep
sources closer to their "vanilla" versions.
* Add more compat #defines and autoconf-checked functions.
 1.16 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.15 26-Oct-2001  lukem improve previous; use %lu and (u_long) to print size_t
 1.14 26-Oct-2001  lukem Cast size_t's to (int) when printing as %d; appeases the sparc port.
Found by Rob Windsor in [bin/14362].
 1.13 25-Oct-2001  lukem minor improvements in wording and flag testing
 1.12 25-Oct-2001  lukem Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.11 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.10 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.9 22-Oct-1999  is Implement positional -C argument to tar.
 1.8 28-Jul-1998  mycroft branches: 1.8.4;
Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.7 06-Mar-1998  mrg - implement -C and -l for pax-as-tar, as inspried by GNU tar.
- minor cleanups to the options parsing code.
- add a cpio frontend.

note: a few GNU/svr4 cpio options are not supported yet (#ifdef
notyet), however all x/open ones are.
 1.6 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.5 11-Jan-1997  tls kill 'register'
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.8.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.20.2.3 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.20.2.2 07-Apr-2004  jmc Pullup rev 1.22-1.29 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.20.2.1 28-Jun-2002  lukem Pull up revision 1.21 (requested by lukem in ticket #388):
Change how "cd .." is handled in next_file() with -M, to ensure that curdir[]
isn't addressed with a negative offset when back at the top of the tree.
This caused pax -M on sparc64 to generate corrupt tar files.
Problem found by Tim Goodwin <tjg@star.le.ac.uk> in [bin/17412].
 1.29.2.1 22-Jun-2004  tron branches: 1.29.2.1.2;
Pull up revision 1.31 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.29.2.1.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.34.4.1 23-Oct-2012  riz Pull up following revision(s) (requested by msaitoh in ticket #1459):
bin/pax/ftree.c: revision 1.42
deal properly with empty lines in spec file
 1.35.4.1 23-Mar-2008  matt sync with HEAD
 1.37.2.1 24-Mar-2008  keiichi sync with head.
 1.38.2.1 18-May-2008  yamt sync with head.
 1.39.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.39.6.1 17-Oct-2012  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1799):
bin/pax/ftree.c: revision 1.42
deal properly with empty lines in spec file
 1.40.8.1 17-Oct-2012  riz Pull up following revision(s) (requested by msaitoh in ticket #586):
bin/pax/ftree.c: revision 1.42
deal properly with empty lines in spec file
 1.40.6.2 30-Oct-2012  yamt sync with head
 1.40.6.1 17-Apr-2012  yamt sync with head
 1.41.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.42.42.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.42.34.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.42.32.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.42.32.1 21-Apr-2020  martin Sync with HEAD
 1.43.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 13-Oct-2003  agc branches: 1.5.98;
Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.3 21-Mar-1995  cgd branches: 1.3.18;
convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.3.18.1 07-Apr-2004  jmc Pullup rev 1.4-1.5 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.5.98.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.5.98.1 21-Apr-2020  martin Sync with HEAD
 1.37 30-Nov-2018  christos Add base-256 decoding support (Micha Gorny)
 1.36 09-Aug-2012  christos branches: 1.36.32; 1.36.34;
PR/46786: Simon Burge: After conversion to 64 bit time_t, tar/pax/cpio
erroneously think that negative time_t's never fit in 32 bits. Rework
conversion code to always use uintmax_t, and detect negative values.
XXX[1]: Perhaps we should do the same (use a signed conversion) for all
fields not just for time_t
XXX[2]: pullup for 6
 1.35 14-Aug-2011  christos branches: 1.35.2;
eliminate dup code and non literal format strings
 1.34 24-Feb-2008  joerg Kill pre-4.4BSD compat code.
 1.33 11-Feb-2006  dsl branches: 1.33.10; 1.33.16;
Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.32 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.31 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.30 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.29 24-Jun-2003  grant backout previous; it was a missing prototype elsewhere.

noted by mrg.
 1.28 24-Jun-2003  grant add cast to fix an integer -> pointer warning.
 1.27 19-Dec-2002  kleink Change verbose output for symbolic links from "%s => %s" to "%s -> %s",
which matches ls(1) (per POSIX), as well as GNU tar output.
 1.26 13-Oct-2002  mrg make this build on LP64
 1.25 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.24 01-Aug-2002  wiz Remove unneeded utmp.h include.
 1.23 31-Jan-2002  tv branches: 1.23.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.22 28-Oct-2001  lukem s/u_longlong_t/unsigned long long/ to shut up the parc port
 1.21 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.20 04-Jan-2001  lukem use more standard %ll_ in favour of %q_
 1.19 22-Oct-2000  kleink LC_TIME holds a locale name, which isn't a strftime() format string.
 1.18 17-Jun-2000  mrg branches: 1.18.2;
minor KNF nits.
 1.17 17-Feb-2000  itohy branches: 1.17.2;
Cleanup and fix typos.
Partially from FreeBSD.
 1.16 22-Oct-1999  mrg remove some old cruft.
 1.15 24-Aug-1999  tron branches: 1.15.2;
Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.14 04-Nov-1998  christos make printf formats conservative
 1.13 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.12 27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.11 26-Jul-1998  mycroft const poisoning.
 1.10 01-Apr-1998  kleink Need <time.h> for strftime(), localtime() and time() prototypes.
 1.9 03-Feb-1998  mycroft Deal with GCC warnings.
 1.8 30-Jul-1997  thorpej Cast off_t's to (long long) for printing with %q*, for the Alpha.
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.15.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.18.2.1 25-Oct-2000  tv Pullup 1.19 [kleink]:
Don't abuse LC_TIME for strftime(3) format strings.
 1.23.2.4 25-Aug-2004  he Apply patch (requested by cube in ticket #1738):
Minimize difference with -current and netbsd-2-0 version.
 1.23.2.3 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.23.2.2 07-Apr-2004  jmc Pullup rev 1.24-1.26,1.28-1.32 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.23.2.1 05-Jan-2003  jmc Pull up revisions 1.26-1.27 (via hand patch and requested by kleink in ticket
#1040)
Change verbose output for symbolic links from "%s => %s" to
"%s -> %s", which matches ls(1) (per POSIX), as well as GNU
tar output.
 1.33.16.1 24-Mar-2008  keiichi sync with head.
 1.33.10.1 23-Mar-2008  matt sync with HEAD
 1.35.2.1 30-Oct-2012  yamt sync with head
 1.36.34.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.36.34.2 21-Apr-2020  martin Sync with HEAD
 1.36.34.1 10-Jun-2019  christos Sync with HEAD
 1.36.32.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.24 03-Oct-2024  rillig bin: fix lint warning "effectively discards 'const'"

For example: src/bin/ed/io.c(339): warning: call to 'strchr' effectively
discards 'const' from argument [346]

No binary change.
 1.23 09-Aug-2012  christos branches: 1.23.34; 1.23.46;
add missing include files
 1.22 11-Feb-2006  dsl branches: 1.22.42;
Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.21 05-Jun-2005  chs appease gcc -Wuninitialized on hp700.
 1.20 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.19 27-Oct-2003  lukem branches: 1.19.2;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.18 24-Jun-2003  christos Revert previous change, and fix the -T problem differently: When the options
of the second argument are exhausted, call the appropriate getopt() routine
to process the rest of the arguments instead of finishing option processing.
Fixes:
tar cf - -T foo
 1.17 23-Jun-2003  christos Simplify the way we deal with old argument style. Old way was broken when
tar cf - -T dir
 1.16 13-Oct-2002  mrg add a "+" to the options string rather than setting POSIXLY_CORRECT
 1.15 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.14 31-Jan-2002  tv branches: 1.14.2;
Roll in fixes to permit cross-compiling from non-NetBSD hosts. This
round has been tested on Solaris/x86 and Linux hosts.

* Add host tools cap_mkdb, ctags, m4, uudecode.
* Protect __RCSID() and __COPYRIGHT() better.
* Reduce the number of places that need to include "config.h", to keep
sources closer to their "vanilla" versions.
* Add more compat #defines and autoconf-checked functions.
 1.13 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.12 03-Nov-2001  lukem fix WARNS=2
 1.11 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.10 04-Jul-2000  thorpej Add GNU tar-style long options for pax's tar front-end. Still many
GNU options not implemented, but there is an #if 0'd out canonical
list.
 1.9 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.8 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.7 01-Nov-1997  lukem getoldopt is expect to return -1 (not EOF), so "make it so"
 1.6 14-Sep-1997  lukem * cleanup manpage
* getopt returns -1 not EOF
* deprecate register
 1.5 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.4 17-May-1996  jtc Fixed typo in comment
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 04-Dec-1994  cgd from James Jegers <jimj@miller.cs.uwm.edu>: quiet -Wall, and squelch
some of the worst style errors.
 1.1 14-Jun-1994  jtc Whoever wrote the tar command line argument parsing code didn't realize
that the order of arguments is different if the command flags are specified
without a `-'. I've integrated getoldopt.c from John Gilmore's pdtar which
handles argument parsing correctly.
 1.14.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.14.2.1 07-Apr-2004  jmc Pullup rev 1.15-1.19 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.19.2.1 22-Jun-2004  tron branches: 1.19.2.1.2;
Pull up revision 1.20 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.19.2.1.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.22.42.1 30-Oct-2012  yamt sync with head
 1.23.46.1 02-Aug-2025  perseant Sync with HEAD
 1.23.34.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.23.34.1 21-Apr-2020  martin Sync with HEAD
 1.122 04-May-2025  rillig pax: remove unreachable 'break' and 'return' statements
 1.121 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.120 20-Jul-2023  lukem branches: 1.120.2;
pax: need <strings.h> for ffs()

Fixes warning as host tool on NetBSD 9.99
 1.119 03-Apr-2020  joerg branches: 1.119.6;
Move definition of chdname and do_chroot to options.c
 1.118 19-Dec-2015  christos branches: 1.118.8; 1.118.16; 1.118.18;
Add the timestamp option to the pax front end.
 1.117 19-Dec-2015  christos PR/50119: Thomas Klausner: Add --timestamp option to tar.
 1.116 11-Apr-2015  christos Add -J/--xz to specifically decompress xz compressed files. We don't really
need this because -z autodetects the compression format; this is for syntax
compatibility with other tar implementations. From Joachim Henke
 1.115 14-Nov-2013  christos add --gnu for pax.
 1.114 09-Aug-2012  christos branches: 1.114.2;
add missing include files
 1.113 20-Mar-2012  matt Use C89 function definitions
 1.112 31-Aug-2011  plunky branches: 1.112.2;
NULL does not need a cast
 1.111 29-Aug-2011  joerg static + __dead
 1.110 18-Jun-2011  christos add --xz
 1.109 31-Aug-2010  enami branches: 1.109.4;
- Raise an error rather than silently creating broken archive
if user don't specify --force-local but opened file is actually
a local file.
- Make cpio to accept -F option as described in manpage.
- Make pax to set forcelocal flag if requested to do so.
- Add missing break statement.
 1.108 25-Aug-2010  sjg Do not throw a usage message for -i followed by -t
since 'cpio -itv' is a valid command.
 1.107 19-Jun-2010  christos add --use-compress-program to pax, requested by mrg.
 1.106 14-Dec-2009  dholland Don't use NOGLOB_MTCH for pax, only for tar. Fixes fix for PR 41167 and
closes PR 42301. Since the 41167 fix was pulled up to -5, this needs to
be too.
 1.105 13-Jul-2009  roy Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.104 07-Apr-2009  perry Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.
 1.103 14-Feb-2009  lukem fix -Wsign-compare issues
 1.102 23-Nov-2008  dholland branches: 1.102.2;
Don't pass strings from argv[] to free(). Fixes PR 39992.
 1.101 26-Oct-2007  hira branches: 1.101.12;
- Add -0 and -V to pax_usage().
- Add -k to tar_usage().
 1.100 23-Apr-2007  christos branches: 1.100.4;
PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.99 16-Jan-2007  cbiere Fix for PR bin/35432:
* The flags "crtux" are mutually exclusive for tar.
* The flags "ipt" and "oA" are mutually exclusive for cpio.
 1.98 16-Oct-2006  christos branches: 1.98.2; 1.98.6;
add missing inititializer
 1.97 16-Apr-2006  christos PR/22995: Sergey Svishchev: If we are cd'ing around and we have directories
with relative paths, convert the directories to absolute paths, so that
restoring timestamps does not fail.
 1.96 14-Apr-2006  christos Don't free str; it is used in pat_add. Noted by: Kouichirou Hiratsuka
 1.95 19-Mar-2006  christos Coverity CID 2734, 2731: Use after free; resource leak
 1.94 18-Mar-2006  christos Coverity CID 345: Add missing free's.
 1.93 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.92 16-Sep-2005  christos Another missing mkdir() race pointed out by chuq. Factor out the mkdir code.
 1.91 13-Sep-2005  christos use stat and not lstat to detect if we have a directory. refactor the mkpath()
code.
 1.90 13-Sep-2005  christos when creating directories, check if the failure occured because someone
else created the directory before we did to avoid races. From chuq.
 1.89 29-Jun-2005  christos Don't compile in cpio usage, if we are SMALL.
 1.88 01-Jun-2005  lukem appease gcc -Wuninitialized
 1.87 15-May-2005  christos be more lenient on the comparison to argv[0] to determine our personality.
 1.86 07-May-2005  christos PR/30167: J.T. Conklin: NetBSD tar does not support GNU tar --no-recursion flag
 1.85 01-May-2005  christos PR/29005: Jesse Off: nbpax requires sys/mtio.h which doesn't exist on Interix
I added an ifdef called HAVE_MTIO_H and fixed the code to use it. It is
always defined now, but you can change this for Interix.
 1.84 24-Apr-2005  christos Pax longopts were not empty element terminated.
 1.83 10-Feb-2005  jmc Fix from PR#29290. Properly terminate the cpio_longopts struct so an unknown
option doesn't run off the end and core dump
 1.82 26-Oct-2004  tron Fix broken cpio(1) option handling:
- "cpio -i -t" should list the contents of a file, not extract it.
- Don't extract a file when only option "-d" is given.
Patch supplied by Paul Ripke in PR bin/26513.
 1.81 22-Oct-2004  jmc For HOSTTOOL builds, just exclude the chroot support as it's not needed and
avoids having to platform check for fchroot(). Fixes PR#27336
 1.80 17-Oct-2004  dsl Add an option --chroot to tar. Causes it to chroot(".") before doing
an extract. With -h this will cause existing absolute symlinks to be treated
as relative to the current directory.
Helps sysinst handle existing symlinks in the target system.
Remove 'L' from the usage (got spilt into 'h' and 'H' many moons ago)
Add 'S' to usage, and put into correct place in options list.
 1.79 10-Oct-2004  christos PR/27212: Greg A. Woods: Accept "-C <dirname>" inside filelists in addition
to "-C\n<dirname>".
But we are not making it the default output option as the patch suggests.
 1.78 26-Sep-2004  christos PR/19490: Julio Merino: Teach tar about --sparse, -S option.
Do it for cpio too.
 1.77 22-Sep-2004  christos update the comment that documents the fields initialized in the array below.
 1.76 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.75 19-Jun-2004  christos add -0 argument to handle nul separated file lists.
 1.74 11-May-2004  christos Welcome to WARNS=3
 1.73 20-Feb-2004  uebayasi branches: 1.73.2;
Tar(1)'s -s option needs an argument. Correct option string (s -> s:).

Reported and tested by Tomoaki Imamura.
 1.72 06-Feb-2004  christos recognize -k [--keep-old-files] short option. From hubertf.
 1.71 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.70 05-Jan-2004  jmmv Rewrite the loop in printflg(): if passing -Z to pax with syntax errors
(like executing "pax -Z" by itself), this caused a shr of 32 bits, which is
undefined behavior (C99) if the variable is 32 bits wide, too. Also solves
a problem where the flgch array could be indexed out of bounds.

Thanks to uwe@ and lha@ for their suggestions... I just found the bug :p
 1.69 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.68 21-Oct-2003  fvdl Don't pass an integer as NULL.
 1.67 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.66 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.65 08-Jul-2003  simonb Add support for gnutar's -O "extract to stdout" option.
 1.64 08-Apr-2003  christos PR/21064: Perry Metzger: Re-add -k to tar (--keep-old-files)
 1.63 31-Mar-2003  christos PR/20495: Soren Jacobsen: Add -j [bzip2] compression to tar.
 1.62 25-Feb-2003  wiz Add support for '-j' to create (and extract, but -z already did that)
bzip2 compressed tar files, for GNU tar compatibility.
Patch from Soren Jacobsen in PR 19467, okayed by christos.
Sync usage with options while here.
 1.61 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.60 19-Jan-2003  wiz tar(1) has no -L any longer.
 1.59 15-Jan-2003  kristerw Correct which _usage function to use for some pax/cpio error cases.
 1.58 09-Jan-2003  christos PR/19757: Andreas Wrede: make tar's -h behave like pax's -L
 1.57 08-Dec-2002  mrg add --exclude support.

XXX: --exclude & --exclude-from are still not 100% compatible, but since
rafal fixed --exclude-from's most annoying bug, they mostly work now.
 1.56 27-Nov-2002  grant void functions should not return a value.
 1.55 18-Oct-2002  christos Handle -C\ndir\n in a file containing a file list. From Eric Gillespie.
 1.54 17-Oct-2002  christos Fix DEFOP botch. DEFOP == LIST so tar -tvf stopped working. (hi soren)
 1.53 16-Oct-2002  soren Tweak tar_usage().
 1.52 16-Oct-2002  soren Have tar require a specific action as documented.
 1.51 16-Oct-2002  soren Sync cpio_usage() with cpio.1 as with pax and tar.
 1.50 16-Oct-2002  christos we need to have -force-local on pax.
 1.49 16-Oct-2002  christos turn gnu tar off by pax and cpio front ends.
 1.48 16-Oct-2002  christos Support gnu long filename extensions by default for tar on create, list, and
extract. We now generate GNU tar archives by default ("ustar ^@" instead of
"ustar^@00"). GNU extensions can be disabled with --strict.

XXX: long symlinks untested.
 1.47 15-Oct-2002  christos PR/18663: Jeremy Reed: pax/tar/cpio allows ".." in names.
We now disallow it by default on both archive creation and extraction.
Add --insecure option to override.
 1.46 15-Oct-2002  christos implement fast read. nothing to it really, it was already there as -q option.
 1.45 15-Oct-2002  christos Add all the gnu cpio long options.
 1.44 14-Oct-2002  soren Sync tar_usage() with tar.1.
 1.43 13-Oct-2002  christos -T expects an argument. From Eric Gillespie, thanks.
 1.42 13-Oct-2002  mrg fix "pax -rw" processing. for some reason, it was now written to process
"pax -rwvpe a b" as "pax -rwvpe b a", and "pax -rwvpe a b c" as
"pax -rwvpe b c a". only the part of revision 1.40 that broken this has
been reverted.
 1.41 13-Oct-2002  mrg add a "+" to the options string rather than setting POSIXLY_CORRECT
 1.40 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.39 02-Feb-2002  lukem branches: 1.39.2;
- don't compile in support for -M (mtree specfile input) or -N dbdir
(alternate directory for id info) if SMALL is defined
- enable -DSMALL and remove unused objects if CRUNCHEDPROG is defined
- minor cleanup in next_file() (preparation for future work)
 1.38 31-Jan-2002  tv Roll in fixes to permit cross-compiling from non-NetBSD hosts. This
round has been tested on Solaris/x86 and Linux hosts.

* Add host tools cap_mkdb, ctags, m4, uudecode.
* Protect __RCSID() and __COPYRIGHT() better.
* Reduce the number of places that need to include "config.h", to keep
sources closer to their "vanilla" versions.
* Add more compat #defines and autoconf-checked functions.
 1.37 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.36 26-Jan-2002  lukem provide meaningful warning if -N is called with a dodgy dbdir
 1.35 24-Jan-2002  lukem Add '-N dbdir', to specify that user & group lookups (via pwcache(3)) are to
be done from dbdir/master.passwd and dbdir/group, using simple text file
parsing routines from ../../usr.sbin/mtree/getid.c.
This does not affect the -G and -U options, which always use the
system databases.
 1.34 25-Oct-2001  lukem Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.33 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.32 22-Jul-2001  wiz seperate -> separate
 1.31 04-Jul-2000  thorpej Implement --atime-preserve.
 1.30 04-Jul-2000  thorpej Implement --use-compress-program.
 1.29 04-Jul-2000  thorpej Add GNU tar-style long options for pax's tar front-end. Still many
GNU options not implemented, but there is an #if 0'd out canonical
list.
 1.28 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.27 30-Mar-2000  thorpej Add a -O option: force one volume. This causes pax to not prompt for
a new volume upon premature end-of-volume (e.g. broken pipe). This is
especially useful in automated environments where error recovery cannot
be performed by a human.
 1.26 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.25 07-Nov-1999  mycroft branches: 1.25.2;
Disable -pf for now, too.
 1.24 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.23 22-Oct-1999  is Implement positional -C argument to tar.
 1.22 24-Aug-1999  tron branches: 1.22.2;
Fix "tar" mode usage string.
 1.21 24-Aug-1999  tron Recognize GnuTAR's "h" (instead of "H") and "P" options.
 1.20 24-Aug-1999  tron Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.19 07-Mar-1999  mycroft Add -z option to usage message.
 1.18 07-Feb-1999  tv Fix opt_add to take const char * so that it can be passed a constant
string legally (it strdup()s the argument). How pax-as-tar `-o' ever
worked without a coredump is beyond me...

Also modify pax-as-tar `-o' to do three things, which depend on the
create/extract mode:

- write V7 format archives (which, though part of GNU tar, actually
goes along with the following point--after all, old pax-as-tar created
V7 archives by default);
- write archives with "write_opt=nodir", as pax already did, and as
specified by 4.2BSD;
- extract archives with owner/group set to invoking user, as specified
by SUS.
 1.17 02-Feb-1999  tv Lost 5 lines in the version that was committed. Re-add them.
 1.16 02-Feb-1999  tv Uh, when called as "tar" we should still default to "ustar" output, not
V7 tar format. Also change meaning of pax-as-tar option "-o" to mean
"use V7 output format" (same as GNU tar's -o).
 1.15 20-Jan-1999  mrg implement the gnutar -X flag in terms of pax -s. fix some bugs in pax -s handling while i am here...
 1.14 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.13 28-Jul-1998  mycroft Be more retentive about use of NOTREACHED and noreturn.
 1.12 28-Jul-1998  mycroft Delint.
 1.11 09-Jun-1998  mrg oops, fix broken cpio options code. tar options code should be made like pax and cpio code.
 1.10 06-Mar-1998  mrg - implement -C and -l for pax-as-tar, as inspried by GNU tar.
- minor cleanups to the options parsing code.
- add a cpio frontend.

note: a few GNU/svr4 cpio options are not supported yet (#ifdef
notyet), however all x/open ones are.
 1.9 14-Sep-1997  lukem * cleanup manpage
* getopt returns -1 not EOF
* deprecate register
 1.8 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.7 11-Jan-1997  tls kill 'register'
 1.6 26-Mar-1996  mrg impliment -z (gzip) in pax and tar, and -Z (compress) in tar.
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 14-Jun-1994  jtc Whoever wrote the tar command line argument parsing code didn't realize
that the order of arguments is different if the command flags are specified
without a `-'. I've integrated getoldopt.c from John Gilmore's pdtar which
handles argument parsing correctly.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.22.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.2.2 07-Nov-1999  mycroft Disable -pf for now, too.
 1.25.2.1 07-Nov-1999  mycroft file options.c was added on branch comdex-fall-1999 on 1999-11-07 15:57:32 +0000
 1.39.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.39.2.1 07-Apr-2004  jmc Pullup rev 1.40-1.73 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.73.2.1 22-Jun-2004  tron branches: 1.73.2.1.2;
Pull up revision 1.76 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.73.2.1.2.3 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.73.2.1.2.2 29-May-2005  riz Pull up revision 1.83 (requested by kleink in ticket #1554):
Fix from PR#29290. Properly terminate the cpio_longopts struct so an unknown
option doesn't run off the end and core dump
 1.73.2.1.2.1 30-Jan-2005  he Pull up revision 1.82 (requested by tron in ticket #952):
Fix broken cpio(1) option handling:
o "cpio -i -t" should list the contents of a file, not
extract it.
o Don't extract a file when only option "-d" is given.
Fixes PR#26513.
 1.98.6.1 25-Aug-2009  snj Pull up following revision(s) (requested by plunky in ticket #1354):
bin/pax/options.c: revision 1.105 via patch
usr.bin/ctags/C.c: revision 1.19
usr.bin/ctags/ctags.h: revision 1.9
usr.bin/ctags/fortran.c: revision 1.11
usr.bin/ctags/lisp.c: revision 1.11
usr.bin/ctags/print.c: revision 1.10
usr.bin/ctags/yacc.c: revision 1.12
usr.bin/gencat/gencat.c: revision 1.30 via patch
Rename internal getline() function to get_line() so it does not
conflict with the soon to be added getline(3) libc function.
 1.98.2.1 25-Aug-2009  snj Pull up following revision(s) (requested by plunky in ticket #1354):
bin/pax/options.c: revision 1.105 via patch
usr.bin/ctags/C.c: revision 1.19
usr.bin/ctags/ctags.h: revision 1.9
usr.bin/ctags/fortran.c: revision 1.11
usr.bin/ctags/lisp.c: revision 1.11
usr.bin/ctags/print.c: revision 1.10
usr.bin/ctags/yacc.c: revision 1.12
usr.bin/gencat/gencat.c: revision 1.30 via patch
Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.100.4.1 06-Nov-2007  matt sync with HEAD
 1.101.12.4 30-Jan-2010  snj Pull up following revision(s) (requested by dholland in ticket #1272):
bin/pax/options.c: revision 1.106
Don't use NOGLOB_MTCH for pax, only for tar. Fixes fix for PR 41167 and
closes PR 42301. Since the 41167 fix was pulled up to -5, this needs to
be too.
 1.101.12.3 14-Aug-2009  snj Pull up following revision(s) (requested by roy in ticket #885):
bin/pax/options.c: revision 1.105
dist/nawk/maketab.c: revision 1.12
dist/nawk/proctab.c: revision 1.11
dist/nawk/proto.h: revision 1.9
dist/nawk/run.c: revision 1.29
usr.bin/ctags/C.c: revision 1.19
usr.bin/ctags/ctags.h: revision 1.9
usr.bin/ctags/fortran.c: revision 1.11
usr.bin/ctags/lisp.c: revision 1.11
usr.bin/ctags/print.c: revision 1.10
usr.bin/ctags/yacc.c: revision 1.12
usr.bin/gencat/gencat.c: revision 1.30
Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.101.12.2 13-Apr-2009  snj branches: 1.101.12.2.2; 1.101.12.2.4;
Pull up following revision(s) (requested by christo in ticket #678):
bin/pax/extern.h: revision 1.56
bin/pax/file_subs.c: revision 1.62
bin/pax/options.c: revision 1.104
bin/pax/pat_rep.c: revision 1.29
bin/pax/pax.h: revision 1.30
Fixes from christos for pr-41167
XXX -X is still broken, but that wasn't part of this PR.
 1.101.12.1 23-Nov-2008  riz Pull up following revision(s) (requested by dholland in ticket #114):
bin/pax/options.c: revision 1.102
Don't pass strings from argv[] to free(). Fixes PR 39992.
 1.101.12.2.4.1 21-Apr-2010  matt sync to netbsd-5
 1.101.12.2.2.1 14-Aug-2009  snj Pull up following revision(s) (requested by roy in ticket #885):
bin/pax/options.c: revision 1.105
dist/nawk/maketab.c: revision 1.12
dist/nawk/proctab.c: revision 1.11
dist/nawk/proto.h: revision 1.9
dist/nawk/run.c: revision 1.29
usr.bin/ctags/C.c: revision 1.19
usr.bin/ctags/ctags.h: revision 1.9
usr.bin/ctags/fortran.c: revision 1.11
usr.bin/ctags/lisp.c: revision 1.11
usr.bin/ctags/print.c: revision 1.10
usr.bin/ctags/yacc.c: revision 1.12
usr.bin/gencat/gencat.c: revision 1.30
Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.102.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.109.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.112.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.112.2.2 30-Oct-2012  yamt sync with head
 1.112.2.1 17-Apr-2012  yamt sync with head
 1.114.2.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.118.18.2 19-Oct-2025  martin Pull up following revision(s) (requested by mrg in ticket #1973):

tools/compat/configure.ac: revision 1.111
tools/compat/compat_defs.h: revision 1.126
tools/compat/compat_defs.h: revision 1.127
usr.bin/nbperf/nbperf.c: revision 1.7
bin/pax/options.c: revision 1.120
tools/compat/nbtool_config.h.in: revision 1.59 (patch)
tools/compat/Makefile: revision 1.95 (patch)
tools/compat/configure.ac: revision 1.110 (patch)
tools/compat/configure (patch for regen from above)

Don't use arc4random for the tools build on NetBSD either.
compat_defs.h explicitly forces _POSIX_SOURCE and this hides the
prototype in stdlib.h.
pax: need <strings.h> for ffs()

Fixes warning as host tool on NetBSD 9.99

Add more functions needed by mandoc

add vsyslog decl check
 1.118.18.1 30-Apr-2021  martin Pull up following revision(s) (requested by mrg in ticket #1263):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100

Avoid depending on common symbols.
 1.118.16.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.118.16.2 21-Apr-2020  martin Sync with HEAD
 1.118.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.118.8.1 07-May-2021  martin Pull up following revision(s) (requested by mrg in ticket #1678):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100
usr.sbin/installboot/Makefile: revisions 1.53,1.54 (patch)
usr.sbin/installboot/installboot.h: revision 1.41 (patch)
usr.sbin/installboot/machines.c: revisisons 1.41,1.42 (patch)

Avoid depending on common symbols.
 1.119.6.1 19-Oct-2025  martin Pull up following revision(s) (requested by mrg in ticket #1174):

tools/compat/configure.ac: revision 1.111 (patch)
tools/compat/compat_defs.h: revision 1.126 (patch)
tools/compat/compat_defs.h: revision 1.127 (patch)
bin/pax/options.c: revision 1.120
tools/compat/nbtool_config.h.in: revision 1.59 (patch)
tools/compat/Makefile: revision 1.95 (patch)
tools/compat/configure.ac: revision 1.110 (patch)

pax: need <strings.h> for ffs()

Fixes warning as host tool on NetBSD 9.99

Add more functions needed by mandoc

add vsyslog decl check
 1.120.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 23-Apr-2007  christos branches: 1.11.78;
PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.10 11-May-2004  christos Welcome to WARNS=3
 1.9 13-Oct-2003  agc branches: 1.9.4;
Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.7 25-Oct-2001  lukem branches: 1.7.2;
Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.6 01-Nov-1999  mrg whoops; reverse the logic of the previous to make it correct. noted by mycroft.
 1.5 01-Nov-1999  mrg add CAF testing to extraction, archiving and listing (where it is used)
 1.4 24-Aug-1999  tron branches: 1.4.2;
Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.4.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.7.2.1 07-Apr-2004  jmc Pullup rev 1.8-1.9 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.9.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.11.78.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.11.78.1 21-Apr-2020  martin Sync with HEAD
 1.32 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.31 20-Mar-2019  gutteridge branches: 1.31.12;
pax: minor adjustments to comments in pat_rep.c

Amend several comments to match present reality (the functionality was
added back in 2007).
 1.30 13-Jun-2018  christos branches: 1.30.2;
PR/53362: Thomas Barabosch: Use strlcpy() to prevent theoretical buffer
overflow.
 1.29 07-Apr-2009  perry branches: 1.29.46;
Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.
 1.28 24-Feb-2008  joerg branches: 1.28.8; 1.28.10;
Kill pre-4.4BSD compat code.
 1.27 04-May-2007  christos branches: 1.27.4; 1.27.8;
PR/36275: john at iastate dot edu: tar -s modifies symlink targets
- This is explained in a comment in pat_rep.c inside mod_name(). I did not
want to change the default behavior, so I added another modifier "s" which
when set, the pattern will not modify the symlink destination.
- While here I fixed another bug that was introduced before by the fix in
PR/35257 where the renaming was happening twice since we called rep_name
twice.
- Finally if we are renaming hard of soft-link targets print the renames for
those too.
 1.26 29-Apr-2007  msaitoh fix typos
 1.25 24-Apr-2006  snj It's "its."
 1.24 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.23 23-Jan-2005  jmc Apply user supplied patterns first before applying actions for -A. This way pax
behavior WRT to patterns lines up with the example in the documentation
and how other implementations do it as well since -A is a non-standard
option/behavior. Fixes items noted in PR#23776
 1.22 21-Jan-2005  dsl Check for *ptr == 0, not ptr == NULL twice when validating -s xxxxx in tar mode.
Fixes PR bin/29040
Also actually report an error to the tty if NET2_REGEX is defined.
 1.21 27-Oct-2003  lukem branches: 1.21.4;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.20 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.18 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.17 29-Nov-2002  rafal Fix lossage with the GNU-tar -X compatibility code: the replacement pattern
code did not properly deal with the fact that the replacement patterns built
by the -X code were on the stack, happily saving pointers into last weeks'
stack into the REPLACE structures.

Now, the replacement string is strdup'ed so it doesn't matter where the
original expression came from or it's lifetime.
 1.16 23-Oct-2002  christos ignore files that contain "..", not symlink sources.
 1.15 15-Oct-2002  christos PR/18663: Jeremy Reed: pax/tar/cpio allows ".." in names.
We now disallow it by default on both archive creation and extraction.
Add --insecure option to override.
 1.14 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.13 31-Jan-2002  tv branches: 1.13.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.12 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.11 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.10 22-Oct-1999  is Implement positional -C argument to tar.
 1.9 24-Mar-1999  pk branches: 1.9.4;
When substituting backreferences source from the pattern, not the replacement
strings.
 1.8 20-Jan-1999  mrg implement the gnutar -X flag in terms of pax -s. fix some bugs in pax -s handling while i am here...
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 29-Mar-1997  mycroft Adjust the input string by the right amount if the pattern wasn't at the
beginning.
 1.5 11-Jan-1997  tls kill 'register'
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.9.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.13.2.1 07-Apr-2004  jmc Pullup rev 1.14-1.21 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.21.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.27.8.1 24-Mar-2008  keiichi sync with head.
 1.27.4.1 23-Mar-2008  matt sync with HEAD
 1.28.10.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.28.8.1 13-Apr-2009  snj Pull up following revision(s) (requested by christo in ticket #678):
bin/pax/extern.h: revision 1.56
bin/pax/file_subs.c: revision 1.62
bin/pax/options.c: revision 1.104
bin/pax/pat_rep.c: revision 1.29
bin/pax/pax.h: revision 1.30
Fixes from christos for pr-41167
XXX -X is still broken, but that wasn't part of this PR.
 1.29.46.1 25-Jun-2018  pgoyette Sync with HEAD
 1.30.2.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.30.2.2 21-Apr-2020  martin Sync with HEAD
 1.30.2.1 10-Jun-2019  christos Sync with HEAD
 1.31.12.1 02-Aug-2025  perseant Sync with HEAD
 1.7 24-Feb-2008  joerg branches: 1.7.66;
Kill pre-4.4BSD compat code.
 1.6 04-May-2007  christos branches: 1.6.4; 1.6.8;
PR/36275: john at iastate dot edu: tar -s modifies symlink targets
- This is explained in a comment in pat_rep.c inside mod_name(). I did not
want to change the default behavior, so I added another modifier "s" which
when set, the pattern will not modify the symlink destination.
- While here I fixed another bug that was introduced before by the fix in
PR/35257 where the renaming was happening twice since we called rep_name
twice.
- Finally if we are renaming hard of soft-link targets print the renames for
those too.
 1.5 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.3 21-Mar-1995  cgd branches: 1.3.18;
convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.3.18.1 07-Apr-2004  jmc Pullup rev 1.4-1.5 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.6.8.1 24-Mar-2008  keiichi sync with head.
 1.6.4.1 23-Mar-2008  matt sync with HEAD
 1.7.66.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.7.66.1 21-Apr-2020  martin Sync with HEAD
 1.72 06-Nov-2021  gutteridge pax.1: minor grammar fixes
 1.71 19-Mar-2019  gutteridge pax.1 & tar.1: add a minor clarification about "-s"

As a somewhat pedantic clarification, "-s" does not accept backslashes
as delimiters. (While here, also make the macro use of an expression
shared between pax.1 and tar.1 consistent.)
 1.70 19-Mar-2019  gutteridge pax.1: document the "s" flag of the "s" option

Note the "s" option has an "s" flag that "prevents substitutions from
being performed on symbolic link destinations". Carry over r. 1.25 from
christos@ and part of r. 1.26 from wiz@ from tar.1, since this
functionality is available in pax as well as tar.
 1.69 03-Jul-2017  wiz branches: 1.69.6;
Remove workaround for ancient HTML generation code.
 1.68 12-Aug-2016  sevan Document the version pax first appeared.
Bump date.
 1.67 19-Dec-2015  wiz Remove trailing whitespace.
 1.66 19-Dec-2015  christos Add the timestamp option to the pax front end.
 1.65 04-Nov-2015  wiz Use An in AUTHORS section.
 1.64 03-Nov-2015  pgoyette By my count, [[[[[cc]yy]mm]dd]hh]mm[.ss] has seven fields, not six!
 1.63 14-Nov-2013  wiz Stop hissing.
 1.62 14-Nov-2013  christos add --gnu for pax.
 1.61 19-Jun-2011  wiz branches: 1.61.2; 1.61.8;
Use Fl Fl for long options.
 1.60 19-Jun-2011  christos document --xz
 1.59 19-Jun-2010  wiz branches: 1.59.4;
Use Fl Fl for long options. Remove unnecessary Bk/Ek.
 1.58 19-Jun-2010  christos add --use-compress-program to pax, requested by mrg.
 1.57 05-Apr-2010  joerg \\ -> \e
 1.56 06-Sep-2009  christos too many dots. noted by anon-ymous
 1.55 02-Dec-2007  wiz Minimally sort options; use Dq.
 1.54 26-Oct-2007  hira Remove extra space from -T option in SYNOPSIS.
 1.53 23-Apr-2007  christos branches: 1.53.4;
bump date.
 1.52 23-Apr-2007  christos PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.51 22-Aug-2006  christos PR/34255: dieter roelants: Remove mention of -p f.
 1.50 11-Sep-2005  wiz Use better section header. Sort sections. From YOMURA Masanori in private mail.
 1.49 19-Jun-2004  christos add -0 argument to handle nul separated file lists.
 1.48 04-May-2004  grant - remove an extraneous word
- it's "backward compatibility" not "backwards compatibility"
 1.47 02-Apr-2004  keihan Revert last, revision 1.46.
 1.46 02-Apr-2004  keihan ".../newdir" --> "../newdir"
 1.45 13-Oct-2003  agc branches: 1.45.2;
Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.44 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.43 19-Jul-2003  mrg note -z is an extention.
 1.42 01-May-2003  wiz Some grammar and punctuation fixes from jmc@openbsd.
 1.41 16-Apr-2003  wiz Bump date for last.
 1.40 31-Mar-2003  christos PR/20495: Soren Jacobsen: Add -j [bzip2] compression to tar.
 1.39 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.38 28-Dec-2002  wiz Whitespace nits.
 1.37 19-Dec-2002  kleink Catch up with gen_subs.c rev. 1.27: the verbose output for symbolic links
is plain ls -l.
 1.36 16-Oct-2002  christos grr, I put these in the wrong spot.
 1.35 16-Oct-2002  christos Document the long options.
 1.34 25-Sep-2002  wiz New policy: New sentences start on a new line.
Patches by Robert Elz <kre at munnari oz au>, with minimal changes by me.
 1.33 21-Apr-2002  wiz branches: 1.33.2;
End sentence with a dot.
 1.32 20-Apr-2002  lukem - Directories marked `optional' won't be stored, even though their
contents will be.
- Document that `optional' faked-up entries won't be created.
 1.31 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.30 24-Jan-2002  lukem Add '-N dbdir', to specify that user & group lookups (via pwcache(3)) are to
be done from dbdir/master.passwd and dbdir/group, using simple text file
parsing routines from ../../usr.sbin/mtree/getid.c.
This does not affect the -G and -U options, which always use the
system databases.
 1.29 08-Nov-2001  hubertf Add a second example for copying directory trees, this time as root
(using -pe, which also preserves ownership).

Proof-read by Perry.
 1.28 07-Nov-2001  hubertf * Fix example on how to copy a tree.
Noted in PR 14486 by Hiramatsu Yoshifumi <hiramatu@boreas.dti.ne.jp>
* In the same example, add flags to preserve permissions (-pp)
 1.27 28-Oct-2001  wiz Whitespace nits, sort sections, fix Dv usage (doesn't like macro argument).
 1.26 25-Oct-2001  lukem Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.25 04-Sep-2000  kleink Elaborate a bit on -t.
 1.24 21-Aug-2000  tv Work around a groff bug by splitting a long .Cm into two parts.
 1.23 30-Mar-2000  thorpej Add a -O option: force one volume. This causes pax to not prompt for
a new volume upon premature end-of-volume (e.g. broken pipe). This is
especially useful in automated environments where error recovery cannot
be performed by a human.
 1.22 07-Nov-1999  mycroft branches: 1.22.2;
Disable -pf for now, too.
 1.21 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.20 26-Sep-1999  jdolecek add SEE ALSO section, xref tar(1), cpio(1), symlink(7)
 1.19 26-Sep-1999  enami Don't emphasys punctuations.
 1.18 24-Aug-1999  tron branches: 1.18.2;
Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.17 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.16 07-Mar-1999  mycroft Do the previous is a slightly different way, to avoid .Po/.Pc.
 1.15 07-Mar-1999  mycroft Clean up embedded angle brackets for mdoc2html.
 1.14 07-Mar-1999  mycroft Finally get all of the highlighting correct in the -T argument.
 1.13 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.12 07-Mar-1999  mycroft Fix formatting errors.
 1.11 07-Mar-1999  mycroft Use .Ns a bit.
 1.10 07-Mar-1999  mycroft Improve the formatting of the SYNOPSIS section.
 1.9 02-Mar-1998  mrg document pax -z. only 2 years late...
 1.8 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.7 21-Jan-1998  mycroft Allow a century to be specified in time stamps.
 1.6 20-Oct-1997  enami branches: 1.6.2;
Fix .Nm usage.
 1.5 14-Sep-1997  lukem * cleanup manpage
* getopt returns -1 not EOF
* deprecate register
 1.4 18-Dec-1996  pk Change misleading example to read `pax -v -f filename' which doesn't
extract files (Robert Dick; PR#3032)
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.6.2.1 29-Jan-1998  mellon Pull up 1.7 (mycroft)
 1.18.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.22.2.2 07-Nov-1999  mycroft Disable -pf for now, too.
 1.22.2.1 07-Nov-1999  mycroft file pax.1 was added on branch comdex-fall-1999 on 1999-11-07 15:57:32 +0000
 1.33.2.3 25-Aug-2004  he Pull up revision 1.48 (requested by cube in ticket #1735):
Remove extraneous word, and fix a grammar error.
 1.33.2.2 07-Apr-2004  jmc Pullup rev 1.34-1.36,1.38-1.47 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.33.2.1 05-Jan-2003  jmc Pull up revisions 1.36-1.37 (requested by kleink in ticket #1040)
Change verbose output for symbolic links from "%s => %s" to
"%s -> %s", which matches ls(1) (per POSIX), as well as GNU
tar output.
 1.45.2.1 09-May-2004  jdc branches: 1.45.2.1.2;
Pull up revision 1.48 (requested by grant in ticket #263)

- remove an extraneous word
- it's "backward compatibility" not "backwards compatibility"
 1.45.2.1.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.53.4.2 09-Jan-2008  matt sync with HEAD
 1.53.4.1 06-Nov-2007  matt sync with HEAD
 1.59.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.61.8.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.61.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.69.6.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.69.6.2 21-Apr-2020  martin Sync with HEAD
 1.69.6.1 10-Jun-2019  christos Sync with HEAD
 1.52 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.51 05-Aug-2024  riastradh pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.50 05-Aug-2024  riastradh pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
 1.49 24-Apr-2019  cheusov branches: 1.49.2; 1.49.10; 1.49.12;
Fix compilation failure with gcc-8.
Equal pointers to 'struct sigaction' should not be passed to sigaction(2).
So, we pass NULL as an "old sigaction" structure.
 1.48 02-Oct-2017  joerg branches: 1.48.4;
Include time.h for time(2). Sort.
 1.47 29-Aug-2011  joerg static + __dead
 1.46 18-Jun-2011  christos add --xz
 1.45 20-Jul-2008  lukem branches: 1.45.18;
Remove the \n and tabs from the __COPYRIGHT() strings.
 1.44 05-Oct-2007  lukem branches: 1.44.8;
Convert to using raise_default_signal(3).
 1.43 03-Jul-2007  lukem branches: 1.43.4;
In sig_cleanup(), attempt to reset the signal handler to the default
and raise the appropriate signal, so the correct wait status is
returned to the parent.
 1.42 29-Apr-2007  msaitoh fix typos
 1.41 23-Apr-2007  christos PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.40 11-Feb-2006  dsl Ensure we exit with an error if we don't actually do anything.
There are a lot of tty_warn(0,...) and syswarn(0,...) which probably ought
to be tty_warn/syswarn(1,...) to force an error exit. However some are
used in interactive parts (eg opening a continuation archive) where there
is a separate retry loop.
So we just pass a failure code out to main() - how quaint!
This should now cause the NetBSD build to fail when gzip tries to write
to a non-existant directory.
(I suspect there are still many errors that don't get reported correctly.)
 1.39 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.38 11-Feb-2006  dsl Actually exit with error if we cannot open("."), make it more obvious that
we exit with error on signals.
 1.37 24-Apr-2005  christos PR/18759: FUKAUMI Naoki: pax/tar dot-dot handling broken
PR/18840: Frederick Bruckman: Fix for PR/18663 incomplete pax symlink handling

This patch makes ``--insecure'' do something. Now if ``--insecure''
is not set (the default) we do a realpath(3) in all the pathnames
that we are trying to create and if either realpath fails, or the
path is outside our working directory, we print a warning and die.
This maybe too strict and might fail on valid archives that create
symlinks and directories in the wrong order.
 1.36 10-Oct-2004  christos PR/27208: Greg A. Woods: pax must call options() before using syswarn()
or tty_warn()
 1.35 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.34 11-May-2004  christos Welcome to WARNS=3
 1.33 13-Feb-2004  matt branches: 1.33.2;
When pax catches a signal and cleans up, make sure to remove any temporary
file that was being extracted to. This will prevent pax from leaving
droppings when you hit ^C.
 1.32 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.31 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.30 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.28 08-Jul-2003  simonb Add support for gnutar's -O "extract to stdout" option.
 1.27 23-Jun-2003  grant consistently use "cannot" instead of "can not".
 1.26 03-Mar-2003  grant call setprogname()
 1.25 25-Feb-2003  wiz Add support for '-j' to create (and extract, but -z already did that)
bzip2 compressed tar files, for GNU tar compatibility.
Patch from Soren Jacobsen in PR 19467, okayed by christos.
Sync usage with options while here.
 1.24 12-Dec-2002  christos fix horrible side effect introduced by changing the append mode into archive.
The append mode already did that, so we always ended up overwriting the archive.
 1.23 10-Dec-2002  christos PR/19339: Martin Weber: Tar fails to append on empty files and exits with
0. Revert previous change for PR/18689. We always want to exit with
an error if we could not determine the archive format. Instead,
treat empty files specially. On list/extract we turn into no/op.
On append, we turn into archive.
 1.22 20-Oct-2002  christos PR/18733: Jed Davis: stderr is not constant under linux and this is a host
tool.
 1.21 17-Oct-2002  christos Fix DEFOP botch. DEFOP == LIST so tar -tvf stopped working. (hi soren)
 1.20 15-Oct-2002  christos PR/18663: Jeremy Reed: pax/tar/cpio allows ".." in names.
We now disallow it by default on both archive creation and extraction.
Add --insecure option to override.
 1.19 13-Oct-2002  mrg include <string.h> for mem* and str*
 1.18 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.17 31-Jan-2002  tv branches: 1.17.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.16 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.15 25-Oct-2001  lukem Implement -M flag: During a write or copy operation, treat the list of
files on standard input as an mtree(8) `specfile' specification, and
write or copy only those items in the specfile.

If the file exists in the underlying file system, its permissions and
modification time will be used unless specifically overridden by the
specfile. An error will be raised if the type of entry in the specfile
conflicts with that of an existing file.

Otherwise, it is necessary to specify at least the following parameters
in the specfile: type, mode, gname or gid, and uname or uid, device
(in the case of block or character devices), and link (in the case of
symbolic links). If time isn't provided, the current time will be used.
 1.14 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.13 22-Oct-2000  kleink LC_TIME holds a locale name, which isn't a strftime() format string.
 1.12 17-Feb-2000  itohy branches: 1.12.4;
Cleanup and fix typos.
Partially from FreeBSD.
 1.11 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.10 24-Aug-1999  tron branches: 1.10.2;
Strip leading slashes from filenames by default, add new "A" option to
disable this behaviour. Patches supplied by Peter Seebach in PR bin/8233.
 1.9 03-Mar-1999  christos Add SIGINFO support.
 1.8 28-Jul-1998  mycroft Delint.
 1.7 27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.6 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.5 26-Mar-1996  mrg impliment -z (gzip) in pax and tar, and -Z (compress) in tar.
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.10.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12.4.1 25-Oct-2000  tv Pullup 1.13 [kleink]:
Don't abuse LC_TIME for strftime(3) format strings.
 1.17.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.17.2.1 07-Apr-2004  jmc Pullup rev 1.18-1.33 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.33.2.1 22-Jun-2004  tron branches: 1.33.2.1.2;
Pull up revision 1.35 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.33.2.1.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.43.4.1 06-Nov-2007  matt sync with HEAD
 1.44.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.45.18.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.48.4.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.48.4.2 21-Apr-2020  martin Sync with HEAD
 1.48.4.1 10-Jun-2019  christos Sync with HEAD
 1.49.12.1 02-Aug-2025  perseant Sync with HEAD
 1.49.10.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.49.2.1 07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.31 09-Aug-2012  christos branches: 1.31.34;
PR/46786: Simon Burge: After conversion to 64 bit time_t, tar/pax/cpio
erroneously think that negative time_t's never fit in 32 bits. Rework
conversion code to always use uintmax_t, and detect negative values.
XXX[1]: Perhaps we should do the same (use a signed conversion) for all
fields not just for time_t
XXX[2]: pullup for 6
 1.30 07-Apr-2009  perry branches: 1.30.6;
Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.
 1.29 14-Feb-2009  lukem fix -Wsign-compare issues
 1.28 24-Feb-2008  joerg branches: 1.28.8; 1.28.10;
Kill pre-4.4BSD compat code.
 1.27 02-Dec-2007  wiz branches: 1.27.4;
Fix typo in comment.
 1.26 29-Apr-2007  msaitoh branches: 1.26.4;
fix typos
 1.25 24-Sep-2005  dsl Don't leave arcn->org_name pointing to ftent->fts_path, if we being cpio
then ftent is freed just below. Take a copy of the name and point org_name
at the copy.
Should fix PR/30627 (the fix in the PR will break pax and tar!)
 1.24 11-May-2004  christos Welcome to WARNS=3
 1.23 12-Feb-2004  matt branches: 1.23.4;
When restoring files from an archive, initially restore to a temp-file and
once it has been instantiated correctly, rename it to desired name. This
prevents the problem of partially created files being accessed before they
are complete. If said file is a shared library, that can cause ramdon core
dumps.
 1.22 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.21 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.19 23-Jun-2003  grant no need for HAVE_LCHOWN and HAVE_LCHMOD anymore.
 1.18 09-May-2003  lukem #ifdef HOSTPROG then explicitly use {major,minor,makedev}_netbsd
macros from pack_dev.h instead of the native versions.
Fixes [toolchain/20051] by Valeriy E. Ushakov.
 1.17 17-Oct-2002  christos Fix DEFOP botch. DEFOP == LIST so tar -tvf stopped working. (hi soren)
 1.16 13-Oct-2002  mrg make this build on LP64
 1.15 12-Oct-2002  thorpej It doesn't help much to skip linking librmt if HOSTPROG but leave
all the librmt calls in the program. So, make librmt support conditional
on #ifdef SUPPORT_RMT, and define that when NOT building as a HOSTPROG.
 1.14 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.13 31-Jan-2002  tv branches: 1.13.2;
Roll in fixes to permit cross-compiling from non-NetBSD hosts. This
round has been tested on Solaris/x86 and Linux hosts.

* Add host tools cap_mkdb, ctags, m4, uudecode.
* Protect __RCSID() and __COPYRIGHT() better.
* Reduce the number of places that need to include "config.h", to keep
sources closer to their "vanilla" versions.
* Add more compat #defines and autoconf-checked functions.
 1.12 28-Oct-2001  lukem s/u_longlong_t/unsigned long long/ to shut up the parc port
 1.11 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.10 04-Sep-2001  wiz Fix typo (specifc instead of specific).
 1.9 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.8 22-Oct-1999  is Implement positional -C argument to tar.
 1.7 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.6 03-Jul-1999  kleink branches: 1.6.2;
Honor the contents of $TMPDIR for the creation of temporary files, and use
_PATH_TMP instead of hardcoding /tmp if not set in the environment; fixes
PR bin/7796 from Chris Demetriou.
 1.5 26-Mar-1998  mycroft branches: 1.5.2;
Use major(), minor() and makedev(), not a hacked up local equivalent, which
only supported 8-bit major and minor numbers.
 1.4 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.5.2.1 07-Jul-1999  perry pullup 1.5->1.6 (kleink)
 1.6.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.13.2.1 07-Apr-2004  jmc Pullup rev 1.14-1.23 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.23.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.26.4.2 23-Mar-2008  matt sync with HEAD
 1.26.4.1 09-Jan-2008  matt sync with HEAD
 1.27.4.1 24-Mar-2008  keiichi sync with head.
 1.28.10.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.28.8.1 13-Apr-2009  snj Pull up following revision(s) (requested by christo in ticket #678):
bin/pax/extern.h: revision 1.56
bin/pax/file_subs.c: revision 1.62
bin/pax/options.c: revision 1.104
bin/pax/pat_rep.c: revision 1.29
bin/pax/pax.h: revision 1.30
Fixes from christos for pr-41167
XXX -X is still broken, but that wasn't part of this PR.
 1.30.6.1 30-Oct-2012  yamt sync with head
 1.31.34.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.31.34.1 21-Apr-2020  martin Sync with HEAD
 1.24 31-Aug-2011  plunky branches: 1.24.44;
NULL does not need a cast
 1.23 21-Dec-2009  christos Remove unnecessary casts.
 1.22 21-Dec-2009  wiz Free pt in another error case.
Found by Henning Petersen using cppcheck, in PR 42488.
 1.21 29-Apr-2007  msaitoh fix typos
 1.20 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.19 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.18 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.16 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.15 31-Jan-2002  tv branches: 1.15.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.14 04-Dec-2001  wiz Replace some misuses of "then" with "than".
 1.13 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.12 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.11 04-Nov-1998  christos char -> unsigned char cast.
 1.10 27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.9 01-Apr-1998  kleink Need <time.h> for time(), localtime() and mktime() prototypes.
 1.8 21-Jan-1998  mycroft Allow a century to be specified in time stamps.
 1.7 20-Jul-1997  christos branches: 1.7.2;
- Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.7.2.1 29-Jan-1998  mellon Pull up 1.8 (mycroft)
 1.15.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.15.2.1 07-Apr-2004  jmc Pullup rev 1.16-1.19 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.24.44.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.24.44.1 21-Apr-2020  martin Sync with HEAD
 1.6 13-Oct-2003  agc branches: 1.6.98;
Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.4 21-Jan-1998  mycroft branches: 1.4.12;
Allow a century to be specified in time stamps.
 1.3 21-Mar-1995  cgd branches: 1.3.4;
convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.3.4.1 29-Jan-1998  mellon Pull up 1.4 (mycroft)
 1.4.12.1 07-Apr-2004  jmc Pullup rev 1.5-1.6 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.6.98.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.6.98.1 21-Apr-2020  martin Sync with HEAD
 1.31 18-Oct-2013  christos branches: 1.31.26;
Fixed unused warnings.
 1.30 10-Jan-2008  tls branches: 1.30.26; 1.30.32;
Teach set_ftime about symbolic links, because it has to know: on some
Linux systems, when we build as a tool we think we have lutimes but it
doesn't work on some filesystems at runtime. A bit ugly but effective
and without use of AC_TRY_RUN in the tool build. Tidier (than mine)
set_ftime reorganization from christos.
 1.29 29-Apr-2007  msaitoh branches: 1.29.4;
fix typos
 1.28 24-Nov-2006  christos fix spelling of accidentally; from Zapher
 1.27 24-Apr-2006  snj It's "its."
 1.26 16-Apr-2006  christos PR/22995: Sergey Svishchev: If we are cd'ing around and we have directories
with relative paths, convert the directories to absolute paths, so that
restoring timestamps does not fail.
 1.25 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.24 16-Sep-2005  christos spelling fixes from Joerg Sonnenberger
 1.23 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.22 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.21 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.20 02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.19 06-Jan-2003  wiz writable, not writeable.
 1.18 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.17 31-Jan-2002  tv branches: 1.17.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.16 29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.15 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.14 24-Oct-2001  lukem fix typo
 1.13 21-Mar-2000  thorpej Use an in-core stack for directory permissions rather than a temporary
file. The temporary file code can be reenabled by building with
-DDIRS_USE_FILE.

Fixes a problem where sysinst would fail to unpack the base set because
the temporary file wouldn't fit in the ramdisk.
 1.12 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.11 17-Feb-2000  itohy Fix SIGINFO botch (PR #8868).
Continue partial write(2) on signals (xwrite()).
Partial read(2) at a few places are also continued (xread()).

Add {read,write}_with_restart() hooks for porting on systems
which don't restart interrupted read()/write() calls.

Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.10 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.9 03-Jul-1999  kleink branches: 1.9.2;
Honor the contents of $TMPDIR for the creation of temporary files, and use
_PATH_TMP instead of hardcoding /tmp if not set in the environment; fixes
PR bin/7796 from Chris Demetriou.
 1.8 12-Feb-1999  kleink branches: 1.8.2;
<sys/fcntl.h> -> <fcntl.h>
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 22-Mar-1997  lukem use mkstemp() instead of tempnam()
 1.5 11-Jan-1997  tls kill 'register'
 1.4 21-Mar-1995  cgd convert to new RCS id conventions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.8.2.1 07-Jul-1999  perry pullup 1.8->1.9 (kleink)
 1.9.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.17.2.1 07-Apr-2004  jmc Pullup rev 1.18-1.23 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.29.4.1 23-Mar-2008  matt sync with HEAD
 1.30.32.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.30.26.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31.26.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.31.26.1 21-Apr-2020  martin Sync with HEAD
 1.10 29-Apr-2007  msaitoh branches: 1.10.78;
fix typos
 1.9 16-Sep-2005  christos spelling fixes from Joerg Sonnenberger
 1.8 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.6 21-Mar-2000  thorpej branches: 1.6.6;
Use an in-core stack for directory permissions rather than a temporary
file. The temporary file code can be reenabled by building with
-DDIRS_USE_FILE.

Fixes a problem where sysinst would fail to unpack the base set because
the temporary file wouldn't fit in the ramdisk.
 1.5 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.4 01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.3 21-Mar-1995  cgd branches: 1.3.10;
convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.3.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.6.1 07-Apr-2004  jmc Pullup rev 1.7-1.8 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.10.78.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.10.78.1 21-Apr-2020  martin Sync with HEAD
 1.39 19-Mar-2019  wiz Whitespace nits.
 1.38 19-Mar-2019  gutteridge pax.1 & tar.1: add a minor clarification about "-s"

As a somewhat pedantic clarification, "-s" does not accept backslashes
as delimiters. (While here, also make the macro use of an expression
shared between pax.1 and tar.1 consistent.)
 1.37 03-Jul-2017  wiz branches: 1.37.6;
Remove workaround for ancient HTML generation code.
 1.36 19-Dec-2015  christos PR/50119: Thomas Klausner: Add --timestamp option to tar.
 1.35 11-Apr-2015  wiz Use An in AUTHORS section.
 1.34 11-Apr-2015  christos Add -J/--xz to specifically decompress xz compressed files. We don't really
need this because -z autodetects the compression format; this is for syntax
compatibility with other tar implementations. From Joachim Henke
 1.33 22-Mar-2012  wiz Fix whitespace nits. Suggested by Bug Hunting.
 1.32 19-Jun-2011  wiz branches: 1.32.2;
Use Fl Fl for long options.
 1.31 19-Jun-2011  christos document --xz
 1.30 05-Apr-2010  joerg branches: 1.30.4;
\\ -> \e
 1.29 23-Mar-2010  dholland bump date for previous
 1.28 23-Mar-2010  dholland The -X option of tar names a file containing exception globs, not
exception filenames, same as in gtar. PR 41168 from Perry.
 1.27 23-Nov-2008  dholland "compatibility", not "compatability".
 1.26 02-Dec-2007  wiz branches: 1.26.12;
Minimally sort options; use Dq; new sentence, new line.
 1.25 04-May-2007  christos branches: 1.25.4;
PR/36275: john at iastate dot edu: tar -s modifies symlink targets
- This is explained in a comment in pat_rep.c inside mod_name(). I did not
want to change the default behavior, so I added another modifier "s" which
when set, the pattern will not modify the symlink destination.
- While here I fixed another bug that was introduced before by the fix in
PR/35257 where the renaming was happening twice since we called rep_name
twice.
- Finally if we are renaming hard of soft-link targets print the renames for
those too.
 1.24 23-Apr-2007  christos bump date.
 1.23 23-Apr-2007  christos PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.22 24-May-2005  wiz branches: 1.22.4;
Bump date for -no-recursion.
 1.21 07-May-2005  christos PR/30167: J.T. Conklin: NetBSD tar does not support GNU tar --no-recursion flag
 1.20 20-Oct-2004  wiz English improvement (remove "be").
 1.19 17-Oct-2004  dsl Update date - before wiz complains
 1.18 17-Oct-2004  dsl Add an option --chroot to tar. Causes it to chroot(".") before doing
an extract. With -h this will cause existing absolute symlinks to be treated
as relative to the current directory.
Helps sysinst handle existing symlinks in the target system.
Remove 'L' from the usage (got spilt into 'h' and 'H' many moons ago)
Add 'S' to usage, and put into correct place in options list.
 1.17 27-Sep-2004  wiz Bump date for -S support.
 1.16 26-Sep-2004  christos PR/19490: Julio Merino: Teach tar about --sparse, -S option.
Do it for cpio too.
 1.15 15-Sep-2004  hubertf Change copyright to 2-clause BSD-copyright.
Changed with explicit permission of Thorsten Lockert (tholo sigmasoft com)
 1.14 04-May-2004  grant --unlink is the default, the argument is ignored and only accepted for
compatibility with other tar(1) implementations.
 1.13 09-Jul-2003  wiz branches: 1.13.2; 1.13.4;
Bump date for -O change.
 1.12 08-Jul-2003  simonb Add support for gnutar's -O "extract to stdout" option.
 1.11 10-Apr-2003  grant some mdoc fixes.
 1.10 08-Apr-2003  christos PR/21064: Perry Metzger: Re-add -k to tar (--keep-old-files)
 1.9 04-Apr-2003  wiz Remove sentence describing pax's -X option. From Jim Bernard in PR 21009.
 1.8 25-Feb-2003  wiz Add support for '-j' to create (and extract, but -z already did that)
bzip2 compressed tar files, for GNU tar compatibility.
Patch from Soren Jacobsen in PR 19467, okayed by christos.
Sync usage with options while here.
 1.7 19-Jan-2003  wiz tar(1) has no -L any longer.
 1.6 06-Nov-2002  wiz Drop a trailing space.
 1.5 06-Nov-2002  enami Let the roff to process the end of sentence.
 1.4 16-Oct-2002  christos add commas between options. Suggested by wiz.
 1.3 16-Oct-2002  christos Document the long options.
 1.2 12-Oct-2002  wiz Miscellaneous fixes.
 1.1 12-Oct-2002  christos man pages from OpenBSD.
TODO: add long option documentation.
 1.13.4.3 25-Aug-2004  he Pull up revision 1.14 (requested by cube in ticket #1734):
Document that ``--unlink'' is the default, and that it is
therefore ignored and only accepted for compatibility with
other tar(1) implememtations.
 1.13.4.2 07-Apr-2004  jmc Pullup rev 0-1.13 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.13.4.1 09-Jul-2003  jmc file tar.1 was added on branch netbsd-1-6 on 2004-04-07 06:58:52 +0000
 1.13.2.2 16-Sep-2004  jmc branches: 1.13.2.2.2;
Pullup rev 1.15 (requested by hubertf in ticket #850)

Change copyright to 2-clause BSD-copyright.
 1.13.2.1 09-May-2004  jdc Pull up revision 1.14 (requested by grant in ticket #263)

--unlink is the default, the argument is ignored and only accepted for
compatibility with other tar(1) implementations.
 1.13.2.2.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.22.4.1 28-Mar-2010  snj Pull up following revision(s) (requested by dholland in ticket #1391):
bin/pax/tar.1: revision 1.28, 1.29 via patch
The -X option of tar names a file containing exception globs, not
exception filenames, same as in gtar. PR 41168 from Perry.
--
bump date for previous
 1.25.4.1 09-Jan-2008  matt sync with HEAD
 1.26.12.2 28-Mar-2010  snj Pull up following revision(s) (requested by dholland in ticket #1354):
bin/pax/tar.1: revision 1.28, 1.29
The -X option of tar names a file containing exception globs, not
exception filenames, same as in gtar. PR 41168 from Perry.
--
bump date for previous
 1.26.12.1 23-Nov-2008  riz branches: 1.26.12.1.4;
Pull up following revision(s) (requested by dholland in ticket #113):
bin/pax/tar.1: revision 1.27
"compatibility", not "compatability".
 1.26.12.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.30.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.32.2.1 17-Apr-2012  yamt sync with head
 1.37.6.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.37.6.2 21-Apr-2020  martin Sync with HEAD
 1.37.6.1 10-Jun-2019  christos Sync with HEAD
 1.76 05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.75 20-Mar-2019  gutteridge branches: 1.75.12;
pax: fix typos in comments in file_subs.c & tar.c

Stamp out "greengrocers' apostrophes" in various places (arguably there
are still more present, but style guides vary on that, and my energies
spent corralling wayward punctuation marks could be spent elsewhere).
 1.74 30-Nov-2018  christos Add base-256 decoding support (Micha Gorny)
 1.73 19-Dec-2015  christos branches: 1.73.14; 1.73.16;
PR/50119: Thomas Klausner: Add --timestamp option to tar.
 1.72 16-Jun-2015  christos remove \n from error messages
 1.71 24-Jan-2013  christos Recognize extended attribute headers and warn about them since we are not
currently handling them.
 1.70 09-Aug-2012  christos branches: 1.70.2;
PR/46786: Simon Burge: After conversion to 64 bit time_t, tar/pax/cpio
erroneously think that negative time_t's never fit in 32 bits. Rework
conversion code to always use uintmax_t, and detect negative values.
XXX[1]: Perhaps we should do the same (use a signed conversion) for all
fields not just for time_t
XXX[2]: pullup for 6
 1.69 20-Mar-2012  matt Use C89 function definitions
 1.68 03-Nov-2011  christos Accept -X -
 1.67 14-Feb-2009  lukem branches: 1.67.6;
fix -Wsign-compare issues
 1.66 24-Feb-2008  joerg branches: 1.66.10;
Kill pre-4.4BSD compat code.
 1.65 23-Apr-2007  christos branches: 1.65.4; 1.65.8;
PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.64 18-Mar-2006  christos Coverity CID 343: Rework code so that we don't write after the end of the
array. The end effect is the same though.
 1.63 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.62 24-Apr-2005  christos PR/20071: Perry Metzger: --extract handling is broken. This patch fixes
Perry's example.
 1.61 20-Feb-2005  christos branches: 1.61.2;
The quagga-0.98.2 tar archive is busted. It was created with an old tar
program, and then someone appended to it a ustar record. Detect this and
warn, but don't treat it as an error.
 1.60 17-Oct-2004  dsl Improve error reporting for invalid tar archives.
 1.59 26-Sep-2004  christos In GNU-tar mode, don't split filenames to prefix+name because GNU tar does
not honor it.
 1.58 22-Sep-2004  christos Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.

The old code assumed that the buffer already contained the necessary
blocks to satisfy the read file request that contained the long
filename. This is not always the case, specially when we are dealing
with pipes which do shorter reads, thus having more probability
that a long file name will fall across a buffer boundary.

To reproduce, create a tar archive with a lot of gnu-long-names
(pkgsrc/devel/libsigc++2 is a good example), do a tar -tf to get
a list of filenames, compress it and do a tar -tzf to get another
list of the filenames. Notice that the two lists differ.
 1.57 14-Jul-2004  christos - Grr! unterminated buffer string in exclude destination buffer
- fix isfoo() ctype macros to take unsigned char.
 1.56 16-Jun-2004  christos PR/25934: Dieter Baron: hard links with long names still fail.
As mentioned in the previous commit, the switch statement in the longlink()
needed simplification and it was a bit incorrect. Only depend on the passed
type to determine what kind of gnu longlink to produce. Don't try to deduce
it from the archive file type.
 1.55 15-Jun-2004  christos PR/25934: Dieter Baron: tar and hardlinks with long filenames don't work.
- always put the @LongLink tag on the name, not the long-link name.
- pass in what type of long name record we want to create; one for long-name
or long-link name.
XXX: We should get rid of the switch too.
 1.54 15-Jun-2004  christos Restructure the code to make it more readable. No functional changes.
 1.53 11-May-2004  christos Welcome to WARNS=3
 1.52 25-Apr-2004  christos PR/25299: grant beattie: 1.5.3/i386 kernel set archives confuse -current pax
PR/25310: Juan RP: tar can't unpack MS-DOS gzip files correctly
 1.51 20-Apr-2004  christos PR/25207: Hubert Feyrer: tar cores on certain archive contents
- On ustar archives with a specified prefix directory, arcn->nlen was not
computed properly.
- While I am here cast some snprintf's() to void.
 1.50 16-Apr-2004  christos PR/25200: Alan Barrett: bug in pax append mode. This problem was introduced
while trying to fix the tar append mode. Restore the correct 2 null blocks
at the end of file, and disable the old bug compatible mode for gnutar.
 1.49 12-Apr-2004  mrg fix bugs in the previous. use snprintf(). fixes the problem reported
in PR#25131.
 1.48 01-Apr-2004  mrg redo GNU tar --exclude emulation to actually work the same. unfortunately,
because alternation (|) isn't available in "pax -s" RE's, we have to pass
four (yes 4!) different patterns:
.*\/<pattern>$
.*\/<pattern>\/.*
^<pattern>$
^<pattern>\/.*
instead of the more elegant
(^|.*\/)<pattern>($|\/.*)

fixes a problem reported by simonb.
 1.47 30-Jan-2004  christos branches: 1.47.2;
While the comment is not correct anymore, this fixes the problem of tar -rf
where tar would skip backwards too much, corrupting the current tar archive
on append.
 1.46 24-Nov-2003  matt Don't emit any warnings when tar is trying to figure out if the file is
really tar format. valid CPIO files should not trigger a warning from tar.c
 1.45 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.44 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.43 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.42 24-Jun-2003  grant backout previous; it was a missing prototype elsewhere.

noted by mrg.
 1.41 24-Jun-2003  grant add cast to fix an integer -> pointer warning.
 1.40 23-Jun-2003  grant consistently use "cannot" instead of "can not".
 1.39 20-Apr-2003  christos PR/6195: Matt Watson: Pax fails for paths of exactly 100 characters.
make sure that we don't strlcpy more than the source buffer.
 1.38 31-Mar-2003  christos PR/18959: Xavier HUMBERT: Don't pay attention to sockets in gnu-tar mode.
 1.37 31-Mar-2003  christos RP/8227: Peter Seeback: Emulate old gnu tar better.
 1.36 09-Jan-2003  christos remove debugging printf's I accidentally committed.
 1.35 09-Jan-2003  christos print a bit more info about checksum mismatches.
 1.34 08-Dec-2002  mrg oops, remove a debug statement from the previous.
 1.33 08-Dec-2002  mrg add --exclude support.

XXX: --exclude & --exclude-from are still not 100% compatible, but since
rafal fixed --exclude-from's most annoying bug, they mostly work now.
 1.32 27-Oct-2002  christos PR/18831: Andreas Wrede: Don't exit with an error when we are reading a gnu
tar archive.
 1.31 18-Oct-2002  christos Only warn the user once about gnu extensions. From Eric Gillespie.
 1.30 17-Oct-2002  christos Factor out some more code, and don't expand names in ././@LongLink records.
 1.29 17-Oct-2002  christos Add proper longlink support. Previously we handled longname support, and
the longlink support was completely wrong.
 1.28 16-Oct-2002  christos turn gnu tar off by pax and cpio front ends.
 1.27 16-Oct-2002  christos Warn if we are trying to read a gnu tar archive, if --strict is specified.
 1.26 16-Oct-2002  christos Support gnu long filename extensions by default for tar on create, list, and
extract. We now generate GNU tar archives by default ("ustar ^@" instead of
"ustar^@00"). GNU extensions can be disabled with --strict.

XXX: long symlinks untested.
 1.25 13-Oct-2002  christos Fix error in counting the archive's name length. From Eric Gillespie, thanks!
 1.24 13-Oct-2002  mrg make this build on LP64
 1.23 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.22 11-Oct-2002  christos str{n,l}cpy fixes and buffer limit fixes from OpenBSD
 1.21 31-Jan-2002  tv branches: 1.21.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.20 28-Oct-2001  lukem s/u_longlong_t/unsigned long long/ to shut up the parc port
 1.19 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.18 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.17 19-Jan-2000  mycroft Fix a glitch with handling files larger than 2GB.
 1.16 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.15 18-Aug-1999  kleink branches: 1.15.2;
Add the ability to handle estranged V7 tar archives that use USTAR-style
directories; addresses PR bin/8220.
 1.14 21-Jan-1999  mycroft branches: 1.14.2;
Make this build on the Alpha.
 1.13 20-Jan-1999  mrg implement the gnutar -X flag in terms of pax -s. fix some bugs in pax -s handling while i am here...
 1.12 15-Oct-1998  mycroft Reconstruct a split file name correctly.
 1.11 10-Aug-1998  tv Transparently handle old-style GNU tar archives that may have garbage in
the trailing block and do not have an end-of-archive marker. (Does this
handling based on whether the ustar id is "ustar" or "ustar ".)
 1.10 28-Jul-1998  mycroft Use the uid/gid caching moved into libc. Fixed a memory leak!
 1.9 20-Jul-1997  christos branches: 1.9.2;
- Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.8 25-Jun-1997  kleink Fix OBOB: when reassembling a file name from the header block's `prefix'
and `name' fields, don't overwrite the glueing '/' between them.
 1.7 16-May-1997  kleink Use '0' to front-pad octal strings, not ' '.
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.9.2.1 15-Oct-1998  cgd pull up rev 1.12 from trunk (mycroft)
 1.14.2.2 21-Jan-2000  he Pull up revision 1.17 (requested by mycroft):
Fix bugs handling files larger than 2GB.
 1.14.2.1 20-Aug-1999  cgd pull up rev 1.15 from trunk (kleink)
 1.15.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.2.3 25-Aug-2004  he Pull up revisions 1.49-1.52,1.54-1.57 (via patch, requested by cube in ticket #1737):
Fix bug in --exclude emulation, and use snprintf. (PR#25131)
Fix bug in pax append mode. (PR#25200)
Fix handling of certain archives, fixing core dump. (PR#25207)
Fix problems with 1.5.3/i386 kernel sets (PR#25299) and
MS-DOS gzip files (PR#25310).
Slight code restructuring.
Fix handling of tar with hardlinks to long file names
(PR#25934, PR#25934).
Fix unterminated buffer string in exaclude destination buffer.
Fix isfoo() ctype macros to take unsigned char.
 1.21.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.21.2.1 07-Apr-2004  jmc Pullup rev 1.22-1.48 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.47.2.8 12-Nov-2004  jmc branches: 1.47.2.8.2;
Pullup rev 1.58 (requested by christos in ticket #921)

Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.
 1.47.2.7 12-Nov-2004  jmc Pullup rev 1.59 (requested by christos in ticket #920)

In GNU-tar mode, dontt split filenames to prefix+name because GNU tar does
not honor it.
 1.47.2.6 15-Jul-2004  tron Pull up revision 1.57 (requested by hubertf in ticket #654):
- Grr! unterminated buffer string in exclude destination buffer
- fix isfoo() ctype macros to take unsigned char.
 1.47.2.5 18-Jun-2004  tron Pull up revision 1.54-1.56 via patch (requested by dillo in ticket #507):
Restructure the code to make it more readable. No functional changes.
PR/25934: Dieter Baron: tar and hardlinks with long filenames don't work.
- always put the @LongLink tag on the name, not the long-link name.
- pass in what type of long name record we want to create; one for long-name
or long-link name.
XXX: We should get rid of the switch too.
PR/25934: Dieter Baron: hard links with long names still fail.
As mentioned in the previous commit, the switch statement in the longlink()
needed simplification and it was a bit incorrect. Only depend on the passed
type to determine what kind of gnu longlink to produce. Don't try to deduce
it from the archive file type.
 1.47.2.4 28-Apr-2004  grant Pull up revision 1.52 (requested by snj in ticket #217):

PR/25299: grant beattie: 1.5.3/i386 kernel set archives confuse -current pax
PR/25310: Juan RP: tar can't unpack MS-DOS gzip files correctly
 1.47.2.3 21-Apr-2004  jmc Pullup rev 1.50-1.51 (requested by christos in ticket #170)

Fixes for multiple pax pr's. PR#25200. PR#25207.
 1.47.2.2 19-Apr-2004  jmc Pullup rev 1.49 (requested by mrg in ticket #145)

Fix bugs in the previous. use snprintf(). PR#25131
 1.47.2.1 19-Apr-2004  jmc Pullup rev 1.48 (requested by mrg in ticket #155)

Redo GNU tar --exclude emulation to actually work the same.
 1.47.2.8.2.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.61.2.1 09-Nov-2005  tron Pull up following revision(s) (requested by christos in ticket #946):
bin/pax/tar.c: revision 1.62
PR/20071: Perry Metzger: --extract handling is broken. This patch fixes
Perry's example.
 1.65.8.1 24-Mar-2008  keiichi sync with head.
 1.65.4.1 23-Mar-2008  matt sync with HEAD
 1.66.10.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.67.6.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.67.6.3 30-Oct-2012  yamt sync with head
 1.67.6.2 17-Apr-2012  yamt sync with head
 1.67.6.1 10-Nov-2011  yamt sync with head
 1.70.2.1 25-Feb-2013  tls resync with head
 1.73.16.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.73.16.2 21-Apr-2020  martin Sync with HEAD
 1.73.16.1 10-Jun-2019  christos Sync with HEAD
 1.73.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.75.12.1 02-Aug-2025  perseant Sync with HEAD
 1.10 24-Jan-2013  christos branches: 1.10.32;
Recognize extended attribute headers and warn about them since we are not
currently handling them.
 1.9 11-May-2004  christos branches: 1.9.48; 1.9.54;
Welcome to WARNS=3
 1.8 13-Oct-2003  agc branches: 1.8.4;
Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.6 12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.5 17-Feb-2000  itohy branches: 1.5.6;
Cleanup and fix typos.
Partially from FreeBSD.
 1.4 22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.3 21-Mar-1995  cgd branches: 1.3.10;
convert to new RCS id conventions.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.3.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.6.1 07-Apr-2004  jmc Pullup rev 1.6-1.8 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.8.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.9.54.1 25-Feb-2013  tls resync with head
 1.9.48.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10.32.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.10.32.1 21-Apr-2020  martin Sync with HEAD
 1.19 23-Apr-2007  christos branches: 1.19.78;
PR/36194: Greg A. Woods: add a '-V' flag to pax for verbose summary without
listing (and other minor fixes)
 1.18 11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.17 10-Oct-2004  christos PR/27209: Greg A. Woods: typo in comment in pax/tty_subs.c
 1.16 27-Oct-2003  lukem branches: 1.16.4;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.15 13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.13 04-Mar-2003  christos No other program prints errors inside angle brackets!
 1.12 09-Feb-2003  grant cosmetic error condition improvements.
- sprinkle some fflush() to print filenames correctly.
- print a \n to stdout to fix formatting.
- English, consistently use "Cannot" in error messages.

some whitespace cleanup.
 1.11 31-Jan-2002  tv branches: 1.11.2;
Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.10 25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.9 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.8 17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.7 20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.6 11-Jan-1997  tls kill 'register'
 1.5 21-Mar-1995  cgd convert to new RCS id conventions.
 1.4 11-Oct-1994  jtc use strerror() instead of sys_errlist[]
 1.3 14-Jun-1994  mycroft Fix up RCS ids.
 1.2 13-Jun-1994  jtc Add RCS ID's
 1.1 13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1 13-Jun-1994  jtc From 4.4 lite
 1.11.2.2 16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.11.2.1 07-Apr-2004  jmc Pullup rev 1.12-1.16 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.16.4.1 23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.19.78.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.19.78.1 21-Apr-2020  martin Sync with HEAD

RSS XML Feed