aboutsummaryrefslogtreecommitdiff
path: root/contrib/libarchive/cpio
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libarchive/cpio')
-rw-r--r--contrib/libarchive/cpio/bsdcpio.1440
-rw-r--r--contrib/libarchive/cpio/cmdline.c389
-rw-r--r--contrib/libarchive/cpio/cpio.c1512
-rw-r--r--contrib/libarchive/cpio/cpio.h120
-rw-r--r--contrib/libarchive/cpio/cpio_platform.h67
-rw-r--r--contrib/libarchive/cpio/test/test.h38
-rw-r--r--contrib/libarchive/cpio/test/test_0.c74
-rw-r--r--contrib/libarchive/cpio/test/test_basic.c239
-rw-r--r--contrib/libarchive/cpio/test/test_cmdline.c106
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.Z.uu7
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.bz2.uu7
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.grz.uu7
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.gz.uu7
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.lrz.uu8
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.lz.uu6
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.lz4.uu7
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.lzma.uu6
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.lzo.uu9
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.xz.uu7
-rw-r--r--contrib/libarchive/cpio/test/test_extract.cpio.zst.uu6
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_Z.c41
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_bz2.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_grz.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_gz.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_lrz.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_lz.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_lz4.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_lzma.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_lzo.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_xz.c47
-rw-r--r--contrib/libarchive/cpio/test/test_extract_cpio_zstd.c47
-rw-r--r--contrib/libarchive/cpio/test/test_format_newc.c357
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat.c107
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref.bin.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref.crc.uu26
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref.newc.uu26
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref.ustar.uu83
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.newc.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.ustar.uu72
-rw-r--r--contrib/libarchive/cpio/test/test_missing_file.c51
-rw-r--r--contrib/libarchive/cpio/test/test_option_0.c91
-rw-r--r--contrib/libarchive/cpio/test/test_option_B_upper.c50
-rw-r--r--contrib/libarchive/cpio/test/test_option_C_upper.c60
-rw-r--r--contrib/libarchive/cpio/test/test_option_J_upper.c59
-rw-r--r--contrib/libarchive/cpio/test/test_option_L_upper.c104
-rw-r--r--contrib/libarchive/cpio/test/test_option_Z_upper.c59
-rw-r--r--contrib/libarchive/cpio/test/test_option_a.c159
-rw-r--r--contrib/libarchive/cpio/test/test_option_b64encode.c55
-rw-r--r--contrib/libarchive/cpio/test/test_option_c.c228
-rw-r--r--contrib/libarchive/cpio/test/test_option_d.c62
-rw-r--r--contrib/libarchive/cpio/test/test_option_f.c75
-rw-r--r--contrib/libarchive/cpio/test/test_option_f.cpio.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_option_grzip.c52
-rw-r--r--contrib/libarchive/cpio/test/test_option_help.c83
-rw-r--r--contrib/libarchive/cpio/test/test_option_l.c49
-rw-r--r--contrib/libarchive/cpio/test/test_option_lrzip.c52
-rw-r--r--contrib/libarchive/cpio/test/test_option_lz4.c87
-rw-r--r--contrib/libarchive/cpio/test/test_option_lzma.c59
-rw-r--r--contrib/libarchive/cpio/test/test_option_lzop.c56
-rw-r--r--contrib/libarchive/cpio/test/test_option_m.c61
-rw-r--r--contrib/libarchive/cpio/test/test_option_m.cpio.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_option_passphrase.c42
-rw-r--r--contrib/libarchive/cpio/test/test_option_passphrase.zip.uu12
-rw-r--r--contrib/libarchive/cpio/test/test_option_t.c114
-rw-r--r--contrib/libarchive/cpio/test/test_option_t.cpio.uu15
-rw-r--r--contrib/libarchive/cpio/test/test_option_t.stdout.uu4
-rw-r--r--contrib/libarchive/cpio/test/test_option_tv.stdout.uu5
-rw-r--r--contrib/libarchive/cpio/test/test_option_u.c83
-rw-r--r--contrib/libarchive/cpio/test/test_option_uuencode.c55
-rw-r--r--contrib/libarchive/cpio/test/test_option_version.c30
-rw-r--r--contrib/libarchive/cpio/test/test_option_xz.c60
-rw-r--r--contrib/libarchive/cpio/test/test_option_y.c56
-rw-r--r--contrib/libarchive/cpio/test/test_option_z.c55
-rw-r--r--contrib/libarchive/cpio/test/test_option_zstd.c84
-rw-r--r--contrib/libarchive/cpio/test/test_owner_parse.c120
-rw-r--r--contrib/libarchive/cpio/test/test_passthrough_dotdot.c75
-rw-r--r--contrib/libarchive/cpio/test/test_passthrough_reverse.c84
79 files changed, 6780 insertions, 0 deletions
diff --git a/contrib/libarchive/cpio/bsdcpio.1 b/contrib/libarchive/cpio/bsdcpio.1
new file mode 100644
index 000000000000..c52764a8c4f7
--- /dev/null
+++ b/contrib/libarchive/cpio/bsdcpio.1
@@ -0,0 +1,440 @@
+.\" Copyright (c) 2003-2007 Tim Kientzle
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd September 16, 2014
+.Dt CPIO 1
+.Os
+.Sh NAME
+.Nm cpio
+.Nd copy files to and from archives
+.Sh SYNOPSIS
+.Nm
+.Fl i
+.Op Ar options
+.Op Ar pattern ...
+.Op Ar < archive
+.Nm
+.Fl o
+.Op Ar options
+.Ar < name-list
+.Op Ar > archive
+.Nm
+.Fl p
+.Op Ar options
+.Ar dest-dir
+.Ar < name-list
+.Sh DESCRIPTION
+.Nm
+copies files between archives and directories.
+This implementation can extract from tar, pax, cpio, zip, jar, ar,
+and ISO 9660 cdrom images and can create tar, pax, cpio, ar,
+and shar archives.
+.Pp
+The first option to
+.Nm
+is a mode indicator from the following list:
+.Bl -tag -compact -width indent
+.It Fl i
+Input.
+Read an archive from standard input (unless overridden) and extract the
+contents to disk or (if the
+.Fl t
+option is specified)
+list the contents to standard output.
+If one or more file patterns are specified, only files matching
+one of the patterns will be extracted.
+.It Fl o
+Output.
+Read a list of filenames from standard input and produce a new archive
+on standard output (unless overridden) containing the specified items.
+.It Fl p
+Pass-through.
+Read a list of filenames from standard input and copy the files to the
+specified directory.
+.El
+.Sh OPTIONS
+Unless specifically stated otherwise, options are applicable in
+all operating modes.
+.Bl -tag -width indent
+.It Fl 0 , Fl Fl null
+Read filenames separated by NUL characters instead of newlines.
+This is necessary if any of the filenames being read might contain newlines.
+.It Fl 6 , Fl Fl pwb
+When reading a binary format archive, assume it's the earlier one,
+from the PWB variant of 6th Edition UNIX.
+When writing a cpio archive, use the PWB format.
+.It Fl 7 , Fl Fl binary
+(o mode only)
+When writing a cpio archive, use the (newer, non-PWB) binary format.
+.It Fl A
+(o mode only)
+Append to the specified archive.
+(Not yet implemented.)
+.It Fl a
+(o and p modes)
+Reset access times on files after they are read.
+.It Fl B
+(o mode only)
+Block output to records of 5120 bytes.
+.It Fl C Ar size
+(o mode only)
+Block output to records of
+.Ar size
+bytes.
+.It Fl c
+(o mode only)
+Use the old POSIX portable character format.
+Equivalent to
+.Fl Fl format Ar odc .
+.It Fl d , Fl Fl make-directories
+(i and p modes)
+Create directories as necessary.
+.It Fl E Ar file
+(i mode only)
+Read list of file name patterns from
+.Ar file
+to list and extract.
+.It Fl F Ar file , Fl Fl file Ar file
+Read archive from or write archive to
+.Ar file .
+.It Fl f Ar pattern
+(i mode only)
+Ignore files that match
+.Ar pattern .
+.It Fl H Ar format , Fl Fl format Ar format
+(o mode only)
+Produce the output archive in the specified format.
+Supported formats include:
+.Pp
+.Bl -tag -width "iso9660" -compact
+.It Ar cpio
+Synonym for
+.Ar odc .
+.It Ar newc
+The SVR4 portable cpio format.
+.It Ar odc
+The old POSIX.1 portable octet-oriented cpio format.
+.It Ar pax
+The POSIX.1 pax format, an extension of the ustar format.
+.It Ar ustar
+The POSIX.1 tar format.
+.El
+.Pp
+The default format is
+.Ar odc .
+See
+.Xr libarchive-formats 5
+for more complete information about the
+formats currently supported by the underlying
+.Xr libarchive 3
+library.
+.It Fl h , Fl Fl help
+Print usage information.
+.It Fl I Ar file
+Read archive from
+.Ar file .
+.It Fl i , Fl Fl extract
+Input mode.
+See above for description.
+.It Fl Fl insecure
+(i and p mode only)
+Disable security checks during extraction or copying.
+This allows extraction via symbolic links, absolute paths,
+and path names containing
+.Sq ..
+in the name.
+.It Fl J , Fl Fl xz
+(o mode only)
+Compress the file with xz-compatible compression before writing it.
+In input mode, this option is ignored; xz compression is recognized
+automatically on input.
+.It Fl j
+Synonym for
+.Fl y .
+.It Fl L
+(o and p modes)
+All symbolic links will be followed.
+Normally, symbolic links are archived and copied as symbolic links.
+With this option, the target of the link will be archived or copied instead.
+.It Fl l , Fl Fl link
+(p mode only)
+Create links from the target directory to the original files,
+instead of copying.
+.It Fl Fl lrzip
+(o mode only)
+Compress the resulting archive with
+.Xr lrzip 1 .
+In input mode, this option is ignored.
+.It Fl Fl lz4
+(o mode only)
+Compress the archive with lz4-compatible compression before writing it.
+In input mode, this option is ignored; lz4 compression is recognized
+automatically on input.
+.It Fl Fl zstd
+(o mode only)
+Compress the archive with zstd-compatible compression before writing it.
+In input mode, this option is ignored; zstd compression is recognized
+automatically on input.
+.It Fl Fl lzma
+(o mode only)
+Compress the file with lzma-compatible compression before writing it.
+In input mode, this option is ignored; lzma compression is recognized
+automatically on input.
+.It Fl Fl lzop
+(o mode only)
+Compress the resulting archive with
+.Xr lzop 1 .
+In input mode, this option is ignored.
+.It Fl Fl passphrase Ar passphrase
+The
+.Pa passphrase
+is used to extract or create an encrypted archive.
+Currently, zip is only a format that
+.Nm
+can handle encrypted archives.
+You shouldn't use this option unless you realize how insecure
+use of this option is.
+.It Fl m , Fl Fl preserve-modification-time
+(i and p modes)
+Set file modification time on created files to match
+those in the source.
+.It Fl n , Fl Fl numeric-uid-gid
+(i mode, only with
+.Fl t )
+Display numeric uid and gid.
+By default,
+.Nm
+displays the user and group names when they are provided in the
+archive, or looks up the user and group names in the system
+password database.
+.It Fl Fl no-preserve-owner
+(i mode only)
+Do not attempt to restore file ownership.
+This is the default when run by non-root users.
+.It Fl O Ar file
+Write archive to
+.Ar file .
+.It Fl o , Fl Fl create
+Output mode.
+See above for description.
+.It Fl p , Fl Fl pass-through
+Pass-through mode.
+See above for description.
+.It Fl Fl preserve-owner
+(i mode only)
+Restore file ownership.
+This is the default when run by the root user.
+.It Fl Fl quiet
+Suppress unnecessary messages.
+.It Fl R Oo user Oc Ns Oo : Oc Ns Oo group Oc , Fl Fl owner Oo user Oc Ns Oo : Oc Ns Oo group Oc
+Set the owner and/or group on files in the output.
+If group is specified with no user
+(for example,
+.Fl R Ar :wheel )
+then the group will be set but not the user.
+If the user is specified with a trailing colon and no group
+(for example,
+.Fl R Ar root: )
+then the group will be set to the user's default group.
+If the user is specified with no trailing colon, then
+the user will be set but not the group.
+In
+.Fl i
+and
+.Fl p
+modes, this option can only be used by the super-user.
+(For compatibility, a period can be used in place of the colon.)
+.It Fl r
+(All modes.)
+Rename files interactively.
+For each file, a prompt is written to
+.Pa /dev/tty
+containing the name of the file and a line is read from
+.Pa /dev/tty .
+If the line read is blank, the file is skipped.
+If the line contains a single period, the file is processed normally.
+Otherwise, the line is taken to be the new name of the file.
+.It Fl t , Fl Fl list
+(i mode only)
+List the contents of the archive to stdout;
+do not restore the contents to disk.
+.It Fl u , Fl Fl unconditional
+(i and p modes)
+Unconditionally overwrite existing files.
+Ordinarily, an older file will not overwrite a newer file on disk.
+.It Fl V , Fl Fl dot
+Print a dot to stderr for each file as it is processed.
+Superseded by
+.Fl v .
+.It Fl v , Fl Fl verbose
+Print the name of each file to stderr as it is processed.
+With
+.Fl t ,
+provide a detailed listing of each file.
+.It Fl Fl version
+Print the program version information and exit.
+.It Fl y
+(o mode only)
+Compress the archive with bzip2-compatible compression before writing it.
+In input mode, this option is ignored;
+bzip2 compression is recognized automatically on input.
+.It Fl Z
+(o mode only)
+Compress the archive with compress-compatible compression before writing it.
+In input mode, this option is ignored;
+compression is recognized automatically on input.
+.It Fl z
+(o mode only)
+Compress the archive with gzip-compatible compression before writing it.
+In input mode, this option is ignored;
+gzip compression is recognized automatically on input.
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh ENVIRONMENT
+The following environment variables affect the execution of
+.Nm :
+.Bl -tag -width ".Ev BLOCKSIZE"
+.It Ev LANG
+The locale to use.
+See
+.Xr environ 7
+for more information.
+.It Ev TZ
+The timezone to use when displaying dates.
+See
+.Xr environ 7
+for more information.
+.El
+.Sh EXAMPLES
+The
+.Nm
+command is traditionally used to copy file hierarchies in conjunction
+with the
+.Xr find 1
+command.
+The first example here simply copies all files from
+.Pa src
+to
+.Pa dest :
+.Dl Nm find Pa src | Nm Fl pmud Pa dest
+.Pp
+By carefully selecting options to the
+.Xr find 1
+command and combining it with other standard utilities,
+it is possible to exercise very fine control over which files are copied.
+This next example copies files from
+.Pa src
+to
+.Pa dest
+that are more than 2 days old and whose names match a particular pattern:
+.Dl Nm find Pa src Fl mtime Ar +2 | Nm grep foo[bar] | Nm Fl pdmu Pa dest
+.Pp
+This example copies files from
+.Pa src
+to
+.Pa dest
+that are more than 2 days old and which contain the word
+.Do foobar Dc :
+.Dl Nm find Pa src Fl mtime Ar +2 | Nm xargs Nm grep -l foobar | Nm Fl pdmu Pa dest
+.Sh COMPATIBILITY
+The mode options i, o, and p and the options
+a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2.
+.Pp
+The old POSIX.1 standard specified that only
+.Fl i ,
+.Fl o ,
+and
+.Fl p
+were interpreted as command-line options.
+Each took a single argument of a list of modifier
+characters.
+For example, the standard syntax allows
+.Fl imu
+but does not support
+.Fl miu
+or
+.Fl i Fl m Fl u ,
+since
+.Ar m
+and
+.Ar u
+are only modifiers to
+.Fl i ,
+they are not command-line options in their own right.
+The syntax supported by this implementation is backwards-compatible
+with the standard.
+For best compatibility, scripts should limit themselves to the
+standard syntax.
+.Sh SEE ALSO
+.Xr bzip2 1 ,
+.Xr gzip 1 ,
+.Xr mt 1 ,
+.Xr pax 1 ,
+.Xr tar 1 ,
+.Xr libarchive 3 ,
+.Xr cpio 5 ,
+.Xr libarchive-formats 5 ,
+.Xr tar 5
+.Sh STANDARDS
+There is no current POSIX standard for the cpio command; it appeared
+in
+.St -p1003.1-96
+but was dropped from
+.St -p1003.1-2001 .
+.Pp
+The cpio, ustar, and pax interchange file formats are defined by
+.St -p1003.1-2001
+for the pax command.
+.Sh HISTORY
+The original
+.Nm cpio
+and
+.Nm find
+utilities were written by Dick Haight
+while working in AT&T's Unix Support Group.
+They first appeared in 1977 in PWB/UNIX 1.0, the
+.Dq Programmer's Work Bench
+system developed for use within AT&T.
+They were first released outside of AT&T as part of System III Unix in 1981.
+As a result,
+.Nm cpio
+actually predates
+.Nm tar ,
+even though it was not well-known outside of AT&T until some time later.
+.Pp
+This is a complete re-implementation based on the
+.Xr libarchive 3
+library.
+.Sh BUGS
+The cpio archive format has several basic limitations:
+It does not store user and group names, only numbers.
+As a result, it cannot be reliably used to transfer
+files between systems with dissimilar user and group numbering.
+Older cpio formats limit the user and group numbers to
+16 or 18 bits, which is insufficient for modern systems.
+The cpio archive formats cannot support files over 4 gigabytes,
+except for the
+.Dq odc
+variant, which can support files up to 8 gigabytes.
diff --git a/contrib/libarchive/cpio/cmdline.c b/contrib/libarchive/cpio/cmdline.c
new file mode 100644
index 000000000000..ab25492ede48
--- /dev/null
+++ b/contrib/libarchive/cpio/cmdline.c
@@ -0,0 +1,389 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "cpio_platform.h"
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "cpio.h"
+#include "err.h"
+
+/*
+ * Short options for cpio. Please keep this sorted.
+ */
+static const char *short_options = "067AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuVvW:yZz";
+
+/*
+ * Long options for cpio. Please keep this sorted.
+ */
+static const struct option {
+ const char *name;
+ int required; /* 1 if this option requires an argument */
+ int equivalent; /* Equivalent short option. */
+} cpio_longopts[] = {
+ { "b64encode", 0, OPTION_B64ENCODE },
+ { "binary", 0, '7' },
+ { "create", 0, 'o' },
+ { "dereference", 0, 'L' },
+ { "dot", 0, 'V' },
+ { "extract", 0, 'i' },
+ { "file", 1, 'F' },
+ { "format", 1, 'H' },
+ { "grzip", 0, OPTION_GRZIP },
+ { "help", 0, 'h' },
+ { "insecure", 0, OPTION_INSECURE },
+ { "link", 0, 'l' },
+ { "list", 0, 't' },
+ { "lrzip", 0, OPTION_LRZIP },
+ { "lz4", 0, OPTION_LZ4 },
+ { "lzma", 0, OPTION_LZMA },
+ { "lzop", 0, OPTION_LZOP },
+ { "make-directories", 0, 'd' },
+ { "no-preserve-owner", 0, OPTION_NO_PRESERVE_OWNER },
+ { "null", 0, '0' },
+ { "numeric-uid-gid", 0, 'n' },
+ { "owner", 1, 'R' },
+ { "passphrase", 1, OPTION_PASSPHRASE },
+ { "pass-through", 0, 'p' },
+ { "preserve-modification-time", 0, 'm' },
+ { "preserve-owner", 0, OPTION_PRESERVE_OWNER },
+ { "pwb", 0, '6' },
+ { "quiet", 0, OPTION_QUIET },
+ { "unconditional", 0, 'u' },
+ { "uuencode", 0, OPTION_UUENCODE },
+ { "verbose", 0, 'v' },
+ { "version", 0, OPTION_VERSION },
+ { "xz", 0, 'J' },
+ { "zstd", 0, OPTION_ZSTD },
+ { NULL, 0, 0 }
+};
+
+/*
+ * I used to try to select platform-provided getopt() or
+ * getopt_long(), but that caused a lot of headaches. In particular,
+ * I couldn't consistently use long options in the test harness
+ * because not all platforms have getopt_long(). That in turn led to
+ * overuse of the -W hack in the test harness, which made it rough to
+ * run the test harness against GNU cpio. (I periodically run the
+ * test harness here against GNU cpio as a sanity-check. Yes,
+ * I've found a couple of bugs in GNU cpio that way.)
+ */
+int
+cpio_getopt(struct cpio *cpio)
+{
+ enum { state_start = 0, state_next_word, state_short, state_long };
+ static int state = state_start;
+ static char *opt_word;
+
+ const struct option *popt, *match, *match2;
+ const char *p, *long_prefix;
+ size_t optlength;
+ int opt;
+ int required;
+
+again:
+ match = NULL;
+ match2 = NULL;
+ long_prefix = "--";
+ opt = '?';
+ required = 0;
+ cpio->argument = NULL;
+
+ /* First time through, initialize everything. */
+ if (state == state_start) {
+ /* Skip program name. */
+ ++cpio->argv;
+ --cpio->argc;
+ state = state_next_word;
+ }
+
+ /*
+ * We're ready to look at the next word in argv.
+ */
+ if (state == state_next_word) {
+ /* No more arguments, so no more options. */
+ if (cpio->argv[0] == NULL)
+ return (-1);
+ /* Doesn't start with '-', so no more options. */
+ if (cpio->argv[0][0] != '-')
+ return (-1);
+ /* "--" marks end of options; consume it and return. */
+ if (strcmp(cpio->argv[0], "--") == 0) {
+ ++cpio->argv;
+ --cpio->argc;
+ return (-1);
+ }
+ /* Get next word for parsing. */
+ opt_word = *cpio->argv++;
+ --cpio->argc;
+ if (opt_word[1] == '-') {
+ /* Set up long option parser. */
+ state = state_long;
+ opt_word += 2; /* Skip leading '--' */
+ } else {
+ /* Set up short option parser. */
+ state = state_short;
+ ++opt_word; /* Skip leading '-' */
+ }
+ }
+
+ /*
+ * We're parsing a group of POSIX-style single-character options.
+ */
+ if (state == state_short) {
+ /* Peel next option off of a group of short options. */
+ opt = *opt_word++;
+ if (opt == '\0') {
+ /* End of this group; recurse to get next option. */
+ state = state_next_word;
+ goto again;
+ }
+
+ /* Does this option take an argument? */
+ p = strchr(short_options, opt);
+ if (p == NULL)
+ return ('?');
+ if (p[1] == ':')
+ required = 1;
+
+ /* If it takes an argument, parse that. */
+ if (required) {
+ /* If arg is run-in, opt_word already points to it. */
+ if (opt_word[0] == '\0') {
+ /* Otherwise, pick up the next word. */
+ opt_word = *cpio->argv;
+ if (opt_word == NULL) {
+ lafe_warnc(0,
+ "Option -%c requires an argument",
+ opt);
+ return ('?');
+ }
+ ++cpio->argv;
+ --cpio->argc;
+ }
+ if (opt == 'W') {
+ state = state_long;
+ long_prefix = "-W "; /* For clearer errors. */
+ } else {
+ state = state_next_word;
+ cpio->argument = opt_word;
+ }
+ }
+ }
+
+ /* We're reading a long option, including -W long=arg convention. */
+ if (state == state_long) {
+ /* After this long option, we'll be starting a new word. */
+ state = state_next_word;
+
+ /* Option name ends at '=' if there is one. */
+ p = strchr(opt_word, '=');
+ if (p != NULL) {
+ optlength = (size_t)(p - opt_word);
+ cpio->argument = (char *)(uintptr_t)(p + 1);
+ } else {
+ optlength = strlen(opt_word);
+ }
+
+ /* Search the table for an unambiguous match. */
+ for (popt = cpio_longopts; popt->name != NULL; popt++) {
+ /* Short-circuit if first chars don't match. */
+ if (popt->name[0] != opt_word[0])
+ continue;
+ /* If option is a prefix of name in table, record it.*/
+ if (strncmp(opt_word, popt->name, optlength) == 0) {
+ match2 = match; /* Record up to two matches. */
+ match = popt;
+ /* If it's an exact match, we're done. */
+ if (strlen(popt->name) == optlength) {
+ match2 = NULL; /* Forget the others. */
+ break;
+ }
+ }
+ }
+
+ /* Fail if there wasn't a unique match. */
+ if (match == NULL) {
+ lafe_warnc(0,
+ "Option %s%s is not supported",
+ long_prefix, opt_word);
+ return ('?');
+ }
+ if (match2 != NULL) {
+ lafe_warnc(0,
+ "Ambiguous option %s%s (matches --%s and --%s)",
+ long_prefix, opt_word, match->name, match2->name);
+ return ('?');
+ }
+
+ /* We've found a unique match; does it need an argument? */
+ if (match->required) {
+ /* Argument required: get next word if necessary. */
+ if (cpio->argument == NULL) {
+ cpio->argument = *cpio->argv;
+ if (cpio->argument == NULL) {
+ lafe_warnc(0,
+ "Option %s%s requires an argument",
+ long_prefix, match->name);
+ return ('?');
+ }
+ ++cpio->argv;
+ --cpio->argc;
+ }
+ } else {
+ /* Argument forbidden: fail if there is one. */
+ if (cpio->argument != NULL) {
+ lafe_warnc(0,
+ "Option %s%s does not allow an argument",
+ long_prefix, match->name);
+ return ('?');
+ }
+ }
+ return (match->equivalent);
+ }
+
+ return (opt);
+}
+
+
+/*
+ * Parse the argument to the -R or --owner flag.
+ *
+ * The format is one of the following:
+ * <username|uid> - Override user but not group
+ * <username>: - Override both, group is user's default group
+ * <uid>: - Override user but not group
+ * <username|uid>:<groupname|gid> - Override both
+ * :<groupname|gid> - Override group but not user
+ *
+ * Where uid/gid are decimal representations and groupname/username
+ * are names to be looked up in system database. Note that we try
+ * to look up an argument as a name first, then try numeric parsing.
+ *
+ * A period can be used instead of the colon.
+ *
+ * Sets uid/gid return as appropriate, -1 indicates uid/gid not specified.
+ * TODO: If the spec uses uname/gname, then return those to the caller
+ * as well. If the spec provides uid/gid, just return names as NULL.
+ *
+ * Returns NULL if no error, otherwise returns error string for display.
+ *
+ */
+const char *
+owner_parse(const char *spec, int *uid, int *gid)
+{
+ static char errbuff[128];
+ const char *u, *ue, *g;
+
+ *uid = -1;
+ *gid = -1;
+
+ if (spec[0] == '\0')
+ return ("Invalid empty user/group spec");
+
+ /*
+ * Split spec into [user][:.][group]
+ * u -> first char of username, NULL if no username
+ * ue -> first char after username (colon, period, or \0)
+ * g -> first char of group name
+ */
+ if (*spec == ':' || *spec == '.') {
+ /* If spec starts with ':' or '.', then just group. */
+ ue = u = NULL;
+ g = spec + 1;
+ } else {
+ /* Otherwise, [user] or [user][:] or [user][:][group] */
+ ue = u = spec;
+ while (*ue != ':' && *ue != '.' && *ue != '\0')
+ ++ue;
+ g = ue;
+ if (*g != '\0') /* Skip : or . to find first char of group. */
+ ++g;
+ }
+
+ if (u != NULL) {
+ /* Look up user: ue is first char after end of user. */
+ char *user;
+ struct passwd *pwent;
+
+ user = (char *)malloc(ue - u + 1);
+ if (user == NULL)
+ return ("Couldn't allocate memory");
+ memcpy(user, u, ue - u);
+ user[ue - u] = '\0';
+ if ((pwent = getpwnam(user)) != NULL) {
+ *uid = pwent->pw_uid;
+ if (*ue != '\0')
+ *gid = pwent->pw_gid;
+ } else {
+ char *end;
+ errno = 0;
+ *uid = (int)strtoul(user, &end, 10);
+ if (errno || *end != '\0') {
+ snprintf(errbuff, sizeof(errbuff),
+ "Couldn't lookup user ``%s''", user);
+ errbuff[sizeof(errbuff) - 1] = '\0';
+ free(user);
+ return (errbuff);
+ }
+ }
+ free(user);
+ }
+
+ if (*g != '\0') {
+ struct group *grp;
+ if ((grp = getgrnam(g)) != NULL) {
+ *gid = grp->gr_gid;
+ } else {
+ char *end;
+ errno = 0;
+ *gid = (int)strtoul(g, &end, 10);
+ if (errno || *end != '\0') {
+ snprintf(errbuff, sizeof(errbuff),
+ "Couldn't lookup group ``%s''", g);
+ errbuff[sizeof(errbuff) - 1] = '\0';
+ return (errbuff);
+ }
+ }
+ }
+ return (NULL);
+}
diff --git a/contrib/libarchive/cpio/cpio.c b/contrib/libarchive/cpio/cpio.c
new file mode 100644
index 000000000000..c9af535f6d0a
--- /dev/null
+++ b/contrib/libarchive/cpio/cpio.c
@@ -0,0 +1,1512 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "cpio_platform.h"
+
+#include <sys/types.h>
+#include <archive.h>
+#include <archive_entry.h>
+
+#ifdef HAVE_SYS_MKDEV_H
+#include <sys/mkdev.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+#include "cpio.h"
+#include "err.h"
+#include "line_reader.h"
+#include "passphrase.h"
+
+/* Fixed size of uname/gname caches. */
+#define name_cache_size 101
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+struct name_cache {
+ int probes;
+ int hits;
+ size_t size;
+ struct {
+ id_t id;
+ char *name;
+ } cache[name_cache_size];
+};
+
+static int extract_data(struct archive *, struct archive *);
+const char * cpio_i64toa(int64_t);
+static const char *cpio_rename(const char *name);
+static int entry_to_archive(struct cpio *, struct archive_entry *);
+static int file_to_archive(struct cpio *, const char *);
+static void free_cache(struct name_cache *cache);
+static void list_item_verbose(struct cpio *, struct archive_entry *);
+static __LA_NORETURN void long_help(void);
+static const char *lookup_gname(struct cpio *, gid_t gid);
+static int lookup_gname_helper(struct cpio *,
+ const char **name, id_t gid);
+static const char *lookup_uname(struct cpio *, uid_t uid);
+static int lookup_uname_helper(struct cpio *,
+ const char **name, id_t uid);
+static __LA_NORETURN void mode_in(struct cpio *);
+static __LA_NORETURN void mode_list(struct cpio *);
+static void mode_out(struct cpio *);
+static void mode_pass(struct cpio *, const char *);
+static const char *remove_leading_slash(const char *);
+static int restore_time(struct cpio *, struct archive_entry *,
+ const char *, int fd);
+static __LA_NORETURN void usage(void);
+static __LA_NORETURN void version(void);
+static const char * passphrase_callback(struct archive *, void *);
+static void passphrase_free(char *);
+
+int
+main(int argc, char *argv[])
+{
+ static char buff[16384];
+ struct cpio _cpio; /* Allocated on stack. */
+ struct cpio *cpio;
+ const char *errmsg;
+ char *tptr;
+ int uid, gid;
+ int opt, t;
+
+ cpio = &_cpio;
+ memset(cpio, 0, sizeof(*cpio));
+ cpio->buff = buff;
+ cpio->buff_size = sizeof(buff);
+
+#if defined(HAVE_SIGACTION) && defined(SIGPIPE)
+ { /* Ignore SIGPIPE signals. */
+ struct sigaction sa;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &sa, NULL);
+ }
+#endif
+
+ /* Set lafe_progname before calling lafe_warnc. */
+ lafe_setprogname(*argv, "bsdcpio");
+
+#if HAVE_SETLOCALE
+ if (setlocale(LC_ALL, "") == NULL)
+ lafe_warnc(0, "Failed to set default locale");
+#endif
+
+ cpio->uid_override = -1;
+ cpio->gid_override = -1;
+ cpio->argv = argv;
+ cpio->argc = argc;
+ cpio->mode = '\0';
+ cpio->verbose = 0;
+ cpio->compress = '\0';
+ cpio->extract_flags = ARCHIVE_EXTRACT_NO_AUTODIR;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_PERM;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
+ cpio->extract_flags |= ARCHIVE_EXTRACT_ACL;
+#if !defined(_WIN32) && !defined(__CYGWIN__)
+ if (geteuid() == 0)
+ cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER;
+#endif
+ cpio->bytes_per_block = 512;
+ cpio->filename = NULL;
+
+ cpio->matching = archive_match_new();
+ if (cpio->matching == NULL)
+ lafe_errc(1, 0, "Out of memory");
+
+ while ((opt = cpio_getopt(cpio)) != -1) {
+ switch (opt) {
+ case '0': /* GNU convention: --null, -0 */
+ cpio->option_null = 1;
+ break;
+ case '6': /* in/out: assume/create 6th edition (PWB) format */
+ cpio->option_pwb = 1;
+ break;
+ case '7': /* out: create archive using 7th Edition binary format */
+ cpio->format = "bin";
+ break;
+ case 'A': /* NetBSD/OpenBSD */
+ cpio->option_append = 1;
+ break;
+ case 'a': /* POSIX 1997 */
+ cpio->option_atime_restore = 1;
+ break;
+ case 'B': /* POSIX 1997 */
+ cpio->bytes_per_block = 5120;
+ break;
+ case OPTION_B64ENCODE:
+ cpio->add_filter = opt;
+ break;
+ case 'C': /* NetBSD/OpenBSD */
+ errno = 0;
+ tptr = NULL;
+ t = (int)strtol(cpio->argument, &tptr, 10);
+ if (errno || t <= 0 || *(cpio->argument) == '\0' ||
+ tptr == NULL || *tptr != '\0') {
+ lafe_errc(1, 0, "Invalid blocksize: %s",
+ cpio->argument);
+ }
+ cpio->bytes_per_block = t;
+ break;
+ case 'c': /* POSIX 1997 */
+ cpio->format = "odc";
+ break;
+ case 'd': /* POSIX 1997 */
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR;
+ break;
+ case 'E': /* NetBSD/OpenBSD */
+ if (archive_match_include_pattern_from_file(
+ cpio->matching, cpio->argument,
+ cpio->option_null) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(cpio->matching));
+ break;
+ case 'F': /* NetBSD/OpenBSD/GNU cpio */
+ cpio->filename = cpio->argument;
+ break;
+ case 'f': /* POSIX 1997 */
+ if (archive_match_exclude_pattern(cpio->matching,
+ cpio->argument) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(cpio->matching));
+ break;
+ case OPTION_GRZIP:
+ cpio->compress = opt;
+ break;
+ case 'H': /* GNU cpio (also --format) */
+ cpio->format = cpio->argument;
+ break;
+ case 'h':
+ long_help();
+ /* NOTREACHED */
+ case 'I': /* NetBSD/OpenBSD */
+ cpio->filename = cpio->argument;
+ break;
+ case 'i': /* POSIX 1997 */
+ if (cpio->mode != '\0')
+ lafe_errc(1, 0,
+ "Cannot use both -i and -%c", cpio->mode);
+ cpio->mode = opt;
+ break;
+ case 'J': /* GNU tar, others */
+ cpio->compress = opt;
+ break;
+ case 'j': /* GNU tar, others */
+ cpio->compress = opt;
+ break;
+ case OPTION_INSECURE:
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS;
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
+ break;
+ case 'L': /* GNU cpio */
+ cpio->option_follow_links = 1;
+ break;
+ case 'l': /* POSIX 1997 */
+ cpio->option_link = 1;
+ break;
+ case OPTION_LRZIP:
+ case OPTION_LZ4:
+ case OPTION_LZMA: /* GNU tar, others */
+ case OPTION_LZOP: /* GNU tar, others */
+ case OPTION_ZSTD:
+ cpio->compress = opt;
+ break;
+ case 'm': /* POSIX 1997 */
+ cpio->extract_flags |= ARCHIVE_EXTRACT_TIME;
+ break;
+ case 'n': /* GNU cpio */
+ cpio->option_numeric_uid_gid = 1;
+ break;
+ case OPTION_NO_PRESERVE_OWNER: /* GNU cpio */
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
+ break;
+ case 'O': /* GNU cpio */
+ cpio->filename = cpio->argument;
+ break;
+ case 'o': /* POSIX 1997 */
+ if (cpio->mode != '\0')
+ lafe_errc(1, 0,
+ "Cannot use both -o and -%c", cpio->mode);
+ cpio->mode = opt;
+ break;
+ case 'p': /* POSIX 1997 */
+ if (cpio->mode != '\0')
+ lafe_errc(1, 0,
+ "Cannot use both -p and -%c", cpio->mode);
+ cpio->mode = opt;
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
+ cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS;
+ break;
+ case OPTION_PASSPHRASE:
+ cpio->passphrase = cpio->argument;
+ break;
+ case OPTION_PRESERVE_OWNER:
+ cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER;
+ break;
+ case OPTION_QUIET: /* GNU cpio */
+ cpio->quiet = 1;
+ break;
+ case 'R': /* GNU cpio, also --owner */
+ /* TODO: owner_parse should return uname/gname
+ * also; use that to set [ug]name_override. */
+ errmsg = owner_parse(cpio->argument, &uid, &gid);
+ if (errmsg) {
+ lafe_warnc(-1, "%s", errmsg);
+ usage();
+ }
+ if (uid != -1) {
+ cpio->uid_override = uid;
+ cpio->uname_override = NULL;
+ }
+ if (gid != -1) {
+ cpio->gid_override = gid;
+ cpio->gname_override = NULL;
+ }
+ break;
+ case 'r': /* POSIX 1997 */
+ cpio->option_rename = 1;
+ break;
+ case 't': /* POSIX 1997 */
+ cpio->option_list = 1;
+ break;
+ case 'u': /* POSIX 1997 */
+ cpio->extract_flags
+ &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
+ break;
+ case OPTION_UUENCODE:
+ cpio->add_filter = opt;
+ break;
+ case 'v': /* POSIX 1997 */
+ cpio->verbose++;
+ break;
+ case 'V': /* GNU cpio */
+ cpio->dot++;
+ break;
+ case OPTION_VERSION: /* GNU convention */
+ version();
+ /* NOTREACHED */
+#if 0
+ /*
+ * cpio_getopt() handles -W specially, so it's not
+ * available here.
+ */
+ case 'W': /* Obscure, but useful GNU convention. */
+ break;
+#endif
+ case 'y': /* tar convention */
+ cpio->compress = opt;
+ break;
+ case 'Z': /* tar convention */
+ cpio->compress = opt;
+ break;
+ case 'z': /* tar convention */
+ cpio->compress = opt;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ /*
+ * Sanity-check args, error out on nonsensical combinations.
+ */
+ /* -t implies -i if no mode was specified. */
+ if (cpio->option_list && cpio->mode == '\0')
+ cpio->mode = 'i';
+ /* -t requires -i */
+ if (cpio->option_list && cpio->mode != 'i')
+ lafe_errc(1, 0, "Option -t requires -i");
+ /* -n requires -it */
+ if (cpio->option_numeric_uid_gid && !cpio->option_list)
+ lafe_errc(1, 0, "Option -n requires -it");
+ /* Can only specify format when writing */
+ if (cpio->format != NULL && cpio->mode != 'o')
+ lafe_errc(1, 0, "Option --format requires -o");
+ /* -l requires -p */
+ if (cpio->option_link && cpio->mode != 'p')
+ lafe_errc(1, 0, "Option -l requires -p");
+ /* -v overrides -V */
+ if (cpio->dot && cpio->verbose)
+ cpio->dot = 0;
+ /* TODO: Flag other nonsensical combinations. */
+
+ switch (cpio->mode) {
+ case 'o':
+ if (cpio->format == NULL) {
+ if (cpio->option_pwb)
+ cpio->format = "pwb";
+ else
+ cpio->format = "cpio";
+ }
+ mode_out(cpio);
+ break;
+ case 'i':
+ while (*cpio->argv != NULL) {
+ if (archive_match_include_pattern(cpio->matching,
+ *cpio->argv) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(cpio->matching));
+ --cpio->argc;
+ ++cpio->argv;
+ }
+ if (cpio->option_list)
+ mode_list(cpio);
+ else
+ mode_in(cpio);
+ /* NOTREACHED */
+ case 'p':
+ if (*cpio->argv == NULL || **cpio->argv == '\0')
+ lafe_errc(1, 0,
+ "-p mode requires a target directory");
+ mode_pass(cpio, *cpio->argv);
+ break;
+ default:
+ lafe_errc(1, 0,
+ "Must specify at least one of -i, -o, or -p");
+ }
+
+ archive_match_free(cpio->matching);
+ free_cache(cpio->gname_cache);
+ free_cache(cpio->uname_cache);
+ archive_read_close(cpio->archive_read_disk);
+ archive_read_free(cpio->archive_read_disk);
+ free(cpio->destdir);
+ passphrase_free(cpio->ppbuff);
+ return (cpio->return_value);
+}
+
+static void
+usage(void)
+{
+ const char *p;
+
+ p = lafe_getprogname();
+
+ fprintf(stderr, "Brief Usage:\n");
+ fprintf(stderr, " List: %s -it < archive\n", p);
+ fprintf(stderr, " Extract: %s -i < archive\n", p);
+ fprintf(stderr, " Create: %s -o < filenames > archive\n", p);
+ fprintf(stderr, " Help: %s --help\n", p);
+ exit(1);
+}
+
+static const char *long_help_msg =
+ "First option must be a mode specifier:\n"
+ " -i Input -o Output -p Pass\n"
+ "Common Options:\n"
+ " -v Verbose filenames -V one dot per file\n"
+ "Create: %p -o [options] < [list of files] > [archive]\n"
+ " -J,-y,-z,--lzma Compress archive with xz/bzip2/gzip/lzma\n"
+ " --format {pwb|bin|odc|newc|ustar} Select archive format\n"
+ "List: %p -it < [archive]\n"
+ "Extract: %p -i [options] < [archive]\n";
+
+
+/*
+ * Note that the word 'bsdcpio' will always appear in the first line
+ * of output.
+ *
+ * In particular, /bin/sh scripts that need to test for the presence
+ * of bsdcpio can use the following template:
+ *
+ * if (cpio --help 2>&1 | grep bsdcpio >/dev/null 2>&1 ) then \
+ * echo bsdcpio; else echo not bsdcpio; fi
+ */
+static void
+long_help(void)
+{
+ const char *prog;
+ const char *p;
+
+ prog = lafe_getprogname();
+
+ fflush(stderr);
+
+ p = (strcmp(prog,"bsdcpio") != 0) ? "(bsdcpio)" : "";
+ printf("%s%s: manipulate archive files\n", prog, p);
+
+ for (p = long_help_msg; *p != '\0'; p++) {
+ if (*p == '%') {
+ if (p[1] == 'p') {
+ fputs(prog, stdout);
+ p++;
+ } else
+ putchar('%');
+ } else
+ putchar(*p);
+ }
+ version();
+}
+
+static void
+version(void)
+{
+ fprintf(stdout,"bsdcpio %s - %s \n",
+ BSDCPIO_VERSION_STRING,
+ archive_version_details());
+ exit(0);
+}
+
+static void
+mode_out(struct cpio *cpio)
+{
+ struct archive_entry *entry, *spare;
+ struct lafe_line_reader *lr;
+ const char *p;
+ int r;
+
+ if (cpio->option_append)
+ lafe_errc(1, 0, "Append mode not yet supported.");
+
+ cpio->archive_read_disk = archive_read_disk_new();
+ if (cpio->archive_read_disk == NULL)
+ lafe_errc(1, 0, "Failed to allocate archive object");
+ if (cpio->option_follow_links)
+ archive_read_disk_set_symlink_logical(cpio->archive_read_disk);
+ else
+ archive_read_disk_set_symlink_physical(cpio->archive_read_disk);
+ archive_read_disk_set_standard_lookup(cpio->archive_read_disk);
+
+ cpio->archive = archive_write_new();
+ if (cpio->archive == NULL)
+ lafe_errc(1, 0, "Failed to allocate archive object");
+ switch (cpio->compress) {
+ case OPTION_GRZIP:
+ r = archive_write_add_filter_grzip(cpio->archive);
+ break;
+ case 'J':
+ r = archive_write_add_filter_xz(cpio->archive);
+ break;
+ case OPTION_LRZIP:
+ r = archive_write_add_filter_lrzip(cpio->archive);
+ break;
+ case OPTION_LZ4:
+ r = archive_write_add_filter_lz4(cpio->archive);
+ break;
+ case OPTION_LZMA:
+ r = archive_write_add_filter_lzma(cpio->archive);
+ break;
+ case OPTION_LZOP:
+ r = archive_write_add_filter_lzop(cpio->archive);
+ break;
+ case OPTION_ZSTD:
+ r = archive_write_add_filter_zstd(cpio->archive);
+ break;
+ case 'j': case 'y':
+ r = archive_write_add_filter_bzip2(cpio->archive);
+ break;
+ case 'z':
+ r = archive_write_add_filter_gzip(cpio->archive);
+ break;
+ case 'Z':
+ r = archive_write_add_filter_compress(cpio->archive);
+ break;
+ default:
+ r = archive_write_add_filter_none(cpio->archive);
+ break;
+ }
+ if (r < ARCHIVE_WARN)
+ lafe_errc(1, 0, "Requested compression not available");
+ switch (cpio->add_filter) {
+ case 0:
+ r = ARCHIVE_OK;
+ break;
+ case OPTION_B64ENCODE:
+ r = archive_write_add_filter_b64encode(cpio->archive);
+ break;
+ case OPTION_UUENCODE:
+ r = archive_write_add_filter_uuencode(cpio->archive);
+ break;
+ }
+ if (r < ARCHIVE_WARN)
+ lafe_errc(1, 0, "Requested filter not available");
+ r = archive_write_set_format_by_name(cpio->archive, cpio->format);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
+ archive_write_set_bytes_per_block(cpio->archive, cpio->bytes_per_block);
+ cpio->linkresolver = archive_entry_linkresolver_new();
+ archive_entry_linkresolver_set_strategy(cpio->linkresolver,
+ archive_format(cpio->archive));
+ if (cpio->passphrase != NULL)
+ r = archive_write_set_passphrase(cpio->archive,
+ cpio->passphrase);
+ else
+ r = archive_write_set_passphrase_callback(cpio->archive, cpio,
+ &passphrase_callback);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
+
+ /*
+ * The main loop: Copy each file into the output archive.
+ */
+ r = archive_write_open_filename(cpio->archive, cpio->filename);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
+ lr = lafe_line_reader("-", cpio->option_null);
+ while ((p = lafe_line_reader_next(lr)) != NULL)
+ file_to_archive(cpio, p);
+ lafe_line_reader_free(lr);
+
+ /*
+ * The hardlink detection may have queued up a couple of entries
+ * that can now be flushed.
+ */
+ entry = NULL;
+ archive_entry_linkify(cpio->linkresolver, &entry, &spare);
+ while (entry != NULL) {
+ entry_to_archive(cpio, entry);
+ archive_entry_free(entry);
+ entry = NULL;
+ archive_entry_linkify(cpio->linkresolver, &entry, &spare);
+ }
+
+ r = archive_write_close(cpio->archive);
+ if (cpio->dot)
+ fprintf(stderr, "\n");
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
+
+ if (!cpio->quiet) {
+ int64_t blocks =
+ (archive_filter_bytes(cpio->archive, 0) + 511)
+ / 512;
+ fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
+ blocks == 1 ? "block" : "blocks");
+ }
+ archive_write_free(cpio->archive);
+ archive_entry_linkresolver_free(cpio->linkresolver);
+}
+
+static const char *
+remove_leading_slash(const char *p)
+{
+ const char *rp;
+
+ /* Remove leading "//./" or "//?/" or "//?/UNC/"
+ * (absolute path prefixes used by Windows API) */
+ if ((p[0] == '/' || p[0] == '\\') &&
+ (p[1] == '/' || p[1] == '\\') &&
+ (p[2] == '.' || p[2] == '?') &&
+ (p[3] == '/' || p[3] == '\\'))
+ {
+ if (p[2] == '?' &&
+ (p[4] == 'U' || p[4] == 'u') &&
+ (p[5] == 'N' || p[5] == 'n') &&
+ (p[6] == 'C' || p[6] == 'c') &&
+ (p[7] == '/' || p[7] == '\\'))
+ p += 8;
+ else
+ p += 4;
+ }
+ do {
+ rp = p;
+ /* Remove leading drive letter from archives created
+ * on Windows. */
+ if (((p[0] >= 'a' && p[0] <= 'z') ||
+ (p[0] >= 'A' && p[0] <= 'Z')) &&
+ p[1] == ':') {
+ p += 2;
+ }
+ /* Remove leading "/../", "//", etc. */
+ while (p[0] == '/' || p[0] == '\\') {
+ if (p[1] == '.' && p[2] == '.' &&
+ (p[3] == '/' || p[3] == '\\')) {
+ p += 3; /* Remove "/..", leave "/"
+ * for next pass. */
+ } else
+ p += 1; /* Remove "/". */
+ }
+ } while (rp != p);
+ return (p);
+}
+
+/*
+ * This is used by both out mode (to copy objects from disk into
+ * an archive) and pass mode (to copy objects from disk to
+ * an archive_write_disk "archive").
+ */
+static int
+file_to_archive(struct cpio *cpio, const char *srcpath)
+{
+ const char *destpath;
+ struct archive_entry *entry, *spare;
+ size_t len;
+ int r;
+
+ /*
+ * Create an archive_entry describing the source file.
+ *
+ */
+ entry = archive_entry_new();
+ if (entry == NULL)
+ lafe_errc(1, 0, "Couldn't allocate entry");
+ archive_entry_copy_sourcepath(entry, srcpath);
+ r = archive_read_disk_entry_from_file(cpio->archive_read_disk,
+ entry, -1, NULL);
+ if (r < ARCHIVE_FAILED)
+ lafe_errc(1, 0, "%s",
+ archive_error_string(cpio->archive_read_disk));
+ if (r < ARCHIVE_OK)
+ lafe_warnc(0, "%s",
+ archive_error_string(cpio->archive_read_disk));
+ if (r <= ARCHIVE_FAILED) {
+ archive_entry_free(entry);
+ cpio->return_value = 1;
+ return (r);
+ }
+
+ if (cpio->uid_override >= 0) {
+ archive_entry_set_uid(entry, cpio->uid_override);
+ archive_entry_set_uname(entry, cpio->uname_override);
+ }
+ if (cpio->gid_override >= 0) {
+ archive_entry_set_gid(entry, cpio->gid_override);
+ archive_entry_set_gname(entry, cpio->gname_override);
+ }
+
+ /*
+ * Generate a destination path for this entry.
+ * "destination path" is the name to which it will be copied in
+ * pass mode or the name that will go into the archive in
+ * output mode.
+ */
+ destpath = srcpath;
+ if (cpio->destdir) {
+ len = cpio->destdir_len + strlen(srcpath) + 8;
+ if (len >= cpio->pass_destpath_alloc) {
+ while (len >= cpio->pass_destpath_alloc) {
+ cpio->pass_destpath_alloc += 512;
+ cpio->pass_destpath_alloc *= 2;
+ }
+ free(cpio->pass_destpath);
+ cpio->pass_destpath = malloc(cpio->pass_destpath_alloc);
+ if (cpio->pass_destpath == NULL)
+ lafe_errc(1, ENOMEM,
+ "Can't allocate path buffer");
+ }
+ strcpy(cpio->pass_destpath, cpio->destdir);
+ strcat(cpio->pass_destpath, remove_leading_slash(srcpath));
+ destpath = cpio->pass_destpath;
+ }
+ if (cpio->option_rename)
+ destpath = cpio_rename(destpath);
+ if (destpath == NULL) {
+ archive_entry_free(entry);
+ return (0);
+ }
+ archive_entry_copy_pathname(entry, destpath);
+
+ /*
+ * If we're trying to preserve hardlinks, match them here.
+ */
+ spare = NULL;
+ if (cpio->linkresolver != NULL
+ && archive_entry_filetype(entry) != AE_IFDIR) {
+ archive_entry_linkify(cpio->linkresolver, &entry, &spare);
+ }
+
+ if (entry != NULL) {
+ r = entry_to_archive(cpio, entry);
+ archive_entry_free(entry);
+ if (spare != NULL) {
+ if (r == 0)
+ r = entry_to_archive(cpio, spare);
+ archive_entry_free(spare);
+ }
+ }
+ return (r);
+}
+
+static int
+entry_to_archive(struct cpio *cpio, struct archive_entry *entry)
+{
+ const char *destpath = archive_entry_pathname(entry);
+ const char *srcpath = archive_entry_sourcepath(entry);
+ int fd = -1;
+ ssize_t bytes_read;
+ int r;
+
+ /* Print out the destination name to the user. */
+ if (cpio->verbose)
+ fprintf(stderr,"%s", destpath);
+ if (cpio->dot)
+ fprintf(stderr, ".");
+
+ /*
+ * Option_link only makes sense in pass mode and for
+ * regular files. Also note: if a link operation fails
+ * because of cross-device restrictions, we'll fall back
+ * to copy mode for that entry.
+ *
+ * TODO: Test other cpio implementations to see if they
+ * hard-link anything other than regular files here.
+ */
+ if (cpio->option_link
+ && archive_entry_filetype(entry) == AE_IFREG)
+ {
+ struct archive_entry *t;
+ /* Save the original entry in case we need it later. */
+ t = archive_entry_clone(entry);
+ if (t == NULL)
+ lafe_errc(1, ENOMEM, "Can't create link");
+ /* Note: link(2) doesn't create parent directories,
+ * so we use archive_write_header() instead as a
+ * convenience. */
+ archive_entry_set_hardlink(t, srcpath);
+ /* This is a straight link that carries no data. */
+ archive_entry_set_size(t, 0);
+ r = archive_write_header(cpio->archive, t);
+ archive_entry_free(t);
+ if (r != ARCHIVE_OK)
+ lafe_warnc(archive_errno(cpio->archive),
+ "%s", archive_error_string(cpio->archive));
+ if (r == ARCHIVE_FATAL)
+ exit(1);
+#ifdef EXDEV
+ if (r != ARCHIVE_OK && archive_errno(cpio->archive) == EXDEV) {
+ /* Cross-device link: Just fall through and use
+ * the original entry to copy the file over. */
+ lafe_warnc(0, "Copying file instead");
+ } else
+#endif
+ return (0);
+ }
+
+ /*
+ * Make sure we can open the file (if necessary) before
+ * trying to write the header.
+ */
+ if (archive_entry_filetype(entry) == AE_IFREG) {
+ if (archive_entry_size(entry) > 0) {
+ fd = open(srcpath, O_RDONLY | O_BINARY);
+ if (fd < 0) {
+ lafe_warnc(errno,
+ "%s: could not open file", srcpath);
+ goto cleanup;
+ }
+ }
+ } else {
+ archive_entry_set_size(entry, 0);
+ }
+
+ r = archive_write_header(cpio->archive, entry);
+
+ if (r != ARCHIVE_OK)
+ lafe_warnc(archive_errno(cpio->archive),
+ "%s: %s",
+ srcpath,
+ archive_error_string(cpio->archive));
+
+ if (r == ARCHIVE_FATAL)
+ exit(1);
+
+ if (r >= ARCHIVE_WARN && archive_entry_size(entry) > 0 && fd >= 0) {
+ bytes_read = read(fd, cpio->buff, (unsigned)cpio->buff_size);
+ while (bytes_read > 0) {
+ ssize_t bytes_write;
+ bytes_write = archive_write_data(cpio->archive,
+ cpio->buff, bytes_read);
+ if (bytes_write < 0)
+ lafe_errc(1, archive_errno(cpio->archive),
+ "%s", archive_error_string(cpio->archive));
+ if (bytes_write < bytes_read) {
+ lafe_warnc(0,
+ "Truncated write; file may have "
+ "grown while being archived.");
+ }
+ bytes_read = read(fd, cpio->buff,
+ (unsigned)cpio->buff_size);
+ }
+ }
+
+ fd = restore_time(cpio, entry, srcpath, fd);
+
+cleanup:
+ if (cpio->verbose)
+ fprintf(stderr,"\n");
+ if (fd >= 0)
+ close(fd);
+ return (0);
+}
+
+static int
+restore_time(struct cpio *cpio, struct archive_entry *entry,
+ const char *name, int fd)
+{
+#ifndef HAVE_UTIMES
+ static int warned = 0;
+
+ (void)cpio; /* UNUSED */
+ (void)entry; /* UNUSED */
+ (void)name; /* UNUSED */
+
+ if (!warned)
+ lafe_warnc(0, "Can't restore access times on this platform");
+ warned = 1;
+ return (fd);
+#else
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ struct __timeval times[2];
+#else
+ struct timeval times[2];
+#endif
+
+ if (!cpio->option_atime_restore)
+ return (fd);
+
+ times[1].tv_sec = archive_entry_mtime(entry);
+ times[1].tv_usec = archive_entry_mtime_nsec(entry) / 1000;
+
+ times[0].tv_sec = archive_entry_atime(entry);
+ times[0].tv_usec = archive_entry_atime_nsec(entry) / 1000;
+
+#if defined(HAVE_FUTIMES) && !defined(__CYGWIN__)
+ if (fd >= 0 && futimes(fd, times) == 0)
+ return (fd);
+#endif
+ /*
+ * Some platform cannot restore access times if the file descriptor
+ * is still opened.
+ */
+ if (fd >= 0) {
+ close(fd);
+ fd = -1;
+ }
+
+#ifdef HAVE_LUTIMES
+ if (lutimes(name, times) != 0)
+#else
+ if ((AE_IFLNK != archive_entry_filetype(entry))
+ && utimes(name, times) != 0)
+#endif
+ lafe_warnc(errno, "Can't update time for %s", name);
+#endif
+ return (fd);
+}
+
+
+static void
+mode_in(struct cpio *cpio)
+{
+ struct archive *a;
+ struct archive_entry *entry;
+ struct archive *ext;
+ const char *destpath;
+ int r;
+
+ ext = archive_write_disk_new();
+ if (ext == NULL)
+ lafe_errc(1, 0, "Couldn't allocate restore object");
+ r = archive_write_disk_set_options(ext, cpio->extract_flags);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(ext));
+ a = archive_read_new();
+ if (a == NULL)
+ lafe_errc(1, 0, "Couldn't allocate archive object");
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+ if (cpio->option_pwb)
+ archive_read_set_options(a, "pwb");
+ if (cpio->passphrase != NULL)
+ r = archive_read_add_passphrase(a, cpio->passphrase);
+ else
+ r = archive_read_set_passphrase_callback(a, cpio,
+ &passphrase_callback);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+
+ if (archive_read_open_filename(a, cpio->filename,
+ cpio->bytes_per_block))
+ lafe_errc(1, archive_errno(a),
+ "%s", archive_error_string(a));
+ for (;;) {
+ r = archive_read_next_header(a, &entry);
+ if (r == ARCHIVE_EOF)
+ break;
+ if (r != ARCHIVE_OK) {
+ lafe_errc(1, archive_errno(a),
+ "%s", archive_error_string(a));
+ }
+ if (archive_match_path_excluded(cpio->matching, entry))
+ continue;
+ if (cpio->option_rename) {
+ destpath = cpio_rename(archive_entry_pathname(entry));
+ archive_entry_set_pathname(entry, destpath);
+ } else
+ destpath = archive_entry_pathname(entry);
+ if (destpath == NULL)
+ continue;
+ if (cpio->verbose)
+ fprintf(stderr, "%s\n", destpath);
+ if (cpio->dot)
+ fprintf(stderr, ".");
+ if (cpio->uid_override >= 0)
+ archive_entry_set_uid(entry, cpio->uid_override);
+ if (cpio->gid_override >= 0)
+ archive_entry_set_gid(entry, cpio->gid_override);
+ r = archive_write_header(ext, entry);
+ if (r != ARCHIVE_OK) {
+ fprintf(stderr, "%s: %s\n",
+ archive_entry_pathname(entry),
+ archive_error_string(ext));
+ } else if (!archive_entry_size_is_set(entry)
+ || archive_entry_size(entry) > 0) {
+ r = extract_data(a, ext);
+ if (r != ARCHIVE_OK)
+ cpio->return_value = 1;
+ }
+ }
+ r = archive_read_close(a);
+ if (cpio->dot)
+ fprintf(stderr, "\n");
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ r = archive_write_close(ext);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(ext));
+ if (!cpio->quiet) {
+ int64_t blocks = (archive_filter_bytes(a, 0) + 511)
+ / 512;
+ fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
+ blocks == 1 ? "block" : "blocks");
+ }
+ archive_read_free(a);
+ archive_write_free(ext);
+ exit(cpio->return_value);
+}
+
+/*
+ * Exits if there's a fatal error. Returns ARCHIVE_OK
+ * if everything is kosher.
+ */
+static int
+extract_data(struct archive *ar, struct archive *aw)
+{
+ int r;
+ size_t size;
+ const void *block;
+ int64_t offset;
+
+ for (;;) {
+ r = archive_read_data_block(ar, &block, &size, &offset);
+ if (r == ARCHIVE_EOF)
+ return (ARCHIVE_OK);
+ if (r != ARCHIVE_OK) {
+ lafe_warnc(archive_errno(ar),
+ "%s", archive_error_string(ar));
+ exit(1);
+ }
+ r = (int)archive_write_data_block(aw, block, size, offset);
+ if (r != ARCHIVE_OK) {
+ lafe_warnc(archive_errno(aw),
+ "%s", archive_error_string(aw));
+ return (r);
+ }
+ }
+}
+
+static void
+mode_list(struct cpio *cpio)
+{
+ struct archive *a;
+ struct archive_entry *entry;
+ int r;
+
+ a = archive_read_new();
+ if (a == NULL)
+ lafe_errc(1, 0, "Couldn't allocate archive object");
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+ if (cpio->option_pwb)
+ archive_read_set_options(a, "pwb");
+ if (cpio->passphrase != NULL)
+ r = archive_read_add_passphrase(a, cpio->passphrase);
+ else
+ r = archive_read_set_passphrase_callback(a, cpio,
+ &passphrase_callback);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+
+ if (archive_read_open_filename(a, cpio->filename,
+ cpio->bytes_per_block))
+ lafe_errc(1, archive_errno(a),
+ "%s", archive_error_string(a));
+ for (;;) {
+ r = archive_read_next_header(a, &entry);
+ if (r == ARCHIVE_EOF)
+ break;
+ if (r != ARCHIVE_OK) {
+ lafe_errc(1, archive_errno(a),
+ "%s", archive_error_string(a));
+ }
+ if (archive_match_path_excluded(cpio->matching, entry))
+ continue;
+ if (cpio->verbose)
+ list_item_verbose(cpio, entry);
+ else
+ fprintf(stdout, "%s\n", archive_entry_pathname(entry));
+ }
+ r = archive_read_close(a);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ if (!cpio->quiet) {
+ int64_t blocks = (archive_filter_bytes(a, 0) + 511)
+ / 512;
+ fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
+ blocks == 1 ? "block" : "blocks");
+ }
+ archive_read_free(a);
+ exit(0);
+}
+
+/*
+ * Display information about the current file.
+ *
+ * The format here roughly duplicates the output of 'ls -l'.
+ * This is based on SUSv2, where 'tar tv' is documented as
+ * listing additional information in an "unspecified format,"
+ * and 'pax -l' is documented as using the same format as 'ls -l'.
+ */
+static void
+list_item_verbose(struct cpio *cpio, struct archive_entry *entry)
+{
+ char size[32];
+ char date[32];
+ char uids[22], gids[22];
+ const char *uname, *gname;
+ FILE *out = stdout;
+ const char *fmt;
+ time_t mtime;
+ static time_t now;
+ struct tm *ltime;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE_LOCALTIME_S)
+ struct tm tmbuf;
+#endif
+
+ if (!now)
+ time(&now);
+
+ if (cpio->option_numeric_uid_gid) {
+ /* Format numeric uid/gid for display. */
+ strcpy(uids, cpio_i64toa(archive_entry_uid(entry)));
+ uname = uids;
+ strcpy(gids, cpio_i64toa(archive_entry_gid(entry)));
+ gname = gids;
+ } else {
+ /* Use uname if it's present, else lookup name from uid. */
+ uname = archive_entry_uname(entry);
+ if (uname == NULL)
+ uname = lookup_uname(cpio, (uid_t)archive_entry_uid(entry));
+ /* Use gname if it's present, else lookup name from gid. */
+ gname = archive_entry_gname(entry);
+ if (gname == NULL)
+ gname = lookup_gname(cpio, (uid_t)archive_entry_gid(entry));
+ }
+
+ /* Print device number or file size. */
+ if (archive_entry_filetype(entry) == AE_IFCHR
+ || archive_entry_filetype(entry) == AE_IFBLK) {
+ snprintf(size, sizeof(size), "%lu,%lu",
+ (unsigned long)archive_entry_rdevmajor(entry),
+ (unsigned long)archive_entry_rdevminor(entry));
+ } else {
+ strcpy(size, cpio_i64toa(archive_entry_size(entry)));
+ }
+
+ /* Format the time using 'ls -l' conventions. */
+ mtime = archive_entry_mtime(entry);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Windows' strftime function does not support %e format. */
+ if (mtime - now > 365*86400/2
+ || mtime - now < -365*86400/2)
+ fmt = cpio->day_first ? "%d %b %Y" : "%b %d %Y";
+ else
+ fmt = cpio->day_first ? "%d %b %H:%M" : "%b %d %H:%M";
+#else
+ if (mtime - now > 365*86400/2
+ || mtime - now < -365*86400/2)
+ fmt = cpio->day_first ? "%e %b %Y" : "%b %e %Y";
+ else
+ fmt = cpio->day_first ? "%e %b %H:%M" : "%b %e %H:%M";
+#endif
+#if defined(HAVE_LOCALTIME_S)
+ ltime = localtime_s(&tmbuf, &mtime) ? NULL : &tmbuf;
+#elif defined(HAVE_LOCALTIME_R)
+ ltime = localtime_r(&mtime, &tmbuf);
+#else
+ ltime = localtime(&mtime);
+#endif
+ if (ltime != NULL)
+ strftime(date, sizeof(date), fmt, ltime);
+ else
+ strcpy(date, "invalid mtime");
+
+ fprintf(out, "%s%3d %-8s %-8s %8s %12s %s",
+ archive_entry_strmode(entry),
+ archive_entry_nlink(entry),
+ uname, gname, size, date,
+ archive_entry_pathname(entry));
+
+ /* Extra information for links. */
+ if (archive_entry_hardlink(entry)) /* Hard link */
+ fprintf(out, " link to %s", archive_entry_hardlink(entry));
+ else if (archive_entry_symlink(entry)) /* Symbolic link */
+ fprintf(out, " -> %s", archive_entry_symlink(entry));
+ fprintf(out, "\n");
+}
+
+static void
+mode_pass(struct cpio *cpio, const char *destdir)
+{
+ struct lafe_line_reader *lr;
+ const char *p;
+ int r;
+
+ /* Ensure target dir has a trailing '/' to simplify path surgery. */
+ cpio->destdir_len = strlen(destdir);
+ cpio->destdir = malloc(cpio->destdir_len + 8);
+ memcpy(cpio->destdir, destdir, cpio->destdir_len);
+ if (cpio->destdir_len == 0 || destdir[cpio->destdir_len - 1] != '/')
+ cpio->destdir[cpio->destdir_len++] = '/';
+ cpio->destdir[cpio->destdir_len] = '\0';
+
+ cpio->archive = archive_write_disk_new();
+ if (cpio->archive == NULL)
+ lafe_errc(1, 0, "Failed to allocate archive object");
+ r = archive_write_disk_set_options(cpio->archive, cpio->extract_flags);
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
+ cpio->linkresolver = archive_entry_linkresolver_new();
+ archive_write_disk_set_standard_lookup(cpio->archive);
+
+ cpio->archive_read_disk = archive_read_disk_new();
+ if (cpio->archive_read_disk == NULL)
+ lafe_errc(1, 0, "Failed to allocate archive object");
+ if (cpio->option_follow_links)
+ archive_read_disk_set_symlink_logical(cpio->archive_read_disk);
+ else
+ archive_read_disk_set_symlink_physical(cpio->archive_read_disk);
+ archive_read_disk_set_standard_lookup(cpio->archive_read_disk);
+
+ lr = lafe_line_reader("-", cpio->option_null);
+ while ((p = lafe_line_reader_next(lr)) != NULL)
+ file_to_archive(cpio, p);
+ lafe_line_reader_free(lr);
+
+ archive_entry_linkresolver_free(cpio->linkresolver);
+ r = archive_write_close(cpio->archive);
+ if (cpio->dot)
+ fprintf(stderr, "\n");
+ if (r != ARCHIVE_OK)
+ lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
+
+ if (!cpio->quiet) {
+ int64_t blocks =
+ (archive_filter_bytes(cpio->archive, 0) + 511)
+ / 512;
+ fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
+ blocks == 1 ? "block" : "blocks");
+ }
+
+ archive_write_free(cpio->archive);
+ free(cpio->pass_destpath);
+}
+
+/*
+ * Prompt for a new name for this entry. Returns a pointer to the
+ * new name or NULL if the entry should not be copied. This
+ * implements the semantics defined in POSIX.1-1996, which specifies
+ * that an input of '.' means the name should be unchanged. GNU cpio
+ * treats '.' as a literal new name.
+ */
+static const char *
+cpio_rename(const char *name)
+{
+ static char buff[1024];
+ FILE *t;
+ char *p, *ret;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ FILE *to;
+
+ t = fopen("CONIN$", "r");
+ if (t == NULL)
+ return (name);
+ to = fopen("CONOUT$", "w");
+ if (to == NULL) {
+ fclose(t);
+ return (name);
+ }
+ fprintf(to, "%s (Enter/./(new name))? ", name);
+ fclose(to);
+#else
+ t = fopen("/dev/tty", "r+");
+ if (t == NULL)
+ return (name);
+ fprintf(t, "%s (Enter/./(new name))? ", name);
+ fflush(t);
+#endif
+
+ p = fgets(buff, sizeof(buff), t);
+ fclose(t);
+ if (p == NULL)
+ /* End-of-file is a blank line. */
+ return (NULL);
+
+ while (*p == ' ' || *p == '\t')
+ ++p;
+ if (*p == '\n' || *p == '\0')
+ /* Empty line. */
+ return (NULL);
+ if (*p == '.' && p[1] == '\n')
+ /* Single period preserves original name. */
+ return (name);
+ ret = p;
+ /* Trim the final newline. */
+ while (*p != '\0' && *p != '\n')
+ ++p;
+ /* Overwrite the final \n with a null character. */
+ *p = '\0';
+ return (ret);
+}
+
+static void
+free_cache(struct name_cache *cache)
+{
+ size_t i;
+
+ if (cache != NULL) {
+ for (i = 0; i < cache->size; i++)
+ free(cache->cache[i].name);
+ free(cache);
+ }
+}
+
+/*
+ * Lookup uname/gname from uid/gid, return NULL if no match.
+ */
+static const char *
+lookup_name(struct cpio *cpio, struct name_cache **name_cache_variable,
+ int (*lookup_fn)(struct cpio *, const char **, id_t), id_t id)
+{
+ char asnum[16];
+ struct name_cache *cache;
+ const char *name;
+ int slot;
+
+
+ if (*name_cache_variable == NULL) {
+ *name_cache_variable = calloc(1, sizeof(struct name_cache));
+ if (*name_cache_variable == NULL)
+ lafe_errc(1, ENOMEM, "No more memory");
+ (*name_cache_variable)->size = name_cache_size;
+ }
+
+ cache = *name_cache_variable;
+ cache->probes++;
+
+ slot = id % cache->size;
+ if (cache->cache[slot].name != NULL) {
+ if (cache->cache[slot].id == id) {
+ cache->hits++;
+ return (cache->cache[slot].name);
+ }
+ free(cache->cache[slot].name);
+ cache->cache[slot].name = NULL;
+ }
+
+ if (lookup_fn(cpio, &name, id)) {
+ /* If lookup failed, format it as a number. */
+ snprintf(asnum, sizeof(asnum), "%u", (unsigned)id);
+ name = asnum;
+ }
+
+ cache->cache[slot].name = strdup(name);
+ if (cache->cache[slot].name != NULL) {
+ cache->cache[slot].id = id;
+ return (cache->cache[slot].name);
+ }
+
+ /*
+ * Conveniently, NULL marks an empty slot, so
+ * if the strdup() fails, we've just failed to
+ * cache it. No recovery necessary.
+ */
+ return (NULL);
+}
+
+static const char *
+lookup_uname(struct cpio *cpio, uid_t uid)
+{
+ return (lookup_name(cpio, &cpio->uname_cache,
+ &lookup_uname_helper, (id_t)uid));
+}
+
+static int
+lookup_uname_helper(struct cpio *cpio, const char **name, id_t id)
+{
+ struct passwd *pwent;
+
+ (void)cpio; /* UNUSED */
+
+ errno = 0;
+ pwent = getpwuid((uid_t)id);
+ if (pwent == NULL) {
+ if (errno && errno != ENOENT)
+ lafe_warnc(errno, "getpwuid(%s) failed",
+ cpio_i64toa((int64_t)id));
+ return 1;
+ }
+
+ *name = pwent->pw_name;
+ return 0;
+}
+
+static const char *
+lookup_gname(struct cpio *cpio, gid_t gid)
+{
+ return (lookup_name(cpio, &cpio->gname_cache,
+ &lookup_gname_helper, (id_t)gid));
+}
+
+static int
+lookup_gname_helper(struct cpio *cpio, const char **name, id_t id)
+{
+ struct group *grent;
+
+ (void)cpio; /* UNUSED */
+
+ errno = 0;
+ grent = getgrgid((gid_t)id);
+ if (grent == NULL) {
+ if (errno && errno != ENOENT)
+ lafe_warnc(errno, "getgrgid(%s) failed",
+ cpio_i64toa((int64_t)id));
+ return 1;
+ }
+
+ *name = grent->gr_name;
+ return 0;
+}
+
+/*
+ * It would be nice to just use printf() for formatting large numbers,
+ * but the compatibility problems are a big headache. Hence the
+ * following simple utility function.
+ */
+const char *
+cpio_i64toa(int64_t n0)
+{
+ /* 2^64 =~ 1.8 * 10^19, so 20 decimal digits suffice.
+ * We also need 1 byte for '-' and 1 for '\0'.
+ */
+ static char buff[22];
+ int64_t n = n0 < 0 ? -n0 : n0;
+ char *p = buff + sizeof(buff);
+
+ *--p = '\0';
+ do {
+ *--p = '0' + (int)(n % 10);
+ n /= 10;
+ } while (n > 0);
+ if (n0 < 0)
+ *--p = '-';
+ return p;
+}
+
+#define PPBUFF_SIZE 1024
+static const char *
+passphrase_callback(struct archive *a, void *_client_data)
+{
+ struct cpio *cpio = (struct cpio *)_client_data;
+ (void)a; /* UNUSED */
+
+ if (cpio->ppbuff == NULL) {
+ cpio->ppbuff = malloc(PPBUFF_SIZE);
+ if (cpio->ppbuff == NULL)
+ lafe_errc(1, errno, "Out of memory");
+ }
+ return lafe_readpassphrase("Enter passphrase:",
+ cpio->ppbuff, PPBUFF_SIZE);
+}
+
+static void
+passphrase_free(char *ppbuff)
+{
+ if (ppbuff != NULL) {
+ memset(ppbuff, 0, PPBUFF_SIZE);
+ free(ppbuff);
+ }
+}
diff --git a/contrib/libarchive/cpio/cpio.h b/contrib/libarchive/cpio/cpio.h
new file mode 100644
index 000000000000..3e97c0900b73
--- /dev/null
+++ b/contrib/libarchive/cpio/cpio.h
@@ -0,0 +1,120 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPIO_H_INCLUDED
+#define CPIO_H_INCLUDED
+
+#include "cpio_platform.h"
+#include <stdio.h>
+
+/*
+ * The internal state for the "cpio" program.
+ *
+ * Keeping all of the state in a structure like this simplifies memory
+ * leak testing (at exit, anything left on the heap is suspect). A
+ * pointer to this structure is passed to most cpio internal
+ * functions.
+ */
+struct cpio {
+ /* Option parsing */
+ const char *argument;
+
+ /* Options */
+ int add_filter; /* --uuencode */
+ const char *filename;
+ int mode; /* -i -o -p */
+ int compress; /* -j, -y, or -z */
+ const char *format; /* -H format */
+ int bytes_per_block; /* -b block_size */
+ int verbose; /* -v */
+ int dot; /* -V */
+ int quiet; /* --quiet */
+ int extract_flags; /* Flags for extract operation */
+ const char *compress_program;
+ int option_append; /* -A, only relevant for -o */
+ int option_atime_restore; /* -a */
+ int option_follow_links; /* -L */
+ int option_link; /* -l */
+ int option_list; /* -t */
+ char option_null; /* --null */
+ int option_numeric_uid_gid; /* -n */
+ int option_pwb; /* -6 */
+ int option_rename; /* -r */
+ char *destdir;
+ size_t destdir_len;
+ size_t pass_destpath_alloc;
+ char *pass_destpath;
+ int uid_override;
+ char *uname_override;
+ int gid_override;
+ char *gname_override;
+ int day_first; /* true if locale prefers day/mon */
+ const char *passphrase;
+
+ /* If >= 0, then close this when done. */
+ int fd;
+
+ /* Miscellaneous state information */
+ struct archive *archive;
+ struct archive *archive_read_disk;
+ int argc;
+ char **argv;
+ int return_value; /* Value returned by main() */
+ struct archive_entry_linkresolver *linkresolver;
+
+ struct name_cache *uname_cache;
+ struct name_cache *gname_cache;
+
+ /* Work data. */
+ struct archive *matching;
+ char *buff;
+ size_t buff_size;
+ char *ppbuff;
+};
+
+const char *owner_parse(const char *, int *, int *);
+
+
+/* Fake short equivalents for long options that otherwise lack them. */
+enum {
+ OPTION_B64ENCODE = 1,
+ OPTION_GRZIP,
+ OPTION_INSECURE,
+ OPTION_LRZIP,
+ OPTION_LZ4,
+ OPTION_LZMA,
+ OPTION_LZOP,
+ OPTION_PASSPHRASE,
+ OPTION_NO_PRESERVE_OWNER,
+ OPTION_PRESERVE_OWNER,
+ OPTION_QUIET,
+ OPTION_UUENCODE,
+ OPTION_VERSION,
+ OPTION_ZSTD,
+};
+
+int cpio_getopt(struct cpio *cpio);
+
+#endif
diff --git a/contrib/libarchive/cpio/cpio_platform.h b/contrib/libarchive/cpio/cpio_platform.h
new file mode 100644
index 000000000000..263404b40dab
--- /dev/null
+++ b/contrib/libarchive/cpio/cpio_platform.h
@@ -0,0 +1,67 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This header is the first thing included in any of the cpio
+ * source files. As far as possible, platform-specific issues should
+ * be dealt with here and not within individual source files.
+ */
+
+#ifndef CPIO_PLATFORM_H_INCLUDED
+#define CPIO_PLATFORM_H_INCLUDED
+
+#if defined(PLATFORM_CONFIG_H)
+/* Use hand-built config.h in environments that need it. */
+#include PLATFORM_CONFIG_H
+#else
+/* Read config.h or die trying. */
+#include "config.h"
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include "cpio_windows.h"
+#endif
+
+#ifdef HAVE_LIBARCHIVE
+/* If we're using the platform libarchive, include system headers. */
+#include <archive.h>
+#include <archive_entry.h>
+#else
+/* Otherwise, include user headers. */
+#include "archive.h"
+#include "archive_entry.h"
+#endif
+
+/* How to mark functions that don't return. */
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+ (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
+#define __LA_NORETURN __attribute__((__noreturn__))
+#elif defined(_MSC_VER)
+#define __LA_NORETURN __declspec(noreturn)
+#else
+#define __LA_NORETURN
+#endif
+
+#endif /* !CPIO_PLATFORM_H_INCLUDED */
diff --git a/contrib/libarchive/cpio/test/test.h b/contrib/libarchive/cpio/test/test.h
new file mode 100644
index 000000000000..f8f3a4038b57
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2003-2017 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* Every test program should #include "test.h" as the first thing. */
+
+#define KNOWNREF "test_option_f.cpio.uu"
+#define ENVBASE "BSDCPIO" /* Prefix for environment variables. */
+#define PROGRAM "bsdcpio" /* Name of program being tested. */
+#define PROGRAM_ALIAS "cpio" /* Generic alias for program */
+#undef LIBRARY /* Not testing a library. */
+#undef EXTRA_DUMP /* How to dump extra data */
+#undef EXTRA_ERRNO /* How to dump errno */
+/* How to generate extra version info. */
+#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "")
+
+#include "test_common.h"
diff --git a/contrib/libarchive/cpio/test/test_0.c b/contrib/libarchive/cpio/test/test_0.c
new file mode 100644
index 000000000000..c09df5e137c4
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_0.c
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * This first test does basic sanity checks on the environment. For
+ * most of these, we just exit on failure.
+ */
+#if !defined(_WIN32) || defined(__CYGWIN__)
+#define DEV_NULL "/dev/null"
+#else
+#define DEV_NULL "NUL"
+#endif
+
+DEFINE_TEST(test_0)
+{
+ struct stat st;
+
+ failure("File %s does not exist?!", testprogfile);
+ if (!assertEqualInt(0, stat(testprogfile, &st))) {
+ fprintf(stderr,
+ "\nFile %s does not exist; aborting test.\n\n",
+ testprog);
+ exit(1);
+ }
+
+ failure("%s is not executable?!", testprogfile);
+ if (!assert((st.st_mode & 0111) != 0)) {
+ fprintf(stderr,
+ "\nFile %s not executable; aborting test.\n\n",
+ testprog);
+ exit(1);
+ }
+
+ /*
+ * Try to successfully run the program; this requires that
+ * we know some option that will succeed.
+ */
+ if (0 == systemf("%s --version >" DEV_NULL, testprog)) {
+ /* This worked. */
+ } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) {
+ /* This worked. */
+ } else {
+ failure("Unable to successfully run any of the following:\n"
+ " * %s --version\n"
+ " * %s -W version\n",
+ testprog, testprog);
+ assert(0);
+ }
+
+ /* TODO: Ensure that our reference files are available. */
+}
diff --git a/contrib/libarchive/cpio/test/test_basic.c b/contrib/libarchive/cpio/test/test_basic.c
new file mode 100644
index 000000000000..993d555b831c
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_basic.c
@@ -0,0 +1,239 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+static void
+verify_files(const char *msg)
+{
+ /*
+ * Verify unpacked files.
+ */
+
+ /* Regular file with 2 links. */
+ failure("%s", msg);
+ assertIsReg("file", 0644);
+ failure("%s", msg);
+ assertFileSize("file", 10);
+ failure("%s", msg);
+ assertFileNLinks("file", 2);
+
+ /* Another name for the same file. */
+ failure("%s", msg);
+ assertIsHardlink("linkfile", "file");
+
+ /* Symlink */
+ if (canSymlink())
+ assertIsSymlink("symlink", "file", 0);
+
+ /* Another file with 1 link and different permissions. */
+ failure("%s", msg);
+ assertIsReg("file2", 0777);
+ failure("%s", msg);
+ assertFileSize("file2", 10);
+ failure("%s", msg);
+ assertFileNLinks("file2", 1);
+
+ /* dir */
+ assertIsDir("dir", 0775);
+}
+
+static void
+basic_cpio(const char *target,
+ const char *pack_options,
+ const char *unpack_options,
+ const char *se, const char *se2)
+{
+ int r;
+
+ if (!assertMakeDir(target, 0775))
+ return;
+
+ /* Use the cpio program to create an archive. */
+ r = systemf("%s -R 1000:1000 -o %s < filelist >%s/archive 2>%s/pack.err",
+ testprog, pack_options, target, target);
+ failure("Error invoking %s -o %s", testprog, pack_options);
+ assertEqualInt(r, 0);
+
+ assertChdir(target);
+
+ /* Verify stderr. */
+ failure("Expected: %s, options=%s", se, pack_options);
+ assertTextFileContents(se, "pack.err");
+
+ /*
+ * Use cpio to unpack the archive into another directory.
+ */
+ r = systemf("%s -i %s< archive >unpack.out 2>unpack.err",
+ testprog, unpack_options);
+ failure("Error invoking %s -i %s", testprog, unpack_options);
+ assertEqualInt(r, 0);
+
+ /* Verify stderr. */
+ failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target);
+ assertTextFileContents(se2, "unpack.err");
+
+ verify_files(pack_options);
+
+ assertChdir("..");
+}
+
+static void
+passthrough(const char *target)
+{
+ int r;
+
+ if (!assertMakeDir(target, 0775))
+ return;
+
+ /*
+ * Use cpio passthrough mode to copy files to another directory.
+ */
+ r = systemf("%s -p %s <filelist >%s/stdout 2>%s/stderr",
+ testprog, target, target, target);
+ failure("Error invoking %s -p", testprog);
+ assertEqualInt(r, 0);
+
+ assertChdir(target);
+
+ /* Verify stderr. */
+ failure("Error invoking %s -p in dir %s",
+ testprog, target);
+ assertTextFileContents("1 block\n", "stderr");
+
+ verify_files("passthrough");
+ assertChdir("..");
+}
+
+DEFINE_TEST(test_basic)
+{
+ FILE *filelist;
+ const char *msg;
+ char result[1024];
+
+ assertUmask(0);
+
+ /*
+ * Create an assortment of files on disk.
+ */
+ filelist = fopen("filelist", "w");
+ memset(result, 0, sizeof(result));
+
+ /* File with 10 bytes content. */
+ assertMakeFile("file", 0644, "1234567890");
+ fprintf(filelist, "file\n");
+ if (is_LargeInode("file")) {
+ strncat(result,
+ "bsdcpio: file: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+
+ /* hardlink to above file. */
+ assertMakeHardlink("linkfile", "file");
+ fprintf(filelist, "linkfile\n");
+ if (is_LargeInode("linkfile")) {
+ strncat(result,
+ "bsdcpio: linkfile: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+
+ /* Symlink to above file. */
+ if (canSymlink()) {
+ assertMakeSymlink("symlink", "file", 0);
+ fprintf(filelist, "symlink\n");
+ if (is_LargeInode("symlink")) {
+ strncat(result,
+ "bsdcpio: symlink: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+ }
+
+ /* Another file with different permissions. */
+ assertMakeFile("file2", 0777, "1234567890");
+ fprintf(filelist, "file2\n");
+ if (is_LargeInode("file2")) {
+ strncat(result,
+ "bsdcpio: file2: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+
+ /* Directory. */
+ assertMakeDir("dir", 0775);
+ fprintf(filelist, "dir\n");
+ if (is_LargeInode("dir")) {
+ strncat(result,
+ "bsdcpio: dir: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result,
+ "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+ strncat(result, "2 blocks\n", sizeof(result) - strlen(result) -1);
+
+ /* All done. */
+ fclose(filelist);
+
+ assertUmask(022);
+
+ /* Archive/dearchive with a variety of options. */
+ msg = canSymlink() ? "2 blocks\n" : "1 block\n";
+ basic_cpio("copy", "", "", msg, msg);
+ basic_cpio("copy_odc", "--format=odc", "", msg, msg);
+ basic_cpio("copy_newc", "-H newc", "", result, "2 blocks\n");
+ basic_cpio("copy_cpio", "-H odc", "", msg, msg);
+ msg = "1 block\n";
+ basic_cpio("copy_bin", "-H bin", "", msg, msg);
+ msg = canSymlink() ? "9 blocks\n" : "8 blocks\n";
+ basic_cpio("copy_ustar", "-H ustar", "", msg, msg);
+
+ /* Copy in one step using -p */
+ passthrough("passthrough");
+}
diff --git a/contrib/libarchive/cpio/test/test_cmdline.c b/contrib/libarchive/cpio/test/test_cmdline.c
new file mode 100644
index 000000000000..f4e05ee58599
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_cmdline.c
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * Test the command-line parsing.
+ */
+
+DEFINE_TEST(test_cmdline)
+{
+ FILE *f;
+
+ /* Create an empty file. */
+ f = fopen("empty", "wb");
+ assert(f != NULL);
+ fclose(f);
+
+ failure("-Q is an invalid option on every cpio program I know of");
+ assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog));
+ assertEmptyFile("1.out");
+
+ failure("-f requires an argument");
+ assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog));
+ assertEmptyFile("2.out");
+
+ failure("-f requires an argument");
+ assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog));
+ assertEmptyFile("3.out");
+
+ failure("--format requires an argument");
+ assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog));
+ assertEmptyFile("4.out");
+
+ failure("--badopt is an invalid option");
+ assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog));
+ assertEmptyFile("5.out");
+
+ failure("--badopt is an invalid option");
+ assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog));
+ assertEmptyFile("6.out");
+
+ failure("--n is ambiguous");
+ assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog));
+ assertEmptyFile("7.out");
+
+ failure("--create forbids an argument");
+ assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog));
+ assertEmptyFile("8.out");
+
+ failure("-i with empty input should succeed");
+ assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog));
+ assertEmptyFile("9.out");
+
+ failure("-o with empty input should succeed");
+ assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog));
+
+ failure("-i -p is nonsense");
+ assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog));
+ assertEmptyFile("11.out");
+
+ failure("-p -i is nonsense");
+ assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog));
+ assertEmptyFile("12.out");
+
+ failure("-i -o is nonsense");
+ assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog));
+ assertEmptyFile("13.out");
+
+ failure("-o -i is nonsense");
+ assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog));
+ assertEmptyFile("14.out");
+
+ failure("-o -p is nonsense");
+ assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog));
+ assertEmptyFile("15.out");
+
+ failure("-p -o is nonsense");
+ assert(0 != systemf("%s -p -o <empty >16.out 2>16.err", testprog));
+ assertEmptyFile("16.out");
+
+ failure("-p with empty input should fail");
+ assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog));
+ assertEmptyFile("17.out");
+}
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.Z.uu b/contrib/libarchive/cpio/test/test_extract.cpio.Z.uu
new file mode 100644
index 000000000000..e520a341628f
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.Z.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.cpio.Z
+M'YV0,&X$'`B#!@P8,0XJC)$0A@T;!A'>J+%PHL*%%P_&D`%CAHP;!F7,B*C0
+M1L:+(LVD85,F!H`Q;]S0*2-S#H@W9D"H9!G#A8*!`@46U)A11L.'$6-8U+CT
+M8D.G'#V"A"&#!L6+)D\>3+FRC(R7,6?6O)ESIU>?0`EJ7<N6[=.V:V/,@$M%
+A2I`D3(I("<$7@-^_@`,+'DRXL.'#B!,K7LRXL>/'D!4#
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.bz2.uu b/contrib/libarchive/cpio/test/test_extract.cpio.bz2.uu
new file mode 100644
index 000000000000..228a95775b88
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.bz2.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.cpio.bz2
+M0EIH.3%!629365?=.4@``#G_@G*0(`#@`7^`(B04``LEC```!"``E`E(>I,H
+M::'J&@_4C3:@E$AD#0&@&@%"E;V/1!XIP>#C9T[41`4PQ1A`@S*4F&BD@B0T
+MBA$$-:\/@BQGNKU1G@%#`G+N0R%$JTHG(XBRB%1$V8F4#F_IWT=S4+ERVL(?
+40V!'@1L4+AO_B[DBG"A(*^Z<I```
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.grz.uu b/contrib/libarchive/cpio/test/test_extract.cpio.grz.uu
new file mode 100644
index 000000000000..19045a9ddeee
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.grz.uu
@@ -0,0 +1,7 @@
+begin 644 test_extract.cpio.grz
+M1U)::7!)20`"!#HI``(``*P-```&`0``"````&X````B%2.02C`PK`#__..F
+MI;8=99?N!6`:IQJ:XU/T"`W`B"?N/D9-0K6VN/D\.2>0,#J&)3G"\^YE?X_'
+M_K._F':0[`DL%IQ=<,Z-JH>V$S,?.[`&42C7]J^XQ@9OY!Z$!$^JLQPKZU[:
+/!M,+.$MY:Y(HS<<]U`&`
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.gz.uu b/contrib/libarchive/cpio/test/test_extract.cpio.gz.uu
new file mode 100644
index 000000000000..7ddccad64e5c
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.gz.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.cpio.gz
+M'XL("`5X<E```W1E<W1?97AT<F%C="YC<&EO`#,P-P!!`Q,#`T,#$#`$4F9F
+M(*ZYJ0&,-(#)&A@:&1@;F9L8&!F;@/EF!C!@9)R6F9-JR)"<GU>2FE=2K)"?
+MI@`6T>,R0+?$B$A+3$RQ6F*$88D1PA*"P!"[J#$2)R3(T=/'-4A149%AF`,`
+(305ZBP`"````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.lrz.uu b/contrib/libarchive/cpio/test/test_extract.cpio.lrz.uu
new file mode 100644
index 000000000000..563f7971040c
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.lrz.uu
@@ -0,0 +1,8 @@
+begin 664 test_extract.cpio.lrz
+M3%):20`&``(``````````%T````!`0```@$`$`,`````#@`#`````"\``QH`
+M&@````!W``$G`&4``#,``2(``0``#0$````U<-`Y!F$`MP$````8#=\$8#<1
+MR/BL39$D4M>["H7&@4%L/4*_(*VGB*YU>?RX.9]HL86'.A)H@Y;Z\^$?M^8_
+M!/-;62G.*7*A&A!_ENZ8$7]O-M7_.FTRC%BCGC95:6'9ZH3)QSCR4RX42P!`
+/-E>/7"L[:OY"/A924S4$
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.lz.uu b/contrib/libarchive/cpio/test/test_extract.cpio.lz.uu
new file mode 100644
index 000000000000..67e41e92f16c
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.lz.uu
@@ -0,0 +1,6 @@
+begin 664 test_extract.cpio.lz
+M3%I)4`$,`!@-WP1@-Q'(^*Q-D212U[L*A<:!06P]0K\@K:>(KG5Y_+@YGVBQ
+MA8<Z$FB#EOKSX1^WYC\$\UM9*<XI<J$:$'^B>;_>8N3MLP="$0SJ#QKYB?@8
+G]@'$$7\&W^T*+9?6B=?__M$G@$T%>HL``@```````($`````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.lz4.uu b/contrib/libarchive/cpio/test/test_extract.cpio.lz4.uu
new file mode 100644
index 000000000000..0adc7bbcc484
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.lz4.uu
@@ -0,0 +1,7 @@
+begin 644 test_extract.cpio.lz4
+M!")-&&1PN9$````A,#<"`&`P-#`P,3`!`&`Q,3`P-C8/`#0W-3`&```)``$&
+M`,$P,3(P,S(W-#`R,S01`!$V!@```@#Q!3(S9FEL93$`8V]N=&5N=',@;V8@
+M$@`A+@IC``AE`!\R90`4$#2#``YE`!TR90`6,F4`#P(`#@+H``P"`"<Q,Q(`
+=OU1204E,15(A(2$``0#'4````````````"BVD[$`
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.lzma.uu b/contrib/libarchive/cpio/test/test_extract.cpio.lzma.uu
new file mode 100644
index 000000000000..449403e9293b
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.lzma.uu
@@ -0,0 +1,6 @@
+begin 664 test_extract.cpio.lzma
+M70``@`#__________P`8#=\$8#<1R/BL39$D4M>["H7&@4%L/4*_(*VGB*YU
+M>?RX.9]HL86'.A)H@Y;Z\^$?M^8_!/-;62G.*7*A&A!_HGF_WF+D[;.+!OW3
+:T_2I)V(;K[FNL#'W%T+L;ATS`A*3__[1Z```
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.lzo.uu b/contrib/libarchive/cpio/test/test_extract.cpio.lzo.uu
new file mode 100644
index 000000000000..8ce87c798ce2
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.lzo.uu
@@ -0,0 +1,9 @@
+begin 664 test_extract.cpio.lzo
+MB4Q:3P`-"AH*$#`@8`E``04#```!``"!M%!R>-T`````$71E<W1?97AT<F%C
+M="YC<&EOOH$+9````@````"DIR,^[`HP-S`W,#<P,#0P,#$P8``#,3$P,#8V
+M>`$#-S4P,#`QE`!@`7`#"C`P,3(P,S(W-#`R,S2!`C:4`'````(R,V9I;&4Q
+M`&-O;G1E;G1S(&]F((8"+@HOD0$R(`:1`31J$#`P+I$!,B^1`3(HD`%L$3L,
+M`+P<+HH`,3,I1``(5%)!24Q%4B$A(0`@JP````$`````````````````````
+*````$0``````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.xz.uu b/contrib/libarchive/cpio/test/test_extract.cpio.xz.uu
new file mode 100644
index 000000000000..5c593cfebca2
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.xz.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.cpio.xz
+M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`'_`&%=`!@-WP1@-Q'(^*Q-D212
+MU[L*A<:!06P]0K\@K:>(KG5Y_+@YGVBQA8<Z$FB#EOKSX1^WYC\$\UM9*<XI
+M<J$:$'^B>;_>8N3MLXL&_=/3]*DG8ANON:ZP,?<70NQN'3"CP@``````J9FA
+=#1$]4L<``7V`!`````?M;4JQQ&?[`@`````$65H`
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract.cpio.zst.uu b/contrib/libarchive/cpio/test/test_extract.cpio.zst.uu
new file mode 100644
index 000000000000..5ec854b85d28
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract.cpio.zst.uu
@@ -0,0 +1,6 @@
+begin 644 test_extract.cpio.zst
+M*+4O_01090,`,@41%X")&@#'G6T\K16_MR)#=DK)5:.1,2J0HY2"!(1!`!7R
+M$(UB`2"*D41;J2UF&)<0!Y7X'TU<%W.\W^R]GO-WW^OO^QX0`%P<]30-!#U`
+?!KD!`#XP,_`U4`HT3+RF:#!7Y\V@R)5"7P"^;WEUK@``
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_Z.c b/contrib/libarchive/cpio/test/test_extract_cpio_Z.c
new file mode 100644
index 000000000000..257d70d04211
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_Z.c
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_Z)
+{
+ const char *reffile = "test_extract.cpio.Z";
+
+ extract_reference_file(reffile);
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_bz2.c b/contrib/libarchive/cpio/test/test_extract_cpio_bz2.c
new file mode 100644
index 000000000000..08fe1fe53468
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_bz2.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_bz2)
+{
+ const char *reffile = "test_extract.cpio.bz2";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canBzip2()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems bzip2 is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_grz.c b/contrib/libarchive/cpio/test/test_extract_cpio_grz.c
new file mode 100644
index 000000000000..969b30e44de5
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_grz.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_grz)
+{
+ const char *reffile = "test_extract.cpio.grz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canGrzip()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems grzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_gz.c b/contrib/libarchive/cpio/test/test_extract_cpio_gz.c
new file mode 100644
index 000000000000..16296146f87e
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_gz.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_gz)
+{
+ const char *reffile = "test_extract.cpio.gz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canGzip()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems gzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_lrz.c b/contrib/libarchive/cpio/test/test_extract_cpio_lrz.c
new file mode 100644
index 000000000000..7ef213f74aac
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_lrz.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_lrz)
+{
+ const char *reffile = "test_extract.cpio.lrz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLrzip()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems lrzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_lz.c b/contrib/libarchive/cpio/test/test_extract_cpio_lz.c
new file mode 100644
index 000000000000..bfdf87869b37
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_lz.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_lz)
+{
+ const char *reffile = "test_extract.cpio.lz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLzip()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems lzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_lz4.c b/contrib/libarchive/cpio/test/test_extract_cpio_lz4.c
new file mode 100644
index 000000000000..f8cf5f8fab0d
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_lz4.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012,2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_lz4)
+{
+ const char *reffile = "test_extract.cpio.lz4";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLz4()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems lz4 is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_lzma.c b/contrib/libarchive/cpio/test/test_extract_cpio_lzma.c
new file mode 100644
index 000000000000..81fc3c236ab5
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_lzma.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_lzma)
+{
+ const char *reffile = "test_extract.cpio.lzma";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLzma()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems lzma is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_lzo.c b/contrib/libarchive/cpio/test/test_extract_cpio_lzo.c
new file mode 100644
index 000000000000..d54d4f712374
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_lzo.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_lzo)
+{
+ const char *reffile = "test_extract.cpio.lzo";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLzop()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems lzop is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_xz.c b/contrib/libarchive/cpio/test/test_extract_cpio_xz.c
new file mode 100644
index 000000000000..faeea202e050
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_xz.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_xz)
+{
+ const char *reffile = "test_extract.cpio.xz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canXz()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems xz is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_extract_cpio_zstd.c b/contrib/libarchive/cpio/test/test_extract_cpio_zstd.c
new file mode 100644
index 000000000000..31421c3b60d7
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_extract_cpio_zstd.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_extract_cpio_zstd)
+{
+ const char *reffile = "test_extract.cpio.zst";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canZstd()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems zstd is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_format_newc.c b/contrib/libarchive/cpio/test/test_format_newc.c
new file mode 100644
index 000000000000..ee0087d4ca94
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_format_newc.c
@@ -0,0 +1,357 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/* Number of bytes needed to pad 'n' to multiple of 'block', assuming
+ * that 'block' is a power of two. This trick can be more easily
+ * remembered as -n & (block - 1), but many compilers quite reasonably
+ * warn about "-n" when n is an unsigned value. (~(n) + 1) is the
+ * same thing, but written in a way that won't offend anyone. */
+#define PAD(n, block) ((~(n) + 1) & ((block) - 1))
+
+static int
+is_hex(const char *p, size_t l)
+{
+ while (l > 0) {
+ if ((*p >= '0' && *p <= '9')
+ || (*p >= 'a' && *p <= 'f')
+ || (*p >= 'A' && *p <= 'F'))
+ {
+ --l;
+ ++p;
+ } else
+ return (0);
+
+ }
+ return (1);
+}
+
+/* Convert up to 8 hex characters to unsigned 32-bit decimal integer */
+static uint32_t
+from_hex(const char *p, size_t l)
+{
+ uint32_t r = 0;
+
+ while (l > 0) {
+ r *= 16;
+ if (*p >= 'a' && *p <= 'f')
+ r += *p + 10 - 'a';
+ else if (*p >= 'A' && *p <= 'F')
+ r += *p + 10 - 'A';
+ else
+ r += *p - '0';
+ --l;
+ ++p;
+ }
+ return (r);
+}
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+static int
+nlinks(const char *p)
+{
+ struct stat st;
+ assertEqualInt(0, stat(p, &st));
+ return st.st_nlink;
+}
+#endif
+
+DEFINE_TEST(test_format_newc)
+{
+ FILE *list;
+ int r;
+ uint32_t devmajor, devminor, ino, gid, uid;
+ time_t t, t2, now;
+ char *p, *e;
+ size_t s;
+ uint64_t fs, ns;
+ char result[1024];
+
+ assertUmask(0);
+
+#if !defined(_WIN32)
+ uid = getuid();
+#endif
+
+ /*
+ * Create an assortment of files.
+ * TODO: Extend this to cover more filetypes.
+ */
+ list = fopen("list", "w");
+
+ /* "file1" */
+ assertMakeFile("file1", 0644, "1234567890");
+ fprintf(list, "file1\n");
+
+ /* "hardlink" */
+ assertMakeHardlink("hardlink", "file1");
+ fprintf(list, "hardlink\n");
+
+ /* Another hardlink, but this one won't be archived. */
+ assertMakeHardlink("hardlink2", "file1");
+
+ /* "symlink" */
+ if (canSymlink()) {
+ assertMakeSymlink("symlink", "file1", 0);
+ fprintf(list, "symlink\n");
+ }
+
+ /* "dir" */
+ assertMakeDir("dir", 0775);
+ fprintf(list, "dir\n");
+
+ /* Setup result message. */
+ memset(result, 0, sizeof(result));
+ if (is_LargeInode("file1")) {
+ strncat(result,
+ "bsdcpio: file1: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result, strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result, "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+ if (canSymlink() && is_LargeInode("symlink")) {
+ strncat(result,
+ "bsdcpio: symlink: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result, strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result, "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+ if (is_LargeInode("dir")) {
+ strncat(result,
+ "bsdcpio: dir: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result, strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result, "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+ if (is_LargeInode("hardlink")) {
+ strncat(result,
+ "bsdcpio: hardlink: large inode number truncated: ",
+ sizeof(result) - strlen(result) -1);
+ strncat(result, strerror(ERANGE),
+ sizeof(result) - strlen(result) -1);
+ strncat(result, "\n",
+ sizeof(result) - strlen(result) -1);
+ }
+
+ /* Record some facts about what we just created: */
+ now = time(NULL); /* They were all created w/in last two seconds. */
+
+ /* Use the cpio program to create an archive. */
+ fclose(list);
+ r = systemf("%s -o --format=newc <list >newc.out 2>newc.err",
+ testprog);
+ if (!assertEqualInt(r, 0))
+ return;
+
+ /* Verify that nothing went to stderr. */
+ if (canSymlink()) {
+ strncat(result, "2 blocks\n", sizeof(result) - strlen(result) -1);
+ } else {
+ strncat(result, "1 block\n", sizeof(result) - strlen(result) -1);
+ }
+ assertTextFileContents(result, "newc.err");
+
+ /* Verify that stdout is a well-formed cpio file in "newc" format. */
+ p = slurpfile(&s, "newc.out");
+ assertEqualInt(s, canSymlink() ? 1024 : 512);
+ e = p;
+
+ /*
+ * Some of these assertions could be stronger, but it's
+ * a little tricky because they depend on the local environment.
+ */
+
+ /* First entry is "file1" */
+ assert(is_hex(e, 110)); /* Entire header is octal digits. */
+ assertEqualMem(e + 0, "070701", 6); /* Magic */
+ ino = from_hex(e + 6, 8); /* ino */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Group members bits and others bits do not work. */
+ assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */
+#else
+ assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */
+#endif
+#if defined(_WIN32)
+ uid = from_hex(e + 22, 8);
+#else
+ assertEqualInt(from_hex(e + 22, 8), uid); /* uid */
+#endif
+ gid = from_hex(e + 30, 8); /* gid */
+ assertEqualMem(e + 38, "00000003", 8); /* nlink */
+ t = from_hex(e + 46, 8); /* mtime */
+ failure("t=%#08jx now=%#08jx=%jd", (intmax_t)t, (intmax_t)now,
+ (intmax_t)now);
+ assert(t <= now); /* File wasn't created in future. */
+ failure("t=%#08jx now - 2=%#08jx=%jd", (intmax_t)t, (intmax_t)now - 2,
+ (intmax_t)now - 2);
+ assert(t >= now - 2); /* File was created w/in last 2 secs. */
+ failure("newc format stores body only with last appearance of a link\n"
+ " first appearance should be empty, so this file size\n"
+ " field should be zero");
+ assertEqualInt(0, from_hex(e + 54, 8)); /* File size */
+ fs = (uint64_t)from_hex(e + 54, 8);
+ fs += PAD(fs, 4);
+ devmajor = from_hex(e + 62, 8); /* devmajor */
+ devminor = from_hex(e + 70, 8); /* devminor */
+ assert(is_hex(e + 78, 8)); /* rdevmajor */
+ assert(is_hex(e + 86, 8)); /* rdevminor */
+ assertEqualMem(e + 94, "00000006", 8); /* Name size */
+ ns = (uint64_t)from_hex(e + 94, 8);
+ ns += PAD(ns + 2, 4);
+ assertEqualInt(0, from_hex(e + 102, 8)); /* check field */
+ assertEqualMem(e + 110, "file1\0", 6); /* Name contents */
+ /* Since there's another link, no file contents here. */
+ /* But add in file size so that an error here doesn't cascade. */
+ e += 110 + fs + ns;
+
+ if (canSymlink()) {
+ /* "symlink" pointing to "file1" */
+ assert(is_hex(e, 110));
+ assertEqualMem(e + 0, "070701", 6); /* Magic */
+ assert(is_hex(e + 6, 8)); /* ino */
+#if defined(_WIN32) && !defined(CYGWIN)
+ /* Mode: Group members bits and others bits do not work. */
+ assertEqualInt(0xa180, from_hex(e + 14, 8) & 0xffc0);
+#else
+ assertEqualInt(0xa1ff, from_hex(e + 14, 8)); /* Mode */
+#endif
+ assertEqualInt(from_hex(e + 22, 8), uid); /* uid */
+ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
+ assertEqualMem(e + 38, "00000001", 8); /* nlink */
+ t2 = from_hex(e + 46, 8); /* mtime */
+ failure("First entry created at t=%#08jx this entry created"
+ " at t2=%#08jx", (intmax_t)t, (intmax_t)t2);
+ assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
+ assertEqualMem(e + 54, "00000005", 8); /* File size */
+ fs = (uint64_t)from_hex(e + 54, 8);
+ fs += PAD(fs, 4);
+ assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */
+ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */
+ assert(is_hex(e + 78, 8)); /* rdevmajor */
+ assert(is_hex(e + 86, 8)); /* rdevminor */
+ assertEqualMem(e + 94, "00000008", 8); /* Name size */
+ ns = (uint64_t)from_hex(e + 94, 8);
+ ns += PAD(ns + 2, 4);
+ assertEqualInt(0, from_hex(e + 102, 8)); /* check field */
+ assertEqualMem(e + 110, "symlink\0\0\0", 10); /* Name contents */
+ assertEqualMem(e + 110 + ns, "file1\0\0\0", 8); /* symlink target */
+ e += 110 + fs + ns;
+ }
+
+ /* "dir" */
+ assert(is_hex(e, 110));
+ assertEqualMem(e + 0, "070701", 6); /* Magic */
+ assert(is_hex(e + 6, 8)); /* ino */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Group members bits and others bits do not work. */
+ assertEqualInt(0x41c0, from_hex(e + 14, 8) & 0xffc0); /* Mode */
+#else
+ /* Mode: sgid bit sometimes propagates from parent dirs, ignore it. */
+ assertEqualInt(040775, from_hex(e + 14, 8) & ~02000);
+#endif
+ assertEqualInt(uid, from_hex(e + 22, 8)); /* uid */
+ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ assertEqualInt(nlinks("dir"), from_hex(e + 38, 8)); /* nlinks */
+#endif
+ t2 = from_hex(e + 46, 8); /* mtime */
+ failure("First entry created at t=%#08jx this entry created at"
+ "t2=%#08jx", (intmax_t)t, (intmax_t)t2);
+ assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
+ assertEqualMem(e + 54, "00000000", 8); /* File size */
+ fs = (uint64_t)from_hex(e + 54, 8);
+ fs += PAD(fs, 4);
+ assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */
+ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */
+ assert(is_hex(e + 78, 8)); /* rdevmajor */
+ assert(is_hex(e + 86, 8)); /* rdevminor */
+ assertEqualMem(e + 94, "00000004", 8); /* Name size */
+ ns = (uint64_t)from_hex(e + 94, 8);
+ ns += PAD(ns + 2, 4);
+ assertEqualInt(0, from_hex(e + 102, 8)); /* check field */
+ assertEqualMem(e + 110, "dir\0\0\0", 6); /* Name contents */
+ e += 110 + fs + ns;
+
+ /* Hardlink identical to "file1" */
+ /* Since we only wrote two of the three links to this
+ * file, this link should get deferred by the hardlink logic. */
+ assert(is_hex(e, 110));
+ assertEqualMem(e + 0, "070701", 6); /* Magic */
+ failure("If these aren't the same, then the hardlink detection failed to match them.");
+ assertEqualInt(ino, from_hex(e + 6, 8)); /* ino */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Group members bits and others bits do not work. */
+ assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */
+#else
+ assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */
+#endif
+ assertEqualInt(from_hex(e + 22, 8), uid); /* uid */
+ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
+ assertEqualMem(e + 38, "00000003", 8); /* nlink */
+ t2 = from_hex(e + 46, 8); /* mtime */
+ failure("First entry created at t=%#08jx this entry created at"
+ "t2=%#08jx", (intmax_t)t, (intmax_t)t2);
+ assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
+ assertEqualInt(10, from_hex(e + 54, 8)); /* File size */
+ fs = (uint64_t)from_hex(e + 54, 8);
+ fs += PAD(fs, 4);
+ assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */
+ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */
+ assert(is_hex(e + 78, 8)); /* rdevmajor */
+ assert(is_hex(e + 86, 8)); /* rdevminor */
+ assertEqualMem(e + 94, "00000009", 8); /* Name size */
+ ns = (uint64_t)from_hex(e + 94, 8);
+ ns += PAD(ns + 2, 4);
+ assertEqualInt(0, from_hex(e + 102, 8)); /* check field */
+ assertEqualMem(e + 110, "hardlink\0\0", 10); /* Name contents */
+ assertEqualMem(e + 110 + ns, "1234567890\0\0", 12); /* File contents */
+ e += 110 + ns + fs;
+
+ /* Last entry is end-of-archive marker. */
+ assert(is_hex(e, 110));
+ assertEqualMem(e + 0, "070701", 6); /* Magic */
+ assertEqualMem(e + 8, "00000000", 8); /* ino */
+ assertEqualMem(e + 14, "00000000", 8); /* mode */
+ assertEqualMem(e + 22, "00000000", 8); /* uid */
+ assertEqualMem(e + 30, "00000000", 8); /* gid */
+ assertEqualMem(e + 38, "00000001", 8); /* nlink */
+ assertEqualMem(e + 46, "00000000", 8); /* mtime */
+ assertEqualMem(e + 54, "00000000", 8); /* size */
+ assertEqualMem(e + 62, "00000000", 8); /* devmajor */
+ assertEqualMem(e + 70, "00000000", 8); /* devminor */
+ assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */
+ assertEqualMem(e + 86, "00000000", 8); /* rdevminor */
+ assertEqualInt(11, from_hex(e + 94, 8)); /* name size */
+ assertEqualMem(e + 102, "00000000", 8); /* check field */
+ assertEqualMem(e + 110, "TRAILER!!!\0\0", 12); /* Name */
+
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat.c b/contrib/libarchive/cpio/test/test_gcpio_compat.c
new file mode 100644
index 000000000000..82c71ec3cd21
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat.c
@@ -0,0 +1,107 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+static void
+unpack_test(const char *from, const char *options, const char *se)
+{
+ int r;
+
+ /* Create a work dir named after the file we're unpacking. */
+ assertMakeDir(from, 0775);
+ assertChdir(from);
+
+ /*
+ * Use cpio to unpack the sample archive
+ */
+ extract_reference_file(from);
+ r = systemf("%s -i %s < %s >unpack.out 2>unpack.err",
+ testprog, options, from);
+ failure("Error invoking %s -i %s < %s",
+ testprog, options, from);
+ assertEqualInt(r, 0);
+
+ /* Verify that nothing went to stderr. */
+ if (canSymlink()) {
+ failure("Error invoking %s -i %s < %s",
+ testprog, options, from);
+ assertTextFileContents(se, "unpack.err");
+ }
+
+ /*
+ * Verify unpacked files.
+ */
+
+ /* Regular file with 2 links. */
+ assertIsReg("file", 0644);
+ failure("%s", from);
+ assertFileSize("file", 10);
+ assertFileSize("linkfile", 10);
+ failure("%s", from);
+ assertFileNLinks("file", 2);
+
+ /* Another name for the same file. */
+ failure("%s", from);
+ assertIsHardlink("linkfile", "file");
+ assertFileSize("file", 10);
+ assertFileSize("linkfile", 10);
+
+ /* Symlink */
+ if (canSymlink())
+ assertIsSymlink("symlink", "file", 0);
+
+ /* dir */
+ assertIsDir("dir", 0775);
+
+ assertChdir("..");
+}
+
+DEFINE_TEST(test_gcpio_compat)
+{
+ assertUmask(0);
+
+ /* Dearchive sample files with a variety of options. */
+ if (canSymlink()) {
+ unpack_test("test_gcpio_compat_ref.bin",
+ "--no-preserve-owner", "1 block\n");
+ unpack_test("test_gcpio_compat_ref.crc",
+ "--no-preserve-owner", "2 blocks\n");
+ unpack_test("test_gcpio_compat_ref.newc",
+ "--no-preserve-owner", "2 blocks\n");
+ /* gcpio-2.9 only reads 6 blocks here */
+ unpack_test("test_gcpio_compat_ref.ustar",
+ "--no-preserve-owner", "7 blocks\n");
+ } else {
+ unpack_test("test_gcpio_compat_ref_nosym.bin",
+ "--no-preserve-owner", "1 block\n");
+ unpack_test("test_gcpio_compat_ref_nosym.crc",
+ "--no-preserve-owner", "2 blocks\n");
+ unpack_test("test_gcpio_compat_ref_nosym.newc",
+ "--no-preserve-owner", "2 blocks\n");
+ /* gcpio-2.9 only reads 6 blocks here */
+ unpack_test("test_gcpio_compat_ref_nosym.ustar",
+ "--no-preserve-owner", "7 blocks\n");
+ }
+}
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref.bin.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.bin.uu
new file mode 100644
index 000000000000..f2ffad975644
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.bin.uu
@@ -0,0 +1,15 @@
+begin 644 test_gcpio_compat_ref.bin
+MQW%9`*IWI('H`^@#`@````U'=YD%````"@!F:6QE```Q,C,T-38W.#D*QW%9
+M`*IWI('H`^@#`@````U'=YD)````"@!L:6YK9FEL90``,3(S-#4V-S@Y"L=Q
+M60"K=^VAZ`/H`P$````-1X29"`````0`<WEM;&EN:P!F:6QEQW%9`*YW_4'H
+M`^@#`@````U'A9D$``````!D:7(`QW$``````````````0`````````+````
+M``!44D%)3$52(2$A````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref.crc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.crc.uu
new file mode 100644
index 000000000000..56ba62c9ed1f
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.crc.uu
@@ -0,0 +1,26 @@
+begin 644 test_gcpio_compat_ref.crc
+M,#<P-S`R,#`S,S<W86$P,#`P.#%A-#`P,#`P,V4X,#`P,#`S93@P,#`P,#`P
+M,C0W,&0Y.3<W,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4Y,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`U,#`P,#`P,#!F:6QE```P-S`W,#(P,#,S-S=A83`P,#`X
+M,6$T,#`P,#`S93@P,#`P,#-E.#`P,#`P,#`R-#<P9#DY-S<P,#`P,#`P83`P
+M,#`P,#`P,#`P,#`P-3DP,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#DP,#`P,#%E
+M-VQI;FMF:6QE```Q,C,T-38W.#D*```P-S`W,#(P,#,S-S=A8C`P,#!A,65D
+M,#`P,#`S93@P,#`P,#-E.#`P,#`P,#`Q-#<P9#DY.#0P,#`P,#`P-#`P,#`P
+M,#`P,#`P,#`P-3DP,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#@P,#`P,#`P,'-Y
+M;6QI;FL```!F:6QE,#<P-S`R,#`S,S<W864P,#`P-#%F9#`P,#`P,V4X,#`P
+M,#`S93@P,#`P,#`P,C0W,&0Y.3@U,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4Y
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`T,#`P,#`P,#!D:7(````P-S`W,#(P
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`Q,#`P,#`P
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,&(P,#`P,#`P,%1204E,15(A(2$`````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+B````````````````````````````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref.newc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.newc.uu
new file mode 100644
index 000000000000..449c083c311c
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.newc.uu
@@ -0,0 +1,26 @@
+begin 644 test_gcpio_compat_ref.newc
+M,#<P-S`Q,#`S,S<W86$P,#`P.#%A-#`P,#`P,V4X,#`P,#`S93@P,#`P,#`P
+M,C0W,&0Y.3<W,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4Y,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`U,#`P,#`P,#!F:6QE```P-S`W,#$P,#,S-S=A83`P,#`X
+M,6$T,#`P,#`S93@P,#`P,#-E.#`P,#`P,#`R-#<P9#DY-S<P,#`P,#`P83`P
+M,#`P,#`P,#`P,#`P-3DP,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#DP,#`P,#`P
+M,&QI;FMF:6QE```Q,C,T-38W.#D*```P-S`W,#$P,#,S-S=A8C`P,#!A,65D
+M,#`P,#`S93@P,#`P,#-E.#`P,#`P,#`Q-#<P9#DY.#0P,#`P,#`P-#`P,#`P
+M,#`P,#`P,#`P-3DP,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#@P,#`P,#`P,'-Y
+M;6QI;FL```!F:6QE,#<P-S`Q,#`S,S<W864P,#`P-#%F9#`P,#`P,V4X,#`P
+M,#`S93@P,#`P,#`P,C0W,&0Y.3@U,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4Y
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`T,#`P,#`P,#!D:7(````P-S`W,#$P
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`Q,#`P,#`P
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,&(P,#`P,#`P,%1204E,15(A(2$`````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+B````````````````````````````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref.ustar.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.ustar.uu
new file mode 100644
index 000000000000..2f6a44057eac
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.ustar.uu
@@ -0,0 +1,83 @@
+begin 644 test_gcpio_compat_ref.ustar
+M9FEL90``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#`V-#0`,#`P,3<U,``P,#`Q-S4P`#`P,#`P,#`P,#$R
+M`#$P-S`S,S$T-38W`#`P,3$S-C,`,```````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
+M````````````````````````````````````=&EM````````````````````
+M```````````````````P,#`P,#`P`#`P,#`P,#``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````Q,C,T-38W.#D*````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````&QI;FMF:6QE````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`P-C0T`#`P,#$W-3``,#`P,3<U,``P,#`P,#`P,#`P,``Q,#<P,S,Q-#4V
+M-P`P,#$S,#<W`#%F:6QE````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#!T:6T`````````````````
+M`````````````````````'1I;0``````````````````````````````````
+M````,#`P,#`P,``P,#`P,#`P````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````<WEM;&EN:P``````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#`W-34`,#`P,3<U,``P,#`Q-S4P`#`P,#`P
+M,#`P,#`P`#$P-S`S,S$T-C`T`#`P,3(W-C0`,F9I;&4`````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,'1I;0``````````````````````````````````````=&EM````````````
+M```````````````````````````P,#`P,#`P`#`P,#`P,#``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````!D:7(O````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````,#`P,#<W-0`P,#`Q
+M-S4P`#`P,#$W-3``,#`P,#`P,#`P,#``,3`W,#,S,30V,#4`,#`Q,3,P,0`U
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````'5S=&%R`#`P=&EM````````````````````````````````
+M``````!T:6T``````````````````````````````````````#`P,#`P,#``
+M,#`P,#`P,```````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+=````````````````````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu
new file mode 100644
index 000000000000..a3e87a7167ed
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu
@@ -0,0 +1,15 @@
+begin 644 test_gcpio_compat_ref_nosym.bin
+MQW%4`-[Z_4'H`^@#`@`VNZU*NQX$``````!D:7(`QW%4`-SZI('H`^@#`@`G
+MNZU*NQX%````"@!F:6QE```Q,C,T-38W.#D*QW%4`-SZI('H`^@#`@`GNZU*
+MNQX)````"@!L:6YK9FEL90``,3(S-#4V-S@Y"L=Q``````````````$`````
+M````"P``````5%)!24Q%4B$A(0``````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu
new file mode 100644
index 000000000000..38ba9fe1431d
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu
@@ -0,0 +1,15 @@
+begin 644 test_gcpio_compat_ref_nosym.crc
+M,#<P-S`R,#`U-D9!1$4P,#`P-#%&1#`P,#`P,T4X,#`P,#`S13@P,#`P,#`P
+M,C1!040Q14)",#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4T,#`P,#`P0D(P,35"
+M,#`S-C`P,#`P,#`T,#`P,#`P,#!D:7(````P-S`W,#(P,#4V1D%$0S`P,#`X
+M,4$T,#`P,#`S13@P,#`P,#-%.#`P,#`P,#`R-$%!1#%%0D(P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P-30P,#`P,#!"0C`Q-4(P,#(W,#`P,#`P,#4P,#`P,#`P
+M,&9I;&4``#`W,#<P,C`P-39&041#,#`P,#@Q030P,#`P,#-%.#`P,#`P,T4X
+M,#`P,#`P,#(T04%$,45"0C`P,#`P,#!!,#`P,#`P,#`P,#`P,#`U-#`P,#`P
+M,$)",#$U0C`P,C<P,#`P,#`P.3`P,#`P,44W;&EN:V9I;&4``#$R,S0U-C<X
+M.0H``#`W,#<P,C`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#$P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P,#`P0C`P,#`P,#`P5%)!24Q%4B$A(0``````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.newc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.newc.uu
new file mode 100644
index 000000000000..24049641f7f5
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.newc.uu
@@ -0,0 +1,15 @@
+begin 644 test_gcpio_compat_ref_nosym.newc
+M,#<P-S`Q,#`U-D9!1$4P,#`P-#%&1#`P,#`P,T4X,#`P,#`S13@P,#`P,#`P
+M,C1!040Q14)",#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4T,#`P,#`P0D(P,35"
+M,#`S-C`P,#`P,#`T,#`P,#`P,#!D:7(````P-S`W,#$P,#4V1D%$0S`P,#`X
+M,4$T,#`P,#`S13@P,#`P,#-%.#`P,#`P,#`R-$%!1#%%0D(P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P-30P,#`P,#!"0C`Q-4(P,#(W,#`P,#`P,#4P,#`P,#`P
+M,&9I;&4``#`W,#<P,3`P-39&041#,#`P,#@Q030P,#`P,#-%.#`P,#`P,T4X
+M,#`P,#`P,#(T04%$,45"0C`P,#`P,#!!,#`P,#`P,#`P,#`P,#`U-#`P,#`P
+M,$)",#$U0C`P,C<P,#`P,#`P.3`P,#`P,#`P;&EN:V9I;&4``#$R,S0U-C<X
+M.0H``#`W,#<P,3`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#$P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P,#`P0C`P,#`P,#`P5%)!24Q%4B$A(0``````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.ustar.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.ustar.uu
new file mode 100644
index 000000000000..5f9fcbe6950e
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.ustar.uu
@@ -0,0 +1,72 @@
+begin 644 test_gcpio_compat_ref_nosym.ustar
+M9&ER+P``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#`W-S4`,#`P,3<U,``P,#`Q-S4P`#`P,#`P,#`P,#`P
+M`#$Q,C4S,C$W,C<S`#`P,3$S-3$`-0``````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
+M````````````````````````````````````=&EM````````````````````
+M```````````````````P,#`P,C<S`#8V,#`P-C8`````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````!F:6QE````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````,#`P,#8T-``P,#`Q-S4P`#`P
+M,#$W-3``,#`P,#`P,#`P,3(`,3$R-3,R,3<R-S,`,#`Q,30R,P`P````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````'5S=&%R`#`P=&EM``````````````````````````````````````!T
+M:6T``````````````````````````````````````#`P,#`R-S,`-C8P,#`T
+M-P``````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````#$R,S0U-C<X.0H`
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````;&EN:V9I;&4`````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#`V-#0`,#`P,3<U,``P,#`Q-S4P`#`P,#`P
+M,#`P,#`P`#$Q,C4S,C$W,C<S`#`P,3,Q,S<`,69I;&4`````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,'1I;0``````````````````````````````````````=&EM````````````
+M```````````````````````````P,#`P,C<S`#8V,#`P-#<`````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+,````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_missing_file.c b/contrib/libarchive/cpio/test/test_missing_file.c
new file mode 100644
index 000000000000..784d53cfe141
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_missing_file.c
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 2016 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_missing_file)
+{
+ int r;
+
+ assertMakeFile("file1", 0644, "file1");
+ assertMakeFile("file2", 0644, "file2");
+
+ assertMakeFile("filelist1", 0644, "file1\nfile2\n");
+ r = systemf("%s -o <filelist1 >stdout1 2>stderr1", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "stderr1");
+
+ assertMakeFile("filelist2", 0644, "file1\nfile2\nfile3\n");
+ r = systemf("%s -o <filelist2 >stdout2 2>stderr2", testprog);
+ assert(r != 0);
+
+ assertMakeFile("filelist3", 0644, "");
+ r = systemf("%s -o <filelist3 >stdout3 2>stderr3", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "stderr3");
+
+ assertMakeFile("filelist4", 0644, "file3\n");
+ r = systemf("%s -o <filelist4 >stdout4 2>stderr4", testprog);
+ assert(r != 0);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_0.c b/contrib/libarchive/cpio/test/test_option_0.c
new file mode 100644
index 000000000000..fbe6f7ac4a85
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_0.c
@@ -0,0 +1,91 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_0)
+{
+ FILE *filelist;
+ int r;
+
+ assertUmask(0);
+
+ /* Create a few files. */
+ assertMakeFile("file1", 0644, "1234567890");
+ assertMakeFile("file2", 0644, "1234567890");
+ assertMakeFile("file3", 0644, "1234567890");
+ assertMakeFile("file4", 0644, "1234567890");
+
+ /* Create a file list of filenames with varying end-of-line. */
+ filelist = fopen("filelist", "wb");
+ assertEqualInt(fwrite("file1\x0a", 1, 6, filelist), 6);
+ assertEqualInt(fwrite("file2\x0d", 1, 6, filelist), 6);
+ assertEqualInt(fwrite("file3\x0a\x0d", 1, 7, filelist), 7);
+ assertEqualInt(fwrite("file4", 1, 5, filelist), 5);
+ fclose(filelist);
+
+ /* Create a file list of null-delimited names. */
+ filelist = fopen("filelistNull", "wb");
+ assertEqualInt(fwrite("file1\0", 1, 6, filelist), 6);
+ assertEqualInt(fwrite("file2\0", 1, 6, filelist), 6);
+ assertEqualInt(fwrite("file3\0", 1, 6, filelist), 6);
+ assertEqualInt(fwrite("file4", 1, 5, filelist), 5);
+ fclose(filelist);
+
+ assertUmask(022);
+
+ /* Pack up using the file list with text line endings. */
+ r = systemf("%s -o < filelist > archive 2> stderr1.txt", testprog);
+ assertEqualInt(r, 0);
+
+ /* Extract into a new dir. */
+ assertMakeDir("copy", 0775);
+ assertChdir("copy");
+ r = systemf("%s -i < ../archive > stdout3.txt 2> stderr3.txt", testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify the files. */
+ assertIsReg("file1", 0644);
+ assertIsReg("file2", 0644);
+ assertIsReg("file3", 0644);
+ assertIsReg("file4", 0644);
+
+ assertChdir("..");
+
+ /* Pack up using the file list with nulls. */
+ r = systemf("%s -o0 < filelistNull > archiveNull 2> stderr2.txt", testprog);
+ assertEqualInt(r, 0);
+
+ /* Extract into a new dir. */
+ assertMakeDir("copyNull", 0775);
+ assertChdir("copyNull");
+ r = systemf("%s -i < ../archiveNull > stdout4.txt 2> stderr4.txt", testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify the files. */
+ assertIsReg("file1", 0644);
+ assertIsReg("file2", 0644);
+ assertIsReg("file3", 0644);
+ assertIsReg("file4", 0644);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_B_upper.c b/contrib/libarchive/cpio/test/test_option_B_upper.c
new file mode 100644
index 000000000000..79dc91efb5ba
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_B_upper.c
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_B_upper)
+{
+ struct stat st;
+ int r;
+
+ /*
+ * Create a file on disk.
+ */
+ assertMakeFile("file", 0644, NULL);
+
+ /* Create an archive without -B; this should be 512 bytes. */
+ r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "small.err");
+ assertEqualInt(0, stat("small.cpio", &st));
+ assertEqualInt(512, st.st_size);
+
+ /* Create an archive with -B; this should be 5120 bytes. */
+ r = systemf("echo file | %s -oB > large.cpio 2>large.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "large.err");
+ assertEqualInt(0, stat("large.cpio", &st));
+ assertEqualInt(5120, st.st_size);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_C_upper.c b/contrib/libarchive/cpio/test/test_option_C_upper.c
new file mode 100644
index 000000000000..f9fd7e159339
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_C_upper.c
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_C_upper)
+{
+ int r;
+
+ /*
+ * Create a file on disk.
+ */
+ assertMakeFile("file", 0644, NULL);
+
+ /* Create an archive without -C; this should be 512 bytes. */
+ r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "small.err");
+ assertFileSize("small.cpio", 512);
+
+ /* Create an archive with -C 513; this should be 513 bytes. */
+ r = systemf("echo file | %s -o -C 513 > 513.cpio 2>513.err",
+ testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "513.err");
+ assertFileSize("513.cpio", 513);
+
+ /* Create an archive with -C 12345; this should be 12345 bytes. */
+ r = systemf("echo file | %s -o -C12345 > 12345.cpio 2>12345.err",
+ testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "12345.err");
+ assertFileSize("12345.cpio", 12345);
+
+ /* Create an archive with invalid -C request */
+ assert(0 != systemf("echo file | %s -o -C > bad.cpio 2>bad.err",
+ testprog));
+ assertEmptyFile("bad.cpio");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_J_upper.c b/contrib/libarchive/cpio/test/test_option_J_upper.c
new file mode 100644
index 000000000000..f76d3b236913
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_J_upper.c
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_J_upper)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with xz compression. */
+ r = systemf("echo f | %s -o -J >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without xz support");
+ free(p);
+ return;
+ }
+ failure("-J option is broken");
+ assertEqualInt(r, 0);
+ goto done;
+ }
+ free(p);
+ /* Check that the archive file has an xz signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\3757zXZ", 5);
+done:
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_L_upper.c b/contrib/libarchive/cpio/test/test_option_L_upper.c
new file mode 100644
index 000000000000..b6fb713f110f
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_L_upper.c
@@ -0,0 +1,104 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/* This is a little pointless, as Windows doesn't support symlinks
+ * (except for the seriously crippled CreateSymbolicLink API) so these
+ * tests won't run on Windows. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define CAT "type"
+#define SEP "\\"
+#else
+#define CAT "cat"
+#define SEP "/"
+#endif
+
+DEFINE_TEST(test_option_L_upper)
+{
+ FILE *filelist;
+ int r;
+
+ if (!canSymlink()) {
+ skipping("Symlink tests");
+ return;
+ }
+
+ filelist = fopen("filelist", "w");
+
+ /* Create a file and a symlink to the file. */
+ assertMakeFile("file", 0644, "1234567890");
+ fprintf(filelist, "file\n");
+
+ /* Symlink to above file. */
+ assertMakeSymlink("symlink", "file", 0);
+ fprintf(filelist, "symlink\n");
+
+ fclose(filelist);
+
+ r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "copy.err");
+
+ failure("Regular -p without -L should preserve symlinks.");
+ assertIsSymlink("copy/symlink", NULL, 0);
+
+ r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog);
+ assertEqualInt(r, 0);
+ assertEmptyFile("copy-L.out");
+ assertTextFileContents("1 block\n", "copy-L.err");
+ failure("-pdL should dereference symlinks and turn them into files.");
+ assertIsReg("copy-L/symlink", -1);
+
+ r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog);
+ failure("Error invoking %s -o ", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "archive.err");
+
+ assertMakeDir("unpack", 0755);
+ assertChdir("unpack");
+ r = systemf(CAT " .." SEP "archive.out | %s -i >unpack.out 2>unpack.err", testprog);
+
+ failure("Error invoking %s -i", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "unpack.err");
+ assertChdir("..");
+
+ assertIsSymlink("unpack/symlink", NULL, 0);
+
+ r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog);
+ failure("Error invoking %s -oL", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "archive-L.err");
+
+ assertMakeDir("unpack-L", 0755);
+ assertChdir("unpack-L");
+ r = systemf(CAT " .." SEP "archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog);
+
+ failure("Error invoking %s -i < archive-L.out", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "unpack-L.err");
+ assertChdir("..");
+ assertIsReg("unpack-L/symlink", -1);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_Z_upper.c b/contrib/libarchive/cpio/test/test_option_Z_upper.c
new file mode 100644
index 000000000000..aa408e4e548c
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_Z_upper.c
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_Z_upper)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with compress compression. */
+ r = systemf("echo f | %s -oZ >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without compress support");
+ free(p);
+ return;
+ }
+ failure("-Z option is broken");
+ assertEqualInt(r, 0);
+ free(p);
+ return;
+ }
+ free(p);
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x1f\x9d", 2);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_a.c b/contrib/libarchive/cpio/test/test_option_a.c
new file mode 100644
index 000000000000..885eb12c80f5
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_a.c
@@ -0,0 +1,159 @@
+/*-
+ * Copyright (c) 2003-2008 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+#if defined(HAVE_UTIME_H)
+#include <utime.h>
+#elif defined(HAVE_SYS_UTIME_H)
+#include <sys/utime.h>
+#endif
+
+static struct {
+ const char *name;
+ time_t atime_sec;
+} files[] = {
+ { "f0", 0 },
+ { "f1", 0 },
+ { "f2", 0 },
+ { "f3", 0 },
+ { "f4", 0 },
+ { "f5", 0 }
+};
+
+/*
+ * Create a bunch of test files and record their atimes.
+ * For the atime preserve/change tests, the files must have
+ * atimes in the past. We can accomplish this by explicitly invoking
+ * utime() on platforms that support it or by simply sleeping
+ * for a second after creating the files. (Creating all of the files
+ * at once means we only need to sleep once.)
+ */
+static void
+test_create(void)
+{
+ struct stat st;
+ struct utimbuf times;
+ static const int numfiles = sizeof(files) / sizeof(files[0]);
+ int i;
+
+ for (i = 0; i < numfiles; ++i) {
+ /*
+ * Note: Have to write at least one byte to the file.
+ * cpio doesn't bother reading the file if it's zero length,
+ * so the atime never gets changed in that case, which
+ * makes the tests below rather pointless.
+ */
+ assertMakeFile(files[i].name, 0644, "a");
+
+ /* If utime() isn't supported on your platform, just
+ * #ifdef this section out. Most of the test below is
+ * still valid. */
+ memset(&times, 0, sizeof(times));
+#if defined(_WIN32) && !defined(CYGWIN)
+ times.actime = 86400;
+ times.modtime = 86400;
+#else
+ times.actime = 1;
+ times.modtime = 3;
+#endif
+ assertEqualInt(0, utime(files[i].name, &times));
+
+ /* Record whatever atime the file ended up with. */
+ /* If utime() is available, this should be 1, but there's
+ * no harm in being careful. */
+ assertEqualInt(0, stat(files[i].name, &st));
+ files[i].atime_sec = st.st_atime;
+ }
+
+ /* Wait until the atime on the last file is actually in the past. */
+ sleepUntilAfter(files[numfiles - 1].atime_sec);
+}
+
+DEFINE_TEST(test_option_a)
+{
+ struct stat st;
+ int r;
+ char *p;
+
+ /* Create all of the test files. */
+ test_create();
+
+ /* Sanity check; verify that atimes really do get modified. */
+ p = slurpfile(NULL, "f0");
+ assert(p != NULL);
+ free(p);
+ assertEqualInt(0, stat("f0", &st));
+ if (st.st_atime == files[0].atime_sec) {
+ skipping("Cannot verify -a option\n"
+ " Your system appears to not support atime.");
+ }
+ else
+ {
+ /*
+ * If this disk is mounted noatime, then we can't
+ * verify correct operation without -a.
+ */
+
+ /* Copy the file without -a; should change the atime. */
+ r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "copy-no-a.err");
+ assertEmptyFile("copy-no-a.out");
+ assertEqualInt(0, stat(files[1].name, &st));
+ failure("Copying file without -a should have changed atime.");
+ assert(st.st_atime != files[1].atime_sec);
+
+ /* Archive the file without -a; should change the atime. */
+ r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "copy-no-a.err");
+ assertEqualInt(0, stat(files[2].name, &st));
+ failure("Archiving file without -a should have changed atime.");
+ assert(st.st_atime != files[2].atime_sec);
+ }
+
+ /*
+ * We can, of course, still verify that the atime is unchanged
+ * when using the -a option.
+ */
+
+ /* Copy the file with -a; should not change the atime. */
+ r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err",
+ files[3].name, testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "copy-a.err");
+ assertEmptyFile("copy-a.out");
+ assertEqualInt(0, stat(files[3].name, &st));
+ failure("Copying file with -a should not have changed atime.");
+ assertEqualInt(st.st_atime, files[3].atime_sec);
+
+ /* Archive the file with -a; should not change the atime. */
+ r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err",
+ files[4].name, testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "copy-a.err");
+ assertEqualInt(0, stat(files[4].name, &st));
+ failure("Archiving file with -a should not have changed atime.");
+ assertEqualInt(st.st_atime, files[4].atime_sec);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_b64encode.c b/contrib/libarchive/cpio/test/test_option_b64encode.c
new file mode 100644
index 000000000000..501976c202a1
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_b64encode.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_b64encode)
+{
+ char *p;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with compress compression and uuencode. */
+ assertEqualInt(0,
+ systemf("echo f | %s -o -Z --b64encode >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin-base64 644", 16);
+ free(p);
+
+ /* Archive it with uuencode only. */
+ assertEqualInt(0,
+ systemf("echo f | %s -o --b64encode >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin-base64 644", 16);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_c.c b/contrib/libarchive/cpio/test/test_option_c.c
new file mode 100644
index 000000000000..0b6bed2fac93
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_c.c
@@ -0,0 +1,228 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+static int
+is_octal(const char *p, size_t l)
+{
+ while (l > 0) {
+ if (*p < '0' || *p > '7')
+ return (0);
+ --l;
+ ++p;
+ }
+ return (1);
+}
+
+static long long int
+from_octal(const char *p, size_t l)
+{
+ long long int r = 0;
+
+ while (l > 0) {
+ r *= 8;
+ r += *p - '0';
+ --l;
+ ++p;
+ }
+ return (r);
+}
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+static int
+nlinks(const char *p)
+{
+ struct stat st;
+ assertEqualInt(0, stat(p, &st));
+ return st.st_nlink;
+}
+#endif
+
+DEFINE_TEST(test_option_c)
+{
+ FILE *filelist;
+ int r;
+ int uid = 1000;
+ int dev, ino, gid = 1000;
+ time_t t, now;
+ char *p, *e;
+ size_t s;
+
+ assertUmask(0);
+
+ /*
+ * Create an assortment of files.
+ * TODO: Extend this to cover more filetypes.
+ */
+ filelist = fopen("filelist", "w");
+
+ /* "file" */
+ assertMakeFile("file", 0644, "1234567890");
+ fprintf(filelist, "file\n");
+
+ /* "symlink" */
+ if (canSymlink()) {
+ assertMakeSymlink("symlink", "file", 0);
+ fprintf(filelist, "symlink\n");
+ }
+
+ /* "dir" */
+ assertMakeDir("dir", 0775);
+ /* Record some facts about what we just created: */
+ now = time(NULL); /* They were all created w/in last two seconds. */
+ fprintf(filelist, "dir\n");
+
+ /* Use the cpio program to create an archive. */
+ fclose(filelist);
+ r = systemf("%s -R 1000:1000 -oc <filelist >basic.out 2>basic.err", testprog);
+ /* Verify that nothing went to stderr. */
+ assertTextFileContents("1 block\n", "basic.err");
+
+ /* Assert that the program finished. */
+ failure("%s -oc crashed", testprog);
+ if (!assertEqualInt(r, 0))
+ return;
+
+ /* Verify that stdout is a well-formed cpio file in "odc" format. */
+ p = slurpfile(&s, "basic.out");
+ assertEqualInt(s, 512);
+ e = p;
+
+ /*
+ * Some of these assertions could be stronger, but it's
+ * a little tricky because they depend on the local environment.
+ */
+
+ /* First entry is "file" */
+ assert(is_octal(e, 76)); /* Entire header is octal digits. */
+ assertEqualMem(e + 0, "070707", 6); /* Magic */
+ assert(is_octal(e + 6, 6)); /* dev */
+ dev = from_octal(e + 6, 6);
+ assert(is_octal(e + 12, 6)); /* ino */
+ ino = from_octal(e + 12, 6);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Group members bits and others bits do not work. */
+ assertEqualMem(e + 18, "100666", 6); /* Mode */
+#else
+ assertEqualMem(e + 18, "100644", 6); /* Mode */
+#endif
+ if (uid < 0)
+ uid = from_octal(e + 24, 6);
+ assertEqualInt(from_octal(e + 24, 6), uid); /* uid */
+ assert(is_octal(e + 30, 6)); /* gid */
+ gid = from_octal(e + 30, 6);
+ assertEqualMem(e + 36, "000001", 6); /* nlink */
+ failure("file entries should not have rdev set (dev field was 0%o)",
+ dev);
+ assertEqualMem(e + 42, "000000", 6); /* rdev */
+ t = from_octal(e + 48, 11); /* mtime */
+ assert(t <= now); /* File wasn't created in future. */
+ assert(t >= now - 2); /* File was created w/in last 2 secs. */
+ assertEqualMem(e + 59, "000005", 6); /* Name size */
+ assertEqualMem(e + 65, "00000000012", 11); /* File size */
+ assertEqualMem(e + 76, "file\0", 5); /* Name contents */
+ assertEqualMem(e + 81, "1234567890", 10); /* File contents */
+ e += 91;
+
+ /* "symlink" pointing to "file" */
+ if (canSymlink()) {
+ assert(is_octal(e, 76)); /* Entire header is octal digits. */
+ assertEqualMem(e + 0, "070707", 6); /* Magic */
+ assertEqualInt(dev, from_octal(e + 6, 6)); /* dev */
+ assert(ino != from_octal(e + 12, 6)); /* ino */
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ /* On Windows, symbolic link and group members bits and
+ * others bits do not work. */
+ assertEqualMem(e + 18, "120777", 6); /* Mode */
+#endif
+ assertEqualInt(from_octal(e + 24, 6), uid); /* uid */
+ assertEqualInt(gid, from_octal(e + 30, 6)); /* gid */
+ assertEqualMem(e + 36, "000001", 6); /* nlink */
+ failure("file entries should have rdev == 0 (dev was 0%llo)",
+ from_octal(e + 6, 6));
+ assertEqualMem(e + 42, "000000", 6); /* rdev */
+ t = from_octal(e + 48, 11); /* mtime */
+ assert(t <= now); /* File wasn't created in future. */
+ assert(t >= now - 2); /* File was created w/in last 2 secs. */
+ assertEqualMem(e + 59, "000010", 6); /* Name size */
+ assertEqualMem(e + 65, "00000000004", 11); /* File size */
+ assertEqualMem(e + 76, "symlink\0", 8); /* Name contents */
+ assertEqualMem(e + 84, "file", 4); /* Symlink target. */
+ e += 88;
+ }
+
+ /* "dir" */
+ assert(is_octal(e, 76));
+ assertEqualMem(e + 0, "070707", 6); /* Magic */
+ /* Dev should be same as first entry. */
+ assert(is_octal(e + 6, 6)); /* dev */
+ assertEqualInt(dev, from_octal(e + 6, 6));
+ /* Ino must be different from first entry. */
+ assert(is_octal(e + 12, 6)); /* ino */
+ assert(ino != from_octal(e + 12, 6));
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Group members bits and others bits do not work. */
+ assertEqualMem(e + 18, "040777", 6); /* Mode */
+#else
+ /* Accept 042775 to accommodate systems where sgid bit propagates. */
+ if (memcmp(e + 18, "042775", 6) != 0)
+ assertEqualMem(e + 18, "040775", 6); /* Mode */
+#endif
+ assertEqualInt(uid, from_octal(e + 24, 6)); /* uid */
+ /* Gid should be same as first entry. */
+ assert(is_octal(e + 30, 6)); /* gid */
+ assertEqualInt(gid, from_octal(e + 30, 6));
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ assertEqualInt(nlinks("dir"), from_octal(e + 36, 6)); /* Nlink */
+#endif
+
+ t = from_octal(e + 48, 11); /* mtime */
+ assert(t <= now); /* File wasn't created in future. */
+ assert(t >= now - 2); /* File was created w/in last 2 secs. */
+ assertEqualMem(e + 59, "000004", 6); /* Name size */
+ assertEqualMem(e + 65, "00000000000", 11); /* File size */
+ assertEqualMem(e + 76, "dir\0", 4); /* name */
+ e += 80;
+
+ /* TODO: Verify other types of entries. */
+
+ /* Last entry is end-of-archive marker. */
+ assert(is_octal(e, 76));
+ assertEqualMem(e + 0, "070707", 6); /* Magic */
+ assertEqualMem(e + 6, "000000", 6); /* dev */
+ assertEqualMem(e + 12, "000000", 6); /* ino */
+ assertEqualMem(e + 18, "000000", 6); /* Mode */
+ assertEqualMem(e + 24, "000000", 6); /* uid */
+ assertEqualMem(e + 30, "000000", 6); /* gid */
+ assertEqualMem(e + 36, "000001", 6); /* Nlink */
+ assertEqualMem(e + 42, "000000", 6); /* rdev */
+ assertEqualMem(e + 48, "00000000000", 11); /* mtime */
+ assertEqualMem(e + 59, "000013", 6); /* Name size */
+ assertEqualMem(e + 65, "00000000000", 11); /* File size */
+ assertEqualMem(e + 76, "TRAILER!!!\0", 11); /* Name */
+
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_d.c b/contrib/libarchive/cpio/test/test_option_d.c
new file mode 100644
index 000000000000..b96430e4f37a
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_d.c
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_d)
+{
+ int r;
+
+ /*
+ * Create a file in a directory.
+ */
+ assertMakeDir("dir", 0755);
+ assertMakeFile("dir/file", 0644, NULL);
+
+ /* Create an archive. */
+ r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "archive.err");
+ assertFileSize("archive.cpio", 512);
+
+ /* Dearchive without -d, this should fail. */
+ assertMakeDir("without-d", 0755);
+ assertChdir("without-d");
+ r = systemf("%s -i < ../archive.cpio >out 2>err", testprog);
+ assertEqualInt(r, 0);
+ assertEmptyFile("out");
+ /* And the file should not be restored. */
+ assertFileNotExists("dir/file");
+
+ /* Dearchive with -d, this should succeed. */
+ assertChdir("..");
+ assertMakeDir("with-d", 0755);
+ assertChdir("with-d");
+ r = systemf("%s -id < ../archive.cpio >out 2>err", testprog);
+ assertEqualInt(r, 0);
+ assertEmptyFile("out");
+ assertTextFileContents("1 block\n", "err");
+ /* And the file should be restored. */
+ assertFileExists("dir/file");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_f.c b/contrib/libarchive/cpio/test/test_option_f.c
new file mode 100644
index 000000000000..72383884ac1e
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_f.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * Unpack the archive in a new dir.
+ */
+static void
+unpack(const char *dirname, const char *option)
+{
+ int r;
+
+ assertMakeDir(dirname, 0755);
+ assertChdir(dirname);
+ extract_reference_file("test_option_f.cpio");
+ r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option);
+ assertEqualInt(0, r);
+ assertChdir("..");
+}
+
+DEFINE_TEST(test_option_f)
+{
+ /* Calibrate: No -f option, so everything should be extracted. */
+ unpack("t0", "--no-preserve-owner");
+ assertFileExists("t0/a123");
+ assertFileExists("t0/a234");
+ assertFileExists("t0/b123");
+ assertFileExists("t0/b234");
+
+ /* Don't extract 'a*' files. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Single quotes isn't used by command.exe. */
+ unpack("t1", "--no-preserve-owner -f a*");
+#else
+ unpack("t1", "--no-preserve-owner -f 'a*'");
+#endif
+ assertFileNotExists("t1/a123");
+ assertFileNotExists("t1/a234");
+ assertFileExists("t1/b123");
+ assertFileExists("t1/b234");
+
+ /* Don't extract 'b*' files. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Single quotes isn't used by command.exe. */
+ unpack("t2", "--no-preserve-owner -f b*");
+#else
+ unpack("t2", "--no-preserve-owner -f 'b*'");
+#endif
+ assertFileExists("t2/a123");
+ assertFileExists("t2/a234");
+ assertFileNotExists("t2/b123");
+ assertFileNotExists("t2/b234");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_f.cpio.uu b/contrib/libarchive/cpio/test/test_option_f.cpio.uu
new file mode 100644
index 000000000000..60b74173f413
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_f.cpio.uu
@@ -0,0 +1,15 @@
+begin 644 test_option_f.cpio
+M,#<P-S`W,#`P,3,Q-C(Q-38Q,3`P-C0T,#`Q-S4P,#`Q-S4P,#`P,#`Q,#`P
+M,#`P,3`W,S4Q,3(U,C8P,#`P,#4P,#`P,#`P,#`P,&$Q,C,`,#<P-S`W,#`P
+M,3,Q-C(Q-38S,3`P-C0T,#`Q-S4P,#`Q-S4P,#`P,#`Q,#`P,#`P,3`W,S4Q
+M,3(U-#`P,#`P,#4P,#`P,#`P,#`P,&$R,S0`,#<P-S`W,#`P,3,Q-C(Q-38R
+M,3`P-C0T,#`Q-S4P,#`Q-S4P,#`P,#`Q,#`P,#`P,3`W,S4Q,3(U,S0P,#`P
+M,#4P,#`P,#`P,#`P,&(Q,C,`,#<P-S`W,#`P,3,Q-C(Q-38T,3`P-C0T,#`Q
+M-S4P,#`Q-S4P,#`P,#`Q,#`P,#`P,3`W,S4Q,3(U-#,P,#`P,#4P,#`P,#`P
+M,#`P,&(R,S0`,#<P-S`W,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#`Q,#`P,#`P,#`P,#`P,#`P,#`P,#`P,3,P,#`P,#`P,#`P,%1204E,
+M15(A(2$`````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_option_grzip.c b/contrib/libarchive/cpio/test/test_option_grzip.c
new file mode 100644
index 000000000000..cd898cd9228f
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_grzip.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_grzip)
+{
+ char *p;
+ size_t s;
+
+ if (!canGrzip()) {
+ skipping("grzip is not supported on this platform");
+ return;
+ }
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with grzip compression. */
+ assertEqualInt(0,
+ systemf("echo f | %s -o --grzip >archive.out 2>archive.err",
+ testprog));
+ p = slurpfile(&s, "archive.err");
+ free(p);
+ /* Check that the archive file has an grzip signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "GRZipII\x00\x02\x04:)", 12);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_help.c b/contrib/libarchive/cpio/test/test_option_help.c
new file mode 100644
index 000000000000..cf69c76496d5
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_help.c
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * Test that "--help", "-h", and "-W help" options all work and
+ * generate reasonable output.
+ */
+
+static int
+in_first_line(const char *p, const char *substring)
+{
+ size_t l = strlen(substring);
+
+ while (*p != '\0' && *p != '\n') {
+ if (memcmp(p, substring, l) == 0)
+ return (1);
+ ++p;
+ }
+ return (0);
+}
+
+DEFINE_TEST(test_option_help)
+{
+ int r;
+ char *p;
+ size_t plen;
+
+ /* Exercise --help option. */
+ r = systemf("%s --help >help.stdout 2>help.stderr", testprog);
+ assertEqualInt(r, 0);
+ failure("--help should generate nothing to stderr.");
+ assertEmptyFile("help.stderr");
+ /* Help message should start with name of program. */
+ p = slurpfile(&plen, "help.stdout");
+ failure("Help output should be long enough.");
+ assert(plen >= 7);
+ failure("First line of help output should contain string 'bsdcpio'");
+ assert(in_first_line(p, "bsdcpio"));
+ /*
+ * TODO: Extend this check to further verify that --help output
+ * looks approximately right.
+ */
+ free(p);
+
+ /* -h option should generate the same output. */
+ r = systemf("%s -h >h.stdout 2>h.stderr", testprog);
+ assertEqualInt(r, 0);
+ failure("-h should generate nothing to stderr.");
+ assertEmptyFile("h.stderr");
+ failure("stdout should be same for -h and --help");
+ assertEqualFile("h.stdout", "help.stdout");
+
+ /* -W help should be another synonym. */
+ r = systemf("%s -W help >Whelp.stdout 2>Whelp.stderr", testprog);
+ assertEqualInt(r, 0);
+ failure("-W help should generate nothing to stderr.");
+ assertEmptyFile("Whelp.stderr");
+ failure("stdout should be same for -W help and --help");
+ assertEqualFile("Whelp.stdout", "help.stdout");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_l.c b/contrib/libarchive/cpio/test/test_option_l.c
new file mode 100644
index 000000000000..3f4390a6ff22
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_l.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_l)
+{
+ int r;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Copy the file to the "copy" dir. */
+ r = systemf("echo f | %s -pd copy >copy.out 2>copy.err",
+ testprog);
+ assertEqualInt(r, 0);
+
+ /* Check that the copy is a true copy and not a link. */
+ assertIsNotHardlink("f", "copy/f");
+
+ /* Copy the file to the "link" dir with the -l option. */
+ r = systemf("echo f | %s -pld link >link.out 2>link.err",
+ testprog);
+ assertEqualInt(r, 0);
+
+ /* Check that this is a link and not a copy. */
+ assertIsHardlink("f", "link/f");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_lrzip.c b/contrib/libarchive/cpio/test/test_option_lrzip.c
new file mode 100644
index 000000000000..4c46f1c65bba
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_lrzip.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_lrzip)
+{
+ char *p;
+ size_t s;
+
+ if (!canLrzip()) {
+ skipping("lrzip is not supported on this platform");
+ return;
+ }
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lrzip compression. */
+ assertEqualInt(0,
+ systemf("echo f | %s -o --lrzip >archive.out 2>archive.err",
+ testprog));
+ p = slurpfile(&s, "archive.err");
+ free(p);
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "LRZI\x00", 5);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_lz4.c b/contrib/libarchive/cpio/test/test_option_lz4.c
new file mode 100644
index 000000000000..4c5186d55ccc
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_lz4.c
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_lz4)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lz4 compression. */
+ r = systemf("echo f | %s -o --lz4 >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without lz4 support");
+ free(p);
+ return;
+ }
+ /* POSIX permits different handling of the spawnp
+ * system call used to launch the subsidiary
+ * program: */
+ /* Some systems fail immediately to spawn the new process. */
+ if (strstr(p, "Can't launch") != NULL && !canLz4()) {
+ skipping("This version of bsdcpio uses an external lz4 program "
+ "but no such program is available on this system.");
+ free(p);
+ return;
+ }
+ /* Some systems successfully spawn the new process,
+ * but fail to exec a program within that process.
+ * This results in failure at the first attempt to
+ * write. */
+ if (strstr(p, "Can't write") != NULL && !canLz4()) {
+ skipping("This version of bsdcpio uses an external lz4 program "
+ "but no such program is available on this system.");
+ free(p);
+ return;
+ }
+ /* On some systems the error won't be detected until closing
+ time, by a 127 exit error returned by waitpid. */
+ if (strstr(p, "Error closing") != NULL && !canLz4()) {
+ skipping("This version of bsdcpio uses an external lz4 program "
+ "but no such program is available on this system.");
+ free(p);
+ return;
+ }
+ failure("--lz4 option is broken: %s", p);
+ free(p);
+ assertEqualInt(r, 0);
+ return;
+ }
+ free(p);
+ /* Check that the archive file has an lz4 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x04\x22\x4d\x18", 4);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_lzma.c b/contrib/libarchive/cpio/test/test_option_lzma.c
new file mode 100644
index 000000000000..3c2648b827cd
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_lzma.c
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_lzma)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lzma compression. */
+ r = systemf("echo f | %s -o --lzma >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without lzma support");
+ free(p);
+ return;
+ }
+ failure("--lzma option is broken");
+ assertEqualInt(r, 0);
+ free(p);
+ return;
+ }
+ free(p);
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x5d\00\00", 3);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_lzop.c b/contrib/libarchive/cpio/test/test_option_lzop.c
new file mode 100644
index 000000000000..b787b720a878
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_lzop.c
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_lzop)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lzop compression. */
+ r = systemf("echo f | %s -o --lzop >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ free(p);
+ if (r != 0) {
+ if (!canLzop()) {
+ skipping("lzop is not supported on this platform");
+ return;
+ }
+ failure("--lzop option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 9);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_m.c b/contrib/libarchive/cpio/test/test_option_m.c
new file mode 100644
index 000000000000..f2f297e10572
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_m.c
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_m)
+{
+ int r;
+
+ /*
+ * The reference archive has one file with an mtime in 1970, 1
+ * second after the start of the epoch.
+ */
+
+ /* Restored without -m, the result should have a current mtime. */
+ assertMakeDir("without-m", 0755);
+ assertChdir("without-m");
+ extract_reference_file("test_option_m.cpio");
+ r = systemf("%s --no-preserve-owner -i < test_option_m.cpio >out 2>err", testprog);
+ assertEqualInt(r, 0);
+ assertEmptyFile("out");
+ assertTextFileContents("1 block\n", "err");
+ /* Should have been created within the last few seconds. */
+ assertFileMtimeRecent("file");
+
+ /* With -m, it should have an mtime in 1970. */
+ assertChdir("..");
+ assertMakeDir("with-m", 0755);
+ assertChdir("with-m");
+ extract_reference_file("test_option_m.cpio");
+ r = systemf("%s --no-preserve-owner -im < test_option_m.cpio >out 2>err", testprog);
+ assertEqualInt(r, 0);
+ assertEmptyFile("out");
+ assertTextFileContents("1 block\n", "err");
+ /*
+ * mtime in reference archive is '1' == 1 second after
+ * midnight Jan 1, 1970 UTC.
+ */
+ assertFileMtime("file", 1, 0);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_m.cpio.uu b/contrib/libarchive/cpio/test/test_option_m.cpio.uu
new file mode 100644
index 000000000000..0c36ac4fdfd5
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_m.cpio.uu
@@ -0,0 +1,15 @@
+begin 644 test_option_m.cpio
+M,#<P-S`W,#`P,3,Q-#4P,#8T,3`P-C0T,#`Q-S4P,#`Q-S4P,#`P,#`Q,#`P
+M,#`P,#`P,#`P,#`P,#$P,#`P,#4P,#`P,#`P,#`P,&9I;&4`,#<P-S`W,#`P
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`Q,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,3,P,#`P,#`P,#`P,%1204E,15(A(2$`````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_option_passphrase.c b/contrib/libarchive/cpio/test/test_option_passphrase.c
new file mode 100644
index 000000000000..d409b30c81cf
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_passphrase.c
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_passphrase)
+{
+ const char *reffile = "test_option_passphrase.zip";
+
+ extract_reference_file(reffile);
+ assertEqualInt(0,
+ systemf("%s -i --passphrase pass1 < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_passphrase.zip.uu b/contrib/libarchive/cpio/test/test_option_passphrase.zip.uu
new file mode 100644
index 000000000000..021ae8585fe8
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_passphrase.zip.uu
@@ -0,0 +1,12 @@
+begin 644 test_option_passphrase.zip
+M4$L#!`H`"0```#B91$7D$C4,'P```!,````%`!P`9FEL93%55`D``VS'+U0"
+MQR]4=7@+``$$]0$```04````BHPD*"^*I04=XKI\_FQ*TE+#),TD7TTKSP/7
+MR6R35%!+!PCD$C4,'P```!,```!02P,$"@`)````09E$1;VL<PX?````$P``
+M``4`'`!F:6QE,E54"0`#><<O5`+'+U1U>`L``03U`0``!!0```!D#6Z\@CI8
+MV1GIJO5TISQF^I:7.;Y3<-G3$YOCL(C_4$L'"+VL<PX?````$P```%!+`0(>
+M`PH`"0```#B91$7D$C4,'P```!,````%`!@```````$```"D@0````!F:6QE
+M,554!0`#;,<O5'5X"P`!!/4!```$%````%!+`0(>`PH`"0```$&91$6]K',.
+M'P```!,````%`!@```````$```"D@6X```!F:6QE,E54!0`#><<O5'5X"P`!
+@!/4!```$%````%!+!08``````@`"`)8```#<````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_option_t.c b/contrib/libarchive/cpio/test/test_option_t.c
new file mode 100644
index 000000000000..953e4a80651e
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_t.c
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+DEFINE_TEST(test_option_t)
+{
+ char *p;
+ int r;
+ time_t mtime;
+ char date[32];
+ char date2[32];
+ struct tm *tmptr;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE_LOCALTIME_S)
+ struct tm tmbuf;
+#endif
+
+ /* List reference archive, make sure the TOC is correct. */
+ extract_reference_file("test_option_t.cpio");
+ r = systemf("%s -it < test_option_t.cpio >it.out 2>it.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "it.err");
+ extract_reference_file("test_option_t.stdout");
+ p = slurpfile(NULL, "test_option_t.stdout");
+ assertTextFileContents(p, "it.out");
+ free(p);
+
+ /* We accept plain "-t" as a synonym for "-it" */
+ r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "t.err");
+ extract_reference_file("test_option_t.stdout");
+ p = slurpfile(NULL, "test_option_t.stdout");
+ assertTextFileContents(p, "t.out");
+ free(p);
+
+ /* But "-ot" is an error. */
+ assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err",
+ testprog));
+ assertEmptyFile("ot.out");
+
+ /* List reference archive verbosely, make sure the TOC is correct. */
+ r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "tv.err");
+ extract_reference_file("test_option_tv.stdout");
+
+ /* This doesn't work because the usernames on different systems
+ * are different and cpio now looks up numeric UIDs on
+ * the local system. */
+ /* assertEqualFile("tv.out", "test_option_tv.stdout"); */
+
+ /* List reference archive with numeric IDs, verify TOC is correct. */
+ r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err",
+ testprog);
+ assertEqualInt(r, 0);
+ assertTextFileContents("1 block\n", "itnv.err");
+ p = slurpfile(NULL, "itnv.out");
+ /* Since -n uses numeric UID/GID, this part should be the
+ * same on every system. */
+ assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42);
+
+ /* Date varies depending on local timezone and locale. */
+ mtime = 1;
+#ifdef HAVE_LOCALE_H
+ setlocale(LC_ALL, "");
+#endif
+#if defined(HAVE_LOCALTIME_S)
+ tmptr = localtime_s(&tmbuf, &mtime) ? NULL : &tmbuf;
+#elif defined(HAVE_LOCALTIME_R)
+ tmptr = localtime_r(&mtime, &tmbuf);
+#else
+ tmptr = localtime(&mtime);
+#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ strftime(date2, sizeof(date2)-1, "%b %d %Y", tmptr);
+ _snprintf(date, sizeof(date)-1, "%12.12s file", date2);
+#else
+ strftime(date2, sizeof(date2)-1, "%b %e %Y", tmptr);
+ snprintf(date, sizeof(date)-1, "%12.12s file", date2);
+#endif
+ assertEqualMem(p + 42, date, strlen(date));
+ free(p);
+
+ /* But "-n" without "-t" is an error. */
+ assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err",
+ testprog));
+ assertEmptyFile("in.out");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_t.cpio.uu b/contrib/libarchive/cpio/test/test_option_t.cpio.uu
new file mode 100644
index 000000000000..d0bf60bf7d9d
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_t.cpio.uu
@@ -0,0 +1,15 @@
+begin 644 test_option_t.cpio
+M,#<P-S`W,#`P,3,Q-#4P,#8T,3`P-C0T,#`Q-S4P,#`Q-S4P,#`P,#`Q,#`P
+M,#`P,#`P,#`P,#`P,#$P,#`P,#4P,#`P,#`P,#`P,&9I;&4`,#<P-S`W,#`P
+M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`Q,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,3,P,#`P,#`P,#`P,%1204E,15(A(2$`````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+1````````````````````````
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_option_t.stdout.uu b/contrib/libarchive/cpio/test/test_option_t.stdout.uu
new file mode 100644
index 000000000000..c5144bb68029
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_t.stdout.uu
@@ -0,0 +1,4 @@
+begin 644 test_option_t.stdout
+%9FEL90H`
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_option_tv.stdout.uu b/contrib/libarchive/cpio/test/test_option_tv.stdout.uu
new file mode 100644
index 000000000000..ad9481360f35
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_tv.stdout.uu
@@ -0,0 +1,5 @@
+begin 644 test_option_tv.stdout
+M+7)W+7(M+7(M+2`@(#$@=&EM("`@("`@=&EM("`@("`@("`@("`@(#`@1&5C
+/(#,Q("`Q.38Y(&9I;&4*
+`
+end
diff --git a/contrib/libarchive/cpio/test/test_option_u.c b/contrib/libarchive/cpio/test/test_option_u.c
new file mode 100644
index 000000000000..fe5b863af0e2
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_u.c
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+#if defined(HAVE_UTIME_H)
+#include <utime.h>
+#elif defined(HAVE_SYS_UTIME_H)
+#include <sys/utime.h>
+#endif
+
+DEFINE_TEST(test_option_u)
+{
+ struct utimbuf times;
+ char *p;
+ size_t s;
+ int r;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Copy the file to the "copy" dir. */
+ r = systemf("echo f| %s -pd copy >copy.out 2>copy.err",
+ testprog);
+ assertEqualInt(r, 0);
+
+ /* Check that the file contains only a single "a" */
+ p = slurpfile(&s, "copy/f");
+ assertEqualInt(s, 1);
+ assertEqualMem(p, "a", 1);
+ free(p);
+
+ /* Recreate the file with a single "b" */
+ assertMakeFile("f", 0644, "b");
+
+ /* Set the mtime to the distant past. */
+ memset(&times, 0, sizeof(times));
+ times.actime = 1;
+ times.modtime = 3;
+ assertEqualInt(0, utime("f", &times));
+
+ /* Copy the file to the "copy" dir. */
+ r = systemf("echo f| %s -pd copy >copy.out 2>copy.err",
+ testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify that the file hasn't changed (it wasn't overwritten) */
+ p = slurpfile(&s, "copy/f");
+ assertEqualInt(s, 1);
+ assertEqualMem(p, "a", 1);
+ free(p);
+
+ /* Copy the file to the "copy" dir with -u (force) */
+ r = systemf("echo f| %s -pud copy >copy.out 2>copy.err",
+ testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify that the file has changed (it was overwritten) */
+ p = slurpfile(&s, "copy/f");
+ assertEqualInt(s, 1);
+ assertEqualMem(p, "b", 1);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_uuencode.c b/contrib/libarchive/cpio/test/test_option_uuencode.c
new file mode 100644
index 000000000000..28662ddfb659
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_uuencode.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_uuencode)
+{
+ char *p;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with compress compression and uuencode. */
+ assertEqualInt(0,
+ systemf("echo f | %s -o -Z --uuencode >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin 644", 9);
+ free(p);
+
+ /* Archive it with uuencode only. */
+ assertEqualInt(0,
+ systemf("echo f | %s -o --uuencode >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin 644", 9);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_version.c b/contrib/libarchive/cpio/test/test_option_version.c
new file mode 100644
index 000000000000..505db27128fe
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_version.c
@@ -0,0 +1,30 @@
+/*-
+ * Copyright (c) 2003-2017 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_version)
+{
+ assertVersion(testprog, "bsdcpio");
+}
diff --git a/contrib/libarchive/cpio/test/test_option_xz.c b/contrib/libarchive/cpio/test/test_option_xz.c
new file mode 100644
index 000000000000..9116ecace3a7
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_xz.c
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_xz)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with xz compression. */
+ r = systemf("echo f | %s -o --xz >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without xz support");
+ free(p);
+ return;
+ }
+ free(p);
+ failure("--xz option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ free(p);
+ /* Check that the archive file has an xz signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\xFD\x37\x7A\x58\x5A\x00", 6);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_y.c b/contrib/libarchive/cpio/test/test_option_y.c
new file mode 100644
index 000000000000..a78dff8cf4ea
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_y.c
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_y)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with bzip2 compression. */
+ r = systemf("echo f | %s -oy >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ free(p);
+ if (r != 0) {
+ if (!canBzip2()) {
+ skipping("bzip2 is not supported on this platform");
+ return;
+ }
+ failure("-y option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ assertTextFileContents("1 block\n", "archive.err");
+ /* Check that the archive file has a bzip2 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "BZh9", 4);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_z.c b/contrib/libarchive/cpio/test/test_option_z.c
new file mode 100644
index 000000000000..9a1500d77f32
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_z.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_z)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with gzip compression. */
+ r = systemf("echo f | %s -oz >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ free(p);
+ if (r != 0) {
+ if (!canGzip()) {
+ skipping("gzip is not supported on this platform");
+ return;
+ }
+ failure("-z option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has a gzip signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 4);
+ assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_option_zstd.c b/contrib/libarchive/cpio/test/test_option_zstd.c
new file mode 100644
index 000000000000..10c3ed9784e8
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_option_zstd.c
@@ -0,0 +1,84 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_option_zstd)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with zstd compression. */
+ r = systemf("echo f | %s -o --zstd >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "Unsupported compression") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without zstd support");
+ goto done;
+ }
+ /* POSIX permits different handling of the spawnp
+ * system call used to launch the subsidiary
+ * program: */
+ /* Some systems fail immediately to spawn the new process. */
+ if (strstr(p, "Can't launch") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ goto done;
+ }
+ /* Some systems successfully spawn the new process,
+ * but fail to exec a program within that process.
+ * This results in failure at the first attempt to
+ * write. */
+ if (strstr(p, "Can't write") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ goto done;
+ }
+ /* On some systems the error won't be detected until closing
+ time, by a 127 exit error returned by waitpid. */
+ if (strstr(p, "Error closing") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ return;
+ }
+ failure("--zstd option is broken: %s", p);
+ assertEqualInt(r, 0);
+ goto done;
+ }
+ free(p);
+ /* Check that the archive file has an zstd signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x28\xb5\x2f\xfd", 4);
+
+done:
+ free(p);
+}
diff --git a/contrib/libarchive/cpio/test/test_owner_parse.c b/contrib/libarchive/cpio/test/test_owner_parse.c
new file mode 100644
index 000000000000..fc6f18943f5d
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_owner_parse.c
@@ -0,0 +1,120 @@
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+#include "../cpio.h"
+#include "err.h"
+
+#if !defined(_WIN32)
+#define ROOT "root"
+static const int root_uids[] = { 0 };
+static const int root_gids[] = { 0, 1 };
+#elif defined(__CYGWIN__)
+/* On cygwin, the Administrator user most likely exists (unless
+ * it has been renamed or is in a non-English localization), but
+ * its primary group membership depends on how the user set up
+ * their /etc/passwd. Likely values are 513 (None), 545 (Users),
+ * or 544 (Administrators). Just check for one of those...
+ * TODO: Handle non-English localizations... e.g. French 'Administrateur'
+ * Use CreateWellKnownSID() and LookupAccountName()?
+ */
+#define ROOT "Administrator"
+static const int root_uids[] = { 500 };
+static const int root_gids[] = { 513, 545, 544 };
+#endif
+
+#if defined(ROOT)
+static int
+int_in_list(int i, const int *l, size_t n)
+{
+ while (n-- > 0)
+ if (*l++ == i)
+ return (1);
+ failure("%d", i);
+ return (0);
+}
+#endif
+
+DEFINE_TEST(test_owner_parse)
+{
+#if !defined(ROOT)
+ skipping("No uid/gid configuration for this OS");
+#else
+ int uid, gid;
+
+ assert(NULL == owner_parse(ROOT, &uid, &gid));
+ assert(int_in_list(uid, root_uids,
+ sizeof(root_uids)/sizeof(root_uids[0])));
+ assertEqualInt(-1, gid);
+
+
+ assert(NULL == owner_parse(ROOT ":", &uid, &gid));
+ assert(int_in_list(uid, root_uids,
+ sizeof(root_uids)/sizeof(root_uids[0])));
+ assert(int_in_list(gid, root_gids,
+ sizeof(root_gids)/sizeof(root_gids[0])));
+
+ assert(NULL == owner_parse(ROOT ".", &uid, &gid));
+ assert(int_in_list(uid, root_uids,
+ sizeof(root_uids)/sizeof(root_uids[0])));
+ assert(int_in_list(gid, root_gids,
+ sizeof(root_gids)/sizeof(root_gids[0])));
+
+ assert(NULL == owner_parse("111", &uid, &gid));
+ assertEqualInt(111, uid);
+ assertEqualInt(-1, gid);
+
+ assert(NULL == owner_parse("112:", &uid, &gid));
+ assertEqualInt(112, uid);
+ /* Can't assert gid, since we don't know gid for user #112. */
+
+ assert(NULL == owner_parse("113.", &uid, &gid));
+ assertEqualInt(113, uid);
+ /* Can't assert gid, since we don't know gid for user #113. */
+
+ assert(NULL == owner_parse(":114", &uid, &gid));
+ assertEqualInt(-1, uid);
+ assertEqualInt(114, gid);
+
+ assert(NULL == owner_parse(".115", &uid, &gid));
+ assertEqualInt(-1, uid);
+ assertEqualInt(115, gid);
+
+ assert(NULL == owner_parse("116:117", &uid, &gid));
+ assertEqualInt(116, uid);
+ assertEqualInt(117, gid);
+
+ /*
+ * TODO: Lookup current user/group name, build strings and
+ * use those to verify username/groupname lookups for ordinary
+ * users.
+ */
+
+ assert(NULL != owner_parse(":nonexistentgroup", &uid, &gid));
+ assert(NULL != owner_parse(ROOT ":nonexistentgroup", &uid, &gid));
+ assert(NULL !=
+ owner_parse("nonexistentuser:nonexistentgroup", &uid, &gid));
+#endif
+}
diff --git a/contrib/libarchive/cpio/test/test_passthrough_dotdot.c b/contrib/libarchive/cpio/test/test_passthrough_dotdot.c
new file mode 100644
index 000000000000..831c1f81c1cb
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_passthrough_dotdot.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * Verify that "cpio -p .." works.
+ */
+
+DEFINE_TEST(test_passthrough_dotdot)
+{
+ int r;
+ FILE *filelist;
+
+ assertUmask(0);
+
+ /*
+ * Create an assortment of files on disk.
+ */
+ filelist = fopen("filelist", "w");
+
+ /* Directory. */
+ assertMakeDir("dir", 0755);
+ assertChdir("dir");
+
+ fprintf(filelist, ".\n");
+
+ /* File with 10 bytes content. */
+ assertMakeFile("file", 0642, "1234567890");
+ fprintf(filelist, "file\n");
+
+ /* All done. */
+ fclose(filelist);
+
+
+ /*
+ * Use cpio passthrough mode to copy files to another directory.
+ */
+ r = systemf("%s -pdvm .. <../filelist >../stdout 2>../stderr",
+ testprog);
+ failure("Error invoking %s -pd ..", testprog);
+ assertEqualInt(r, 0);
+
+ assertChdir("..");
+
+ /* Verify stderr and stdout. */
+ assertTextFileContents("../.\n../file\n1 block\n", "stderr");
+ assertEmptyFile("stdout");
+
+ /* Regular file. */
+ assertIsReg("file", 0642);
+ assertFileSize("file", 10);
+ assertFileNLinks("file", 1);
+}
diff --git a/contrib/libarchive/cpio/test/test_passthrough_reverse.c b/contrib/libarchive/cpio/test/test_passthrough_reverse.c
new file mode 100644
index 000000000000..7ae0e6602a34
--- /dev/null
+++ b/contrib/libarchive/cpio/test/test_passthrough_reverse.c
@@ -0,0 +1,84 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * As reported by Bernd Walter: Some people are in the habit of
+ * using "find -d" to generate a list for cpio -p because that
+ * copies the top-level dir last, which preserves owner and mode
+ * information. That's not necessary for bsdcpio (libarchive defers
+ * restoring directory information), but bsdcpio should still generate
+ * the correct results with this usage.
+ */
+
+DEFINE_TEST(test_passthrough_reverse)
+{
+ int r;
+ FILE *filelist;
+
+ assertUmask(0);
+
+ /*
+ * Create an assortment of files on disk.
+ */
+ filelist = fopen("filelist", "w");
+
+ /* Directory. */
+ assertMakeDir("dir", 0743);
+
+ /* File with 10 bytes content. */
+ assertMakeFile("dir/file", 0644, "1234567890");
+ fprintf(filelist, "dir/file\n");
+
+ /* Write dir last. */
+ fprintf(filelist, "dir\n");
+
+ /* All done. */
+ fclose(filelist);
+
+
+ /*
+ * Use cpio passthrough mode to copy files to another directory.
+ */
+ r = systemf("%s -pdvm out <filelist >stdout 2>stderr", testprog);
+ failure("Error invoking %s -pd out", testprog);
+ assertEqualInt(r, 0);
+
+ assertChdir("out");
+
+ /* Verify stderr and stdout. */
+ assertTextFileContents("out/dir/file\nout/dir\n1 block\n",
+ "../stderr");
+ assertEmptyFile("../stdout");
+
+ /* dir */
+ assertIsDir("dir", 0743);
+
+
+ /* Regular file. */
+ assertIsReg("dir/file", 0644);
+ assertFileSize("dir/file", 10);
+ assertFileNLinks("dir/file", 1);
+}