summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/tar
diff options
context:
space:
mode:
Diffstat (limited to 'archivers/libarchive/files/tar')
-rw-r--r--archivers/libarchive/files/tar/CMakeLists.txt55
-rw-r--r--archivers/libarchive/files/tar/bsdtar.1169
-rw-r--r--archivers/libarchive/files/tar/bsdtar.c535
-rw-r--r--archivers/libarchive/files/tar/bsdtar.h67
-rw-r--r--archivers/libarchive/files/tar/bsdtar_platform.h86
-rw-r--r--archivers/libarchive/files/tar/bsdtar_windows.c298
-rw-r--r--archivers/libarchive/files/tar/bsdtar_windows.h60
-rw-r--r--archivers/libarchive/files/tar/cmdline.c381
-rw-r--r--archivers/libarchive/files/tar/config_freebsd.h84
-rw-r--r--archivers/libarchive/files/tar/getdate.c2613
-rw-r--r--archivers/libarchive/files/tar/read.c167
-rw-r--r--archivers/libarchive/files/tar/subst.c46
-rw-r--r--archivers/libarchive/files/tar/test/CMakeLists.txt67
-rw-r--r--archivers/libarchive/files/tar/test/list.h16
-rw-r--r--archivers/libarchive/files/tar/test/main.c2221
-rw-r--r--archivers/libarchive/files/tar/test/test.h219
-rw-r--r--archivers/libarchive/files/tar/test/test_0.c11
-rw-r--r--archivers/libarchive/files/tar/test/test_basic.c113
-rw-r--r--archivers/libarchive/files/tar/test/test_copy.c398
-rw-r--r--archivers/libarchive/files/tar/test/test_empty_mtree.c45
-rw-r--r--archivers/libarchive/files/tar/test/test_getdate.c46
-rw-r--r--archivers/libarchive/files/tar/test/test_help.c3
-rw-r--r--archivers/libarchive/files/tar/test/test_option_T_upper.c188
-rw-r--r--archivers/libarchive/files/tar/test/test_option_q.c129
-rw-r--r--archivers/libarchive/files/tar/test/test_option_r.c117
-rw-r--r--archivers/libarchive/files/tar/test/test_option_s.c107
-rw-r--r--archivers/libarchive/files/tar/test/test_patterns.c151
-rw-r--r--archivers/libarchive/files/tar/test/test_patterns_2.tar.uu231
-rw-r--r--archivers/libarchive/files/tar/test/test_patterns_3.tar.uu231
-rw-r--r--archivers/libarchive/files/tar/test/test_patterns_4.tar.uu641
-rw-r--r--archivers/libarchive/files/tar/test/test_stdio.c33
-rw-r--r--archivers/libarchive/files/tar/test/test_strip_components.c109
-rw-r--r--archivers/libarchive/files/tar/test/test_symlink_dir.c160
-rw-r--r--archivers/libarchive/files/tar/test/test_version.c20
-rw-r--r--archivers/libarchive/files/tar/test/test_windows.c323
-rw-r--r--archivers/libarchive/files/tar/tree.c471
-rw-r--r--archivers/libarchive/files/tar/tree.h58
-rw-r--r--archivers/libarchive/files/tar/util.c478
-rw-r--r--archivers/libarchive/files/tar/write.c1090
39 files changed, 7850 insertions, 4387 deletions
diff --git a/archivers/libarchive/files/tar/CMakeLists.txt b/archivers/libarchive/files/tar/CMakeLists.txt
new file mode 100644
index 00000000000..2ed8161d985
--- /dev/null
+++ b/archivers/libarchive/files/tar/CMakeLists.txt
@@ -0,0 +1,55 @@
+############################################
+#
+# How to build bsdtar
+#
+############################################
+IF (ENABLE_TAR)
+
+ SET(bsdtar_SOURCES
+ bsdtar.c
+ bsdtar.h
+ bsdtar_platform.h
+ cmdline.c
+ getdate.c
+ read.c
+ subst.c
+ tree.c
+ tree.h
+ util.c
+ write.c
+ ../libarchive_fe/err.c
+ ../libarchive_fe/err.h
+ ../libarchive_fe/lafe_platform.h
+ ../libarchive_fe/line_reader.c
+ ../libarchive_fe/line_reader.h
+ ../libarchive_fe/matching.c
+ ../libarchive_fe/matching.h
+ ../libarchive_fe/pathmatch.c
+ ../libarchive_fe/pathmatch.h
+ )
+ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libarchive_fe)
+ IF(WIN32 AND NOT CYGWIN)
+ LIST(APPEND bsdtar_SOURCES bsdtar_windows.c)
+ LIST(APPEND bsdtar_SOURCES bsdtar_windows.h)
+ ENDIF(WIN32 AND NOT CYGWIN)
+
+ # bsdtar documentation
+ SET(bsdtar_MANS bsdtar.1)
+
+ # How to build bsdtar
+ ADD_EXECUTABLE(bsdtar ${bsdtar_SOURCES})
+ IF(ENABLE_TAR_SHARED)
+ TARGET_LINK_LIBRARIES(bsdtar archive ${ADDITIONAL_LIBS})
+ ELSE(ENABLE_TAR_SHARED)
+ TARGET_LINK_LIBRARIES(bsdtar archive_static ${ADDITIONAL_LIBS})
+ SET_TARGET_PROPERTIES(bsdtar PROPERTIES COMPILE_DEFINITIONS
+ LIBARCHIVE_STATIC)
+ ENDIF(ENABLE_TAR_SHARED)
+ GET_TARGET_PROPERTY(BSDTAR bsdtar LOCATION)
+
+ # Installation rules
+ INSTALL(TARGETS bsdtar RUNTIME DESTINATION bin)
+ INSTALL_MAN(${bsdtar_MANS})
+ENDIF(ENABLE_TAR)
+
+add_subdirectory(test)
diff --git a/archivers/libarchive/files/tar/bsdtar.1 b/archivers/libarchive/files/tar/bsdtar.1
index e790d60ccb9..67cac1099a0 100644
--- a/archivers/libarchive/files/tar/bsdtar.1
+++ b/archivers/libarchive/files/tar/bsdtar.1
@@ -22,9 +22,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/usr.bin/tar/bsdtar.1,v 1.43 2008/05/26 17:10:10 kientzle Exp $
+.\" $FreeBSD: src/usr.bin/tar/bsdtar.1,v 1.46 2008/12/06 07:37:55 kientzle Exp $
.\"
-.Dd May 15, 2008
+.Dd Oct 12, 2009
.Dt BSDTAR 1
.Os
.Sh NAME
@@ -37,12 +37,12 @@
.Nm
.Brq Fl c
.Op Ar options
-.Op Ar files | directories
+.Op Ar files | Ar directories
.Nm
.Brq Fl r | Fl u
.Fl f Ar archive-file
.Op Ar options
-.Op Ar files | directories
+.Op Ar files | Ar directories
.Nm
.Brq Fl t | Fl x
.Op Ar options
@@ -144,21 +144,21 @@ In c and r mode, this changes the directory before adding
the following files.
In x mode, change directories after opening the archive
but before extracting entries from the archive.
-.It Fl -check-links ( Fl W Cm check-links )
+.It Fl -check-links
(c and r modes only)
Issue a warning message unless all links to each file are archived.
-.It Fl -chroot ( Fl W Cm chroot )
+.It Fl -chroot
(x mode only)
.Fn chroot
to the current directory after processing any
.Fl C
options and before extracting any files.
-.It Fl -exclude Ar pattern ( Fl W Cm exclude Ns = Ns Ar pattern )
+.It Fl -exclude Ar pattern
Do not process files or directories that match the
specified pattern.
Note that exclusions take precedence over patterns or filenames
specified on the command line.
-.It Fl -format Ar format ( Fl W Cm format Ns = Ns Ar format )
+.It Fl -format Ar format
(c, r, u mode only)
Use the specified format for the created archive.
Supported formats include
@@ -193,7 +193,7 @@ Synonym for
.It Fl I
Synonym for
.Fl T .
-.It Fl -include Ar pattern ( Fl W Cm include Ns = Ns Ar pattern )
+.It Fl -include Ar pattern
Process only files or directories that match the specified pattern.
Note that exclusions specified with
.Fl -exclude
@@ -225,7 +225,7 @@ automatically when reading archives.
Do not overwrite existing files.
In particular, if a file appears more than once in an archive,
later copies will not overwrite earlier copies.
-.It Fl -keep-newer-files ( Fl W Cm keep-newer-files )
+.It Fl -keep-newer-files
(x mode only)
Do not overwrite existing files that are newer than the
versions appearing in the archive being extracted.
@@ -245,28 +245,28 @@ By default, the modification time is set to the time stored in the archive.
.It Fl n
(c, r, u modes only)
Do not recursively archive the contents of directories.
-.It Fl -newer Ar date ( Fl W Cm newer Ns = Ns Ar date )
+.It Fl -newer Ar date
(c, r, u modes only)
Only include files and directories newer than the specified date.
This compares ctime entries.
-.It Fl -newer-mtime Ar date ( Fl W Cm newer-mtime Ns = Ns Ar date )
+.It Fl -newer-mtime Ar date
(c, r, u modes only)
Like
.Fl -newer ,
except it compares mtime entries instead of ctime entries.
-.It Fl -newer-than Pa file ( Fl W Cm newer-than Ns = Ns Pa file )
+.It Fl -newer-than Pa file
(c, r, u modes only)
Only include files and directories newer than the specified file.
This compares ctime entries.
-.It Fl -newer-mtime-than Pa file ( Fl W Cm newer-mtime-than Ns = Ns Pa file )
+.It Fl -newer-mtime-than Pa file
(c, r, u modes only)
Like
.Fl -newer-than ,
except it compares mtime entries instead of ctime entries.
-.It Fl -nodump ( Fl W Cm nodump )
+.It Fl -nodump
(c and r modes only)
Honor the nodump file flag by skipping this file.
-.It Fl -null ( Fl W Cm null )
+.It Fl -null
(use with
.Fl I ,
.Fl T ,
@@ -302,9 +302,80 @@ the archive will be discarded.
(c, r, u mode)
A synonym for
.Fl -format Ar ustar
-.It Fl -one-file-system ( Fl W Cm one-file-system )
+.It Fl -one-file-system
(c, r, and u modes)
Do not cross mount points.
+.It Fl -options Ar options
+Select optional behaviors for particular modules.
+The argument is a text string containing comma-separated
+keywords and values.
+These are passed to the modules that handle particular
+formats to control how those formats will behave.
+Each option has one of the following forms:
+.Bl -tag -compact -width indent
+.It Ar key=value
+The key will be set to the specified value in every module that supports it.
+Modules that do not support this key will ignore it.
+.It Ar key
+The key will be enabled in every module that supports it.
+This is equivalent to
+.Ar key Ns Cm =1 .
+.It Ar !key
+The key will be disabled in every module that supports it.
+.It Ar module:key=value , Ar module:key , Ar module:!key
+As above, but the corresponding key and value will be provided
+only to modules whose name matches
+.Ar module .
+.El
+The currently supported modules and keys are:
+.Bl -tag -compact -width indent
+.It Cm iso9660:joliet
+Support Joliet extensions.
+This is enabled by default, use
+.Cm !joliet
+or
+.Cm iso9660:!joliet
+to disable.
+.It Cm iso9660:rockridge
+Support Rock Ridge extensions.
+This is enabled by default, use
+.Cm !rockridge
+or
+.Cm iso9660:!rockridge
+to disable.
+.It Cm gzip:compression-level
+A decimal integer from 0 to 9 specifying the gzip compression level.
+.It Cm xz:compression-level
+A decimal integer from 0 to 9 specifying the xz compression level.
+.It Cm mtree: Ns Ar keyword
+The mtree writer module allows you to specify which mtree keywords
+will be included in the output.
+Supported keywords include:
+.Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent ,
+.Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 ,
+.Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname .
+The default is equivalent to:
+.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname .
+.It Cm mtree:all
+Enables all of the above keywords.
+You can also use
+.Cm mtree:!all
+to disable all keywords.
+.It Cm mtree:use-set
+Enable generation of
+.Cm /set
+lines in the output.
+.It Cm mtree:indent
+Produce human-readable output by indenting options and splitting lines
+to fit into 80 columns.
+.It Cm zip:compression Ns = Ns Ar type
+Use
+.Ar type
+as compression method.
+Supported values are store (uncompressed) and deflate (gzip algorithm).
+.El
+If a provided option is not supported by any module, that
+is a fatal error.
.It Fl P
Preserve pathnames.
By default, absolute pathnames (those that begin with a /
@@ -345,8 +416,8 @@ Extract files as sparse files.
For every block on disk, check first if it contains only NULL bytes and seek
over it otherwise.
This works similiar to the conv=sparse option of dd.
-.It Fl -strip-components Ar count ( Fl W Cm strip-components Ns = Ns Ar count )
-(x and t mode only)
+.It Fl -strip-components Ar count
+(x mode only)
Remove the specified number of leading path elements.
Pathnames with fewer elements will be silently skipped.
Note that the pathname is edited after checking inclusion/exclusion patterns
@@ -354,10 +425,20 @@ but before security checks.
.It Fl s Ar pattern
Modify file or archive member names according to
.Pa pattern .
-The pattern has the format /old/new/[gps].
-old is a basic regular expression.
-If it doesn't apply, the pattern is skipped.
-new is the replacement string of the matched part.
+The pattern has the format
+.Ar /old/new/ Ns Op gps
+where
+.Ar old
+is a basic regular expression,
+.Ar new
+is the replacement string of the matched part,
+and the optional trailing letters modify
+how the replacement is handled.
+If
+.Ar old
+is not matched, the pattern is skipped.
+Within
+.Ar new ,
~ is substituted with the match, \1 to \9 with the content of
the corresponding captured group.
The optional trailing g specifies that matching should continue
@@ -412,16 +493,12 @@ will produce output similar to that of
Additional
.Fl v
options will provide additional detail.
-.It Fl W Ar longopt=value
-Long options (preceded by
-.Fl - )
-are only supported directly on systems that have the
-.Xr getopt_long 3
-function.
-The
-.Fl W
-option can be used to access long options on systems that
-do not support this function.
+.It Fl -version
+Print version of
+.Nm
+and
+.Nm libarchive ,
+and exit.
.It Fl w
Ask for confirmation for every action.
.It Fl X Ar filename
@@ -544,6 +621,7 @@ format can be used to create an output archive with arbitrary ownership,
permissions, or names that differ from existing data on disk:
.Pp
.Dl $ cat input.mtree
+.Dl #mtree
.Dl usr/bin uid=0 gid=0 mode=0755 type=dir
.Dl usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls
.Dl $ tar -cvf output.tar @input.mtree
@@ -558,6 +636,27 @@ switches accept a variety of common date and time specifications, including
.Dq 5 minutes ago ,
and
.Dq 19:14 PST May 1 .
+.Pp
+The
+.Fl -options
+argument can be used to control various details of archive generation
+or reading.
+For example, you can generate mtree output which only contains
+.Cm type , Cm time ,
+and
+.Cm uid
+keywords:
+.Dl Nm Fl cf Pa file.tar Fl -format=mtree Fl -options='!all,type,time,uid' Pa dir
+or you can set the compression level used by gzip or xz compression:
+.Dl Nm Fl czf Pa file.tar Fl -options='compression-level=9' .
+For more details, see the explanation of the
+.Fn archive_read_set_options
+and
+.Fn archive_write_set_options
+API calls that are described in
+.Xr archive_read 3
+and
+.Xr archive_write 3 .
.Sh COMPATIBILITY
The bundled-arguments format is supported for compatibility
with historic implementations.
@@ -610,8 +709,8 @@ and
.Cm w
options.
.Pp
-On systems that support getopt_long(), additional long options
-are available to improve compatibility with other tar implementations.
+Additional long options are provided to improve compatibility with other
+tar implementations.
.Sh SECURITY
Certain security issues are common to many archiving programs, including
.Nm .
diff --git a/archivers/libarchive/files/tar/bsdtar.c b/archivers/libarchive/files/tar/bsdtar.c
index 1c13cc6bfbe..d8f8286842e 100644
--- a/archivers/libarchive/files/tar/bsdtar.c
+++ b/archivers/libarchive/files/tar/bsdtar.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2003-2008 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@
*/
#include "bsdtar_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/bsdtar.c,v 1.91 2008/05/26 17:10:10 kientzle Exp $");
+__FBSDID("$FreeBSD: src/usr.bin/tar/bsdtar.c,v 1.93 2008/11/08 04:43:24 kientzle Exp $");
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
@@ -38,18 +38,6 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/bsdtar.c,v 1.91 2008/05/26 17:10:10 kientzle
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_GETOPT_LONG
-#include <getopt.h>
-#else
-struct option {
- const char *name;
- int has_arg;
- int *flag;
- int val;
-};
-#define no_argument 0
-#define required_argument 1
-#endif
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
@@ -59,6 +47,9 @@ struct option {
#ifdef HAVE_PATHS_H
#include <paths.h>
#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -77,14 +68,7 @@ struct option {
#endif
#include "bsdtar.h"
-
-#if !HAVE_DECL_OPTARG
-extern int optarg;
-#endif
-
-#if !HAVE_DECL_OPTIND
-extern int optind;
-#endif
+#include "err.h"
/*
* Per POSIX.1-1988, tar defaults to reading/writing archives to/from
@@ -93,140 +77,53 @@ extern int optind;
#ifdef __linux
#define _PATH_DEFTAPE "/dev/st0"
#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define _PATH_DEFTAPE "\\\\.\\tape0"
+#endif
#ifndef _PATH_DEFTAPE
#define _PATH_DEFTAPE "/dev/tape"
#endif
-/* External function to parse a date/time string (from getdate.y) */
-time_t get_date(const char *);
+#ifdef __MINGW32__
+int _CRT_glob = 0; /* Disable broken CRT globbing. */
+#endif
-static int bsdtar_getopt(struct bsdtar *, const char *optstring,
- const struct option **poption);
-static void long_help(struct bsdtar *);
-static void only_mode(struct bsdtar *, const char *opt,
- const char *valid);
-static char ** rewrite_argv(struct bsdtar *,
- int *argc, char ** src_argv,
- const char *optstring);
-static void set_mode(struct bsdtar *, char opt);
-static void version(void);
+static struct bsdtar *_bsdtar;
-/*
- * The leading '+' here forces the GNU version of getopt() (as well as
- * both the GNU and BSD versions of getopt_long) to stop at the first
- * non-option. Otherwise, GNU getopt() permutes the arguments and
- * screws up -C processing.
- */
-static const char *tar_opts = "+Bb:C:cf:HhI:jkLlmnOoPprts:ST:UuvW:wX:xyZz";
+#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1))
+static volatile int siginfo_occurred;
-/*
- * Most of these long options are deliberately not documented. They
- * are provided only to make life easier for people who also use GNU tar.
- * The only long options documented in the manual page are the ones
- * with no corresponding short option, such as --exclude, --nodump,
- * and --fast-read.
- *
- * On systems that lack getopt_long, long options can be specified
- * using -W longopt and -W longopt=value, e.g. "-W nodump" is the same
- * as "--nodump" and "-W exclude=pattern" is the same as "--exclude
- * pattern". This does not rely the GNU getopt() "W;" extension, so
- * should work correctly on any system with a POSIX-compliant getopt().
- */
+static void
+siginfo_handler(int sig)
+{
+ (void)sig; /* UNUSED */
+ siginfo_occurred = 1;
+}
+
+int
+need_report(void)
+{
+ int r = siginfo_occurred;
+ siginfo_occurred = 0;
+ return (r);
+}
+#else
+int
+need_report(void)
+{
+ return (0);
+}
+#endif
-/* Fake short equivalents for long options that otherwise lack them. */
-enum {
- OPTION_CHECK_LINKS = 1,
- OPTION_CHROOT,
- OPTION_EXCLUDE,
- OPTION_FORMAT,
- OPTION_HELP,
- OPTION_INCLUDE,
- OPTION_KEEP_NEWER_FILES,
- OPTION_NEWER_CTIME,
- OPTION_NEWER_CTIME_THAN,
- OPTION_NEWER_MTIME,
- OPTION_NEWER_MTIME_THAN,
- OPTION_NODUMP,
- OPTION_NO_SAME_OWNER,
- OPTION_NO_SAME_PERMISSIONS,
- OPTION_NULL,
- OPTION_NUMERIC_OWNER,
- OPTION_ONE_FILE_SYSTEM,
- OPTION_POSIX,
- OPTION_STRIP_COMPONENTS,
- OPTION_TOTALS,
- OPTION_USE_COMPRESS_PROGRAM,
- OPTION_VERSION
-};
+/* External function to parse a date/time string */
+time_t get_date(time_t, const char *);
-/*
- * If you add anything, be very careful to keep this list properly
- * sorted, as the -W logic relies on it.
- */
-static const struct option tar_longopts[] = {
- { "absolute-paths", no_argument, NULL, 'P' },
- { "append", no_argument, NULL, 'r' },
- { "block-size", required_argument, NULL, 'b' },
- { "bunzip2", no_argument, NULL, 'j' },
- { "bzip", no_argument, NULL, 'j' },
- { "bzip2", no_argument, NULL, 'j' },
- { "cd", required_argument, NULL, 'C' },
- { "check-links", no_argument, NULL, OPTION_CHECK_LINKS },
- { "chroot", no_argument, NULL, OPTION_CHROOT },
- { "compress", no_argument, NULL, 'Z' },
- { "confirmation", no_argument, NULL, 'w' },
- { "create", no_argument, NULL, 'c' },
- { "dereference", no_argument, NULL, 'L' },
- { "directory", required_argument, NULL, 'C' },
- { "exclude", required_argument, NULL, OPTION_EXCLUDE },
- { "exclude-from", required_argument, NULL, 'X' },
- { "extract", no_argument, NULL, 'x' },
- { "fast-read", no_argument, NULL, 'q' },
- { "file", required_argument, NULL, 'f' },
- { "files-from", required_argument, NULL, 'T' },
- { "format", required_argument, NULL, OPTION_FORMAT },
- { "gunzip", no_argument, NULL, 'z' },
- { "gzip", no_argument, NULL, 'z' },
- { "help", no_argument, NULL, OPTION_HELP },
- { "include", required_argument, NULL, OPTION_INCLUDE },
- { "interactive", no_argument, NULL, 'w' },
- { "insecure", no_argument, NULL, 'P' },
- { "keep-newer-files", no_argument, NULL, OPTION_KEEP_NEWER_FILES },
- { "keep-old-files", no_argument, NULL, 'k' },
- { "list", no_argument, NULL, 't' },
- { "modification-time", no_argument, NULL, 'm' },
- { "newer", required_argument, NULL, OPTION_NEWER_CTIME },
- { "newer-ctime", required_argument, NULL, OPTION_NEWER_CTIME },
- { "newer-ctime-than", required_argument, NULL, OPTION_NEWER_CTIME_THAN },
- { "newer-mtime", required_argument, NULL, OPTION_NEWER_MTIME },
- { "newer-mtime-than", required_argument, NULL, OPTION_NEWER_MTIME_THAN },
- { "newer-than", required_argument, NULL, OPTION_NEWER_CTIME_THAN },
- { "nodump", no_argument, NULL, OPTION_NODUMP },
- { "norecurse", no_argument, NULL, 'n' },
- { "no-recursion", no_argument, NULL, 'n' },
- { "no-same-owner", no_argument, NULL, OPTION_NO_SAME_OWNER },
- { "no-same-permissions",no_argument, NULL, OPTION_NO_SAME_PERMISSIONS },
- { "null", no_argument, NULL, OPTION_NULL },
- { "numeric-owner", no_argument, NULL, OPTION_NUMERIC_OWNER },
- { "one-file-system", no_argument, NULL, OPTION_ONE_FILE_SYSTEM },
- { "posix", no_argument, NULL, OPTION_POSIX },
- { "preserve-permissions", no_argument, NULL, 'p' },
- { "read-full-blocks", no_argument, NULL, 'B' },
- { "same-permissions", no_argument, NULL, 'p' },
- { "strip-components", required_argument, NULL, OPTION_STRIP_COMPONENTS },
- { "to-stdout", no_argument, NULL, 'O' },
- { "totals", no_argument, NULL, OPTION_TOTALS },
- { "uncompress", no_argument, NULL, 'Z' },
- { "unlink", no_argument, NULL, 'U' },
- { "unlink-first", no_argument, NULL, 'U' },
- { "update", no_argument, NULL, 'u' },
- { "use-compress-program",
- required_argument, NULL, OPTION_USE_COMPRESS_PROGRAM },
- { "verbose", no_argument, NULL, 'v' },
- { "version", no_argument, NULL, OPTION_VERSION },
- { NULL, 0, NULL, 0 }
-};
+static void long_help(void);
+static void only_mode(struct bsdtar *, const char *opt,
+ const char *valid);
+static void set_mode(struct bsdtar *, char opt);
+static void version(void);
/* A basic set of security flags to request from libarchive. */
#define SECURITY \
@@ -237,34 +134,61 @@ int
main(int argc, char **argv)
{
struct bsdtar *bsdtar, bsdtar_storage;
- const struct option *option;
int opt, t;
char option_o;
char possible_help_request;
char buff[16];
+ time_t now;
/*
* Use a pointer for consistency, but stack-allocated storage
* for ease of cleanup.
*/
- bsdtar = &bsdtar_storage;
+ _bsdtar = bsdtar = &bsdtar_storage;
memset(bsdtar, 0, sizeof(*bsdtar));
bsdtar->fd = -1; /* Mark as "unused" */
option_o = 0;
- /* Need bsdtar->progname before calling bsdtar_warnc. */
+#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1))
+ { /* Catch SIGINFO and SIGUSR1, if they exist. */
+ struct sigaction sa;
+ sa.sa_handler = siginfo_handler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+#ifdef SIGINFO
+ if (sigaction(SIGINFO, &sa, NULL))
+ lafe_errc(1, errno, "sigaction(SIGINFO) failed");
+#endif
+#ifdef SIGUSR1
+ /* ... and treat SIGUSR1 the same way as SIGINFO. */
+ if (sigaction(SIGUSR1, &sa, NULL))
+ lafe_errc(1, errno, "sigaction(SIGUSR1) failed");
+#endif
+ }
+#endif
+
+
+ /* Need lafe_progname before calling lafe_warnc. */
if (*argv == NULL)
- bsdtar->progname = "bsdtar";
+ lafe_progname = "bsdtar";
else {
- bsdtar->progname = strrchr(*argv, '/');
- if (bsdtar->progname != NULL)
- bsdtar->progname++;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ lafe_progname = strrchr(*argv, '\\');
+#else
+ lafe_progname = strrchr(*argv, '/');
+#endif
+ if (lafe_progname != NULL)
+ lafe_progname++;
else
- bsdtar->progname = *argv;
+ lafe_progname = *argv;
}
+ time(&now);
+
+#if HAVE_SETLOCALE
if (setlocale(LC_ALL, "") == NULL)
- bsdtar_warnc(bsdtar, 0, "Failed to set default locale");
+ lafe_warnc(0, "Failed to set default locale");
+#endif
#if defined(HAVE_NL_LANGINFO) && defined(HAVE_D_MD_ORDER)
bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd');
#endif
@@ -284,7 +208,9 @@ main(int argc, char **argv)
/* Default: Perform basic security checks. */
bsdtar->extract_flags |= SECURITY;
- /* Defaults for root user: */
+#ifndef _WIN32
+ /* On POSIX systems, assume --same-owner and -p when run by
+ * the root user. This doesn't make any sense on Windows. */
if (bsdtar->user_uid == 0) {
/* --same-owner */
bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER;
@@ -294,34 +220,31 @@ main(int argc, char **argv)
bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR;
bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
}
-
- /* Rewrite traditional-style tar arguments, if used. */
- argv = rewrite_argv(bsdtar, &argc, argv, tar_opts);
+#endif
bsdtar->argv = argv;
bsdtar->argc = argc;
- /* Process all remaining arguments now. */
/*
* Comments following each option indicate where that option
* originated: SUSv2, POSIX, GNU tar, star, etc. If there's
* no such comment, then I don't know of anyone else who
* implements that option.
*/
- while ((opt = bsdtar_getopt(bsdtar, tar_opts, &option)) != -1) {
+ while ((opt = bsdtar_getopt(bsdtar)) != -1) {
switch (opt) {
case 'B': /* GNU tar */
/* libarchive doesn't need this; just ignore it. */
break;
case 'b': /* SUSv2 */
- t = atoi(optarg);
- if (t <= 0 || t > 1024)
- bsdtar_errc(bsdtar, 1, 0,
- "Argument to -b is out of range (1..1024)");
+ t = atoi(bsdtar->optarg);
+ if (t <= 0 || t > 8192)
+ lafe_errc(1, 0,
+ "Argument to -b is out of range (1..8192)");
bsdtar->bytes_per_block = 512 * t;
break;
case 'C': /* GNU tar */
- set_chdir(bsdtar, optarg);
+ set_chdir(bsdtar, bsdtar->optarg);
break;
case 'c': /* SUSv2 */
set_mode(bsdtar, opt);
@@ -333,15 +256,18 @@ main(int argc, char **argv)
bsdtar->option_chroot = 1;
break;
case OPTION_EXCLUDE: /* GNU tar */
- if (exclude(bsdtar, optarg))
- bsdtar_errc(bsdtar, 1, 0,
- "Couldn't exclude %s\n", optarg);
+ if (lafe_exclude(&bsdtar->matching, bsdtar->optarg))
+ lafe_errc(1, 0,
+ "Couldn't exclude %s\n", bsdtar->optarg);
break;
case OPTION_FORMAT: /* GNU tar, others */
- bsdtar->create_format = optarg;
+ bsdtar->create_format = bsdtar->optarg;
+ break;
+ case OPTION_OPTIONS:
+ bsdtar->option_options = bsdtar->optarg;
break;
case 'f': /* SUSv2 */
- bsdtar->filename = optarg;
+ bsdtar->filename = bsdtar->optarg;
if (strcmp(bsdtar->filename, "-") == 0)
bsdtar->filename = NULL;
break;
@@ -354,7 +280,7 @@ main(int argc, char **argv)
possible_help_request = 1;
break;
case OPTION_HELP: /* GNU tar, others */
- long_help(bsdtar);
+ long_help();
exit(0);
break;
case 'I': /* GNU tar */
@@ -368,7 +294,7 @@ main(int argc, char **argv)
* permissions without having to create those
* permissions on disk.
*/
- bsdtar->names_from_file = optarg;
+ bsdtar->names_from_file = bsdtar->optarg;
break;
case OPTION_INCLUDE:
/*
@@ -376,22 +302,24 @@ main(int argc, char **argv)
* noone else needs this to filter entries
* when transforming archives.
*/
- if (include(bsdtar, optarg))
- bsdtar_errc(bsdtar, 1, 0,
+ if (lafe_include(&bsdtar->matching, bsdtar->optarg))
+ lafe_errc(1, 0,
"Failed to add %s to inclusion list",
- optarg);
+ bsdtar->optarg);
break;
case 'j': /* GNU tar */
-#if HAVE_LIBBZ2
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
+ "Can't specify both -%c and -%c", opt,
+ bsdtar->create_compression);
+ bsdtar->create_compression = opt;
+ break;
+ case 'J': /* GNU tar 1.21 and later */
+ if (bsdtar->create_compression != '\0')
+ lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
-#else
- bsdtar_warnc(bsdtar, 0, "-j compression not supported by this version of bsdtar");
- usage(bsdtar);
-#endif
break;
case 'k': /* GNU tar */
bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
@@ -406,6 +334,13 @@ main(int argc, char **argv)
/* GNU tar 1.13 used -l for --one-file-system */
bsdtar->option_warn_links = 1;
break;
+ case OPTION_LZMA:
+ if (bsdtar->create_compression != '\0')
+ lafe_errc(1, 0,
+ "Can't specify both -%c and -%c", opt,
+ bsdtar->create_compression);
+ bsdtar->create_compression = opt;
+ break;
case 'm': /* SUSv2 */
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME;
break;
@@ -420,28 +355,28 @@ main(int argc, char **argv)
* TODO: Add corresponding "older" options to reverse these.
*/
case OPTION_NEWER_CTIME: /* GNU tar */
- bsdtar->newer_ctime_sec = get_date(optarg);
+ bsdtar->newer_ctime_sec = get_date(now, bsdtar->optarg);
break;
case OPTION_NEWER_CTIME_THAN:
{
struct stat st;
- if (stat(optarg, &st) != 0)
- bsdtar_errc(bsdtar, 1, 0,
- "Can't open file %s", optarg);
+ if (stat(bsdtar->optarg, &st) != 0)
+ lafe_errc(1, 0,
+ "Can't open file %s", bsdtar->optarg);
bsdtar->newer_ctime_sec = st.st_ctime;
bsdtar->newer_ctime_nsec =
ARCHIVE_STAT_CTIME_NANOS(&st);
}
break;
case OPTION_NEWER_MTIME: /* GNU tar */
- bsdtar->newer_mtime_sec = get_date(optarg);
+ bsdtar->newer_mtime_sec = get_date(now, bsdtar->optarg);
break;
case OPTION_NEWER_MTIME_THAN:
{
struct stat st;
- if (stat(optarg, &st) != 0)
- bsdtar_errc(bsdtar, 1, 0,
- "Can't open file %s", optarg);
+ if (stat(bsdtar->optarg, &st) != 0)
+ lafe_errc(1, 0,
+ "Can't open file %s", bsdtar->optarg);
bsdtar->newer_mtime_sec = st.st_mtime;
bsdtar->newer_mtime_nsec =
ARCHIVE_STAT_MTIME_NANOS(&st);
@@ -509,17 +444,21 @@ main(int argc, char **argv)
break;
case 's': /* NetBSD pax-as-tar */
#if HAVE_REGEX_H
- add_substitution(bsdtar, optarg);
+ add_substitution(bsdtar, bsdtar->optarg);
#else
- bsdtar_warnc(bsdtar, 0, "-s is not supported by this version of bsdtar");
- usage(bsdtar);
+ lafe_warnc(0,
+ "-s is not supported by this version of bsdtar");
+ usage();
#endif
break;
+ case OPTION_SAME_OWNER: /* GNU tar */
+ bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER;
+ break;
case OPTION_STRIP_COMPONENTS: /* GNU tar 1.15 */
- bsdtar->strip_components = atoi(optarg);
+ bsdtar->strip_components = atoi(bsdtar->optarg);
break;
case 'T': /* GNU tar */
- bsdtar->names_from_file = optarg;
+ bsdtar->names_from_file = bsdtar->optarg;
break;
case 't': /* SUSv2 */
set_mode(bsdtar, opt);
@@ -544,59 +483,49 @@ main(int argc, char **argv)
#if 0
/*
* The -W longopt feature is handled inside of
- * bsdtar_getop(), so -W is not available here.
+ * bsdtar_getopt(), so -W is not available here.
*/
- case 'W': /* Obscure, but useful GNU convention. */
+ case 'W': /* Obscure GNU convention. */
break;
#endif
case 'w': /* SUSv2 */
bsdtar->option_interactive = 1;
break;
case 'X': /* GNU tar */
- if (exclude_from_file(bsdtar, optarg))
- bsdtar_errc(bsdtar, 1, 0,
+ if (lafe_exclude_from_file(&bsdtar->matching, bsdtar->optarg))
+ lafe_errc(1, 0,
"failed to process exclusions from file %s",
- optarg);
+ bsdtar->optarg);
break;
case 'x': /* SUSv2 */
set_mode(bsdtar, opt);
break;
case 'y': /* FreeBSD version of GNU tar */
-#if HAVE_LIBBZ2
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
-#else
- bsdtar_warnc(bsdtar, 0, "-y compression not supported by this version of bsdtar");
- usage(bsdtar);
-#endif
break;
case 'Z': /* GNU tar */
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
break;
case 'z': /* GNU tar, star, many others */
-#if HAVE_LIBZ
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
-#else
- bsdtar_warnc(bsdtar, 0, "-z compression not supported by this version of bsdtar");
- usage(bsdtar);
-#endif
break;
case OPTION_USE_COMPRESS_PROGRAM:
- bsdtar->compress_program = optarg;
+ bsdtar->compress_program = bsdtar->optarg;
break;
default:
- usage(bsdtar);
+ usage();
}
}
@@ -606,13 +535,13 @@ main(int argc, char **argv)
/* If no "real" mode was specified, treat -h as --help. */
if ((bsdtar->mode == '\0') && possible_help_request) {
- long_help(bsdtar);
+ long_help();
exit(0);
}
/* Otherwise, a mode is required. */
if (bsdtar->mode == '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Must specify one of -c, -r, -t, -u, -x");
/* Check boolean options only permitted in certain modes. */
@@ -668,9 +597,6 @@ main(int argc, char **argv)
if (bsdtar->strip_components != 0)
only_mode(bsdtar, "--strip-components", "xt");
- bsdtar->argc -= optind;
- bsdtar->argv += optind;
-
switch(bsdtar->mode) {
case 'c':
tar_mode_c(bsdtar);
@@ -689,13 +615,13 @@ main(int argc, char **argv)
break;
}
- cleanup_exclusions(bsdtar);
+ lafe_cleanup_exclusions(&bsdtar->matching);
#if HAVE_REGEX_H
cleanup_substitution(bsdtar);
#endif
if (bsdtar->return_value != 0)
- bsdtar_warnc(bsdtar, 0,
+ lafe_warnc(0,
"Error exit delayed from previous errors.");
return (bsdtar->return_value);
}
@@ -704,7 +630,7 @@ static void
set_mode(struct bsdtar *bsdtar, char opt)
{
if (bsdtar->mode != '\0' && bsdtar->mode != opt)
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt, bsdtar->mode);
bsdtar->mode = opt;
}
@@ -716,94 +642,24 @@ static void
only_mode(struct bsdtar *bsdtar, const char *opt, const char *valid_modes)
{
if (strchr(valid_modes, bsdtar->mode) == NULL)
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Option %s is not permitted in mode -%c",
opt, bsdtar->mode);
}
-/*-
- * Convert traditional tar arguments into new-style.
- * For example,
- * tar tvfb file.tar 32 --exclude FOO
- * will be converted to
- * tar -t -v -f file.tar -b 32 --exclude FOO
- *
- * This requires building a new argv array. The initial bundled word
- * gets expanded into a new string that looks like "-t\0-v\0-f\0-b\0".
- * The new argv array has pointers into this string intermingled with
- * pointers to the existing arguments. Arguments are moved to
- * immediately follow their options.
- *
- * The optstring argument here is the same one passed to getopt(3).
- * It is used to determine which option letters have trailing arguments.
- */
-char **
-rewrite_argv(struct bsdtar *bsdtar, int *argc, char **src_argv,
- const char *optstring)
-{
- char **new_argv, **dest_argv;
- const char *p;
- char *src, *dest;
-
- if (src_argv[0] == NULL || src_argv[1] == NULL ||
- src_argv[1][0] == '-' || src_argv[1][0] == '\0')
- return (src_argv);
-
- *argc += strlen(src_argv[1]) - 1;
- new_argv = malloc((*argc + 1) * sizeof(new_argv[0]));
- if (new_argv == NULL)
- bsdtar_errc(bsdtar, 1, errno, "No Memory");
-
- dest_argv = new_argv;
- *dest_argv++ = *src_argv++;
-
- dest = malloc(strlen(*src_argv) * 3);
- if (dest == NULL)
- bsdtar_errc(bsdtar, 1, errno, "No memory");
- for (src = *src_argv++; *src != '\0'; src++) {
- *dest_argv++ = dest;
- *dest++ = '-';
- *dest++ = *src;
- *dest++ = '\0';
- /* If option takes an argument, insert that into the list. */
- for (p = optstring; p != NULL && *p != '\0'; p++) {
- if (*p != *src)
- continue;
- if (p[1] != ':') /* No arg required, done. */
- break;
- if (*src_argv == NULL) /* No arg available? Error. */
- bsdtar_errc(bsdtar, 1, 0,
- "Option %c requires an argument",
- *src);
- *dest_argv++ = *src_argv++;
- break;
- }
- }
-
- /* Copy remaining arguments, including trailing NULL. */
- while ((*dest_argv++ = *src_argv++) != NULL)
- ;
-
- return (new_argv);
-}
-
void
-usage(struct bsdtar *bsdtar)
+usage(void)
{
const char *p;
- p = bsdtar->progname;
+ p = lafe_progname;
fprintf(stderr, "Usage:\n");
fprintf(stderr, " List: %s -tf <archive-filename>\n", p);
fprintf(stderr, " Extract: %s -xf <archive-filename>\n", p);
fprintf(stderr, " Create: %s -cf <archive-filename> [filenames...]\n", p);
-#ifdef HAVE_GETOPT_LONG
fprintf(stderr, " Help: %s --help\n", p);
-#else
- fprintf(stderr, " Help: %s -h\n", p);
-#endif
exit(1);
}
@@ -826,13 +682,9 @@ static const char *long_help_msg =
" -w Interactive\n"
"Create: %p -c [options] [<file> | <dir> | @<archive> | -C <dir> ]\n"
" <file>, <dir> add these items to archive\n"
- " -z, -j Compress archive with gzip/bzip2\n"
+ " -z, -j, -J, --lzma Compress archive with gzip/bzip2/xz/lzma\n"
" --format {ustar|pax|cpio|shar} Select archive format\n"
-#ifdef HAVE_GETOPT_LONG
" --exclude <pattern> Skip files that match pattern\n"
-#else
- " -W exclude=<pattern> Skip files that match pattern\n"
-#endif
" -C <dir> Change to <dir> before processing remaining files\n"
" @<archive> Add entries from <archive> to output\n"
"List: %p -t [options] [<patterns>]\n"
@@ -856,12 +708,12 @@ static const char *long_help_msg =
* echo bsdtar; else echo not bsdtar; fi
*/
static void
-long_help(struct bsdtar *bsdtar)
+long_help(void)
{
const char *prog;
const char *p;
- prog = bsdtar->progname;
+ prog = lafe_progname;
fflush(stderr);
@@ -880,80 +732,3 @@ long_help(struct bsdtar *bsdtar)
}
version();
}
-
-static int
-bsdtar_getopt(struct bsdtar *bsdtar, const char *optstring,
- const struct option **poption)
-{
- char *p, *q;
- const struct option *option;
- int opt;
- int option_index;
- size_t option_length;
-
- option_index = -1;
- *poption = NULL;
-
-#ifdef HAVE_GETOPT_LONG
- opt = getopt_long(bsdtar->argc, bsdtar->argv, optstring,
- tar_longopts, &option_index);
- if (option_index > -1)
- *poption = tar_longopts + option_index;
-#else
- opt = getopt(bsdtar->argc, bsdtar->argv, optstring);
-#endif
-
- /* Support long options through -W longopt=value */
- if (opt == 'W') {
- p = optarg;
- q = strchr(optarg, '=');
- if (q != NULL) {
- option_length = (size_t)(q - p);
- optarg = q + 1;
- } else {
- option_length = strlen(p);
- optarg = NULL;
- }
- option = tar_longopts;
- while (option->name != NULL &&
- (strlen(option->name) < option_length ||
- strncmp(p, option->name, option_length) != 0 )) {
- option++;
- }
-
- if (option->name != NULL) {
- *poption = option;
- opt = option->val;
-
- /* If the first match was exact, we're done. */
- if (strncmp(p, option->name, strlen(option->name)) == 0) {
- while (option->name != NULL)
- option++;
- } else {
- /* Check if there's another match. */
- option++;
- while (option->name != NULL &&
- (strlen(option->name) < option_length ||
- strncmp(p, option->name, option_length) != 0)) {
- option++;
- }
- }
- if (option->name != NULL)
- bsdtar_errc(bsdtar, 1, 0,
- "Ambiguous option %s "
- "(matches both %s and %s)",
- p, (*poption)->name, option->name);
-
- if ((*poption)->has_arg == required_argument
- && optarg == NULL)
- bsdtar_errc(bsdtar, 1, 0,
- "Option \"%s\" requires argument", p);
- } else {
- opt = '?';
- /* TODO: Set up a fake 'struct option' for
- * error reporting... ? ? ? */
- }
- }
-
- return (opt);
-}
diff --git a/archivers/libarchive/files/tar/bsdtar.h b/archivers/libarchive/files/tar/bsdtar.h
index 4153a44f946..5e8dc7f89ec 100644
--- a/archivers/libarchive/files/tar/bsdtar.h
+++ b/archivers/libarchive/files/tar/bsdtar.h
@@ -22,12 +22,14 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.33 2008/05/26 17:10:10 kientzle Exp $
+ * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $
*/
#include "bsdtar_platform.h"
#include <stdio.h>
+#include "matching.h"
+
#define DEFAULT_BYTES_PER_BLOCK (20*512)
/*
@@ -60,6 +62,7 @@ struct bsdtar {
char option_chroot; /* --chroot */
char option_dont_traverse_mounts; /* --one-file-system */
char option_fast_read; /* --fast-read */
+ const char *option_options; /* --options */
char option_honor_nodump; /* --nodump */
char option_interactive; /* -w */
char option_no_owner; /* -o */
@@ -76,10 +79,9 @@ struct bsdtar {
int fd;
/* Miscellaneous state information */
- struct archive *archive;
- const char *progname;
int argc;
char **argv;
+ const char *optarg;
size_t gs_width; /* For 'list_item' in read.c */
size_t u_width; /* for 'list_item' in read.c */
uid_t user_uid; /* UID running this program */
@@ -91,45 +93,62 @@ struct bsdtar {
* Data for various subsystems. Full definitions are located in
* the file where they are used.
*/
- struct archive_entry_linkresolver *resolver;
+ struct archive *diskreader; /* for write.c */
+ struct archive_entry_linkresolver *resolver; /* for write.c */
struct archive_dir *archive_dir; /* for write.c */
struct name_cache *gname_cache; /* for write.c */
- struct matching *matching; /* for matching.c */
+ char *buff; /* for write.c */
+ struct lafe_matching *matching; /* for matching.c */
struct security *security; /* for read.c */
struct name_cache *uname_cache; /* for write.c */
struct siginfo_data *siginfo; /* for siginfo.c */
struct substitution *substitution; /* for subst.c */
};
-void bsdtar_errc(struct bsdtar *, int _eval, int _code,
- const char *fmt, ...);
-void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
-void cleanup_exclusions(struct bsdtar *);
+/* Fake short equivalents for long options that otherwise lack them. */
+enum {
+ OPTION_CHECK_LINKS = 1,
+ OPTION_CHROOT,
+ OPTION_EXCLUDE,
+ OPTION_FORMAT,
+ OPTION_OPTIONS,
+ OPTION_HELP,
+ OPTION_INCLUDE,
+ OPTION_KEEP_NEWER_FILES,
+ OPTION_LZMA,
+ OPTION_NEWER_CTIME,
+ OPTION_NEWER_CTIME_THAN,
+ OPTION_NEWER_MTIME,
+ OPTION_NEWER_MTIME_THAN,
+ OPTION_NODUMP,
+ OPTION_NO_SAME_OWNER,
+ OPTION_NO_SAME_PERMISSIONS,
+ OPTION_NULL,
+ OPTION_NUMERIC_OWNER,
+ OPTION_ONE_FILE_SYSTEM,
+ OPTION_POSIX,
+ OPTION_SAME_OWNER,
+ OPTION_STRIP_COMPONENTS,
+ OPTION_TOTALS,
+ OPTION_USE_COMPRESS_PROGRAM,
+ OPTION_VERSION
+};
+
+
+int bsdtar_getopt(struct bsdtar *);
void do_chdir(struct bsdtar *);
int edit_pathname(struct bsdtar *, struct archive_entry *);
-int exclude(struct bsdtar *, const char *pattern);
-int exclude_from_file(struct bsdtar *, const char *pathname);
-int excluded(struct bsdtar *, const char *pathname);
-int include(struct bsdtar *, const char *pattern);
-int include_from_file(struct bsdtar *, const char *pathname);
+int need_report(void);
int pathcmp(const char *a, const char *b);
-int process_lines(struct bsdtar *bsdtar, const char *pathname,
- int (*process)(struct bsdtar *, const char *));
void safe_fprintf(FILE *, const char *fmt, ...);
void set_chdir(struct bsdtar *, const char *newdir);
-void siginfo_init(struct bsdtar *);
-void siginfo_setinfo(struct bsdtar *, const char * oper,
- const char * path, int64_t size);
-void siginfo_printinfo(struct bsdtar *, off_t progress);
-void siginfo_done(struct bsdtar *);
+const char *tar_i64toa(int64_t);
void tar_mode_c(struct bsdtar *bsdtar);
void tar_mode_r(struct bsdtar *bsdtar);
void tar_mode_t(struct bsdtar *bsdtar);
void tar_mode_u(struct bsdtar *bsdtar);
void tar_mode_x(struct bsdtar *bsdtar);
-int unmatched_inclusions(struct bsdtar *bsdtar);
-int unmatched_inclusions_warn(struct bsdtar *bsdtar, const char *msg);
-void usage(struct bsdtar *);
+void usage(void);
int yes(const char *fmt, ...);
#if HAVE_REGEX_H
diff --git a/archivers/libarchive/files/tar/bsdtar_platform.h b/archivers/libarchive/files/tar/bsdtar_platform.h
index ccb9d3c0257..fce9c99815a 100644
--- a/archivers/libarchive/files/tar/bsdtar_platform.h
+++ b/archivers/libarchive/files/tar/bsdtar_platform.h
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.25 2008/01/02 00:23:00 kientzle Exp $
+ * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $
*/
/*
@@ -37,19 +37,18 @@
#if defined(PLATFORM_CONFIG_H)
/* Use hand-built config.h in environments that need it. */
#include PLATFORM_CONFIG_H
-#elif defined(HAVE_CONFIG_H)
-/* Most POSIX platforms use the 'configure' script to build config.h */
-#include "../config.h"
#else
-/* Warn if bsdtar hasn't been (automatically or manually) configured. */
-#error Oops: No config.h and no built-in configuration in bsdtar_platform.h.
-#endif /* !HAVE_CONFIG_H */
+/* Not having a config.h of some sort is a serious problem. */
+#include "config.h"
+#endif
-/* No non-FreeBSD platform will have __FBSDID, so just define it here. */
-#ifdef __FreeBSD__
-#include <sys/cdefs.h> /* For __FBSDID */
-#else
-/* Just leaving this macro replacement empty leads to a dangling semicolon. */
+/* Get a real definition for __FBSDID if we can */
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+
+/* If not, define it so as to avoid dangling semicolons. */
+#ifndef __FBSDID
#define __FBSDID(a) struct _undefined_hack
#endif
@@ -63,29 +62,10 @@
#include "archive_entry.h"
#endif
-/*
- * Does this platform have complete-looking POSIX-style ACL support,
- * including some variant of the acl_get_perm() function (which was
- * omitted from the POSIX.1e draft)?
- */
-#if HAVE_SYS_ACL_H && HAVE_ACL_PERMSET_T && HAVE_ACL_USER
-#if HAVE_ACL_GET_PERM || HAVE_ACL_GET_PERM_NP
-#define HAVE_POSIX_ACL 1
-#endif
-#endif
-
#ifdef HAVE_LIBACL
#include <acl/libacl.h>
#endif
-#if HAVE_ACL_GET_PERM
-#define ACL_GET_PERM acl_get_perm
-#else
-#if HAVE_ACL_GET_PERM_NP
-#define ACL_GET_PERM acl_get_perm_np
-#endif
-#endif
-
/*
* Include "dirent.h" (or it's equivalent on several different platforms).
*
@@ -115,36 +95,38 @@
# endif
#endif
-
-/*
- * We need to be able to display a filesize using printf(). The type
- * and format string here must be compatible with one another and
- * large enough for any file.
- */
-#if HAVE_UINTMAX_T
-#define BSDTAR_FILESIZE_TYPE uintmax_t
-#define BSDTAR_FILESIZE_PRINTF "%ju"
-#else
-#if HAVE_UNSIGNED_LONG_LONG
-#define BSDTAR_FILESIZE_TYPE unsigned long long
-#define BSDTAR_FILESIZE_PRINTF "%llu"
-#else
-#define BSDTAR_FILESIZE_TYPE unsigned long
-#define BSDTAR_FILESIZE_PRINTF "%lu"
-#endif
-#endif
-
#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec
#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
-#else
-#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec
#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_MTIME_N
+#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n
+#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n
+#elif HAVE_STRUCT_STAT_ST_UMTIME
+#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000
+#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000
+#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
+#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000
+#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000
#else
#define ARCHIVE_STAT_CTIME_NANOS(st) (0)
#define ARCHIVE_STAT_MTIME_NANOS(st) (0)
#endif
+
+/* How to mark functions that don't return. */
+/* This facilitates use of some newer static code analysis tools. */
+#undef __LA_DEAD
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+ (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
+#define __LA_DEAD __attribute__((__noreturn__))
+#else
+#define __LA_DEAD
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include "bsdtar_windows.h"
#endif
#endif /* !BSDTAR_PLATFORM_H_INCLUDED */
diff --git a/archivers/libarchive/files/tar/bsdtar_windows.c b/archivers/libarchive/files/tar/bsdtar_windows.c
new file mode 100644
index 00000000000..4d1205028f3
--- /dev/null
+++ b/archivers/libarchive/files/tar/bsdtar_windows.c
@@ -0,0 +1,298 @@
+/*-
+ * Copyright (c) 2009 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.
+ *
+ * $FreeBSD$
+ */
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+#include "bsdtar_platform.h"
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <io.h>
+#include <stddef.h>
+#ifdef HAVE_SYS_UTIME_H
+#include <sys/utime.h>
+#endif
+#include <sys/stat.h>
+#include <process.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <windows.h>
+#include <sddl.h>
+
+#include "bsdtar.h"
+#include "err.h"
+
+/* This may actually not be needed anymore.
+ * TODO: Review the error handling for chdir() failures and
+ * simply dump this if it's not really needed. */
+static void __tar_dosmaperr(unsigned long);
+
+/*
+ * Prepend "\\?\" to the path name and convert it to unicode to permit
+ * an extended-length path for a maximum total path length of 32767
+ * characters.
+ * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx
+ */
+static wchar_t *
+permissive_name(const char *name)
+{
+ wchar_t *wn, *wnp;
+ wchar_t *ws, *wsp;
+ DWORD l, len, slen, alloclen;
+ int unc;
+
+ len = (DWORD)strlen(name);
+ wn = malloc((len + 1) * sizeof(wchar_t));
+ if (wn == NULL)
+ return (NULL);
+ l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len);
+ if (l == 0) {
+ free(wn);
+ return (NULL);
+ }
+ wn[l] = L'\0';
+
+ /* Get a full path names */
+ l = GetFullPathNameW(wn, 0, NULL, NULL);
+ if (l == 0) {
+ free(wn);
+ return (NULL);
+ }
+ wnp = malloc(l * sizeof(wchar_t));
+ if (wnp == NULL) {
+ free(wn);
+ return (NULL);
+ }
+ len = GetFullPathNameW(wn, l, wnp, NULL);
+ free(wn);
+ wn = wnp;
+
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
+ wnp[2] == L'?' && wnp[3] == L'\\')
+ /* We have already permissive names. */
+ return (wn);
+
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
+ wnp[2] == L'.' && wnp[3] == L'\\') {
+ /* Device names */
+ if (((wnp[4] >= L'a' && wnp[4] <= L'z') ||
+ (wnp[4] >= L'A' && wnp[4] <= L'Z')) &&
+ wnp[5] == L':' && wnp[6] == L'\\')
+ wnp[2] = L'?';/* Not device names. */
+ return (wn);
+ }
+
+ unc = 0;
+ if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') {
+ wchar_t *p = &wnp[2];
+
+ /* Skip server-name letters. */
+ while (*p != L'\\' && *p != L'\0')
+ ++p;
+ if (*p == L'\\') {
+ wchar_t *rp = ++p;
+ /* Skip share-name letters. */
+ while (*p != L'\\' && *p != L'\0')
+ ++p;
+ if (*p == L'\\' && p != rp) {
+ /* Now, match patterns such as
+ * "\\server-name\share-name\" */
+ wnp += 2;
+ len -= 2;
+ unc = 1;
+ }
+ }
+ }
+
+ alloclen = slen = 4 + (unc * 4) + len + 1;
+ ws = wsp = malloc(slen * sizeof(wchar_t));
+ if (ws == NULL) {
+ free(wn);
+ return (NULL);
+ }
+ /* prepend "\\?\" */
+ wcsncpy(wsp, L"\\\\?\\", 4);
+ wsp += 4;
+ slen -= 4;
+ if (unc) {
+ /* append "UNC\" ---> "\\?\UNC\" */
+ wcsncpy(wsp, L"UNC\\", 4);
+ wsp += 4;
+ slen -= 4;
+ }
+ wcsncpy(wsp, wnp, slen);
+ free(wn);
+ ws[alloclen - 1] = L'\0';
+ return (ws);
+}
+
+int
+__tar_chdir(const char *path)
+{
+ wchar_t *ws;
+ int r;
+
+ r = SetCurrentDirectoryA(path);
+ if (r == 0) {
+ if (GetLastError() != ERROR_FILE_NOT_FOUND) {
+ __tar_dosmaperr(GetLastError());
+ return (-1);
+ }
+ } else
+ return (0);
+ ws = permissive_name(path);
+ if (ws == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ r = SetCurrentDirectoryW(ws);
+ free(ws);
+ if (r == 0) {
+ __tar_dosmaperr(GetLastError());
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * The following function was modified from PostgreSQL sources and is
+ * subject to the copyright below.
+ */
+/*-------------------------------------------------------------------------
+ *
+ * win32error.c
+ * Map win32 error codes to errno values
+ *
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+/*
+PostgreSQL Database Management System
+(formerly known as Postgres, then as Postgres95)
+
+Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+
+Portions Copyright (c) 1994, The Regents of the University of California
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose, without fee, and without a written agreement
+is hereby granted, provided that the above copyright notice and this
+paragraph and the following two paragraphs appear in all copies.
+
+IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
+LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
+DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
+PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+*/
+
+static const struct {
+ DWORD winerr;
+ int doserr;
+} doserrors[] =
+{
+ { ERROR_INVALID_FUNCTION, EINVAL },
+ { ERROR_FILE_NOT_FOUND, ENOENT },
+ { ERROR_PATH_NOT_FOUND, ENOENT },
+ { ERROR_TOO_MANY_OPEN_FILES, EMFILE },
+ { ERROR_ACCESS_DENIED, EACCES },
+ { ERROR_INVALID_HANDLE, EBADF },
+ { ERROR_ARENA_TRASHED, ENOMEM },
+ { ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
+ { ERROR_INVALID_BLOCK, ENOMEM },
+ { ERROR_BAD_ENVIRONMENT, E2BIG },
+ { ERROR_BAD_FORMAT, ENOEXEC },
+ { ERROR_INVALID_ACCESS, EINVAL },
+ { ERROR_INVALID_DATA, EINVAL },
+ { ERROR_INVALID_DRIVE, ENOENT },
+ { ERROR_CURRENT_DIRECTORY, EACCES },
+ { ERROR_NOT_SAME_DEVICE, EXDEV },
+ { ERROR_NO_MORE_FILES, ENOENT },
+ { ERROR_LOCK_VIOLATION, EACCES },
+ { ERROR_SHARING_VIOLATION, EACCES },
+ { ERROR_BAD_NETPATH, ENOENT },
+ { ERROR_NETWORK_ACCESS_DENIED, EACCES },
+ { ERROR_BAD_NET_NAME, ENOENT },
+ { ERROR_FILE_EXISTS, EEXIST },
+ { ERROR_CANNOT_MAKE, EACCES },
+ { ERROR_FAIL_I24, EACCES },
+ { ERROR_INVALID_PARAMETER, EINVAL },
+ { ERROR_NO_PROC_SLOTS, EAGAIN },
+ { ERROR_DRIVE_LOCKED, EACCES },
+ { ERROR_BROKEN_PIPE, EPIPE },
+ { ERROR_DISK_FULL, ENOSPC },
+ { ERROR_INVALID_TARGET_HANDLE, EBADF },
+ { ERROR_INVALID_HANDLE, EINVAL },
+ { ERROR_WAIT_NO_CHILDREN, ECHILD },
+ { ERROR_CHILD_NOT_COMPLETE, ECHILD },
+ { ERROR_DIRECT_ACCESS_HANDLE, EBADF },
+ { ERROR_NEGATIVE_SEEK, EINVAL },
+ { ERROR_SEEK_ON_DEVICE, EACCES },
+ { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
+ { ERROR_NOT_LOCKED, EACCES },
+ { ERROR_BAD_PATHNAME, ENOENT },
+ { ERROR_MAX_THRDS_REACHED, EAGAIN },
+ { ERROR_LOCK_FAILED, EACCES },
+ { ERROR_ALREADY_EXISTS, EEXIST },
+ { ERROR_FILENAME_EXCED_RANGE, ENOENT },
+ { ERROR_NESTING_NOT_ALLOWED, EAGAIN },
+ { ERROR_NOT_ENOUGH_QUOTA, ENOMEM }
+};
+
+static void
+__tar_dosmaperr(unsigned long e)
+{
+ int i;
+
+ if (e == 0) {
+ errno = 0;
+ return;
+ }
+
+ for (i = 0; i < sizeof(doserrors); i++) {
+ if (doserrors[i].winerr == e) {
+ errno = doserrors[i].doserr;
+ return;
+ }
+ }
+
+ /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */
+ errno = EINVAL;
+ return;
+}
+
+#endif
diff --git a/archivers/libarchive/files/tar/bsdtar_windows.h b/archivers/libarchive/files/tar/bsdtar_windows.h
new file mode 100644
index 00000000000..092ea6959d8
--- /dev/null
+++ b/archivers/libarchive/files/tar/bsdtar_windows.h
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2009 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef BSDTAR_WINDOWS_H
+#define BSDTAR_WINDOWS_H 1
+#include <direct.h>
+#include <windows.h>
+
+#ifndef PRId64
+#define PRId64 "I64"
+#endif
+#define geteuid() 0
+
+#ifndef S_IFIFO
+#define S_IFIFO 0010000 /* pipe */
+#endif
+
+#include <string.h> /* Must include before redefining 'strdup' */
+#if !defined(__BORLANDC__)
+#define strdup _strdup
+#endif
+#if !defined(__BORLANDC__)
+#define getcwd _getcwd
+#endif
+
+#define chdir __tar_chdir
+int __tar_chdir(const char *);
+
+#ifndef S_ISREG
+#define S_ISREG(a) (a & _S_IFREG)
+#endif
+#ifndef S_ISBLK
+#define S_ISBLK(a) (0)
+#endif
+
+#endif /* BSDTAR_WINDOWS_H */
diff --git a/archivers/libarchive/files/tar/cmdline.c b/archivers/libarchive/files/tar/cmdline.c
new file mode 100644
index 00000000000..ba3e8a1b2a8
--- /dev/null
+++ b/archivers/libarchive/files/tar/cmdline.c
@@ -0,0 +1,381 @@
+/*-
+ * 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.
+ */
+
+/*
+ * Command line parser for tar.
+ */
+
+#include "bsdtar_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "bsdtar.h"
+#include "err.h"
+
+/*
+ * Short options for tar. Please keep this sorted.
+ */
+static const char *short_options
+ = "Bb:C:cf:HhI:JjkLlmnOoPpqrSs:T:tUuvW:wX:xyZz";
+
+/*
+ * Long options for tar. Please keep this list sorted.
+ *
+ * The symbolic names for options that lack a short equivalent are
+ * defined in bsdtar.h. Also note that so far I've found no need
+ * to support optional arguments to long options. That would be
+ * a small change to the code below.
+ */
+
+static struct option {
+ const char *name;
+ int required; /* 1 if this option requires an argument. */
+ int equivalent; /* Equivalent short option. */
+} tar_longopts[] = {
+ { "absolute-paths", 0, 'P' },
+ { "append", 0, 'r' },
+ { "block-size", 1, 'b' },
+ { "bunzip2", 0, 'j' },
+ { "bzip", 0, 'j' },
+ { "bzip2", 0, 'j' },
+ { "cd", 1, 'C' },
+ { "check-links", 0, OPTION_CHECK_LINKS },
+ { "chroot", 0, OPTION_CHROOT },
+ { "compress", 0, 'Z' },
+ { "confirmation", 0, 'w' },
+ { "create", 0, 'c' },
+ { "dereference", 0, 'L' },
+ { "directory", 1, 'C' },
+ { "exclude", 1, OPTION_EXCLUDE },
+ { "exclude-from", 1, 'X' },
+ { "extract", 0, 'x' },
+ { "fast-read", 0, 'q' },
+ { "file", 1, 'f' },
+ { "files-from", 1, 'T' },
+ { "format", 1, OPTION_FORMAT },
+ { "options", 1, OPTION_OPTIONS },
+ { "gunzip", 0, 'z' },
+ { "gzip", 0, 'z' },
+ { "help", 0, OPTION_HELP },
+ { "include", 1, OPTION_INCLUDE },
+ { "interactive", 0, 'w' },
+ { "insecure", 0, 'P' },
+ { "keep-newer-files", 0, OPTION_KEEP_NEWER_FILES },
+ { "keep-old-files", 0, 'k' },
+ { "list", 0, 't' },
+ { "lzma", 0, OPTION_LZMA },
+ { "modification-time", 0, 'm' },
+ { "newer", 1, OPTION_NEWER_CTIME },
+ { "newer-ctime", 1, OPTION_NEWER_CTIME },
+ { "newer-ctime-than", 1, OPTION_NEWER_CTIME_THAN },
+ { "newer-mtime", 1, OPTION_NEWER_MTIME },
+ { "newer-mtime-than", 1, OPTION_NEWER_MTIME_THAN },
+ { "newer-than", 1, OPTION_NEWER_CTIME_THAN },
+ { "nodump", 0, OPTION_NODUMP },
+ { "norecurse", 0, 'n' },
+ { "no-recursion", 0, 'n' },
+ { "no-same-owner", 0, OPTION_NO_SAME_OWNER },
+ { "no-same-permissions", 0, OPTION_NO_SAME_PERMISSIONS },
+ { "null", 0, OPTION_NULL },
+ { "numeric-owner", 0, OPTION_NUMERIC_OWNER },
+ { "one-file-system", 0, OPTION_ONE_FILE_SYSTEM },
+ { "posix", 0, OPTION_POSIX },
+ { "preserve-permissions", 0, 'p' },
+ { "read-full-blocks", 0, 'B' },
+ { "same-owner", 0, OPTION_SAME_OWNER },
+ { "same-permissions", 0, 'p' },
+ { "strip-components", 1, OPTION_STRIP_COMPONENTS },
+ { "to-stdout", 0, 'O' },
+ { "totals", 0, OPTION_TOTALS },
+ { "uncompress", 0, 'Z' },
+ { "unlink", 0, 'U' },
+ { "unlink-first", 0, 'U' },
+ { "update", 0, 'u' },
+ { "use-compress-program", 1, OPTION_USE_COMPRESS_PROGRAM },
+ { "verbose", 0, 'v' },
+ { "version", 0, OPTION_VERSION },
+ { "xz", 0, 'J' },
+ { NULL, 0, 0 }
+};
+
+/*
+ * This getopt implementation has two key features that common
+ * getopt_long() implementations lack. Apart from those, it's a
+ * straightforward option parser, considerably simplified by not
+ * needing to support the wealth of exotic getopt_long() features. It
+ * has, of course, been shamelessly tailored for bsdtar. (If you're
+ * looking for a generic getopt_long() implementation for your
+ * project, I recommend Gregory Pietsch's public domain getopt_long()
+ * implementation.) The two additional features are:
+ *
+ * Old-style tar arguments: The original tar implementation treated
+ * the first argument word as a list of single-character option
+ * letters. All arguments follow as separate words. For example,
+ * tar xbf 32 /dev/tape
+ * Here, the "xbf" is three option letters, "32" is the argument for
+ * "b" and "/dev/tape" is the argument for "f". We support this usage
+ * if the first command-line argument does not begin with '-'. We
+ * also allow regular short and long options to follow, e.g.,
+ * tar xbf 32 /dev/tape -P --format=pax
+ *
+ * -W long options: There's an obscure GNU convention (only rarely
+ * supported even there) that allows "-W option=argument" as an
+ * alternative way to support long options. This was supported in
+ * early bsdtar as a way to access long options on platforms that did
+ * not support getopt_long() and is preserved here for backwards
+ * compatibility. (Of course, if I'd started with a custom
+ * command-line parser from the beginning, I would have had normal
+ * long option support on every platform so that hack wouldn't have
+ * been necessary. Oh, well. Some mistakes you just have to live
+ * with.)
+ *
+ * TODO: We should be able to use this to pull files and intermingled
+ * options (such as -C) from the command line in write mode. That
+ * will require a little rethinking of the argument handling in
+ * bsdtar.c.
+ *
+ * TODO: If we want to support arbitrary command-line options from -T
+ * input (as GNU tar does), we may need to extend this to handle option
+ * words from sources other than argv/arc. I'm not really sure if I
+ * like that feature of GNU tar, so it's certainly not a priority.
+ */
+
+int
+bsdtar_getopt(struct bsdtar *bsdtar)
+{
+ enum { state_start = 0, state_old_tar, state_next_word,
+ state_short, state_long };
+ static int state = state_start;
+ static char *opt_word;
+
+ const struct option *popt, *match = NULL, *match2 = NULL;
+ const char *p, *long_prefix = "--";
+ size_t optlength;
+ int opt = '?';
+ int required = 0;
+
+ bsdtar->optarg = NULL;
+
+ /* First time through, initialize everything. */
+ if (state == state_start) {
+ /* Skip program name. */
+ ++bsdtar->argv;
+ --bsdtar->argc;
+ if (*bsdtar->argv == NULL)
+ return (-1);
+ /* Decide between "new style" and "old style" arguments. */
+ if (bsdtar->argv[0][0] == '-') {
+ state = state_next_word;
+ } else {
+ state = state_old_tar;
+ opt_word = *bsdtar->argv++;
+ --bsdtar->argc;
+ }
+ }
+
+ /*
+ * We're parsing old-style tar arguments
+ */
+ if (state == state_old_tar) {
+ /* Get the next option character. */
+ opt = *opt_word++;
+ if (opt == '\0') {
+ /* New-style args can follow old-style. */
+ state = state_next_word;
+ } else {
+ /* See if it takes an argument. */
+ p = strchr(short_options, opt);
+ if (p == NULL)
+ return ('?');
+ if (p[1] == ':') {
+ bsdtar->optarg = *bsdtar->argv;
+ if (bsdtar->optarg == NULL) {
+ lafe_warnc(0,
+ "Option %c requires an argument",
+ opt);
+ return ('?');
+ }
+ ++bsdtar->argv;
+ --bsdtar->argc;
+ }
+ }
+ }
+
+ /*
+ * We're ready to look at the next word in argv.
+ */
+ if (state == state_next_word) {
+ /* No more arguments, so no more options. */
+ if (bsdtar->argv[0] == NULL)
+ return (-1);
+ /* Doesn't start with '-', so no more options. */
+ if (bsdtar->argv[0][0] != '-')
+ return (-1);
+ /* "--" marks end of options; consume it and return. */
+ if (strcmp(bsdtar->argv[0], "--") == 0) {
+ ++bsdtar->argv;
+ --bsdtar->argc;
+ return (-1);
+ }
+ /* Get next word for parsing. */
+ opt_word = *bsdtar->argv++;
+ --bsdtar->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;
+ return bsdtar_getopt(bsdtar);
+ }
+
+ /* 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 = *bsdtar->argv;
+ if (opt_word == NULL) {
+ lafe_warnc(0,
+ "Option -%c requires an argument",
+ opt);
+ return ('?');
+ }
+ ++bsdtar->argv;
+ --bsdtar->argc;
+ }
+ if (opt == 'W') {
+ state = state_long;
+ long_prefix = "-W "; /* For clearer errors. */
+ } else {
+ state = state_next_word;
+ bsdtar->optarg = 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);
+ bsdtar->optarg = (char *)(uintptr_t)(p + 1);
+ } else {
+ optlength = strlen(opt_word);
+ }
+
+ /* Search the table for an unambiguous match. */
+ for (popt = tar_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 (bsdtar->optarg == NULL) {
+ bsdtar->optarg = *bsdtar->argv;
+ if (bsdtar->optarg == NULL) {
+ lafe_warnc(0,
+ "Option %s%s requires an argument",
+ long_prefix, match->name);
+ return ('?');
+ }
+ ++bsdtar->argv;
+ --bsdtar->argc;
+ }
+ } else {
+ /* Argument forbidden: fail if there is one. */
+ if (bsdtar->optarg != NULL) {
+ lafe_warnc(0,
+ "Option %s%s does not allow an argument",
+ long_prefix, match->name);
+ return ('?');
+ }
+ }
+ return (match->equivalent);
+ }
+
+ return (opt);
+}
diff --git a/archivers/libarchive/files/tar/config_freebsd.h b/archivers/libarchive/files/tar/config_freebsd.h
new file mode 100644
index 00000000000..37aa9dcae17
--- /dev/null
+++ b/archivers/libarchive/files/tar/config_freebsd.h
@@ -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.
+ *
+ * $FreeBSD: src/usr.bin/tar/config_freebsd.h,v 1.8 2008/11/29 20:06:53 kientzle Exp $
+ */
+
+/* A default configuration for FreeBSD, used if there is no config.h. */
+
+#include <sys/param.h> /* __FreeBSD_version */
+
+#undef HAVE_ATTR_XATTR_H
+#define HAVE_CHROOT 1
+#define HAVE_DIRENT_D_NAMLEN 1
+#define HAVE_DIRENT_H 1
+#define HAVE_D_MD_ORDER 1
+#define HAVE_ERRNO_H 1
+#undef HAVE_EXT2FS_EXT2_FS_H
+#define HAVE_FCHDIR 1
+#define HAVE_FCNTL_H 1
+#define HAVE_GRP_H 1
+#define HAVE_LANGINFO_H 1
+#undef HAVE_LIBACL
+#define HAVE_LIBARCHIVE 1
+#define HAVE_LIMITS_H 1
+#define HAVE_LINK 1
+#undef HAVE_LINUX_EXT2_FS_H
+#undef HAVE_LINUX_FS_H
+#define HAVE_LOCALE_H 1
+#define HAVE_MBTOWC 1
+#undef HAVE_NDIR_H
+#if __FreeBSD_version >= 450002 /* nl_langinfo introduced */
+#define HAVE_NL_LANGINFO 1
+#endif
+#define HAVE_PATHS_H 1
+#define HAVE_PWD_H 1
+#define HAVE_READLINK 1
+#define HAVE_REGEX_H 1
+#define HAVE_SETLOCALE 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDARG_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRING_H 1
+#define HAVE_STRUCT_STAT_ST_FLAGS 1
+#undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+#undef HAVE_STRUCT_STAT_ST_MTIME_N
+#undef HAVE_STRUCT_STAT_ST_MTIME_USEC
+#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
+#undef HAVE_STRUCT_STAT_ST_UMTIME
+#define HAVE_SYMLINK 1
+#define HAVE_SYS_CDEFS_H 1
+#undef HAVE_SYS_DIR_H
+#define HAVE_SYS_IOCTL_H 1
+#undef HAVE_SYS_NDIR_H
+#define HAVE_SYS_PARAM_H 1
+#define HAVE_SYS_STAT_H 1
+#define HAVE_TIME_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_UINTMAX_T 1
+#define HAVE_UNISTD_H 1
+#define HAVE_UNSIGNED_LONG_LONG
+#define HAVE_WCTYPE_H 1
+#define HAVE_ZLIB_H 1
+#undef MAJOR_IN_MKDEV
diff --git a/archivers/libarchive/files/tar/getdate.c b/archivers/libarchive/files/tar/getdate.c
index 895320bd670..ffaa679ba1a 100644
--- a/archivers/libarchive/files/tar/getdate.c
+++ b/archivers/libarchive/files/tar/getdate.c
@@ -1,101 +1,19 @@
-/* A Bison parser, made by GNU Bison 2.1. */
-
-/* Skeleton parser for Yacc-like parsing with Bison,
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
-
-/* As a special exception, when this file is copied by Bison into a
- Bison output file, you may use that output file without restriction.
- This special exception was added by the Free Software Foundation
- in version 1.24 of Bison. */
-
-/* Written by Richard Stallman by simplifying the original so called
- ``semantic'' parser. */
-
-/* All symbols defined below should begin with yy or YY, to avoid
- infringing on user name space. This should be done even for local
- variables, as they might otherwise be expanded by user macros.
- There are some unavoidable exceptions within include files to
- define necessary library symbols; they are noted "INFRINGES ON
- USER NAME SPACE" below. */
-
-/* Identify Bison output. */
-#define YYBISON 1
-
-/* Bison version. */
-#define YYBISON_VERSION "2.1"
-
-/* Skeleton name. */
-#define YYSKELETON_NAME "yacc.c"
-
-/* Pure parsers. */
-#define YYPURE 0
-
-/* Using locations. */
-#define YYLSP_NEEDED 0
-
-
-
-/* Tokens. */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum yytokentype {
- tAGO = 258,
- tDAY = 259,
- tDAYZONE = 260,
- tAMPM = 261,
- tMONTH = 262,
- tMONTH_UNIT = 263,
- tSEC_UNIT = 264,
- tUNUMBER = 265,
- tZONE = 266,
- tDST = 267
- };
-#endif
-/* Tokens. */
-#define tAGO 258
-#define tDAY 259
-#define tDAYZONE 260
-#define tAMPM 261
-#define tMONTH 262
-#define tMONTH_UNIT 263
-#define tSEC_UNIT 264
-#define tUNUMBER 265
-#define tZONE 266
-#define tDST 267
-
-
-
-
-/* Copy the first part of user declarations. */
-#line 1 "getdate.y"
+/*
+ * This code is in the public domain and has no copyright.
+ *
+ * This is a plain C recursive-descent translation of an old
+ * public-domain YACC grammar that has been used for parsing dates in
+ * very many open-source projects.
+ *
+ * Since the original authors were generous enough to donate their
+ * work to the public domain, I feel compelled to match their
+ * generosity.
+ *
+ * Tim Kientzle, February 2009.
+ */
/*
- * March 2005: Further modified and simplified by Tim Kientzle:
- * Eliminate minutes-based calculations (just do everything in
- * seconds), have lexer only recognize unsigned integers (handle '+'
- * and '-' characters in grammar), combine tables into one table with
- * explicit abbreviation notes, do am/pm adjustments in the grammar
- * (eliminate some state variables and post-processing). Among other
- * things, these changes eliminated two shift/reduce conflicts. (Went
- * from 10 to 8.)
- * All of Tim Kientzle's changes to this file are public domain.
+ * Header comment from original getdate.y:
*/
/*
@@ -108,12 +26,10 @@
**
** This code is in the public domain and has no copyright.
*/
-/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
-/* SUPPRESS 288 on yyerrlab *//* Label unused */
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/tar/getdate.y,v 1.9 2007/07/20 01:27:50 kientzle Exp $");
+__FBSDID("$FreeBSD$");
#endif
#include <ctype.h>
@@ -122,1742 +38,484 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/getdate.y,v 1.9 2007/07/20 01:27:50 kientzle
#include <string.h>
#include <time.h>
-#define yyparse getdate_yyparse
-#define yylex getdate_yylex
-#define yyerror getdate_yyerror
-
-static int yyparse(void);
-static int yylex(void);
-static int yyerror(const char *);
-
-time_t get_date(char *);
+/* This file defines a single public function. */
+time_t get_date(time_t now, char *);
-#define EPOCH 1970
-#define HOUR(x) ((time_t)(x) * 60)
-#define SECSPERDAY (24L * 60L * 60L)
+/* Basic time units. */
+#define EPOCH 1970
+#define MINUTE (60L)
+#define HOUR (60L * MINUTE)
+#define DAY (24L * HOUR)
-/*
-** Daylight-savings mode: on, off, or not yet known.
-*/
-typedef enum _DSTMODE {
- DSTon, DSToff, DSTmaybe
-} DSTMODE;
-
-/*
-** Meridian: am or pm.
-*/
+/* Daylight-savings mode: on, off, or not yet known. */
+enum DSTMODE { DSTon, DSToff, DSTmaybe };
+/* Meridian: am or pm. */
enum { tAM, tPM };
+/* Token types returned by nexttoken() */
+enum { tAGO = 260, tDAY, tDAYZONE, tAMPM, tMONTH, tMONTH_UNIT, tSEC_UNIT,
+ tUNUMBER, tZONE, tDST };
+struct token { int token; time_t value; };
/*
-** Global variables. We could get rid of most of these by using a good
-** union as the yacc stack. (This routine was originally written before
-** yacc had the %union construct.) Maybe someday; right now we only use
-** the %union very rarely.
-*/
-static char *yyInput;
-
-static DSTMODE yyDSTmode;
-static time_t yyDayOrdinal;
-static time_t yyDayNumber;
-static int yyHaveDate;
-static int yyHaveDay;
-static int yyHaveRel;
-static int yyHaveTime;
-static int yyHaveZone;
-static time_t yyTimezone;
-static time_t yyDay;
-static time_t yyHour;
-static time_t yyMinutes;
-static time_t yyMonth;
-static time_t yySeconds;
-static time_t yyYear;
-static time_t yyRelMonth;
-static time_t yyRelSeconds;
-
-
-
-/* Enabling traces. */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-
-/* Enabling verbose error messages. */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 0
-#endif
-
-/* Enabling the token table. */
-#ifndef YYTOKEN_TABLE
-# define YYTOKEN_TABLE 0
-#endif
-
-#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
-#line 92 "getdate.y"
-typedef union YYSTYPE {
- time_t Number;
-} YYSTYPE;
-/* Line 196 of yacc.c. */
-#line 204 "tar/getdate.c"
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
-# define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
-#endif
-
-
-
-/* Copy the second part of user declarations. */
-
-
-/* Line 219 of yacc.c. */
-#line 216 "tar/getdate.c"
-
-#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
-# define YYSIZE_T __SIZE_TYPE__
-#endif
-#if ! defined (YYSIZE_T) && defined (size_t)
-# define YYSIZE_T size_t
-#endif
-#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
-#endif
-#if ! defined (YYSIZE_T)
-# define YYSIZE_T unsigned int
-#endif
-
-#ifndef YY_
-# if YYENABLE_NLS
-# if ENABLE_NLS
-# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-# define YY_(msgid) dgettext ("bison-runtime", msgid)
-# endif
-# endif
-# ifndef YY_
-# define YY_(msgid) msgid
-# endif
-#endif
-
-#if ! defined (yyoverflow) || YYERROR_VERBOSE
-
-/* The parser invokes alloca or malloc; define the necessary symbols. */
-
-# ifdef YYSTACK_USE_ALLOCA
-# if YYSTACK_USE_ALLOCA
-# ifdef __GNUC__
-# define YYSTACK_ALLOC __builtin_alloca
-# else
-# define YYSTACK_ALLOC alloca
-# if defined (__STDC__) || defined (__cplusplus)
-# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-# define YYINCLUDED_STDLIB_H
-# endif
-# endif
-# endif
-# endif
-
-# ifdef YYSTACK_ALLOC
- /* Pacify GCC's `empty if-body' warning. */
-# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
-# ifndef YYSTACK_ALLOC_MAXIMUM
- /* The OS might guarantee only one guard page at the bottom of the stack,
- and a page size can be as small as 4096 bytes. So we cannot safely
- invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
- to allow for a few compiler-allocated temporary stack slots. */
-# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */
-# endif
-# else
-# define YYSTACK_ALLOC YYMALLOC
-# define YYSTACK_FREE YYFREE
-# ifndef YYSTACK_ALLOC_MAXIMUM
-# define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
-# endif
-# ifdef __cplusplus
-extern "C" {
-# endif
-# ifndef YYMALLOC
-# define YYMALLOC malloc
-# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
- && (defined (__STDC__) || defined (__cplusplus)))
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
-# endif
-# endif
-# ifndef YYFREE
-# define YYFREE free
-# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
- && (defined (__STDC__) || defined (__cplusplus)))
-void free (void *); /* INFRINGES ON USER NAME SPACE */
-# endif
-# endif
-# ifdef __cplusplus
-}
-# endif
-# endif
-#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
-
-
-#if (! defined (yyoverflow) \
- && (! defined (__cplusplus) \
- || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
-
-/* A type that is properly aligned for any stack member. */
-union yyalloc
-{
- short int yyss;
- YYSTYPE yyvs;
- };
-
-/* The size of the maximum gap between one aligned stack and the next. */
-# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
-
-/* The size of an array large to enough to hold all stacks, each with
- N elements. */
-# define YYSTACK_BYTES(N) \
- ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \
- + YYSTACK_GAP_MAXIMUM)
-
-/* Copy COUNT objects from FROM to TO. The source and destination do
- not overlap. */
-# ifndef YYCOPY
-# if defined (__GNUC__) && 1 < __GNUC__
-# define YYCOPY(To, From, Count) \
- __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
-# else
-# define YYCOPY(To, From, Count) \
- do \
- { \
- YYSIZE_T yyi; \
- for (yyi = 0; yyi < (Count); yyi++) \
- (To)[yyi] = (From)[yyi]; \
- } \
- while (0)
-# endif
-# endif
-
-/* Relocate STACK from its old location to the new one. The
- local variables YYSIZE and YYSTACKSIZE give the old and new number of
- elements in the stack, and YYPTR gives the new location of the
- stack. Advance YYPTR to a properly aligned location for the next
- stack. */
-# define YYSTACK_RELOCATE(Stack) \
- do \
- { \
- YYSIZE_T yynewbytes; \
- YYCOPY (&yyptr->Stack, Stack, yysize); \
- Stack = &yyptr->Stack; \
- yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
- yyptr += yynewbytes / sizeof (*yyptr); \
- } \
- while (0)
-
-#endif
-
-#if defined (__STDC__) || defined (__cplusplus)
- typedef signed char yysigned_char;
-#else
- typedef short int yysigned_char;
-#endif
-
-/* YYFINAL -- State number of the termination state. */
-#define YYFINAL 2
-/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 50
-
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS 18
-/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS 11
-/* YYNRULES -- Number of rules. */
-#define YYNRULES 41
-/* YYNRULES -- Number of states. */
-#define YYNSTATES 59
-
-/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
-#define YYUNDEFTOK 2
-#define YYMAXUTOK 267
-
-#define YYTRANSLATE(YYX) \
- ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
-static const unsigned char yytranslate[] =
-{
- 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 13, 16, 14, 2, 17, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 15, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
- 5, 6, 7, 8, 9, 10, 11, 12
-};
-
-#if YYDEBUG
-/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
- YYRHS. */
-static const unsigned char yyprhs[] =
-{
- 0, 0, 3, 4, 7, 9, 11, 13, 15, 17,
- 19, 22, 24, 27, 31, 35, 39, 45, 47, 49,
- 52, 54, 57, 60, 64, 70, 76, 82, 85, 90,
- 93, 97, 100, 102, 106, 110, 113, 115, 119, 123,
- 126, 128
-};
-
-/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const yysigned_char yyrhs[] =
-{
- 19, 0, -1, -1, 19, 20, -1, 21, -1, 23,
- -1, 25, -1, 24, -1, 26, -1, 28, -1, 10,
- 6, -1, 22, -1, 22, 6, -1, 22, 13, 10,
- -1, 22, 14, 10, -1, 10, 15, 10, -1, 10,
- 15, 10, 15, 10, -1, 11, -1, 5, -1, 11,
- 12, -1, 4, -1, 4, 16, -1, 10, 4, -1,
- 10, 17, 10, -1, 10, 17, 10, 17, 10, -1,
- 10, 14, 10, 14, 10, -1, 10, 14, 7, 14,
- 10, -1, 7, 10, -1, 7, 10, 16, 10, -1,
- 10, 7, -1, 10, 7, 10, -1, 27, 3, -1,
- 27, -1, 14, 10, 9, -1, 13, 10, 9, -1,
- 10, 9, -1, 9, -1, 14, 10, 8, -1, 13,
- 10, 8, -1, 10, 8, -1, 8, -1, 10, -1
-};
-
-/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
-static const unsigned short int yyrline[] =
-{
- 0, 104, 104, 105, 108, 109, 110, 111, 112, 113,
- 116, 126, 129, 136, 141, 148, 153, 160, 164, 168,
- 174, 178, 183, 190, 195, 214, 220, 233, 238, 244,
- 249, 257, 261, 264, 268, 272, 276, 280, 284, 288,
- 292, 298
-};
-#endif
-
-#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
-/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
- "$end", "error", "$undefined", "tAGO", "tDAY", "tDAYZONE", "tAMPM",
- "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tUNUMBER", "tZONE", "tDST", "'+'",
- "'-'", "':'", "','", "'/'", "$accept", "spec", "item", "time",
- "bare_time", "zone", "day", "date", "rel", "relunit", "number", 0
-};
-#endif
-
-# ifdef YYPRINT
-/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
- token YYLEX-NUM. */
-static const unsigned short int yytoknum[] =
-{
- 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
- 265, 266, 267, 43, 45, 58, 44, 47
-};
-# endif
-
-/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
-static const unsigned char yyr1[] =
-{
- 0, 18, 19, 19, 20, 20, 20, 20, 20, 20,
- 21, 21, 21, 21, 21, 22, 22, 23, 23, 23,
- 24, 24, 24, 25, 25, 25, 25, 25, 25, 25,
- 25, 26, 26, 27, 27, 27, 27, 27, 27, 27,
- 27, 28
-};
-
-/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
-static const unsigned char yyr2[] =
-{
- 0, 2, 0, 2, 1, 1, 1, 1, 1, 1,
- 2, 1, 2, 3, 3, 3, 5, 1, 1, 2,
- 1, 2, 2, 3, 5, 5, 5, 2, 4, 2,
- 3, 2, 1, 3, 3, 2, 1, 3, 3, 2,
- 1, 1
-};
-
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
- STATE-NUM when YYTABLE doesn't specify something else to do. Zero
- means the default is an error. */
-static const unsigned char yydefact[] =
-{
- 2, 0, 1, 20, 18, 0, 40, 36, 41, 17,
- 0, 0, 3, 4, 11, 5, 7, 6, 8, 32,
- 9, 21, 27, 22, 10, 29, 39, 35, 0, 0,
- 0, 19, 0, 0, 12, 0, 0, 31, 0, 30,
- 0, 0, 15, 23, 38, 34, 37, 33, 13, 14,
- 28, 0, 0, 0, 0, 26, 25, 16, 24
-};
-
-/* YYDEFGOTO[NTERM-NUM]. */
-static const yysigned_char yydefgoto[] =
-{
- -1, 1, 12, 13, 14, 15, 16, 17, 18, 19,
- 20
-};
-
-/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
- STATE-NUM. */
-#define YYPACT_NINF -8
-static const yysigned_char yypact[] =
-{
- -8, 0, -8, 14, -8, 2, -8, -8, 11, 15,
- 19, 21, -8, -8, 10, -8, -8, -8, -8, 29,
- -8, -8, 17, -8, -8, 24, -8, -8, -4, 25,
- 26, -8, -7, 13, -8, 27, 28, -8, 30, -8,
- 31, 32, 33, 22, -8, -8, -8, -8, -8, -8,
- -8, 34, 37, 39, 40, -8, -8, -8, -8
-};
-
-/* YYPGOTO[NTERM-NUM]. */
-static const yysigned_char yypgoto[] =
-{
- -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
- -8
-};
-
-/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
- positive, shift that token. If negative, reduce the rule which
- number is the opposite. If zero, do what YYDEFACT says.
- If YYTABLE_NINF, syntax error. */
-#define YYTABLE_NINF -1
-static const unsigned char yytable[] =
-{
- 2, 44, 45, 40, 3, 4, 41, 5, 6, 7,
- 8, 9, 22, 10, 11, 23, 34, 24, 25, 26,
- 27, 46, 47, 35, 36, 28, 29, 31, 30, 32,
- 21, 33, 37, 38, 39, 42, 43, 48, 49, 54,
- 50, 0, 0, 0, 55, 51, 52, 56, 53, 57,
- 58
-};
-
-static const yysigned_char yycheck[] =
-{
- 0, 8, 9, 7, 4, 5, 10, 7, 8, 9,
- 10, 11, 10, 13, 14, 4, 6, 6, 7, 8,
- 9, 8, 9, 13, 14, 14, 15, 12, 17, 10,
- 16, 10, 3, 16, 10, 10, 10, 10, 10, 17,
- 10, -1, -1, -1, 10, 14, 14, 10, 15, 10,
- 10
-};
-
-/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
- symbol of state STATE-NUM. */
-static const unsigned char yystos[] =
-{
- 0, 19, 0, 4, 5, 7, 8, 9, 10, 11,
- 13, 14, 20, 21, 22, 23, 24, 25, 26, 27,
- 28, 16, 10, 4, 6, 7, 8, 9, 14, 15,
- 17, 12, 10, 10, 6, 13, 14, 3, 16, 10,
- 7, 10, 10, 10, 8, 9, 8, 9, 10, 10,
- 10, 14, 14, 15, 17, 10, 10, 10, 10
+ * Parser state.
+ */
+struct gdstate {
+ struct token *tokenp; /* Pointer to next token. */
+ /* HaveXxxx counts how many of this kind of phrase we've seen;
+ * it's a fatal error to have more than one time, zone, day,
+ * or date phrase. */
+ int HaveYear;
+ int HaveMonth;
+ int HaveDay;
+ int HaveWeekDay; /* Day of week */
+ int HaveTime; /* Hour/minute/second */
+ int HaveZone; /* timezone and/or DST info */
+ int HaveRel; /* time offset; we can have more than one */
+ /* Absolute time values. */
+ time_t Timezone; /* Seconds offset from GMT */
+ time_t Day;
+ time_t Hour;
+ time_t Minutes;
+ time_t Month;
+ time_t Seconds;
+ time_t Year;
+ /* DST selection */
+ enum DSTMODE DSTmode;
+ /* Day of week accounting, e.g., "3rd Tuesday" */
+ time_t DayOrdinal; /* "3" in "3rd Tuesday" */
+ time_t DayNumber; /* "Tuesday" in "3rd Tuesday" */
+ /* Relative time values: hour/day/week offsets are measured in
+ * seconds, month/year are counted in months. */
+ time_t RelMonth;
+ time_t RelSeconds;
};
-#define yyerrok (yyerrstatus = 0)
-#define yyclearin (yychar = YYEMPTY)
-#define YYEMPTY (-2)
-#define YYEOF 0
-
-#define YYACCEPT goto yyacceptlab
-#define YYABORT goto yyabortlab
-#define YYERROR goto yyerrorlab
-
-
-/* Like YYERROR except do call yyerror. This remains here temporarily
- to ease the transition to the new meaning of YYERROR, for GCC.
- Once GCC version 2 has supplanted version 1, this can go. */
-
-#define YYFAIL goto yyerrlab
-
-#define YYRECOVERING() (!!yyerrstatus)
-
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY && yylen == 1) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- yytoken = YYTRANSLATE (yychar); \
- YYPOPSTACK; \
- goto yybackup; \
- } \
- else \
- { \
- yyerror (YY_("syntax error: cannot back up")); \
- YYERROR; \
- } \
-while (0)
-
-
-#define YYTERROR 1
-#define YYERRCODE 256
-
-
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (0)
-#endif
-
-
-/* YY_LOCATION_PRINT -- Print the location on the stream.
- This macro was not mandated originally: define only if we know
- we won't break user code: when these are the locations we know. */
-
-#ifndef YY_LOCATION_PRINT
-# if YYLTYPE_IS_TRIVIAL
-# define YY_LOCATION_PRINT(File, Loc) \
- fprintf (File, "%d.%d-%d.%d", \
- (Loc).first_line, (Loc).first_column, \
- (Loc).last_line, (Loc).last_column)
-# else
-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
-#endif
-
-
-/* YYLEX -- calling `yylex' with the right arguments. */
-
-#ifdef YYLEX_PARAM
-# define YYLEX yylex (YYLEX_PARAM)
-#else
-# define YYLEX yylex ()
-#endif
-
-/* Enable debugging if requested. */
-#if YYDEBUG
-
-# ifndef YYFPRINTF
-# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
-# define YYFPRINTF fprintf
-# endif
-
-# define YYDPRINTF(Args) \
-do { \
- if (yydebug) \
- YYFPRINTF Args; \
-} while (0)
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
-do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yysymprint (stderr, \
- Type, Value); \
- YYFPRINTF (stderr, "\n"); \
- } \
-} while (0)
-
-/*------------------------------------------------------------------.
-| yy_stack_print -- Print the state stack from its BOTTOM up to its |
-| TOP (included). |
-`------------------------------------------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yy_stack_print (short int *bottom, short int *top)
-#else
-static void
-yy_stack_print (bottom, top)
- short int *bottom;
- short int *top;
-#endif
-{
- YYFPRINTF (stderr, "Stack now");
- for (/* Nothing. */; bottom <= top; ++bottom)
- YYFPRINTF (stderr, " %d", *bottom);
- YYFPRINTF (stderr, "\n");
-}
-
-# define YY_STACK_PRINT(Bottom, Top) \
-do { \
- if (yydebug) \
- yy_stack_print ((Bottom), (Top)); \
-} while (0)
-
-
-/*------------------------------------------------.
-| Report that the YYRULE is going to be reduced. |
-`------------------------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yy_reduce_print (int yyrule)
-#else
-static void
-yy_reduce_print (yyrule)
- int yyrule;
-#endif
-{
- int yyi;
- unsigned long int yylno = yyrline[yyrule];
- YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
- yyrule - 1, yylno);
- /* Print the symbols being reduced, and their result. */
- for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
- YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
- YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
-}
-
-# define YY_REDUCE_PRINT(Rule) \
-do { \
- if (yydebug) \
- yy_reduce_print (Rule); \
-} while (0)
-
-/* Nonzero means print parse trace. It is left uninitialized so that
- multiple parsers can coexist. */
-int yydebug;
-#else /* !YYDEBUG */
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-# define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
-#endif /* !YYDEBUG */
-
-
-/* YYINITDEPTH -- initial size of the parser's stacks. */
-#ifndef YYINITDEPTH
-# define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
- if the built-in stack extension method is used).
-
- Do not make this value too large; the results are undefined if
- YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
- evaluated with infinite-precision integer arithmetic. */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH 10000
-#endif
-
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystrlen
-# if defined (__GLIBC__) && defined (_STRING_H)
-# define yystrlen strlen
-# else
-/* Return the length of YYSTR. */
-static YYSIZE_T
-# if defined (__STDC__) || defined (__cplusplus)
-yystrlen (const char *yystr)
-# else
-yystrlen (yystr)
- const char *yystr;
-# endif
-{
- const char *yys = yystr;
-
- while (*yys++ != '\0')
- continue;
-
- return yys - yystr - 1;
-}
-# endif
-# endif
-
-# ifndef yystpcpy
-# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
-# define yystpcpy stpcpy
-# else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
- YYDEST. */
-static char *
-# if defined (__STDC__) || defined (__cplusplus)
-yystpcpy (char *yydest, const char *yysrc)
-# else
-yystpcpy (yydest, yysrc)
- char *yydest;
- const char *yysrc;
-# endif
-{
- char *yyd = yydest;
- const char *yys = yysrc;
-
- while ((*yyd++ = *yys++) != '\0')
- continue;
-
- return yyd - 1;
-}
-# endif
-# endif
-
-# ifndef yytnamerr
-/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
- quotes and backslashes, so that it's suitable for yyerror. The
- heuristic is that double-quoting is unnecessary unless the string
- contains an apostrophe, a comma, or backslash (other than
- backslash-backslash). YYSTR is taken from yytname. If YYRES is
- null, do not copy; instead, return the length of what the result
- would have been. */
-static YYSIZE_T
-yytnamerr (char *yyres, const char *yystr)
-{
- if (*yystr == '"')
- {
- size_t yyn = 0;
- char const *yyp = yystr;
-
- for (;;)
- switch (*++yyp)
- {
- case '\'':
- case ',':
- goto do_not_strip_quotes;
-
- case '\\':
- if (*++yyp != '\\')
- goto do_not_strip_quotes;
- /* Fall through. */
- default:
- if (yyres)
- yyres[yyn] = *yyp;
- yyn++;
- break;
-
- case '"':
- if (yyres)
- yyres[yyn] = '\0';
- return yyn;
- }
- do_not_strip_quotes: ;
- }
-
- if (! yyres)
- return yystrlen (yystr);
-
- return yystpcpy (yyres, yystr) - yyres;
-}
-# endif
-
-#endif /* YYERROR_VERBOSE */
-
-
-
-#if YYDEBUG
-/*--------------------------------.
-| Print this symbol on YYOUTPUT. |
-`--------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
-#else
-static void
-yysymprint (yyoutput, yytype, yyvaluep)
- FILE *yyoutput;
- int yytype;
- YYSTYPE *yyvaluep;
-#endif
-{
- /* Pacify ``unused variable'' warnings. */
- (void) yyvaluep;
-
- if (yytype < YYNTOKENS)
- YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
- else
- YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
-
-
-# ifdef YYPRINT
- if (yytype < YYNTOKENS)
- YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# endif
- switch (yytype)
- {
- default:
- break;
- }
- YYFPRINTF (yyoutput, ")");
-}
-
-#endif /* ! YYDEBUG */
-/*-----------------------------------------------.
-| Release the memory associated to this symbol. |
-`-----------------------------------------------*/
-
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
-#else
-static void
-yydestruct (yymsg, yytype, yyvaluep)
- const char *yymsg;
- int yytype;
- YYSTYPE *yyvaluep;
-#endif
-{
- /* Pacify ``unused variable'' warnings. */
- (void) yyvaluep;
-
- if (!yymsg)
- yymsg = "Deleting";
- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-
- switch (yytype)
- {
-
- default:
- break;
- }
-}
-
-
-/* Prevent warnings from -Wmissing-prototypes. */
-
-#ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void *YYPARSE_PARAM);
-# else
-int yyparse ();
-# endif
-#else /* ! YYPARSE_PARAM */
-#if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
-
-
-
-/* The look-ahead symbol. */
-int yychar;
-
-/* The semantic value of the look-ahead symbol. */
-YYSTYPE yylval;
-
-/* Number of syntax errors so far. */
-int yynerrs;
-
-
-
-/*----------.
-| yyparse. |
-`----------*/
+/*
+ * A series of functions that recognize certain common time phrases.
+ * Each function returns 1 if it managed to make sense of some of the
+ * tokens, zero otherwise.
+ */
-#ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void *YYPARSE_PARAM)
-# else
-int yyparse (YYPARSE_PARAM)
- void *YYPARSE_PARAM;
-# endif
-#else /* ! YYPARSE_PARAM */
-#if defined (__STDC__) || defined (__cplusplus)
-int
-yyparse (void)
-#else
-int
-yyparse ()
- ;
-#endif
-#endif
+/*
+ * hour:minute or hour:minute:second with optional AM, PM, or numeric
+ * timezone offset
+ */
+static int
+timephrase(struct gdstate *gds)
{
-
- int yystate;
- int yyn;
- int yyresult;
- /* Number of tokens to shift before error messages enabled. */
- int yyerrstatus;
- /* Look-ahead token as an internal (translated) token number. */
- int yytoken = 0;
-
- /* Three stacks and their tools:
- `yyss': related to states,
- `yyvs': related to semantic values,
- `yyls': related to locations.
-
- Refer to the stacks thru separate pointers, to allow yyoverflow
- to reallocate them elsewhere. */
-
- /* The state stack. */
- short int yyssa[YYINITDEPTH];
- short int *yyss = yyssa;
- short int *yyssp;
-
- /* The semantic value stack. */
- YYSTYPE yyvsa[YYINITDEPTH];
- YYSTYPE *yyvs = yyvsa;
- YYSTYPE *yyvsp;
-
-
-
-#define YYPOPSTACK (yyvsp--, yyssp--)
-
- YYSIZE_T yystacksize = YYINITDEPTH;
-
- /* The variables used to return semantic value and location from the
- action routines. */
- YYSTYPE yyval;
-
-
- /* When reducing, the number of symbols on the RHS of the reduced
- rule. */
- int yylen;
-
- YYDPRINTF ((stderr, "Starting parse\n"));
-
- yystate = 0;
- yyerrstatus = 0;
- yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
-
- /* Initialize stack pointers.
- Waste one element of value and location stack
- so that they stay on the same level as the state stack.
- The wasted elements are never initialized. */
-
- yyssp = yyss;
- yyvsp = yyvs;
-
- goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate. |
-`------------------------------------------------------------*/
- yynewstate:
- /* In all cases, when you get here, the value and location stacks
- have just been pushed. so pushing a state here evens the stacks.
- */
- yyssp++;
-
- yysetstate:
- *yyssp = yystate;
-
- if (yyss + yystacksize - 1 <= yyssp)
- {
- /* Get the current used size of the three stacks, in elements. */
- YYSIZE_T yysize = yyssp - yyss + 1;
-
-#ifdef yyoverflow
- {
- /* Give user a chance to reallocate the stack. Use copies of
- these so that the &'s don't force the real ones into
- memory. */
- YYSTYPE *yyvs1 = yyvs;
- short int *yyss1 = yyss;
-
-
- /* Each stack pointer address is followed by the size of the
- data in use in that stack, in bytes. This used to be a
- conditional around just the two extra args, but that might
- be undefined if yyoverflow is a macro. */
- yyoverflow (YY_("memory exhausted"),
- &yyss1, yysize * sizeof (*yyssp),
- &yyvs1, yysize * sizeof (*yyvsp),
-
- &yystacksize);
-
- yyss = yyss1;
- yyvs = yyvs1;
- }
-#else /* no yyoverflow */
-# ifndef YYSTACK_RELOCATE
- goto yyexhaustedlab;
-# else
- /* Extend the stack our own way. */
- if (YYMAXDEPTH <= yystacksize)
- goto yyexhaustedlab;
- yystacksize *= 2;
- if (YYMAXDEPTH < yystacksize)
- yystacksize = YYMAXDEPTH;
-
- {
- short int *yyss1 = yyss;
- union yyalloc *yyptr =
- (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
- if (! yyptr)
- goto yyexhaustedlab;
- YYSTACK_RELOCATE (yyss);
- YYSTACK_RELOCATE (yyvs);
-
-# undef YYSTACK_RELOCATE
- if (yyss1 != yyssa)
- YYSTACK_FREE (yyss1);
- }
-# endif
-#endif /* no yyoverflow */
-
- yyssp = yyss + yysize - 1;
- yyvsp = yyvs + yysize - 1;
-
-
- YYDPRINTF ((stderr, "Stack size increased to %lu\n",
- (unsigned long int) yystacksize));
-
- if (yyss + yystacksize - 1 <= yyssp)
- YYABORT;
- }
-
- YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
- goto yybackup;
-
-/*-----------.
-| yybackup. |
-`-----------*/
-yybackup:
-
-/* Do appropriate processing given the current state. */
-/* Read a look-ahead token if we need one and don't already have one. */
-/* yyresume: */
-
- /* First try to decide what to do without reference to look-ahead token. */
-
- yyn = yypact[yystate];
- if (yyn == YYPACT_NINF)
- goto yydefault;
-
- /* Not known => get a look-ahead token if don't already have one. */
-
- /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
- if (yychar == YYEMPTY)
- {
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = YYLEX;
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
- goto yydefault;
- yyn = yytable[yyn];
- if (yyn <= 0)
- {
- if (yyn == 0 || yyn == YYTABLE_NINF)
- goto yyerrlab;
- yyn = -yyn;
- goto yyreduce;
- }
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- /* Shift the look-ahead token. */
- YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-
- /* Discard the token being shifted unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
-
- *++yyvsp = yylval;
-
-
- /* Count tokens shifted since error; after three, turn off error
- status. */
- if (yyerrstatus)
- yyerrstatus--;
-
- yystate = yyn;
- goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state. |
-`-----------------------------------------------------------*/
-yydefault:
- yyn = yydefact[yystate];
- if (yyn == 0)
- goto yyerrlab;
- goto yyreduce;
-
-
-/*-----------------------------.
-| yyreduce -- Do a reduction. |
-`-----------------------------*/
-yyreduce:
- /* yyn is the number of a rule to reduce with. */
- yylen = yyr2[yyn];
-
- /* If YYLEN is nonzero, implement the default value of the action:
- `$$ = $1'.
-
- Otherwise, the following line sets YYVAL to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. Assigning to YYVAL
- unconditionally makes the parser a bit smaller, and it avoids a
- GCC warning that YYVAL may be used uninitialized. */
- yyval = yyvsp[1-yylen];
-
-
- YY_REDUCE_PRINT (yyn);
- switch (yyn)
- {
- case 4:
-#line 108 "getdate.y"
- { yyHaveTime++; }
- break;
-
- case 5:
-#line 109 "getdate.y"
- { yyHaveZone++; }
- break;
-
- case 6:
-#line 110 "getdate.y"
- { yyHaveDate++; }
- break;
-
- case 7:
-#line 111 "getdate.y"
- { yyHaveDay++; }
- break;
-
- case 8:
-#line 112 "getdate.y"
- { yyHaveRel++; }
- break;
-
- case 10:
-#line 116 "getdate.y"
- {
- /* "7am" */
- yyHour = (yyvsp[-1].Number);
- if (yyHour == 12)
- yyHour = 0;
- yyMinutes = 0;
- yySeconds = 0;
- if ((yyvsp[0].Number) == tPM)
- yyHour += 12;
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == ':'
+ && gds->tokenp[2].token == tUNUMBER
+ && gds->tokenp[3].token == ':'
+ && gds->tokenp[4].token == tUNUMBER) {
+ /* "12:14:18" or "22:08:07" */
+ ++gds->HaveTime;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = gds->tokenp[2].value;
+ gds->Seconds = gds->tokenp[4].value;
+ gds->tokenp += 5;
}
- break;
-
- case 11:
-#line 126 "getdate.y"
- {
- /* "7:12:18" "19:17" */
+ else if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == ':'
+ && gds->tokenp[2].token == tUNUMBER) {
+ /* "12:14" or "22:08" */
+ ++gds->HaveTime;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = gds->tokenp[2].value;
+ gds->Seconds = 0;
+ gds->tokenp += 3;
+ }
+ else if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tAMPM) {
+ /* "7" is a time if it's followed by "am" or "pm" */
+ ++gds->HaveTime;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = gds->Seconds = 0;
+ /* We'll handle the AM/PM below. */
+ gds->tokenp += 1;
+ } else {
+ /* We can't handle this. */
+ return 0;
}
- break;
- case 12:
-#line 129 "getdate.y"
- {
+ if (gds->tokenp[0].token == tAMPM) {
/* "7:12pm", "12:20:13am" */
- if (yyHour == 12)
- yyHour = 0;
- if ((yyvsp[0].Number) == tPM)
- yyHour += 12;
+ if (gds->Hour == 12)
+ gds->Hour = 0;
+ if (gds->tokenp[0].value == tPM)
+ gds->Hour += 12;
+ gds->tokenp += 1;
}
- break;
-
- case 13:
-#line 136 "getdate.y"
- {
+ if (gds->tokenp[0].token == '+'
+ && gds->tokenp[1].token == tUNUMBER) {
/* "7:14+0700" */
- yyDSTmode = DSToff;
- yyTimezone = - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60);
+ gds->HaveZone++;
+ gds->DSTmode = DSToff;
+ gds->Timezone = - ((gds->tokenp[1].value / 100) * HOUR
+ + (gds->tokenp[1].value % 100) * MINUTE);
+ gds->tokenp += 2;
}
- break;
-
- case 14:
-#line 141 "getdate.y"
- {
+ if (gds->tokenp[0].token == '-'
+ && gds->tokenp[1].token == tUNUMBER) {
/* "19:14:12-0530" */
- yyDSTmode = DSToff;
- yyTimezone = + ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60);
- }
- break;
-
- case 15:
-#line 148 "getdate.y"
- {
- yyHour = (yyvsp[-2].Number);
- yyMinutes = (yyvsp[0].Number);
- yySeconds = 0;
- }
- break;
-
- case 16:
-#line 153 "getdate.y"
- {
- yyHour = (yyvsp[-4].Number);
- yyMinutes = (yyvsp[-2].Number);
- yySeconds = (yyvsp[0].Number);
- }
- break;
-
- case 17:
-#line 160 "getdate.y"
- {
- yyTimezone = (yyvsp[0].Number);
- yyDSTmode = DSToff;
+ gds->HaveZone++;
+ gds->DSTmode = DSToff;
+ gds->Timezone = + ((gds->tokenp[1].value / 100) * HOUR
+ + (gds->tokenp[1].value % 100) * MINUTE);
+ gds->tokenp += 2;
}
- break;
-
- case 18:
-#line 164 "getdate.y"
- {
- yyTimezone = (yyvsp[0].Number);
- yyDSTmode = DSTon;
- }
- break;
-
- case 19:
-#line 168 "getdate.y"
- {
- yyTimezone = (yyvsp[-1].Number);
- yyDSTmode = DSTon;
- }
- break;
+ return 1;
+}
- case 20:
-#line 174 "getdate.y"
- {
- yyDayOrdinal = 1;
- yyDayNumber = (yyvsp[0].Number);
- }
- break;
-
- case 21:
-#line 178 "getdate.y"
- {
- /* "tue," "wednesday," */
- yyDayOrdinal = 1;
- yyDayNumber = (yyvsp[-1].Number);
+/*
+ * Timezone name, possibly including DST.
+ */
+static int
+zonephrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tZONE
+ && gds->tokenp[1].token == tDST) {
+ gds->HaveZone++;
+ gds->Timezone = gds->tokenp[0].value;
+ gds->DSTmode = DSTon;
+ gds->tokenp += 1;
+ return 1;
}
- break;
- case 22:
-#line 183 "getdate.y"
- {
- /* "second tues" "3 wed" */
- yyDayOrdinal = (yyvsp[-1].Number);
- yyDayNumber = (yyvsp[0].Number);
+ if (gds->tokenp[0].token == tZONE) {
+ gds->HaveZone++;
+ gds->Timezone = gds->tokenp[0].value;
+ gds->DSTmode = DSToff;
+ gds->tokenp += 1;
+ return 1;
}
- break;
- case 23:
-#line 190 "getdate.y"
- {
- /* "1/15" */
- yyMonth = (yyvsp[-2].Number);
- yyDay = (yyvsp[0].Number);
+ if (gds->tokenp[0].token == tDAYZONE) {
+ gds->HaveZone++;
+ gds->Timezone = gds->tokenp[0].value;
+ gds->DSTmode = DSTon;
+ gds->tokenp += 1;
+ return 1;
}
- break;
+ return 0;
+}
- case 24:
-#line 195 "getdate.y"
- {
- if ((yyvsp[-4].Number) >= 13) {
+/*
+ * Year/month/day in various combinations.
+ */
+static int
+datephrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '/'
+ && gds->tokenp[2].token == tUNUMBER
+ && gds->tokenp[3].token == '/'
+ && gds->tokenp[4].token == tUNUMBER) {
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ if (gds->tokenp[0].value >= 13) {
/* First number is big: 2004/01/29, 99/02/17 */
- yyYear = (yyvsp[-4].Number);
- yyMonth = (yyvsp[-2].Number);
- yyDay = (yyvsp[0].Number);
- } else if (((yyvsp[0].Number) >= 13) || ((yyvsp[-2].Number) >= 13)) {
+ gds->Year = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Day = gds->tokenp[4].value;
+ } else if ((gds->tokenp[4].value >= 13)
+ || (gds->tokenp[2].value >= 13)) {
/* Last number is big: 01/07/98 */
/* Middle number is big: 01/29/04 */
- yyMonth = (yyvsp[-4].Number);
- yyDay = (yyvsp[-2].Number);
- yyYear = (yyvsp[0].Number);
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[2].value;
+ gds->Year = gds->tokenp[4].value;
} else {
/* No significant clues: 02/03/04 */
- yyMonth = (yyvsp[-4].Number);
- yyDay = (yyvsp[-2].Number);
- yyYear = (yyvsp[0].Number);
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[2].value;
+ gds->Year = gds->tokenp[4].value;
}
+ gds->tokenp += 5;
+ return 1;
+ }
+
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '/'
+ && gds->tokenp[2].token == tUNUMBER) {
+ /* "1/15" */
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
- case 25:
-#line 214 "getdate.y"
- {
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '-'
+ && gds->tokenp[2].token == tUNUMBER
+ && gds->tokenp[3].token == '-'
+ && gds->tokenp[4].token == tUNUMBER) {
/* ISO 8601 format. yyyy-mm-dd. */
- yyYear = (yyvsp[-4].Number);
- yyMonth = (yyvsp[-2].Number);
- yyDay = (yyvsp[0].Number);
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Year = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Day = gds->tokenp[4].value;
+ gds->tokenp += 5;
+ return 1;
}
- break;
- case 26:
-#line 220 "getdate.y"
- {
- if ((yyvsp[-4].Number) > 31) {
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == '-'
+ && gds->tokenp[2].token == tMONTH
+ && gds->tokenp[3].token == '-'
+ && gds->tokenp[4].token == tUNUMBER) {
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ if (gds->tokenp[0].value > 31) {
/* e.g. 1992-Jun-17 */
- yyYear = (yyvsp[-4].Number);
- yyMonth = (yyvsp[-2].Number);
- yyDay = (yyvsp[0].Number);
+ gds->Year = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Day = gds->tokenp[4].value;
} else {
/* e.g. 17-JUN-1992. */
- yyDay = (yyvsp[-4].Number);
- yyMonth = (yyvsp[-2].Number);
- yyYear = (yyvsp[0].Number);
+ gds->Day = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[2].value;
+ gds->Year = gds->tokenp[4].value;
}
+ gds->tokenp += 5;
+ return 1;
}
- break;
- case 27:
-#line 233 "getdate.y"
- {
- /* "May 3" */
- yyMonth = (yyvsp[-1].Number);
- yyDay = (yyvsp[0].Number);
- }
- break;
-
- case 28:
-#line 238 "getdate.y"
- {
+ if (gds->tokenp[0].token == tMONTH
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == ','
+ && gds->tokenp[3].token == tUNUMBER) {
/* "June 17, 2001" */
- yyMonth = (yyvsp[-3].Number);
- yyDay = (yyvsp[-2].Number);
- yyYear = (yyvsp[0].Number);
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[1].value;
+ gds->Year = gds->tokenp[3].value;
+ gds->tokenp += 4;
+ return 1;
}
- break;
- case 29:
-#line 244 "getdate.y"
- {
- /* "12 Sept" */
- yyDay = (yyvsp[-1].Number);
- yyMonth = (yyvsp[0].Number);
+ if (gds->tokenp[0].token == tMONTH
+ && gds->tokenp[1].token == tUNUMBER) {
+ /* "May 3" */
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Month = gds->tokenp[0].value;
+ gds->Day = gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
}
- break;
- case 30:
-#line 249 "getdate.y"
- {
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tMONTH
+ && gds->tokenp[2].token == tUNUMBER) {
/* "12 Sept 1997" */
- yyDay = (yyvsp[-2].Number);
- yyMonth = (yyvsp[-1].Number);
- yyYear = (yyvsp[0].Number);
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Day = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[1].value;
+ gds->Year = gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
- case 31:
-#line 257 "getdate.y"
- {
- yyRelSeconds = -yyRelSeconds;
- yyRelMonth = -yyRelMonth;
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tMONTH) {
+ /* "12 Sept" */
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Day = gds->tokenp[0].value;
+ gds->Month = gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
}
- break;
- case 33:
-#line 264 "getdate.y"
- {
+ return 0;
+}
+
+/*
+ * Relative time phrase: "tomorrow", "yesterday", "+1 hour", etc.
+ */
+static int
+relunitphrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == '-'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tSEC_UNIT) {
/* "-3 hours" */
- yyRelSeconds -= (yyvsp[-1].Number) * (yyvsp[0].Number);
+ gds->HaveRel++;
+ gds->RelSeconds -= gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
-
- case 34:
-#line 268 "getdate.y"
- {
+ if (gds->tokenp[0].token == '+'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tSEC_UNIT) {
/* "+1 minute" */
- yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
+ gds->HaveRel++;
+ gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
-
- case 35:
-#line 272 "getdate.y"
- {
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tSEC_UNIT) {
/* "1 day" */
- yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
+ gds->HaveRel++;
+ gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
-
- case 36:
-#line 276 "getdate.y"
- {
- /* "hour" */
- yyRelSeconds += (yyvsp[0].Number);
- }
- break;
-
- case 37:
-#line 280 "getdate.y"
- {
+ if (gds->tokenp[0].token == '-'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tMONTH_UNIT) {
/* "-3 months" */
- yyRelMonth -= (yyvsp[-1].Number) * (yyvsp[0].Number);
+ gds->HaveRel++;
+ gds->RelMonth -= gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
-
- case 38:
-#line 284 "getdate.y"
- {
+ if (gds->tokenp[0].token == '+'
+ && gds->tokenp[1].token == tUNUMBER
+ && gds->tokenp[2].token == tMONTH_UNIT) {
/* "+5 years" */
- yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
+ gds->HaveRel++;
+ gds->RelMonth += gds->tokenp[1].value * gds->tokenp[2].value;
+ gds->tokenp += 3;
+ return 1;
}
- break;
-
- case 39:
-#line 288 "getdate.y"
- {
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tMONTH_UNIT) {
/* "2 years" */
- yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
+ gds->HaveRel++;
+ gds->RelMonth += gds->tokenp[0].value * gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
}
- break;
-
- case 40:
-#line 292 "getdate.y"
- {
- /* "6 months" */
- yyRelMonth += (yyvsp[0].Number);
+ if (gds->tokenp[0].token == tSEC_UNIT) {
+ /* "now", "tomorrow" */
+ gds->HaveRel++;
+ gds->RelSeconds += gds->tokenp[0].value;
+ ++gds->tokenp;
+ return 1;
}
- break;
-
- case 41:
-#line 298 "getdate.y"
- {
- if (yyHaveTime && yyHaveDate && !yyHaveRel)
- yyYear = (yyvsp[0].Number);
- else {
- if((yyvsp[0].Number)>10000) {
- /* "20040301" */
- yyHaveDate++;
- yyDay= ((yyvsp[0].Number))%100;
- yyMonth= ((yyvsp[0].Number)/100)%100;
- yyYear = (yyvsp[0].Number)/10000;
- }
- else {
- /* "513" is same as "5:13" */
- yyHaveTime++;
- if ((yyvsp[0].Number) < 100) {
- yyHour = (yyvsp[0].Number);
- yyMinutes = 0;
- }
- else {
- yyHour = (yyvsp[0].Number) / 100;
- yyMinutes = (yyvsp[0].Number) % 100;
- }
- yySeconds = 0;
- }
- }
+ if (gds->tokenp[0].token == tMONTH_UNIT) {
+ /* "month" */
+ gds->HaveRel++;
+ gds->RelMonth += gds->tokenp[0].value;
+ gds->tokenp += 1;
+ return 1;
}
- break;
-
-
- default: break;
- }
+ return 0;
+}
-/* Line 1126 of yacc.c. */
-#line 1590 "tar/getdate.c"
-
- yyvsp -= yylen;
- yyssp -= yylen;
-
-
- YY_STACK_PRINT (yyss, yyssp);
-
- *++yyvsp = yyval;
-
-
- /* Now `shift' the result of the reduction. Determine what state
- that goes to, based on the state we popped back to and the rule
- number reduced by. */
-
- yyn = yyr1[yyn];
-
- yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
- if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTOKENS];
-
- goto yynewstate;
-
-
-/*------------------------------------.
-| yyerrlab -- here on detecting error |
-`------------------------------------*/
-yyerrlab:
- /* If not already recovering from an error, report this error. */
- if (!yyerrstatus)
- {
- ++yynerrs;
-#if YYERROR_VERBOSE
- yyn = yypact[yystate];
-
- if (YYPACT_NINF < yyn && yyn < YYLAST)
- {
- int yytype = YYTRANSLATE (yychar);
- YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
- YYSIZE_T yysize = yysize0;
- YYSIZE_T yysize1;
- int yysize_overflow = 0;
- char *yymsg = 0;
-# define YYERROR_VERBOSE_ARGS_MAXIMUM 5
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
- int yyx;
-
-#if 0
- /* This is so xgettext sees the translatable formats that are
- constructed on the fly. */
- YY_("syntax error, unexpected %s");
- YY_("syntax error, unexpected %s, expecting %s");
- YY_("syntax error, unexpected %s, expecting %s or %s");
- YY_("syntax error, unexpected %s, expecting %s or %s or %s");
- YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
-#endif
- char *yyfmt;
- char const *yyf;
- static char const yyunexpected[] = "syntax error, unexpected %s";
- static char const yyexpecting[] = ", expecting %s";
- static char const yyor[] = " or %s";
- char yyformat[sizeof yyunexpected
- + sizeof yyexpecting - 1
- + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
- * (sizeof yyor - 1))];
- char const *yyprefix = yyexpecting;
-
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
-
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = YYLAST - yyn;
- int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
- int yycount = 1;
-
- yyarg[0] = yytname[yytype];
- yyfmt = yystpcpy (yyformat, yyunexpected);
-
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
- {
- yycount = 1;
- yysize = yysize0;
- yyformat[sizeof yyunexpected - 1] = '\0';
- break;
- }
- yyarg[yycount++] = yytname[yyx];
- yysize1 = yysize + yytnamerr (0, yytname[yyx]);
- yysize_overflow |= yysize1 < yysize;
- yysize = yysize1;
- yyfmt = yystpcpy (yyfmt, yyprefix);
- yyprefix = yyor;
- }
-
- yyf = YY_(yyformat);
- yysize1 = yysize + yystrlen (yyf);
- yysize_overflow |= yysize1 < yysize;
- yysize = yysize1;
-
- if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
- yymsg = (char *) YYSTACK_ALLOC (yysize);
- if (yymsg)
- {
- /* Avoid sprintf, as that infringes on the user's name space.
- Don't have undefined behavior even if the translation
- produced a string with the wrong number of "%s"s. */
- char *yyp = yymsg;
- int yyi = 0;
- while ((*yyp = *yyf))
- {
- if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
- {
- yyp += yytnamerr (yyp, yyarg[yyi++]);
- yyf += 2;
- }
- else
- {
- yyp++;
- yyf++;
- }
- }
- yyerror (yymsg);
- YYSTACK_FREE (yymsg);
- }
- else
- {
- yyerror (YY_("syntax error"));
- goto yyexhaustedlab;
- }
+/*
+ * Day of the week specification.
+ */
+static int
+dayphrase(struct gdstate *gds)
+{
+ if (gds->tokenp[0].token == tDAY) {
+ /* "tues", "wednesday," */
+ gds->HaveWeekDay++;
+ gds->DayOrdinal = 1;
+ gds->DayNumber = gds->tokenp[0].value;
+ gds->tokenp += 1;
+ if (gds->tokenp[0].token == ',')
+ gds->tokenp += 1;
+ return 1;
}
- else
-#endif /* YYERROR_VERBOSE */
- yyerror (YY_("syntax error"));
- }
-
-
-
- if (yyerrstatus == 3)
- {
- /* If just tried and failed to reuse look-ahead token after an
- error, discard it. */
-
- if (yychar <= YYEOF)
- {
- /* Return failure if at end of input. */
- if (yychar == YYEOF)
- YYABORT;
- }
- else
- {
- yydestruct ("Error: discarding", yytoken, &yylval);
- yychar = YYEMPTY;
+ if (gds->tokenp[0].token == tUNUMBER
+ && gds->tokenp[1].token == tDAY) {
+ /* "second tues" "3 wed" */
+ gds->HaveWeekDay++;
+ gds->DayOrdinal = gds->tokenp[0].value;
+ gds->DayNumber = gds->tokenp[1].value;
+ gds->tokenp += 2;
+ return 1;
}
- }
+ return 0;
+}
- /* Else will try to reuse look-ahead token after shifting the error
- token. */
- goto yyerrlab1;
-
-
-/*---------------------------------------------------.
-| yyerrorlab -- error raised explicitly by YYERROR. |
-`---------------------------------------------------*/
-yyerrorlab:
-
- /* Pacify compilers like GCC when the user code never invokes
- YYERROR and the label yyerrorlab therefore never appears in user
- code. */
- if (0)
- goto yyerrorlab;
-
-yyvsp -= yylen;
- yyssp -= yylen;
- yystate = *yyssp;
- goto yyerrlab1;
-
-
-/*-------------------------------------------------------------.
-| yyerrlab1 -- common code for both syntax error and YYERROR. |
-`-------------------------------------------------------------*/
-yyerrlab1:
- yyerrstatus = 3; /* Each real token shifted decrements this. */
-
- for (;;)
- {
- yyn = yypact[yystate];
- if (yyn != YYPACT_NINF)
- {
- yyn += YYTERROR;
- if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
- {
- yyn = yytable[yyn];
- if (0 < yyn)
- break;
- }
+/*
+ * Try to match a phrase using one of the above functions.
+ * This layer also deals with a couple of generic issues.
+ */
+static int
+phrase(struct gdstate *gds)
+{
+ if (timephrase(gds))
+ return 1;
+ if (zonephrase(gds))
+ return 1;
+ if (datephrase(gds))
+ return 1;
+ if (dayphrase(gds))
+ return 1;
+ if (relunitphrase(gds)) {
+ if (gds->tokenp[0].token == tAGO) {
+ gds->RelSeconds = -gds->RelSeconds;
+ gds->RelMonth = -gds->RelMonth;
+ gds->tokenp += 1;
+ }
+ return 1;
}
- /* Pop the current state because it cannot handle the error token. */
- if (yyssp == yyss)
- YYABORT;
-
-
- yydestruct ("Error: popping", yystos[yystate], yyvsp);
- YYPOPSTACK;
- yystate = *yyssp;
- YY_STACK_PRINT (yyss, yyssp);
- }
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- *++yyvsp = yylval;
-
-
- /* Shift the error token. */
- YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
-
- yystate = yyn;
- goto yynewstate;
-
+ /* Bare numbers sometimes have meaning. */
+ if (gds->tokenp[0].token == tUNUMBER) {
+ if (gds->HaveTime && !gds->HaveYear && !gds->HaveRel) {
+ gds->HaveYear++;
+ gds->Year = gds->tokenp[0].value;
+ gds->tokenp += 1;
+ return 1;
+ }
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here. |
-`-------------------------------------*/
-yyacceptlab:
- yyresult = 0;
- goto yyreturn;
+ if(gds->tokenp[0].value > 10000) {
+ /* "20040301" */
+ gds->HaveYear++;
+ gds->HaveMonth++;
+ gds->HaveDay++;
+ gds->Day= (gds->tokenp[0].value)%100;
+ gds->Month= (gds->tokenp[0].value/100)%100;
+ gds->Year = gds->tokenp[0].value/10000;
+ gds->tokenp += 1;
+ return 1;
+ }
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here. |
-`-----------------------------------*/
-yyabortlab:
- yyresult = 1;
- goto yyreturn;
+ if (gds->tokenp[0].value < 24) {
+ gds->HaveTime++;
+ gds->Hour = gds->tokenp[0].value;
+ gds->Minutes = 0;
+ gds->Seconds = 0;
+ gds->tokenp += 1;
+ return 1;
+ }
-#ifndef yyoverflow
-/*-------------------------------------------------.
-| yyexhaustedlab -- memory exhaustion comes here. |
-`-------------------------------------------------*/
-yyexhaustedlab:
- yyerror (YY_("memory exhausted"));
- yyresult = 2;
- /* Fall through. */
-#endif
+ if ((gds->tokenp[0].value / 100 < 24)
+ && (gds->tokenp[0].value % 100 < 60)) {
+ /* "513" is same as "5:13" */
+ gds->Hour = gds->tokenp[0].value / 100;
+ gds->Minutes = gds->tokenp[0].value % 100;
+ gds->Seconds = 0;
+ gds->tokenp += 1;
+ return 1;
+ }
+ }
-yyreturn:
- if (yychar != YYEOF && yychar != YYEMPTY)
- yydestruct ("Cleanup: discarding lookahead",
- yytoken, &yylval);
- while (yyssp != yyss)
- {
- yydestruct ("Cleanup: popping",
- yystos[*yyssp], yyvsp);
- YYPOPSTACK;
- }
-#ifndef yyoverflow
- if (yyss != yyssa)
- YYSTACK_FREE (yyss);
-#endif
- return yyresult;
+ return 0;
}
-
-#line 327 "getdate.y"
-
-
-static struct TABLE {
+/*
+ * A dictionary of time words.
+ */
+static struct LEXICON {
size_t abbrev;
const char *name;
int type;
@@ -1890,84 +548,84 @@ static struct TABLE {
{ 2, "friday", tDAY, 5 },
{ 2, "saturday", tDAY, 6 },
- /* Timezones: Offsets are in minutes. */
- { 0, "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
- { 0, "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */
- { 0, "utc", tZONE, HOUR( 0) },
- { 0, "wet", tZONE, HOUR( 0) }, /* Western European */
- { 0, "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
- { 0, "wat", tZONE, HOUR( 1) }, /* West Africa */
- { 0, "at", tZONE, HOUR( 2) }, /* Azores */
- /* { 0, "bst", tZONE, HOUR( 3) }, */ /* Brazil Standard: Conflict */
- /* { 0, "gst", tZONE, HOUR( 3) }, */ /* Greenland Standard: Conflict*/
- { 0, "nft", tZONE, HOUR(3)+30 }, /* Newfoundland */
- { 0, "nst", tZONE, HOUR(3)+30 }, /* Newfoundland Standard */
- { 0, "ndt", tDAYZONE, HOUR(3)+30 }, /* Newfoundland Daylight */
- { 0, "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
- { 0, "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
- { 0, "est", tZONE, HOUR( 5) }, /* Eastern Standard */
- { 0, "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
- { 0, "cst", tZONE, HOUR( 6) }, /* Central Standard */
- { 0, "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
- { 0, "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
- { 0, "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
- { 0, "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
- { 0, "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
- { 0, "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
- { 0, "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
- { 0, "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
- { 0, "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */
- { 0, "cat", tZONE, HOUR(10) }, /* Central Alaska */
- { 0, "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */
- { 0, "nt", tZONE, HOUR(11) }, /* Nome */
- { 0, "idlw", tZONE, HOUR(12) }, /* Intl Date Line West */
- { 0, "cet", tZONE, -HOUR(1) }, /* Central European */
- { 0, "met", tZONE, -HOUR(1) }, /* Middle European */
- { 0, "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
- { 0, "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
- { 0, "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
- { 0, "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
- { 0, "fwt", tZONE, -HOUR(1) }, /* French Winter */
- { 0, "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
- { 0, "eet", tZONE, -HOUR(2) }, /* Eastern Eur, USSR Zone 1 */
- { 0, "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
- { 0, "it", tZONE, -HOUR(3)-30 },/* Iran */
- { 0, "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
- { 0, "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
- { 0, "ist", tZONE, -HOUR(5)-30 },/* Indian Standard */
- { 0, "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
- /* { 0, "nst", tZONE, -HOUR(6.5) }, */ /* North Sumatra: Conflict */
- /* { 0, "sst", tZONE, -HOUR(7) }, */ /* So Sumatra, USSR 6: Conflict */
- { 0, "wast", tZONE, -HOUR(7) }, /* West Australian Standard */
- { 0, "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */
- { 0, "jt", tZONE, -HOUR(7)-30 },/* Java (3pm in Cronusland!)*/
- { 0, "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */
- { 0, "jst", tZONE, -HOUR(9) }, /* Japan Std, USSR Zone 8 */
- { 0, "cast", tZONE, -HOUR(9)-30 },/* Central Australian Std */
- { 0, "cadt", tDAYZONE, -HOUR(9)-30 },/* Central Australian Daylt */
- { 0, "east", tZONE, -HOUR(10) }, /* Eastern Australian Std */
- { 0, "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylt */
- { 0, "gst", tZONE, -HOUR(10) }, /* Guam Std, USSR Zone 9 */
- { 0, "nzt", tZONE, -HOUR(12) }, /* New Zealand */
- { 0, "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
- { 0, "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
- { 0, "idle", tZONE, -HOUR(12) }, /* Intl Date Line East */
+ /* Timezones: Offsets are in seconds. */
+ { 0, "gmt", tZONE, 0*HOUR }, /* Greenwich Mean */
+ { 0, "ut", tZONE, 0*HOUR }, /* Universal (Coordinated) */
+ { 0, "utc", tZONE, 0*HOUR },
+ { 0, "wet", tZONE, 0*HOUR }, /* Western European */
+ { 0, "bst", tDAYZONE, 0*HOUR }, /* British Summer */
+ { 0, "wat", tZONE, 1*HOUR }, /* West Africa */
+ { 0, "at", tZONE, 2*HOUR }, /* Azores */
+ /* { 0, "bst", tZONE, 3*HOUR }, */ /* Brazil Standard: Conflict */
+ /* { 0, "gst", tZONE, 3*HOUR }, */ /* Greenland Standard: Conflict*/
+ { 0, "nft", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland */
+ { 0, "nst", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Standard */
+ { 0, "ndt", tDAYZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Daylight */
+ { 0, "ast", tZONE, 4*HOUR }, /* Atlantic Standard */
+ { 0, "adt", tDAYZONE, 4*HOUR }, /* Atlantic Daylight */
+ { 0, "est", tZONE, 5*HOUR }, /* Eastern Standard */
+ { 0, "edt", tDAYZONE, 5*HOUR }, /* Eastern Daylight */
+ { 0, "cst", tZONE, 6*HOUR }, /* Central Standard */
+ { 0, "cdt", tDAYZONE, 6*HOUR }, /* Central Daylight */
+ { 0, "mst", tZONE, 7*HOUR }, /* Mountain Standard */
+ { 0, "mdt", tDAYZONE, 7*HOUR }, /* Mountain Daylight */
+ { 0, "pst", tZONE, 8*HOUR }, /* Pacific Standard */
+ { 0, "pdt", tDAYZONE, 8*HOUR }, /* Pacific Daylight */
+ { 0, "yst", tZONE, 9*HOUR }, /* Yukon Standard */
+ { 0, "ydt", tDAYZONE, 9*HOUR }, /* Yukon Daylight */
+ { 0, "hst", tZONE, 10*HOUR }, /* Hawaii Standard */
+ { 0, "hdt", tDAYZONE, 10*HOUR }, /* Hawaii Daylight */
+ { 0, "cat", tZONE, 10*HOUR }, /* Central Alaska */
+ { 0, "ahst", tZONE, 10*HOUR }, /* Alaska-Hawaii Standard */
+ { 0, "nt", tZONE, 11*HOUR }, /* Nome */
+ { 0, "idlw", tZONE, 12*HOUR }, /* Intl Date Line West */
+ { 0, "cet", tZONE, -1*HOUR }, /* Central European */
+ { 0, "met", tZONE, -1*HOUR }, /* Middle European */
+ { 0, "mewt", tZONE, -1*HOUR }, /* Middle European Winter */
+ { 0, "mest", tDAYZONE, -1*HOUR }, /* Middle European Summer */
+ { 0, "swt", tZONE, -1*HOUR }, /* Swedish Winter */
+ { 0, "sst", tDAYZONE, -1*HOUR }, /* Swedish Summer */
+ { 0, "fwt", tZONE, -1*HOUR }, /* French Winter */
+ { 0, "fst", tDAYZONE, -1*HOUR }, /* French Summer */
+ { 0, "eet", tZONE, -2*HOUR }, /* Eastern Eur, USSR Zone 1 */
+ { 0, "bt", tZONE, -3*HOUR }, /* Baghdad, USSR Zone 2 */
+ { 0, "it", tZONE, -3*HOUR-30*MINUTE },/* Iran */
+ { 0, "zp4", tZONE, -4*HOUR }, /* USSR Zone 3 */
+ { 0, "zp5", tZONE, -5*HOUR }, /* USSR Zone 4 */
+ { 0, "ist", tZONE, -5*HOUR-30*MINUTE },/* Indian Standard */
+ { 0, "zp6", tZONE, -6*HOUR }, /* USSR Zone 5 */
+ /* { 0, "nst", tZONE, -6.5*HOUR }, */ /* North Sumatra: Conflict */
+ /* { 0, "sst", tZONE, -7*HOUR }, */ /* So Sumatra, USSR 6: Conflict */
+ { 0, "wast", tZONE, -7*HOUR }, /* West Australian Standard */
+ { 0, "wadt", tDAYZONE, -7*HOUR }, /* West Australian Daylight */
+ { 0, "jt", tZONE, -7*HOUR-30*MINUTE },/* Java (3pm in Cronusland!)*/
+ { 0, "cct", tZONE, -8*HOUR }, /* China Coast, USSR Zone 7 */
+ { 0, "jst", tZONE, -9*HOUR }, /* Japan Std, USSR Zone 8 */
+ { 0, "cast", tZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Std */
+ { 0, "cadt", tDAYZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Daylt */
+ { 0, "east", tZONE, -10*HOUR }, /* Eastern Australian Std */
+ { 0, "eadt", tDAYZONE, -10*HOUR }, /* Eastern Australian Daylt */
+ { 0, "gst", tZONE, -10*HOUR }, /* Guam Std, USSR Zone 9 */
+ { 0, "nzt", tZONE, -12*HOUR }, /* New Zealand */
+ { 0, "nzst", tZONE, -12*HOUR }, /* New Zealand Standard */
+ { 0, "nzdt", tDAYZONE, -12*HOUR }, /* New Zealand Daylight */
+ { 0, "idle", tZONE, -12*HOUR }, /* Intl Date Line East */
{ 0, "dst", tDST, 0 },
/* Time units. */
{ 4, "years", tMONTH_UNIT, 12 },
{ 5, "months", tMONTH_UNIT, 1 },
- { 9, "fortnights", tSEC_UNIT, 14 * 24 * 60 * 60 },
- { 4, "weeks", tSEC_UNIT, 7 * 24 * 60 * 60 },
- { 3, "days", tSEC_UNIT, 1 * 24 * 60 * 60 },
- { 4, "hours", tSEC_UNIT, 60 * 60 },
- { 3, "minutes", tSEC_UNIT, 60 },
+ { 9, "fortnights", tSEC_UNIT, 14 * DAY },
+ { 4, "weeks", tSEC_UNIT, 7 * DAY },
+ { 3, "days", tSEC_UNIT, DAY },
+ { 4, "hours", tSEC_UNIT, HOUR },
+ { 3, "minutes", tSEC_UNIT, MINUTE },
{ 3, "seconds", tSEC_UNIT, 1 },
/* Relative-time words. */
- { 0, "tomorrow", tSEC_UNIT, 1 * 24 * 60 * 60 },
- { 0, "yesterday", tSEC_UNIT, -1 * 24 * 60 * 60 },
+ { 0, "tomorrow", tSEC_UNIT, DAY },
+ { 0, "yesterday", tSEC_UNIT, -DAY },
{ 0, "today", tSEC_UNIT, 0 },
{ 0, "now", tSEC_UNIT, 0 },
{ 0, "last", tUNUMBER, -1 },
@@ -1993,69 +651,49 @@ static struct TABLE {
{ 0, "ago", tAGO, 1 },
/* Military timezones. */
- { 0, "a", tZONE, HOUR( 1) },
- { 0, "b", tZONE, HOUR( 2) },
- { 0, "c", tZONE, HOUR( 3) },
- { 0, "d", tZONE, HOUR( 4) },
- { 0, "e", tZONE, HOUR( 5) },
- { 0, "f", tZONE, HOUR( 6) },
- { 0, "g", tZONE, HOUR( 7) },
- { 0, "h", tZONE, HOUR( 8) },
- { 0, "i", tZONE, HOUR( 9) },
- { 0, "k", tZONE, HOUR( 10) },
- { 0, "l", tZONE, HOUR( 11) },
- { 0, "m", tZONE, HOUR( 12) },
- { 0, "n", tZONE, HOUR(- 1) },
- { 0, "o", tZONE, HOUR(- 2) },
- { 0, "p", tZONE, HOUR(- 3) },
- { 0, "q", tZONE, HOUR(- 4) },
- { 0, "r", tZONE, HOUR(- 5) },
- { 0, "s", tZONE, HOUR(- 6) },
- { 0, "t", tZONE, HOUR(- 7) },
- { 0, "u", tZONE, HOUR(- 8) },
- { 0, "v", tZONE, HOUR(- 9) },
- { 0, "w", tZONE, HOUR(-10) },
- { 0, "x", tZONE, HOUR(-11) },
- { 0, "y", tZONE, HOUR(-12) },
- { 0, "z", tZONE, HOUR( 0) },
+ { 0, "a", tZONE, 1*HOUR },
+ { 0, "b", tZONE, 2*HOUR },
+ { 0, "c", tZONE, 3*HOUR },
+ { 0, "d", tZONE, 4*HOUR },
+ { 0, "e", tZONE, 5*HOUR },
+ { 0, "f", tZONE, 6*HOUR },
+ { 0, "g", tZONE, 7*HOUR },
+ { 0, "h", tZONE, 8*HOUR },
+ { 0, "i", tZONE, 9*HOUR },
+ { 0, "k", tZONE, 10*HOUR },
+ { 0, "l", tZONE, 11*HOUR },
+ { 0, "m", tZONE, 12*HOUR },
+ { 0, "n", tZONE, -1*HOUR },
+ { 0, "o", tZONE, -2*HOUR },
+ { 0, "p", tZONE, -3*HOUR },
+ { 0, "q", tZONE, -4*HOUR },
+ { 0, "r", tZONE, -5*HOUR },
+ { 0, "s", tZONE, -6*HOUR },
+ { 0, "t", tZONE, -7*HOUR },
+ { 0, "u", tZONE, -8*HOUR },
+ { 0, "v", tZONE, -9*HOUR },
+ { 0, "w", tZONE, -10*HOUR },
+ { 0, "x", tZONE, -11*HOUR },
+ { 0, "y", tZONE, -12*HOUR },
+ { 0, "z", tZONE, 0*HOUR },
/* End of table. */
{ 0, NULL, 0, 0 }
};
-
-
-
-/* ARGSUSED */
-static int
-yyerror(const char *s)
-{
- (void)s;
- return 0;
-}
-
-static time_t
-ToSeconds(time_t Hours, time_t Minutes, time_t Seconds)
-{
- if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
- return -1;
- if (Hours < 0 || Hours > 23)
- return -1;
- return (Hours * 60L + Minutes) * 60L + Seconds;
-}
-
-
-/* Year is either
- * A number from 0 to 99, which means a year from 1970 to 2069, or
- * The actual year (>=100). */
+/*
+ * Year is either:
+ * = A number from 0 to 99, which means a year from 1970 to 2069, or
+ * = The actual year (>=100).
+ */
static time_t
Convert(time_t Month, time_t Day, time_t Year,
- time_t Hours, time_t Minutes, time_t Seconds, DSTMODE DSTmode)
+ time_t Hours, time_t Minutes, time_t Seconds,
+ time_t Timezone, enum DSTMODE DSTmode)
{
static int DaysInMonth[12] = {
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
- time_t tod;
time_t Julian;
int i;
@@ -2070,7 +708,10 @@ Convert(time_t Month, time_t Day, time_t Year,
if (Year < EPOCH || Year > 2038
|| Month < 1 || Month > 12
/* Lint fluff: "conversion from long may lose accuracy" */
- || Day < 1 || Day > DaysInMonth[(int)--Month])
+ || Day < 1 || Day > DaysInMonth[(int)--Month]
+ || Hours < 0 || Hours > 23
+ || Minutes < 0 || Minutes > 59
+ || Seconds < 0 || Seconds > 59)
return -1;
Julian = Day - 1;
@@ -2078,14 +719,12 @@ Convert(time_t Month, time_t Day, time_t Year,
Julian += DaysInMonth[i];
for (i = EPOCH; i < Year; i++)
Julian += 365 + (i % 4 == 0);
- Julian *= SECSPERDAY;
- Julian += yyTimezone * 60L;
- if ((tod = ToSeconds(Hours, Minutes, Seconds)) < 0)
- return -1;
- Julian += tod;
+ Julian *= DAY;
+ Julian += Timezone;
+ Julian += Hours * HOUR + Minutes * MINUTE + Seconds;
if (DSTmode == DSTon
|| (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
- Julian -= 60 * 60;
+ Julian -= HOUR;
return Julian;
}
@@ -2098,26 +737,30 @@ DSTcorrect(time_t Start, time_t Future)
StartDay = (localtime(&Start)->tm_hour + 1) % 24;
FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
- return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
+ return (Future - Start) + (StartDay - FutureDay) * HOUR;
}
static time_t
-RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber)
+RelativeDate(time_t Start, time_t zone, int dstmode,
+ time_t DayOrdinal, time_t DayNumber)
{
struct tm *tm;
- time_t now;
+ time_t t, now;
+ t = Start - zone;
+ tm = gmtime(&t);
now = Start;
- tm = localtime(&now);
- now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
- now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
- return DSTcorrect(Start, now);
+ now += DAY * ((DayNumber - tm->tm_wday + 7) % 7);
+ now += 7 * DAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
+ if (dstmode == DSTmaybe)
+ return DSTcorrect(Start, now);
+ return now - Start;
}
static time_t
-RelativeMonth(time_t Start, time_t RelMonth)
+RelativeMonth(time_t Start, time_t Timezone, time_t RelMonth)
{
struct tm *tm;
time_t Month;
@@ -2132,24 +775,27 @@ RelativeMonth(time_t Start, time_t RelMonth)
return DSTcorrect(Start,
Convert(Month, (time_t)tm->tm_mday, Year,
(time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
- DSTmaybe));
+ Timezone, DSTmaybe));
}
+/*
+ * Tokenizer.
+ */
static int
-yylex(void)
+nexttoken(char **in, time_t *value)
{
char c;
char buff[64];
for ( ; ; ) {
- while (isspace((unsigned char)*yyInput))
- yyInput++;
+ while (isspace((unsigned char)**in))
+ ++*in;
/* Skip parenthesized comments. */
- if (*yyInput == '(') {
+ if (**in == '(') {
int Count = 0;
do {
- c = *yyInput++;
+ c = *(*in)++;
if (c == '\0')
return c;
if (c == '(')
@@ -2163,8 +809,8 @@ yylex(void)
/* Try the next token in the word table first. */
/* This allows us to match "2nd", for example. */
{
- char *src = yyInput;
- const struct TABLE *tp;
+ char *src = *in;
+ const struct LEXICON *tp;
unsigned i = 0;
/* Force to lowercase and strip '.' characters. */
@@ -2179,7 +825,7 @@ yylex(void)
}
src++;
}
- buff[i++] = '\0';
+ buff[i] = '\0';
/*
* Find the first match. If the word can be
@@ -2194,9 +840,9 @@ yylex(void)
&& strncmp(tp->name, buff, strlen(buff))
== 0) {
/* Skip over token. */
- yyInput = src;
+ *in = src;
/* Return the match. */
- yylval.Number = tp->value;
+ *value = tp->value;
return tp->type;
}
}
@@ -2207,14 +853,14 @@ yylex(void)
* Because '-' and '+' have other special meanings, I
* don't deal with signed numbers here.
*/
- if (isdigit((unsigned char)(c = *yyInput))) {
- for (yylval.Number = 0; isdigit((unsigned char)(c = *yyInput++)); )
- yylval.Number = 10 * yylval.Number + c - '0';
- yyInput--;
+ if (isdigit((unsigned char)(c = **in))) {
+ for (*value = 0; isdigit((unsigned char)(c = *(*in)++)); )
+ *value = 10 * *value + c - '0';
+ (*in)--;
return (tUNUMBER);
}
- return (*yyInput++);
+ return *(*in)++;
}
}
@@ -2236,86 +882,135 @@ difftm (struct tm *a, struct tm *b)
/* + difference in years * 365 */
+ (long)(ay-by) * 365
);
- return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
- + (a->tm_min - b->tm_min))
+ return (days * DAY + (a->tm_hour - b->tm_hour) * HOUR
+ + (a->tm_min - b->tm_min) * MINUTE
+ (a->tm_sec - b->tm_sec));
}
+/*
+ *
+ * The public function.
+ *
+ * TODO: tokens[] array should be dynamically sized.
+ */
time_t
-get_date(char *p)
+get_date(time_t now, char *p)
{
- struct tm *tm;
+ struct token tokens[256];
+ struct gdstate _gds;
+ struct token *lasttoken;
+ struct gdstate *gds;
+ struct tm local, *tm;
struct tm gmt, *gmt_ptr;
time_t Start;
time_t tod;
- time_t nowtime;
long tzone;
- memset(&gmt, 0, sizeof(gmt));
- yyInput = p;
+ /* Clear out the parsed token array. */
+ memset(tokens, 0, sizeof(tokens));
+ /* Initialize the parser state. */
+ memset(&_gds, 0, sizeof(_gds));
+ gds = &_gds;
- (void)time (&nowtime);
+ /* Look up the current time. */
+ memset(&local, 0, sizeof(local));
+ tm = localtime (&now);
+ if (tm == NULL)
+ return -1;
+ local = *tm;
- gmt_ptr = gmtime (&nowtime);
+ /* Look up UTC if we can and use that to determine the current
+ * timezone offset. */
+ memset(&gmt, 0, sizeof(gmt));
+ gmt_ptr = gmtime (&now);
if (gmt_ptr != NULL) {
/* Copy, in case localtime and gmtime use the same buffer. */
gmt = *gmt_ptr;
}
-
- if (! (tm = localtime (&nowtime)))
- return -1;
-
if (gmt_ptr != NULL)
- tzone = difftm (&gmt, tm) / 60;
+ tzone = difftm (&gmt, &local);
else
/* This system doesn't understand timezones; fake it. */
tzone = 0;
- if(tm->tm_isdst)
- tzone += 60;
-
- yyYear = tm->tm_year + 1900;
- yyMonth = tm->tm_mon + 1;
- yyDay = tm->tm_mday;
- yyTimezone = tzone;
- yyDSTmode = DSTmaybe;
- yyHour = 0;
- yyMinutes = 0;
- yySeconds = 0;
- yyRelSeconds = 0;
- yyRelMonth = 0;
- yyHaveDate = 0;
- yyHaveDay = 0;
- yyHaveRel = 0;
- yyHaveTime = 0;
- yyHaveZone = 0;
-
- if (yyparse()
- || yyHaveTime > 1 || yyHaveZone > 1
- || yyHaveDate > 1 || yyHaveDay > 1)
+ if(local.tm_isdst)
+ tzone += HOUR;
+
+ /* Tokenize the input string. */
+ lasttoken = tokens;
+ while ((lasttoken->token = nexttoken(&p, &lasttoken->value)) != 0) {
+ ++lasttoken;
+ if (lasttoken > tokens + 255)
+ return -1;
+ }
+ gds->tokenp = tokens;
+
+ /* Match phrases until we run out of input tokens. */
+ while (gds->tokenp < lasttoken) {
+ if (!phrase(gds))
+ return -1;
+ }
+
+ /* Use current local timezone if none was specified. */
+ if (!gds->HaveZone) {
+ gds->Timezone = tzone;
+ gds->DSTmode = DSTmaybe;
+ }
+
+ /* If a timezone was specified, use that for generating the default
+ * time components instead of the local timezone. */
+ if (gds->HaveZone && gmt_ptr != NULL) {
+ now -= gds->Timezone;
+ gmt_ptr = gmtime (&now);
+ if (gmt_ptr != NULL)
+ local = *gmt_ptr;
+ now += gds->Timezone;
+ }
+
+ if (!gds->HaveYear)
+ gds->Year = local.tm_year + 1900;
+ if (!gds->HaveMonth)
+ gds->Month = local.tm_mon + 1;
+ if (!gds->HaveDay)
+ gds->Day = local.tm_mday;
+ /* Note: No default for hour/min/sec; a specifier that just
+ * gives date always refers to 00:00 on that date. */
+
+ /* If we saw more than one time, timezone, weekday, year, month,
+ * or day, then give up. */
+ if (gds->HaveTime > 1 || gds->HaveZone > 1 || gds->HaveWeekDay > 1
+ || gds->HaveYear > 1 || gds->HaveMonth > 1 || gds->HaveDay > 1)
return -1;
- if (yyHaveDate || yyHaveTime || yyHaveDay) {
- Start = Convert(yyMonth, yyDay, yyYear,
- yyHour, yyMinutes, yySeconds, yyDSTmode);
+ /* Compute an absolute time based on whatever absolute information
+ * we collected. */
+ if (gds->HaveYear || gds->HaveMonth || gds->HaveDay
+ || gds->HaveTime || gds->HaveWeekDay) {
+ Start = Convert(gds->Month, gds->Day, gds->Year,
+ gds->Hour, gds->Minutes, gds->Seconds,
+ gds->Timezone, gds->DSTmode);
if (Start < 0)
return -1;
} else {
- Start = nowtime;
- if (!yyHaveRel)
- Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
+ Start = now;
+ if (!gds->HaveRel)
+ Start -= local.tm_hour * HOUR + local.tm_min * MINUTE
+ + local.tm_sec;
}
- Start += yyRelSeconds;
- Start += RelativeMonth(Start, yyRelMonth);
+ /* Add the relative offset. */
+ Start += gds->RelSeconds;
+ Start += RelativeMonth(Start, gds->Timezone, gds->RelMonth);
- if (yyHaveDay && !yyHaveDate) {
- tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
+ /* Adjust for day-of-week offsets. */
+ if (gds->HaveWeekDay
+ && !(gds->HaveYear || gds->HaveMonth || gds->HaveDay)) {
+ tod = RelativeDate(Start, gds->Timezone,
+ gds->DSTmode, gds->DayOrdinal, gds->DayNumber);
Start += tod;
}
- /* Have to do *something* with a legitimate -1 so it's
- * distinguishable from the error return value. (Alternately
- * could set errno on error.) */
+ /* -1 is an error indicator, so return 0 instead of -1 if
+ * that's the actual time. */
return Start == -1 ? 0 : Start;
}
@@ -2340,5 +1035,3 @@ main(int argc, char **argv)
/* NOTREACHED */
}
#endif /* defined(TEST) */
-
-
diff --git a/archivers/libarchive/files/tar/read.c b/archivers/libarchive/files/tar/read.c
index fbb82533a72..aaaacac0dca 100644
--- a/archivers/libarchive/files/tar/read.c
+++ b/archivers/libarchive/files/tar/read.c
@@ -24,16 +24,11 @@
*/
#include "bsdtar_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.38 2008/05/26 17:10:10 kientzle Exp $");
+__FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.40 2008/08/21 06:41:14 kientzle Exp $");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
-#ifdef MAJOR_IN_MKDEV
-#include <sys/mkdev.h>
-#elif defined(MAJOR_IN_SYSMACROS)
-#include <sys/sysmacros.h>
-#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@@ -53,6 +48,9 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.38 2008/05/26 17:10:10 kientzle E
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -68,6 +66,13 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.38 2008/05/26 17:10:10 kientzle E
#endif
#include "bsdtar.h"
+#include "err.h"
+
+struct progress_data {
+ struct bsdtar *bsdtar;
+ struct archive *archive;
+ struct archive_entry *entry;
+};
static void list_item_verbose(struct bsdtar *, FILE *,
struct archive_entry *);
@@ -77,28 +82,48 @@ void
tar_mode_t(struct bsdtar *bsdtar)
{
read_archive(bsdtar, 't');
- unmatched_inclusions_warn(bsdtar, "Not found in archive");
+ if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0)
+ bsdtar->return_value = 1;
}
void
tar_mode_x(struct bsdtar *bsdtar)
{
- /* We want to catch SIGINFO and SIGUSR1. */
- siginfo_init(bsdtar);
-
read_archive(bsdtar, 'x');
- unmatched_inclusions_warn(bsdtar, "Not found in archive");
- /* Restore old SIGINFO + SIGUSR1 handlers. */
- siginfo_done(bsdtar);
+ if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0)
+ bsdtar->return_value = 1;
}
static void
-progress_func(void * cookie)
+progress_func(void *cookie)
{
- struct bsdtar * bsdtar = cookie;
-
- siginfo_printinfo(bsdtar, 0);
+ struct progress_data *progress_data = cookie;
+ struct bsdtar *bsdtar = progress_data->bsdtar;
+ struct archive *a = progress_data->archive;
+ struct archive_entry *entry = progress_data->entry;
+ uint64_t comp, uncomp;
+
+ if (!need_report())
+ return;
+
+ if (bsdtar->verbose)
+ fprintf(stderr, "\n");
+ if (a != NULL) {
+ comp = archive_position_compressed(a);
+ uncomp = archive_position_uncompressed(a);
+ fprintf(stderr,
+ "In: %s bytes, compression %d%%;",
+ tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
+ fprintf(stderr, " Out: %d files, %s bytes\n",
+ archive_file_count(a), tar_i64toa(uncomp));
+ }
+ if (entry != NULL) {
+ safe_fprintf(stderr, "Current: %s",
+ archive_entry_pathname(entry));
+ fprintf(stderr, " (%s bytes)\n",
+ tar_i64toa(archive_entry_size(entry)));
+ }
}
/*
@@ -107,6 +132,7 @@ progress_func(void * cookie)
static void
read_archive(struct bsdtar *bsdtar, char mode)
{
+ struct progress_data progress_data;
FILE *out;
struct archive *a;
struct archive_entry *entry;
@@ -114,12 +140,13 @@ read_archive(struct bsdtar *bsdtar, char mode)
int r;
while (*bsdtar->argv) {
- include(bsdtar, *bsdtar->argv);
+ lafe_include(&bsdtar->matching, *bsdtar->argv);
bsdtar->argv++;
}
if (bsdtar->names_from_file != NULL)
- include_from_file(bsdtar, bsdtar->names_from_file);
+ lafe_include_from_file(&bsdtar->matching,
+ bsdtar->names_from_file, bsdtar->option_null);
a = archive_read_new();
if (bsdtar->compress_program != NULL)
@@ -127,26 +154,30 @@ read_archive(struct bsdtar *bsdtar, char mode)
else
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
+ if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
if (archive_read_open_file(a, bsdtar->filename,
bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
DEFAULT_BYTES_PER_BLOCK))
- bsdtar_errc(bsdtar, 1, 0, "Error opening archive: %s",
+ lafe_errc(1, 0, "Error opening archive: %s",
archive_error_string(a));
do_chdir(bsdtar);
if (mode == 'x') {
/* Set an extract callback so that we can handle SIGINFO. */
+ progress_data.bsdtar = bsdtar;
+ progress_data.archive = a;
archive_read_extract_set_progress_callback(a, progress_func,
- bsdtar);
+ &progress_data);
}
if (mode == 'x' && bsdtar->option_chroot) {
#if HAVE_CHROOT
if (chroot(".") != 0)
- bsdtar_errc(bsdtar, 1, errno, "Can't chroot to \".\"");
+ lafe_errc(1, errno, "Can't chroot to \".\"");
#else
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"chroot isn't supported on this platform");
#endif
}
@@ -154,19 +185,20 @@ read_archive(struct bsdtar *bsdtar, char mode)
for (;;) {
/* Support --fast-read option */
if (bsdtar->option_fast_read &&
- unmatched_inclusions(bsdtar) == 0)
+ lafe_unmatched_inclusions(bsdtar->matching) == 0)
break;
r = archive_read_next_header(a, &entry);
+ progress_data.entry = entry;
if (r == ARCHIVE_EOF)
break;
if (r < ARCHIVE_OK)
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ lafe_warnc(0, "%s", archive_error_string(a));
if (r <= ARCHIVE_WARN)
bsdtar->return_value = 1;
if (r == ARCHIVE_RETRY) {
/* Retryable error: try again */
- bsdtar_warnc(bsdtar, 0, "Retrying...");
+ lafe_warnc(0, "Retrying...");
continue;
}
if (r == ARCHIVE_FATAL)
@@ -207,25 +239,20 @@ read_archive(struct bsdtar *bsdtar, char mode)
* rewrite, there would be no way to exclude foo1/bar
* while allowing foo2/bar.)
*/
- if (excluded(bsdtar, archive_entry_pathname(entry)))
+ if (lafe_excluded(bsdtar->matching, archive_entry_pathname(entry)))
continue; /* Excluded by a pattern test. */
- /*
- * Modify the pathname as requested by the user. We
- * do this for -t as well to give users a way to
- * preview the effects of their rewrites. We also do
- * this before extraction security checks (including
- * leading '/' removal). Note that some rewrite
- * failures prevent extraction.
- */
- if (edit_pathname(bsdtar, entry))
- continue; /* Excluded by a rewrite failure. */
-
if (mode == 't') {
/* Perversely, gtar uses -O to mean "send to stderr"
* when used with -t. */
out = bsdtar->option_stdout ? stderr : stdout;
+ /*
+ * TODO: Provide some reasonable way to
+ * preview rewrites. gtar always displays
+ * the unedited path in -t output, which means
+ * you cannot easily preview rewrites.
+ */
if (bsdtar->verbose < 2)
safe_fprintf(out, "%s",
archive_entry_pathname(entry));
@@ -235,23 +262,27 @@ read_archive(struct bsdtar *bsdtar, char mode)
r = archive_read_data_skip(a);
if (r == ARCHIVE_WARN) {
fprintf(out, "\n");
- bsdtar_warnc(bsdtar, 0, "%s",
+ lafe_warnc(0, "%s",
archive_error_string(a));
}
if (r == ARCHIVE_RETRY) {
fprintf(out, "\n");
- bsdtar_warnc(bsdtar, 0, "%s",
+ lafe_warnc(0, "%s",
archive_error_string(a));
}
if (r == ARCHIVE_FATAL) {
fprintf(out, "\n");
- bsdtar_warnc(bsdtar, 0, "%s",
+ lafe_warnc(0, "%s",
archive_error_string(a));
bsdtar->return_value = 1;
break;
}
fprintf(out, "\n");
} else {
+ /* Note: some rewrite failures prevent extraction. */
+ if (edit_pathname(bsdtar, entry))
+ continue; /* Excluded by a rewrite failure. */
+
if (bsdtar->option_interactive &&
!yes("extract '%s'", archive_entry_pathname(entry)))
continue;
@@ -266,10 +297,7 @@ read_archive(struct bsdtar *bsdtar, char mode)
fflush(stderr);
}
- /* Tell the SIGINFO-handler code what we're doing. */
- siginfo_setinfo(bsdtar, "extracting",
- archive_entry_pathname(entry), 0);
- siginfo_printinfo(bsdtar, 0);
+ // TODO siginfo_printinfo(bsdtar, 0);
if (bsdtar->option_stdout)
r = archive_read_data_into_fd(a, 1);
@@ -293,6 +321,13 @@ read_archive(struct bsdtar *bsdtar, char mode)
}
}
+
+ r = archive_read_close(a);
+ if (r != ARCHIVE_OK)
+ lafe_warnc(0, "%s", archive_error_string(a));
+ if (r <= ARCHIVE_WARN)
+ bsdtar->return_value = 1;
+
if (bsdtar->verbose > 2)
fprintf(stdout, "Archive Format: %s, Compression: %s\n",
archive_format_name(a), archive_compression_name(a));
@@ -312,7 +347,6 @@ read_archive(struct bsdtar *bsdtar, char mode)
static void
list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
{
- const struct stat *st;
char tmp[100];
size_t w;
const char *p;
@@ -320,8 +354,6 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
time_t tim;
static time_t now;
- st = archive_entry_stat(entry);
-
/*
* We avoid collecting the entire list in memory at once by
* listing things as we see them. However, that also means we can't
@@ -337,12 +369,13 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
time(&now);
fprintf(out, "%s %d ",
archive_entry_strmode(entry),
- (int)(st->st_nlink));
+ archive_entry_nlink(entry));
/* Use uname if it's present, else uid. */
p = archive_entry_uname(entry);
if ((p == NULL) || (*p == '\0')) {
- sprintf(tmp, "%lu ", (unsigned long)st->st_uid);
+ sprintf(tmp, "%lu ",
+ (unsigned long)archive_entry_uid(entry));
p = tmp;
}
w = strlen(p);
@@ -356,7 +389,8 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
fprintf(out, "%s", p);
w = strlen(p);
} else {
- sprintf(tmp, "%lu", (unsigned long)st->st_gid);
+ sprintf(tmp, "%lu",
+ (unsigned long)archive_entry_gid(entry));
w = strlen(tmp);
fprintf(out, "%s", tmp);
}
@@ -366,29 +400,30 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
* total width of group and devnum/filesize fields be gs_width.
* If gs_width is too small, grow it.
*/
- if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
+ if (archive_entry_filetype(entry) == AE_IFCHR
+ || archive_entry_filetype(entry) == AE_IFBLK) {
sprintf(tmp, "%lu,%lu",
- (unsigned long)major(st->st_rdev),
- (unsigned long)minor(st->st_rdev)); /* ls(1) also casts here. */
+ (unsigned long)archive_entry_rdevmajor(entry),
+ (unsigned long)archive_entry_rdevminor(entry));
} else {
- /*
- * Note the use of platform-dependent macros to format
- * the filesize here. We need the format string and the
- * corresponding type for the cast.
- */
- sprintf(tmp, BSDTAR_FILESIZE_PRINTF,
- (BSDTAR_FILESIZE_TYPE)st->st_size);
+ strcpy(tmp, tar_i64toa(archive_entry_size(entry)));
}
if (w + strlen(tmp) >= bsdtar->gs_width)
bsdtar->gs_width = w+strlen(tmp)+1;
fprintf(out, "%*s", (int)(bsdtar->gs_width - w), tmp);
/* Format the time using 'ls -l' conventions. */
- tim = (time_t)st->st_mtime;
- if (abs(tim - now) > (365/2)*86400)
- fmt = bsdtar->day_first ? "%e %b %Y" : "%b %e %Y";
+ tim = archive_entry_mtime(entry);
+#define HALF_YEAR (time_t)365 * 86400 / 2
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define DAY_FMT "%d" /* Windows' strftime function does not support %e format. */
+#else
+#define DAY_FMT "%e" /* Day number without leading zeros */
+#endif
+ if (tim < now - HALF_YEAR || tim > now + HALF_YEAR)
+ fmt = bsdtar->day_first ? DAY_FMT " %b %Y" : "%b " DAY_FMT " %Y";
else
- fmt = bsdtar->day_first ? "%e %b %H:%M" : "%b %e %H:%M";
+ fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M";
strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
fprintf(out, " %s ", tmp);
safe_fprintf(out, "%s", archive_entry_pathname(entry));
@@ -397,6 +432,6 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
if (archive_entry_hardlink(entry)) /* Hard link */
safe_fprintf(out, " link to %s",
archive_entry_hardlink(entry));
- else if (S_ISLNK(st->st_mode)) /* Symbolic link */
+ else if (archive_entry_symlink(entry)) /* Symbolic link */
safe_fprintf(out, " -> %s", archive_entry_symlink(entry));
}
diff --git a/archivers/libarchive/files/tar/subst.c b/archivers/libarchive/files/tar/subst.c
index 1c32fb0752b..3982054193c 100644
--- a/archivers/libarchive/files/tar/subst.c
+++ b/archivers/libarchive/files/tar/subst.c
@@ -38,6 +38,8 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/subst.c,v 1.4 2008/06/15 10:08:16 kientzle E
#define REG_BASIC 0
#endif
+#include "err.h"
+
struct subst_rule {
struct subst_rule *next;
regex_t re;
@@ -56,7 +58,7 @@ init_substitution(struct bsdtar *bsdtar)
bsdtar->substitution = subst = malloc(sizeof(*subst));
if (subst == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ lafe_errc(1, errno, "Out of memory");
subst->first_rule = subst->last_rule = NULL;
}
@@ -76,7 +78,7 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
rule = malloc(sizeof(*rule));
if (rule == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ lafe_errc(1, errno, "Out of memory");
rule->next = NULL;
if (subst->last_rule == NULL)
@@ -86,32 +88,32 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
subst->last_rule = rule;
if (*rule_text == '\0')
- bsdtar_errc(bsdtar, 1, 0, "Empty replacement string");
+ lafe_errc(1, 0, "Empty replacement string");
end_pattern = strchr(rule_text + 1, *rule_text);
if (end_pattern == NULL)
- bsdtar_errc(bsdtar, 1, 0, "Invalid replacement string");
+ lafe_errc(1, 0, "Invalid replacement string");
pattern = malloc(end_pattern - rule_text);
if (pattern == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ lafe_errc(1, errno, "Out of memory");
memcpy(pattern, rule_text + 1, end_pattern - rule_text - 1);
pattern[end_pattern - rule_text - 1] = '\0';
if ((r = regcomp(&rule->re, pattern, REG_BASIC)) != 0) {
char buf[80];
regerror(r, &rule->re, buf, sizeof(buf));
- bsdtar_errc(bsdtar, 1, 0, "Invalid regular expression: %s", buf);
+ lafe_errc(1, 0, "Invalid regular expression: %s", buf);
}
free(pattern);
start_subst = end_pattern + 1;
end_pattern = strchr(start_subst, *rule_text);
if (end_pattern == NULL)
- bsdtar_errc(bsdtar, 1, 0, "Invalid replacement string");
+ lafe_errc(1, 0, "Invalid replacement string");
rule->result = malloc(end_pattern - start_subst + 1);
if (rule->result == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ lafe_errc(1, errno, "Out of memory");
memcpy(rule->result, start_subst, end_pattern - start_subst);
rule->result[end_pattern - start_subst] = '\0';
@@ -134,13 +136,13 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
rule->symlink = 1;
break;
default:
- bsdtar_errc(bsdtar, 1, 0, "Invalid replacement flag %c", *end_pattern);
+ lafe_errc(1, 0, "Invalid replacement flag %c", *end_pattern);
}
}
}
static void
-realloc_strncat(struct bsdtar *bsdtar, char **str, const char *append, size_t len)
+realloc_strncat(char **str, const char *append, size_t len)
{
char *new_str;
size_t old_len;
@@ -152,7 +154,7 @@ realloc_strncat(struct bsdtar *bsdtar, char **str, const char *append, size_t le
new_str = malloc(old_len + len + 1);
if (new_str == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ lafe_errc(1, errno, "Out of memory");
memcpy(new_str, *str, old_len);
memcpy(new_str + old_len, append, len);
new_str[old_len + len] = '\0';
@@ -161,7 +163,7 @@ realloc_strncat(struct bsdtar *bsdtar, char **str, const char *append, size_t le
}
static void
-realloc_strcat(struct bsdtar *bsdtar, char **str, const char *append)
+realloc_strcat(char **str, const char *append)
{
char *new_str;
size_t old_len;
@@ -173,7 +175,7 @@ realloc_strcat(struct bsdtar *bsdtar, char **str, const char *append)
new_str = malloc(old_len + strlen(append) + 1);
if (new_str == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ lafe_errc(1, errno, "Out of memory");
memcpy(new_str, *str, old_len);
strcpy(new_str + old_len, append);
free(*str);
@@ -202,16 +204,16 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
if (symlink_only && !rule->symlink)
continue;
if (regexec(&rule->re, name, 10, matches, 0))
- break;
+ continue;
got_match = 1;
print_match |= rule->print;
- realloc_strncat(bsdtar, result, name, matches[0].rm_so);
+ realloc_strncat(result, name, matches[0].rm_so);
for (i = 0, j = 0; rule->result[i] != '\0'; ++i) {
if (rule->result[i] == '~') {
- realloc_strncat(bsdtar, result, rule->result + j, i - j);
- realloc_strncat(bsdtar, result, name, matches[0].rm_eo);
+ realloc_strncat(result, rule->result + j, i - j);
+ realloc_strncat(result, name, matches[0].rm_eo);
j = i + 1;
continue;
}
@@ -223,7 +225,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
switch (c) {
case '~':
case '\\':
- realloc_strncat(bsdtar, result, rule->result + j, i - j - 1);
+ realloc_strncat(result, rule->result + j, i - j - 1);
j = i;
break;
case '1':
@@ -235,13 +237,13 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
case '7':
case '8':
case '9':
- realloc_strncat(bsdtar, result, rule->result + j, i - j - 1);
+ realloc_strncat(result, rule->result + j, i - j - 1);
if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) {
free(*result);
*result = NULL;
return -1;
}
- realloc_strncat(bsdtar, result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so);
+ realloc_strncat(result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so);
j = i + 1;
break;
default:
@@ -251,7 +253,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
}
- realloc_strcat(bsdtar, result, rule->result + j);
+ realloc_strcat(result, rule->result + j);
name += matches[0].rm_eo;
@@ -260,7 +262,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
}
if (got_match)
- realloc_strcat(bsdtar, result, name);
+ realloc_strcat(result, name);
if (print_match)
fprintf(stderr, "%s >> %s\n", path, *result);
diff --git a/archivers/libarchive/files/tar/test/CMakeLists.txt b/archivers/libarchive/files/tar/test/CMakeLists.txt
new file mode 100644
index 00000000000..6064e142407
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/CMakeLists.txt
@@ -0,0 +1,67 @@
+############################################
+#
+# How to build bsdtar_test
+#
+############################################
+IF(ENABLE_TAR AND ENABLE_TEST)
+ SET(bsdtar_test_SOURCES
+ ../getdate.c
+ main.c
+ test.h
+ test_0.c
+ test_basic.c
+ test_copy.c
+ test_empty_mtree.c
+ test_getdate.c
+ test_help.c
+ test_option_T_upper.c
+ test_option_q.c
+ test_option_r.c
+ test_option_s.c
+ test_patterns.c
+ test_stdio.c
+ test_strip_components.c
+ test_symlink_dir.c
+ test_version.c
+ test_windows.c
+ )
+ IF(WIN32 AND NOT CYGWIN)
+ LIST(APPEND bsdtar_test_SOURCES ../bsdtar_windows.c)
+ LIST(APPEND bsdtar_test_SOURCES ../bsdtar_windows.h)
+ ENDIF(WIN32 AND NOT CYGWIN)
+
+ #
+ # Register target
+ #
+ ADD_EXECUTABLE(bsdtar_test ${bsdtar_test_SOURCES})
+ SET_PROPERTY(TARGET bsdtar_test PROPERTY COMPILE_DEFINITIONS LIST_H)
+
+ #
+ # Generate list.h by grepping DEFINE_TEST() lines out of the C sources.
+ #
+ GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h
+ ${CMAKE_CURRENT_LIST_FILE} ${bsdtar_test_SOURCES})
+ SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES
+ ${CMAKE_CURRENT_BINARY_DIR})
+
+ # list.h has a line DEFINE_TEST(testname) for every
+ # test. We can use that to define the tests for cmake by
+ # defining a DEFINE_TEST macro and reading list.h in.
+ MACRO (DEFINE_TEST _testname)
+ ADD_TEST_28(
+ NAME bsdtar_${_testname}
+ COMMAND bsdtar_test -vv
+ -p $<TARGET_FILE:bsdtar>
+ -r ${CMAKE_CURRENT_SOURCE_DIR}
+ ${_testname})
+ ENDMACRO (DEFINE_TEST _testname)
+
+ INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
+
+ # Experimental new test handling
+ ADD_CUSTOM_TARGET(run_bsdtar_test
+ COMMAND bsdtar_test -p ${BSDTAR} -r ${CMAKE_CURRENT_SOURCE_DIR})
+ ADD_DEPENDENCIES(run_bsdtar_test bsdtar)
+ ADD_DEPENDENCIES(run_all_tests run_bsdtar_test)
+
+ENDIF (ENABLE_TAR AND ENABLE_TEST)
diff --git a/archivers/libarchive/files/tar/test/list.h b/archivers/libarchive/files/tar/test/list.h
new file mode 100644
index 00000000000..4b91fb68416
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/list.h
@@ -0,0 +1,16 @@
+DEFINE_TEST(test_0)
+DEFINE_TEST(test_basic)
+DEFINE_TEST(test_copy)
+DEFINE_TEST(test_empty_mtree)
+DEFINE_TEST(test_getdate)
+DEFINE_TEST(test_help)
+DEFINE_TEST(test_option_T_upper)
+DEFINE_TEST(test_option_q)
+DEFINE_TEST(test_option_r)
+DEFINE_TEST(test_option_s)
+DEFINE_TEST(test_patterns)
+DEFINE_TEST(test_stdio)
+DEFINE_TEST(test_strip_components)
+DEFINE_TEST(test_symlink_dir)
+DEFINE_TEST(test_version)
+DEFINE_TEST(test_windows)
diff --git a/archivers/libarchive/files/tar/test/main.c b/archivers/libarchive/files/tar/test/main.c
index 27bb48d4094..6028d7789a4 100644
--- a/archivers/libarchive/files/tar/test/main.c
+++ b/archivers/libarchive/files/tar/test/main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2003-2009 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,12 +23,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- * Various utility routines useful for test programs.
- * Each test program is linked against this file.
- */
#include "test.h"
-
#include <errno.h>
#include <locale.h>
#include <stdarg.h>
@@ -38,148 +33,319 @@
* This same file is used pretty much verbatim for all test harnesses.
*
* The next few lines are the only differences.
+ * TODO: Move this into a separate configuration header, have all test
+ * suites share one copy of this file.
*/
-#define PROGRAM "bsdtar" /* Name of program being tested. */
-#define ENVBASE "BSDTAR" /* Prefix for environment variables. */
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.6 2008/11/05 06:40:53 kientzle Exp $");
+#define KNOWNREF "test_patterns_2.tar.uu"
+#define ENVBASE "BSDTAR" /* Prefix for environment variables. */
+#define PROGRAM "bsdtar" /* Name of program being tested. */
+#undef LIBRARY /* Not testing a library. */
#undef EXTRA_DUMP /* How to dump extra data */
/* How to generate extra version info. */
#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "")
-__FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.3 2008/06/15 10:07:54 kientzle Exp $");
/*
- * "list.h" is simply created by "grep DEFINE_TEST"; it has
- * a line like
- * DEFINE_TEST(test_function)
- * for each test.
- * Include it here with a suitable DEFINE_TEST to declare all of the
- * test functions.
+ *
+ * Windows support routines
+ *
+ * Note: Configuration is a tricky issue. Using HAVE_* feature macros
+ * in the test harness is dangerous because they cover up
+ * configuration errors. The classic example of this is omitting a
+ * configure check. If libarchive and libarchive_test both look for
+ * the same feature macro, such errors are hard to detect. Platform
+ * macros (e.g., _WIN32 or __GNUC__) are a little better, but can
+ * easily lead to very messy code. It's best to limit yourself
+ * to only the most generic programming techniques in the test harness
+ * and thus avoid conditionals altogether. Where that's not possible,
+ * try to minimize conditionals by grouping platform-specific tests in
+ * one place (e.g., test_acl_freebsd) or by adding new assert()
+ * functions (e.g., assertMakeHardlink()) to cover up platform
+ * differences. Platform-specific coding in libarchive_test is often
+ * a symptom that some capability is missing from libarchive itself.
*/
-#undef DEFINE_TEST
-#define DEFINE_TEST(name) void name(void);
-#include "list.h"
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <io.h>
+#include <windows.h>
+#ifndef F_OK
+#define F_OK (0)
+#endif
+#ifndef S_ISDIR
+#define S_ISDIR(m) ((m) & _S_IFDIR)
+#endif
+#ifndef S_ISREG
+#define S_ISREG(m) ((m) & _S_IFREG)
+#endif
+#if !defined(__BORLANDC__)
+#define access _access
+#undef chdir
+#define chdir _chdir
+#endif
+#ifndef fileno
+#define fileno _fileno
+#endif
+/*#define fstat _fstat64*/
+#if !defined(__BORLANDC__)
+#define getcwd _getcwd
+#endif
+#define lstat stat
+/*#define lstat _stat64*/
+/*#define stat _stat64*/
+#define rmdir _rmdir
+#if !defined(__BORLANDC__)
+#define strdup _strdup
+#define umask _umask
+#endif
+#define int64_t __int64
+#endif
+
+#if defined(HAVE__CrtSetReportMode)
+# include <crtdbg.h>
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+void *GetFunctionKernel32(const char *name)
+{
+ static HINSTANCE lib;
+ static int set;
+ if (!set) {
+ set = 1;
+ lib = LoadLibrary("kernel32.dll");
+ }
+ if (lib == NULL) {
+ fprintf(stderr, "Can't load kernel32.dll?!\n");
+ exit(1);
+ }
+ return (void *)GetProcAddress(lib, name);
+}
+
+static int
+my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags)
+{
+ static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD);
+ static int set;
+ if (!set) {
+ set = 1;
+ f = GetFunctionKernel32("CreateSymbolicLinkA");
+ }
+ return f == NULL ? 0 : (*f)(linkname, target, flags);
+}
+
+static int
+my_CreateHardLinkA(const char *linkname, const char *target)
+{
+ static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES);
+ static int set;
+ if (!set) {
+ set = 1;
+ f = GetFunctionKernel32("CreateHardLinkA");
+ }
+ return f == NULL ? 0 : (*f)(linkname, target, NULL);
+}
+
+int
+my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi)
+{
+ HANDLE h;
+ int r;
+
+ memset(bhfi, 0, sizeof(*bhfi));
+ h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ return (0);
+ r = GetFileInformationByHandle(h, bhfi);
+ CloseHandle(h);
+ return (r);
+}
+#endif
-/* Interix doesn't define these in a standard header. */
-#if __INTERIX__
-extern char *optarg;
-extern int optind;
+#if defined(HAVE__CrtSetReportMode)
+static void
+invalid_parameter_handler(const wchar_t * expression,
+ const wchar_t * function, const wchar_t * file,
+ unsigned int line, uintptr_t pReserved)
+{
+ /* nop */
+}
#endif
+/*
+ *
+ * OPTIONS FLAGS
+ *
+ */
+
/* Enable core dump on failure. */
static int dump_on_failure = 0;
-/* Default is to remove temp dirs for successful tests. */
+/* Default is to remove temp dirs and log data for successful tests. */
static int keep_temp_files = 0;
-/* Default is to print some basic information about each test. */
-static int quiet_flag = 0;
-/* Default is to summarize repeated failures. */
-static int verbose = 0;
-/* Cumulative count of component failures. */
+/* Default is to just report pass/fail for each test. */
+static int verbosity = 0;
+#define VERBOSITY_SUMMARY_ONLY -1 /* -q */
+#define VERBOSITY_PASSFAIL 0 /* Default */
+#define VERBOSITY_LIGHT_REPORT 1 /* -v */
+#define VERBOSITY_FULL 2 /* -vv */
+/* A few places generate even more output for verbosity > VERBOSITY_FULL,
+ * mostly for debugging the test harness itself. */
+/* Cumulative count of assertion failures. */
static int failures = 0;
-/* Cumulative count of skipped component tests. */
+/* Cumulative count of reported skips. */
static int skips = 0;
-/* Cumulative count of assertions. */
+/* Cumulative count of assertions checked. */
static int assertions = 0;
/* Directory where uuencoded reference files can be found. */
-static char *refdir;
+static const char *refdir;
/*
- * My own implementation of the standard assert() macro emits the
- * message in the same format as GCC (file:line: message).
- * It also includes some additional useful information.
- * This makes it a lot easier to skim through test failures in
- * Emacs. ;-)
- *
- * It also supports a few special features specifically to simplify
- * test harnesses:
- * failure(fmt, args) -- Stores a text string that gets
- * printed if the following assertion fails, good for
- * explaining subtle tests.
+ * Report log information selectively to console and/or disk log.
*/
-static char msg[4096];
-
-/*
- * For each test source file, we remember how many times each
- * failure was reported.
- */
-static const char *failed_filename = NULL;
-static struct line {
- int line;
- int count;
-} failed_lines[1000];
-
-/*
- * Count this failure; return the number of previous failures.
- */
-static int
-previous_failures(const char *filename, int line)
+static int log_console = 0;
+static FILE *logfile;
+static void
+vlogprintf(const char *fmt, va_list ap)
{
- unsigned int i;
- int count;
+#ifdef va_copy
+ va_list lfap;
+ va_copy(lfap, ap);
+#endif
+ if (log_console)
+ vfprintf(stdout, fmt, ap);
+ if (logfile != NULL)
+#ifdef va_copy
+ vfprintf(logfile, fmt, lfap);
+ va_end(lfap);
+#else
+ vfprintf(logfile, fmt, ap);
+#endif
+}
- if (failed_filename == NULL || strcmp(failed_filename, filename) != 0)
- memset(failed_lines, 0, sizeof(failed_lines));
- failed_filename = filename;
+static void
+logprintf(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vlogprintf(fmt, ap);
+ va_end(ap);
+}
- for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
- if (failed_lines[i].line == line) {
- count = failed_lines[i].count;
- failed_lines[i].count++;
- return (count);
- }
- if (failed_lines[i].line == 0) {
- failed_lines[i].line = line;
- failed_lines[i].count = 1;
- return (0);
- }
- }
- return (0);
+/* Set up a message to display only if next assertion fails. */
+static char msgbuff[4096];
+static const char *msg, *nextmsg;
+void
+failure(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vsprintf(msgbuff, fmt, ap);
+ va_end(ap);
+ nextmsg = msgbuff;
}
/*
* Copy arguments into file-local variables.
+ * This was added to permit vararg assert() functions without needing
+ * variadic wrapper macros. Turns out that the vararg capability is almost
+ * never used, so almost all of the vararg assertions can be simplified
+ * by removing the vararg capability and reworking the wrapper macro to
+ * pass __FILE__, __LINE__ directly into the function instead of using
+ * this hook. I suspect this machinery is used so rarely that we
+ * would be better off just removing it entirely. That would simplify
+ * the code here noticably.
*/
static const char *test_filename;
static int test_line;
static void *test_extra;
-void test_setup(const char *filename, int line)
+void assertion_setup(const char *filename, int line)
{
test_filename = filename;
test_line = line;
}
+/* Called at the beginning of each assert() function. */
+static void
+assertion_count(const char *file, int line)
+{
+ (void)file; /* UNUSED */
+ (void)line; /* UNUSED */
+ ++assertions;
+ /* Proper handling of "failure()" message. */
+ msg = nextmsg;
+ nextmsg = NULL;
+ /* Uncomment to print file:line after every assertion.
+ * Verbose, but occasionally useful in tracking down crashes. */
+ /* printf("Checked %s:%d\n", file, line); */
+}
+
/*
- * Inform user that we're skipping a test.
+ * For each test source file, we remember how many times each
+ * assertion was reported. Cleared before each new test,
+ * used by test_summarize().
*/
-void
-test_skipping(const char *fmt, ...)
+static struct line {
+ int count;
+ int skip;
+} failed_lines[10000];
+
+/* Count this failure, setup up log destination and handle initial report. */
+static void
+failure_start(const char *filename, int line, const char *fmt, ...)
{
va_list ap;
- if (previous_failures(test_filename, test_line))
- return;
+ /* Record another failure for this line. */
+ ++failures;
+ /* test_filename = filename; */
+ failed_lines[line].count++;
+
+ /* Determine whether to log header to console. */
+ switch (verbosity) {
+ case VERBOSITY_FULL:
+ log_console = 1;
+ break;
+ case VERBOSITY_LIGHT_REPORT:
+ log_console = (failed_lines[line].count < 2);
+ break;
+ default:
+ log_console = 0;
+ }
+ /* Log file:line header for this failure */
va_start(ap, fmt);
- fprintf(stderr, " *** SKIPPING: ");
- vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
+#if _MSC_VER
+ logprintf("%s(%d): ", filename, line);
+#else
+ logprintf("%s:%d: ", filename, line);
+#endif
+ vlogprintf(fmt, ap);
va_end(ap);
- ++skips;
+ logprintf("\n");
+
+ if (msg != NULL && msg[0] != '\0') {
+ logprintf(" Description: %s\n", msg);
+ msg = NULL;
+ }
+
+ /* Determine whether to log details to console. */
+ if (verbosity == VERBOSITY_LIGHT_REPORT)
+ log_console = 0;
}
-/* Common handling of failed tests. */
+/* Complete reporting of failed tests. */
+/*
+ * The 'extra' hook here is used by libarchive to include libarchive
+ * error messages with assertion failures. It could also be used
+ * to add strerror() output, for example. Just define the EXTRA_DUMP()
+ * macro appropriately.
+ */
static void
-report_failure(void *extra)
+failure_finish(void *extra)
{
- if (msg[0] != '\0') {
- fprintf(stderr, " Description: %s\n", msg);
- msg[0] = '\0';
- }
-
+ (void)extra; /* UNUSED (maybe) */
#ifdef EXTRA_DUMP
if (extra != NULL)
- fprintf(stderr, " detail: %s\n", EXTRA_DUMP(extra));
-#else
- (void)extra; /* UNUSED */
+ logprintf(" detail: %s\n", EXTRA_DUMP(extra));
#endif
if (dump_on_failure) {
@@ -190,203 +356,154 @@ report_failure(void *extra)
}
}
-/*
- * Summarize repeated failures in the just-completed test file.
- * The reports above suppress multiple failures from the same source
- * line; this reports on any tests that did fail multiple times.
- */
-static int
-summarize_comparator(const void *a0, const void *b0)
-{
- const struct line *a = a0, *b = b0;
- if (a->line == 0 && b->line == 0)
- return (0);
- if (a->line == 0)
- return (1);
- if (b->line == 0)
- return (-1);
- return (a->line - b->line);
-}
-
-static void
-summarize(void)
-{
- unsigned int i;
-
- qsort(failed_lines, sizeof(failed_lines)/sizeof(failed_lines[0]),
- sizeof(failed_lines[0]), summarize_comparator);
- for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
- if (failed_lines[i].line == 0)
- break;
- if (failed_lines[i].count > 1)
- fprintf(stderr, "%s:%d: Failed %d times\n",
- failed_filename, failed_lines[i].line,
- failed_lines[i].count);
- }
- /* Clear the failure history for the next file. */
- memset(failed_lines, 0, sizeof(failed_lines));
-}
-
-/* Set up a message to display only after a test fails. */
+/* Inform user that we're skipping some checks. */
void
-failure(const char *fmt, ...)
+test_skipping(const char *fmt, ...)
{
+ char buff[1024];
va_list ap;
+
va_start(ap, fmt);
- vsprintf(msg, fmt, ap);
+ vsprintf(buff, fmt, ap);
va_end(ap);
+ /* failure_start() isn't quite right, but is awfully convenient. */
+ failure_start(test_filename, test_line, "SKIPPING: %s", buff);
+ --failures; /* Undo failures++ in failure_start() */
+ /* Don't failure_finish() here. */
+ /* Mark as skip, so doesn't count as failed test. */
+ failed_lines[test_line].skip = 1;
+ ++skips;
}
+/*
+ *
+ * ASSERTIONS
+ *
+ */
+
/* Generic assert() just displays the failed condition. */
int
-test_assert(const char *file, int line, int value, const char *condition, void *extra)
+assertion_assert(const char *file, int line, int value,
+ const char *condition, void *extra)
{
- ++assertions;
- if (value) {
- msg[0] = '\0';
- return (value);
+ assertion_count(file, line);
+ if (!value) {
+ failure_start(file, line, "Assertion failed: %s", condition);
+ failure_finish(extra);
}
- failures ++;
- if (!verbose && previous_failures(file, line))
- return (value);
- fprintf(stderr, "%s:%d: Assertion failed\n", file, line);
- fprintf(stderr, " Condition: %s\n", condition);
- report_failure(extra);
return (value);
}
-/* assertEqualInt() displays the values of the two integers. */
+/* chdir() and report any errors */
int
-test_assert_equal_int(const char *file, int line,
- int v1, const char *e1, int v2, const char *e2, void *extra)
+assertion_chdir(const char *file, int line, const char *pathname)
{
- ++assertions;
- if (v1 == v2) {
- msg[0] = '\0';
+ assertion_count(file, line);
+ if (chdir(pathname) == 0)
return (1);
- }
- failures ++;
- if (!verbose && previous_failures(file, line))
- return (0);
- fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
- file, line);
- fprintf(stderr, " %s=%d\n", e1, v1);
- fprintf(stderr, " %s=%d\n", e2, v2);
- report_failure(extra);
+ failure_start(file, line, "chdir(\"%s\")", pathname);
+ failure_finish(NULL);
return (0);
+
}
-static void strdump(const char *p)
+/* Verify two integers are equal. */
+int
+assertion_equal_int(const char *file, int line,
+ long long v1, const char *e1, long long v2, const char *e2, void *extra)
{
+ assertion_count(file, line);
+ if (v1 == v2)
+ return (1);
+ failure_start(file, line, "%s != %s", e1, e2);
+ logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1);
+ logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2);
+ failure_finish(extra);
+ return (0);
+}
+
+static void strdump(const char *e, const char *p)
+{
+ const char *q = p;
+
+ logprintf(" %s = ", e);
if (p == NULL) {
- fprintf(stderr, "(null)");
+ logprintf("NULL");
return;
}
- fprintf(stderr, "\"");
+ logprintf("\"");
while (*p != '\0') {
unsigned int c = 0xff & *p++;
switch (c) {
- case '\a': fprintf(stderr, "\a"); break;
- case '\b': fprintf(stderr, "\b"); break;
- case '\n': fprintf(stderr, "\n"); break;
- case '\r': fprintf(stderr, "\r"); break;
+ case '\a': printf("\a"); break;
+ case '\b': printf("\b"); break;
+ case '\n': printf("\n"); break;
+ case '\r': printf("\r"); break;
default:
if (c >= 32 && c < 127)
- fprintf(stderr, "%c", c);
+ logprintf("%c", c);
else
- fprintf(stderr, "\\x%02X", c);
+ logprintf("\\x%02X", c);
}
}
- fprintf(stderr, "\"");
+ logprintf("\"");
+ logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q));
}
-/* assertEqualString() displays the values of the two strings. */
+/* Verify two strings are equal, dump them if not. */
int
-test_assert_equal_string(const char *file, int line,
+assertion_equal_string(const char *file, int line,
const char *v1, const char *e1,
const char *v2, const char *e2,
void *extra)
{
- ++assertions;
- if (v1 == NULL || v2 == NULL) {
- if (v1 == v2) {
- msg[0] = '\0';
- return (1);
- }
- } else if (strcmp(v1, v2) == 0) {
- msg[0] = '\0';
+ assertion_count(file, line);
+ if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0))
return (1);
- }
- failures ++;
- if (!verbose && previous_failures(file, line))
- return (0);
- fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
- file, line);
- fprintf(stderr, " %s = ", e1);
- strdump(v1);
- fprintf(stderr, " (length %d)\n", v1 == NULL ? 0 : strlen(v1));
- fprintf(stderr, " %s = ", e2);
- strdump(v2);
- fprintf(stderr, " (length %d)\n", v2 == NULL ? 0 : strlen(v2));
- report_failure(extra);
+ failure_start(file, line, "%s != %s", e1, e2);
+ strdump(e1, v1);
+ strdump(e2, v2);
+ failure_finish(extra);
return (0);
}
-static void wcsdump(const wchar_t *w)
+static void
+wcsdump(const char *e, const wchar_t *w)
{
+ logprintf(" %s = ", e);
if (w == NULL) {
- fprintf(stderr, "(null)");
+ logprintf("(null)");
return;
}
- fprintf(stderr, "\"");
+ logprintf("\"");
while (*w != L'\0') {
unsigned int c = *w++;
if (c >= 32 && c < 127)
- fprintf(stderr, "%c", c);
+ logprintf("%c", c);
else if (c < 256)
- fprintf(stderr, "\\x%02X", c);
+ logprintf("\\x%02X", c);
else if (c < 0x10000)
- fprintf(stderr, "\\u%04X", c);
+ logprintf("\\u%04X", c);
else
- fprintf(stderr, "\\U%08X", c);
+ logprintf("\\U%08X", c);
}
- fprintf(stderr, "\"");
+ logprintf("\"\n");
}
-/* assertEqualWString() displays the values of the two strings. */
+/* Verify that two wide strings are equal, dump them if not. */
int
-test_assert_equal_wstring(const char *file, int line,
+assertion_equal_wstring(const char *file, int line,
const wchar_t *v1, const char *e1,
const wchar_t *v2, const char *e2,
void *extra)
{
- ++assertions;
- if (v1 == NULL) {
- if (v2 == NULL) {
- msg[0] = '\0';
- return (1);
- }
- } else if (v2 == NULL) {
- if (v1 == NULL) {
- msg[0] = '\0';
- return (1);
- }
- } else if (wcscmp(v1, v2) == 0) {
- msg[0] = '\0';
+ assertion_count(file, line);
+ if (v1 == v2 || wcscmp(v1, v2) == 0)
return (1);
- }
- failures ++;
- if (!verbose && previous_failures(file, line))
- return (0);
- fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
- file, line);
- fprintf(stderr, " %s = ", e1);
- wcsdump(v1);
- fprintf(stderr, "\n");
- fprintf(stderr, " %s = ", e2);
- wcsdump(v2);
- fprintf(stderr, "\n");
- report_failure(extra);
+ failure_start(file, line, "%s != %s", e1, e2);
+ wcsdump(e1, v1);
+ wcsdump(e2, v2);
+ failure_finish(extra);
return (0);
}
@@ -401,226 +518,1051 @@ hexdump(const char *p, const char *ref, size_t l, size_t offset)
size_t i, j;
char sep;
+ if (p == NULL) {
+ logprintf("(null)\n");
+ return;
+ }
for(i=0; i < l; i+=16) {
- fprintf(stderr, "%04x", i + offset);
+ logprintf("%04x", (unsigned)(i + offset));
sep = ' ';
for (j = 0; j < 16 && i + j < l; j++) {
if (ref != NULL && p[i + j] != ref[i + j])
sep = '_';
- fprintf(stderr, "%c%02x", sep, 0xff & (int)p[i+j]);
+ logprintf("%c%02x", sep, 0xff & (int)p[i+j]);
if (ref != NULL && p[i + j] == ref[i + j])
sep = ' ';
}
for (; j < 16; j++) {
- fprintf(stderr, "%c ", sep);
+ logprintf("%c ", sep);
sep = ' ';
}
- fprintf(stderr, "%c", sep);
+ logprintf("%c", sep);
for (j=0; j < 16 && i + j < l; j++) {
int c = p[i + j];
if (c >= ' ' && c <= 126)
- fprintf(stderr, "%c", c);
+ logprintf("%c", c);
else
- fprintf(stderr, ".");
+ logprintf(".");
}
- fprintf(stderr, "\n");
+ logprintf("\n");
}
}
-/* assertEqualMem() displays the values of the two memory blocks. */
-/* TODO: For long blocks, hexdump the first bytes that actually differ. */
+/* Verify that two blocks of memory are the same, display the first
+ * block of differences if they're not. */
int
-test_assert_equal_mem(const char *file, int line,
- const char *v1, const char *e1,
- const char *v2, const char *e2,
+assertion_equal_mem(const char *file, int line,
+ const void *_v1, const char *e1,
+ const void *_v2, const char *e2,
size_t l, const char *ld, void *extra)
{
- ++assertions;
- if (v1 == NULL || v2 == NULL) {
- if (v1 == v2) {
- msg[0] = '\0';
- return (1);
- }
- } else if (memcmp(v1, v2, l) == 0) {
- msg[0] = '\0';
+ const char *v1 = (const char *)_v1;
+ const char *v2 = (const char *)_v2;
+ size_t offset;
+
+ assertion_count(file, line);
+ if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
return (1);
+
+ failure_start(file, line, "%s != %s", e1, e2);
+ logprintf(" size %s = %d\n", ld, (int)l);
+ /* Dump 48 bytes (3 lines) so that the first difference is
+ * in the second line. */
+ offset = 0;
+ while (l > 64 && memcmp(v1, v2, 32) == 0) {
+ /* Two lines agree, so step forward one line. */
+ v1 += 16;
+ v2 += 16;
+ l -= 16;
+ offset += 16;
}
- failures ++;
- if (!verbose && previous_failures(file, line))
- return (0);
- fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
- file, line);
- fprintf(stderr, " size %s = %d\n", ld, (int)l);
- fprintf(stderr, " Dump of %s\n", e1);
- hexdump(v1, v2, l < 32 ? l : 32, 0);
- fprintf(stderr, " Dump of %s\n", e2);
- hexdump(v2, v1, l < 32 ? l : 32, 0);
- fprintf(stderr, "\n");
- report_failure(extra);
+ logprintf(" Dump of %s\n", e1);
+ hexdump(v1, v2, l < 64 ? l : 64, offset);
+ logprintf(" Dump of %s\n", e2);
+ hexdump(v2, v1, l < 64 ? l : 64, offset);
+ logprintf("\n");
+ failure_finish(extra);
return (0);
}
+/* Verify that the named file exists and is empty. */
int
-test_assert_empty_file(const char *f1fmt, ...)
+assertion_empty_file(const char *f1fmt, ...)
{
char buff[1024];
char f1[1024];
struct stat st;
va_list ap;
ssize_t s;
- int fd;
-
+ FILE *f;
+ assertion_count(test_filename, test_line);
va_start(ap, f1fmt);
vsprintf(f1, f1fmt, ap);
va_end(ap);
if (stat(f1, &st) != 0) {
- fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1);
- report_failure(NULL);
+ failure_start(test_filename, test_line, "Stat failed: %s", f1);
+ failure_finish(NULL);
return (0);
}
if (st.st_size == 0)
return (1);
- failures ++;
- if (!verbose && previous_failures(test_filename, test_line))
- return (0);
-
- fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
- fprintf(stderr, " File size: %d\n", (int)st.st_size);
- fprintf(stderr, " Contents:\n");
- fd = open(f1, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, " Unable to open %s\n", f1);
+ failure_start(test_filename, test_line, "File should be empty: %s", f1);
+ logprintf(" File size: %d\n", (int)st.st_size);
+ logprintf(" Contents:\n");
+ f = fopen(f1, "rb");
+ if (f == NULL) {
+ logprintf(" Unable to open %s\n", f1);
} else {
- s = sizeof(buff) < st.st_size ? sizeof(buff) : st.st_size;
- s = read(fd, buff, s);
+ s = ((off_t)sizeof(buff) < st.st_size) ?
+ (ssize_t)sizeof(buff) : (ssize_t)st.st_size;
+ s = fread(buff, 1, s, f);
hexdump(buff, NULL, s, 0);
+ fclose(f);
}
- report_failure(NULL);
+ failure_finish(NULL);
return (0);
}
-/* assertEqualFile() asserts that two files have the same contents. */
+/* Verify that the named file exists and is not empty. */
+int
+assertion_non_empty_file(const char *f1fmt, ...)
+{
+ char f1[1024];
+ struct stat st;
+ va_list ap;
+
+ assertion_count(test_filename, test_line);
+ va_start(ap, f1fmt);
+ vsprintf(f1, f1fmt, ap);
+ va_end(ap);
+
+ if (stat(f1, &st) != 0) {
+ failure_start(test_filename, test_line, "Stat failed: %s", f1);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (st.st_size == 0) {
+ failure_start(test_filename, test_line, "File empty: %s", f1);
+ failure_finish(NULL);
+ return (0);
+ }
+ return (1);
+}
+
+/* Verify that two files have the same contents. */
/* TODO: hexdump the first bytes that actually differ. */
int
-test_assert_equal_file(const char *f1, const char *f2pattern, ...)
+assertion_equal_file(const char *fn1, const char *f2pattern, ...)
{
- char f2[1024];
+ char fn2[1024];
va_list ap;
char buff1[1024];
char buff2[1024];
- int fd1, fd2;
+ FILE *f1, *f2;
int n1, n2;
+ assertion_count(test_filename, test_line);
va_start(ap, f2pattern);
- vsprintf(f2, f2pattern, ap);
+ vsprintf(fn2, f2pattern, ap);
va_end(ap);
- fd1 = open(f1, O_RDONLY);
- fd2 = open(f2, O_RDONLY);
+ f1 = fopen(fn1, "rb");
+ f2 = fopen(fn2, "rb");
for (;;) {
- n1 = read(fd1, buff1, sizeof(buff1));
- n2 = read(fd2, buff2, sizeof(buff2));
+ n1 = fread(buff1, 1, sizeof(buff1), f1);
+ n2 = fread(buff2, 1, sizeof(buff2), f2);
if (n1 != n2)
break;
- if (n1 == 0 && n2 == 0)
+ if (n1 == 0 && n2 == 0) {
+ fclose(f1);
+ fclose(f2);
return (1);
+ }
if (memcmp(buff1, buff2, n1) != 0)
break;
}
- failures ++;
- if (!verbose && previous_failures(test_filename, test_line))
- return (0);
- fprintf(stderr, "%s:%d: Files are not identical\n",
- test_filename, test_line);
- fprintf(stderr, " file1=\"%s\"\n", f1);
- fprintf(stderr, " file2=\"%s\"\n", f2);
- report_failure(test_extra);
+ fclose(f1);
+ fclose(f2);
+ failure_start(test_filename, test_line, "Files not identical");
+ logprintf(" file1=\"%s\"\n", fn1);
+ logprintf(" file2=\"%s\"\n", fn2);
+ failure_finish(test_extra);
return (0);
}
+/* Verify that the named file does exist. */
int
-test_assert_file_exists(const char *fpattern, ...)
+assertion_file_exists(const char *fpattern, ...)
{
char f[1024];
va_list ap;
+ assertion_count(test_filename, test_line);
va_start(ap, fpattern);
vsprintf(f, fpattern, ap);
va_end(ap);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (!_access(f, 0))
+ return (1);
+#else
if (!access(f, F_OK))
return (1);
- if (!previous_failures(test_filename, test_line)) {
- fprintf(stderr, "%s:%d: File doesn't exist\n",
- test_filename, test_line);
- fprintf(stderr, " file=\"%s\"\n", f);
- report_failure(test_extra);
- }
+#endif
+ failure_start(test_filename, test_line, "File should exist: %s", f);
+ failure_finish(test_extra);
return (0);
}
+/* Verify that the named file doesn't exist. */
int
-test_assert_file_not_exists(const char *fpattern, ...)
+assertion_file_not_exists(const char *fpattern, ...)
{
char f[1024];
va_list ap;
+ assertion_count(test_filename, test_line);
va_start(ap, fpattern);
vsprintf(f, fpattern, ap);
va_end(ap);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (_access(f, 0))
+ return (1);
+#else
if (access(f, F_OK))
return (1);
- if (!previous_failures(test_filename, test_line)) {
- fprintf(stderr, "%s:%d: File exists and shouldn't\n",
- test_filename, test_line);
- fprintf(stderr, " file=\"%s\"\n", f);
- report_failure(test_extra);
- }
+#endif
+ failure_start(test_filename, test_line, "File should not exist: %s", f);
+ failure_finish(test_extra);
return (0);
}
-/* assertFileContents() asserts the contents of a file. */
+/* Compare the contents of a file to a block of memory. */
int
-test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
+assertion_file_contents(const void *buff, int s, const char *fpattern, ...)
{
- char f[1024];
+ char fn[1024];
va_list ap;
char *contents;
- int fd;
+ FILE *f;
int n;
+ assertion_count(test_filename, test_line);
va_start(ap, fpattern);
- vsprintf(f, fpattern, ap);
+ vsprintf(fn, fpattern, ap);
va_end(ap);
- fd = open(f, O_RDONLY);
+ f = fopen(fn, "rb");
+ if (f == NULL) {
+ failure_start(test_filename, test_line,
+ "File should exist: %s", fn);
+ failure_finish(test_extra);
+ return (0);
+ }
contents = malloc(s * 2);
- n = read(fd, contents, s * 2);
+ n = fread(contents, 1, s * 2, f);
+ fclose(f);
if (n == s && memcmp(buff, contents, s) == 0) {
free(contents);
return (1);
}
- failures ++;
- if (!previous_failures(test_filename, test_line)) {
- fprintf(stderr, "%s:%d: File contents don't match\n",
- test_filename, test_line);
- fprintf(stderr, " file=\"%s\"\n", f);
- if (n > 0)
- hexdump(contents, buff, n, 0);
- else {
- fprintf(stderr, " File empty, contents should be:\n");
- hexdump(buff, NULL, s, 0);
+ failure_start(test_filename, test_line, "File contents don't match");
+ logprintf(" file=\"%s\"\n", fn);
+ if (n > 0)
+ hexdump(contents, buff, n > 512 ? 512 : n, 0);
+ else {
+ logprintf(" File empty, contents should be:\n");
+ hexdump(buff, NULL, s > 512 ? 512 : s, 0);
+ }
+ failure_finish(test_extra);
+ free(contents);
+ return (0);
+}
+
+/* Check the contents of a text file, being tolerant of line endings. */
+int
+assertion_text_file_contents(const char *buff, const char *fn)
+{
+ char *contents;
+ const char *btxt, *ftxt;
+ FILE *f;
+ int n, s;
+
+ assertion_count(test_filename, test_line);
+ f = fopen(fn, "r");
+ s = strlen(buff);
+ contents = malloc(s * 2 + 128);
+ n = fread(contents, 1, s * 2 + 128 - 1, f);
+ if (n >= 0)
+ contents[n] = '\0';
+ fclose(f);
+ /* Compare texts. */
+ btxt = buff;
+ ftxt = (const char *)contents;
+ while (*btxt != '\0' && *ftxt != '\0') {
+ if (*btxt == *ftxt) {
+ ++btxt;
+ ++ftxt;
+ continue;
}
- report_failure(test_extra);
+ if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') {
+ /* Pass over different new line characters. */
+ ++btxt;
+ ftxt += 2;
+ continue;
+ }
+ break;
+ }
+ if (*btxt == '\0' && *ftxt == '\0') {
+ free(contents);
+ return (1);
+ }
+ failure_start(test_filename, test_line, "Contents don't match");
+ logprintf(" file=\"%s\"\n", fn);
+ if (n > 0)
+ hexdump(contents, buff, n, 0);
+ else {
+ logprintf(" File empty, contents should be:\n");
+ hexdump(buff, NULL, s, 0);
}
+ failure_finish(test_extra);
free(contents);
return (0);
}
+/* Verify that a text file contains the specified lines, regardless of order */
+/* This could be more efficient if we sorted both sets of lines, etc, but
+ * since this is used only for testing and only ever deals with a dozen or so
+ * lines at a time, this relatively crude approach is just fine. */
+int
+assertion_file_contains_lines_any_order(const char *file, int line,
+ const char *pathname, const char *lines[])
+{
+ char *buff;
+ size_t buff_size;
+ size_t expected_count, actual_count, i, j;
+ char **expected;
+ char *p, **actual;
+ char c;
+ int expected_failure = 0, actual_failure = 0;
+
+ assertion_count(file, line);
+
+ buff = slurpfile(&buff_size, "%s", pathname);
+ if (buff == NULL) {
+ failure_start(pathname, line, "Can't read file: %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+
+ // Make a copy of the provided lines and count up the expected file size.
+ expected_count = 0;
+ for (i = 0; lines[i] != NULL; ++i) {
+ }
+ expected_count = i;
+ expected = malloc(sizeof(char *) * expected_count);
+ for (i = 0; lines[i] != NULL; ++i) {
+ expected[i] = strdup(lines[i]);
+ }
+
+ // Break the file into lines
+ actual_count = 0;
+ for (c = '\0', p = buff; p < buff + buff_size; ++p) {
+ if (*p == '\x0d' || *p == '\x0a')
+ *p = '\0';
+ if (c == '\0' && *p != '\0')
+ ++actual_count;
+ c = *p;
+ }
+ actual = malloc(sizeof(char *) * actual_count);
+ for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
+ if (*p != '\0') {
+ actual[j] = p;
+ ++j;
+ }
+ }
+
+ // Erase matching lines from both lists
+ for (i = 0; i < expected_count; ++i) {
+ if (expected[i] == NULL)
+ continue;
+ for (j = 0; j < actual_count; ++j) {
+ if (actual[j] == NULL)
+ continue;
+ if (strcmp(expected[i], actual[j]) == 0) {
+ free(expected[i]);
+ expected[i] = NULL;
+ actual[j] = NULL;
+ break;
+ }
+ }
+ }
+
+ // If there's anything left, it's a failure
+ for (i = 0; i < expected_count; ++i) {
+ if (expected[i] != NULL)
+ ++expected_failure;
+ }
+ for (j = 0; j < actual_count; ++j) {
+ if (actual[j] != NULL)
+ ++actual_failure;
+ }
+ if (expected_failure == 0 && actual_failure == 0) {
+ free(buff);
+ free(expected);
+ free(actual);
+ return (1);
+ }
+ failure_start(file, line, "File doesn't match: %s", pathname);
+ for (i = 0; i < expected_count; ++i) {
+ if (expected[i] != NULL) {
+ logprintf(" Expected but not present: %s\n", expected[i]);
+ free(expected[i]);
+ }
+ }
+ for (j = 0; j < actual_count; ++j) {
+ if (actual[j] != NULL)
+ logprintf(" Present but not expected: %s\n", actual[j]);
+ }
+ failure_finish(NULL);
+ free(buff);
+ free(expected);
+ free(actual);
+ return (0);
+}
+
+/* Test that two paths point to the same file. */
+/* As a side-effect, asserts that both files exist. */
+static int
+is_hardlink(const char *file, int line,
+ const char *path1, const char *path2)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2;
+ int r;
+
+ assertion_count(file, line);
+ r = my_GetFileInformationByName(path1, &bhfi1);
+ if (r == 0) {
+ failure_start(file, line, "File %s can't be inspected?", path1);
+ failure_finish(NULL);
+ return (0);
+ }
+ r = my_GetFileInformationByName(path2, &bhfi2);
+ if (r == 0) {
+ failure_start(file, line, "File %s can't be inspected?", path2);
+ failure_finish(NULL);
+ return (0);
+ }
+ return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber
+ && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
+ && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow);
+#else
+ struct stat st1, st2;
+ int r;
+
+ assertion_count(file, line);
+ r = lstat(path1, &st1);
+ if (r != 0) {
+ failure_start(file, line, "File should exist: %s", path1);
+ failure_finish(NULL);
+ return (0);
+ }
+ r = lstat(path2, &st2);
+ if (r != 0) {
+ failure_start(file, line, "File should exist: %s", path2);
+ failure_finish(NULL);
+ return (0);
+ }
+ return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev);
+#endif
+}
+
+int
+assertion_is_hardlink(const char *file, int line,
+ const char *path1, const char *path2)
+{
+ if (is_hardlink(file, line, path1, path2))
+ return (1);
+ failure_start(file, line,
+ "Files %s and %s are not hardlinked", path1, path2);
+ failure_finish(NULL);
+ return (0);
+}
+
+int
+assertion_is_not_hardlink(const char *file, int line,
+ const char *path1, const char *path2)
+{
+ if (!is_hardlink(file, line, path1, path2))
+ return (1);
+ failure_start(file, line,
+ "Files %s and %s should not be hardlinked", path1, path2);
+ failure_finish(NULL);
+ return (0);
+}
+
+/* Verify a/b/mtime of 'pathname'. */
+/* If 'recent', verify that it's within last 10 seconds. */
+static int
+assertion_file_time(const char *file, int line,
+ const char *pathname, long t, long nsec, char type, int recent)
+{
+ long long filet, filet_nsec;
+ int r;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define EPOC_TIME (116444736000000000ULL)
+ FILETIME ftime, fbirthtime, fatime, fmtime;
+ ULARGE_INTEGER wintm;
+ HANDLE h;
+ ftime.dwLowDateTime = 0;
+ ftime.dwHighDateTime = 0;
+
+ assertion_count(file, line);
+ h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ failure_start(file, line, "Can't access %s\n", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ r = GetFileTime(h, &fbirthtime, &fatime, &fmtime);
+ switch (type) {
+ case 'a': ftime = fatime; break;
+ case 'b': ftime = fbirthtime; break;
+ case 'm': ftime = fmtime; break;
+ }
+ CloseHandle(h);
+ if (r == 0) {
+ failure_start(file, line, "Can't GetFileTime %s\n", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ wintm.LowPart = ftime.dwLowDateTime;
+ wintm.HighPart = ftime.dwHighDateTime;
+ filet = (wintm.QuadPart - EPOC_TIME) / 10000000;
+ filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100;
+ nsec = (nsec / 100) * 100; /* Round the request */
+#else
+ struct stat st;
+
+ assertion_count(file, line);
+ r = lstat(pathname, &st);
+ if (r != 0) {
+ failure_start(file, line, "Can't stat %s\n", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ switch (type) {
+ case 'a': filet = st.st_atime; break;
+ case 'm': filet = st.st_mtime; break;
+ case 'b': filet = 0; break;
+ default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type);
+ exit(1);
+ }
+#if defined(__FreeBSD__)
+ switch (type) {
+ case 'a': filet_nsec = st.st_atimespec.tv_nsec; break;
+ case 'b': filet = st.st_birthtime;
+ filet_nsec = st.st_birthtimespec.tv_nsec; break;
+ case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break;
+ default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type);
+ exit(1);
+ }
+ /* FreeBSD generally only stores to microsecond res, so round. */
+ filet_nsec = (filet_nsec / 1000) * 1000;
+ nsec = (nsec / 1000) * 1000;
+#else
+ filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */
+ if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */
+#if defined(__HAIKU__)
+ if (type == 'a') return (1); /* Haiku doesn't have atime. */
+#endif
+#endif
+#endif
+ if (recent) {
+ /* Check that requested time is up-to-date. */
+ time_t now = time(NULL);
+ if (filet < now - 10 || filet > now + 1) {
+ failure_start(file, line,
+ "File %s has %ctime %ld, %ld seconds ago\n",
+ pathname, type, filet, now - filet);
+ failure_finish(NULL);
+ return (0);
+ }
+ } else if (filet != t || filet_nsec != nsec) {
+ failure_start(file, line,
+ "File %s has %ctime %ld.%09ld, expected %ld.%09ld",
+ pathname, type, filet, filet_nsec, t, nsec);
+ failure_finish(NULL);
+ return (0);
+ }
+ return (1);
+}
+
+/* Verify atime of 'pathname'. */
+int
+assertion_file_atime(const char *file, int line,
+ const char *pathname, long t, long nsec)
+{
+ return assertion_file_time(file, line, pathname, t, nsec, 'a', 0);
+}
+
+/* Verify atime of 'pathname' is up-to-date. */
+int
+assertion_file_atime_recent(const char *file, int line, const char *pathname)
+{
+ return assertion_file_time(file, line, pathname, 0, 0, 'a', 1);
+}
+
+/* Verify birthtime of 'pathname'. */
+int
+assertion_file_birthtime(const char *file, int line,
+ const char *pathname, long t, long nsec)
+{
+ return assertion_file_time(file, line, pathname, t, nsec, 'b', 0);
+}
+
+/* Verify birthtime of 'pathname' is up-to-date. */
+int
+assertion_file_birthtime_recent(const char *file, int line,
+ const char *pathname)
+{
+ return assertion_file_time(file, line, pathname, 0, 0, 'b', 1);
+}
+
+/* Verify mtime of 'pathname'. */
+int
+assertion_file_mtime(const char *file, int line,
+ const char *pathname, long t, long nsec)
+{
+ return assertion_file_time(file, line, pathname, t, nsec, 'm', 0);
+}
+
+/* Verify mtime of 'pathname' is up-to-date. */
+int
+assertion_file_mtime_recent(const char *file, int line, const char *pathname)
+{
+ return assertion_file_time(file, line, pathname, 0, 0, 'm', 1);
+}
+
+/* Verify number of links to 'pathname'. */
+int
+assertion_file_nlinks(const char *file, int line,
+ const char *pathname, int nlinks)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ BY_HANDLE_FILE_INFORMATION bhfi;
+ int r;
+
+ assertion_count(file, line);
+ r = my_GetFileInformationByName(pathname, &bhfi);
+ if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks)
+ return (1);
+ failure_start(file, line, "File %s has %d links, expected %d",
+ pathname, bhfi.nNumberOfLinks, nlinks);
+ failure_finish(NULL);
+ return (0);
+#else
+ struct stat st;
+ int r;
+
+ assertion_count(file, line);
+ r = lstat(pathname, &st);
+ if (r == 0 && st.st_nlink == nlinks)
+ return (1);
+ failure_start(file, line, "File %s has %d links, expected %d",
+ pathname, st.st_nlink, nlinks);
+ failure_finish(NULL);
+ return (0);
+#endif
+}
+
+/* Verify size of 'pathname'. */
+int
+assertion_file_size(const char *file, int line, const char *pathname, long size)
+{
+ int64_t filesize;
+ int r;
+
+ assertion_count(file, line);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ {
+ BY_HANDLE_FILE_INFORMATION bhfi;
+ r = !my_GetFileInformationByName(pathname, &bhfi);
+ filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow;
+ }
+#else
+ {
+ struct stat st;
+ r = lstat(pathname, &st);
+ filesize = st.st_size;
+ }
+#endif
+ if (r == 0 && filesize == size)
+ return (1);
+ failure_start(file, line, "File %s has size %ld, expected %ld",
+ pathname, (long)filesize, (long)size);
+ failure_finish(NULL);
+ return (0);
+}
+
+/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */
+int
+assertion_is_dir(const char *file, int line, const char *pathname, int mode)
+{
+ struct stat st;
+ int r;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ (void)mode; /* UNUSED */
+#endif
+ assertion_count(file, line);
+ r = lstat(pathname, &st);
+ if (r != 0) {
+ failure_start(file, line, "Dir should exist: %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (!S_ISDIR(st.st_mode)) {
+ failure_start(file, line, "%s is not a dir", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ /* Windows doesn't handle permissions the same way as POSIX,
+ * so just ignore the mode tests. */
+ /* TODO: Can we do better here? */
+ if (mode >= 0 && mode != (st.st_mode & 07777)) {
+ failure_start(file, line, "Dir %s has wrong mode", pathname);
+ logprintf(" Expected: 0%3o\n", mode);
+ logprintf(" Found: 0%3o\n", st.st_mode & 07777);
+ failure_finish(NULL);
+ return (0);
+ }
+#endif
+ return (1);
+}
+
+/* Verify that 'pathname' is a regular file. If 'mode' is >= 0,
+ * verify that too. */
+int
+assertion_is_reg(const char *file, int line, const char *pathname, int mode)
+{
+ struct stat st;
+ int r;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ (void)mode; /* UNUSED */
+#endif
+ assertion_count(file, line);
+ r = lstat(pathname, &st);
+ if (r != 0 || !S_ISREG(st.st_mode)) {
+ failure_start(file, line, "File should exist: %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ /* Windows doesn't handle permissions the same way as POSIX,
+ * so just ignore the mode tests. */
+ /* TODO: Can we do better here? */
+ if (mode >= 0 && mode != (st.st_mode & 07777)) {
+ failure_start(file, line, "File %s has wrong mode", pathname);
+ logprintf(" Expected: 0%3o\n", mode);
+ logprintf(" Found: 0%3o\n", st.st_mode & 07777);
+ failure_finish(NULL);
+ return (0);
+ }
+#endif
+ return (1);
+}
+
+/* Check whether 'pathname' is a symbolic link. If 'contents' is
+ * non-NULL, verify that the symlink has those contents. */
+static int
+is_symlink(const char *file, int line,
+ const char *pathname, const char *contents)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ (void)pathname; /* UNUSED */
+ (void)contents; /* UNUSED */
+ assertion_count(file, line);
+ /* Windows sort-of has real symlinks, but they're only usable
+ * by privileged users and are crippled even then, so there's
+ * really not much point in bothering with this. */
+ return (0);
+#else
+ char buff[300];
+ struct stat st;
+ ssize_t linklen;
+ int r;
+
+ assertion_count(file, line);
+ r = lstat(pathname, &st);
+ if (r != 0) {
+ failure_start(file, line,
+ "Symlink should exist: %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (!S_ISLNK(st.st_mode))
+ return (0);
+ if (contents == NULL)
+ return (1);
+ linklen = readlink(pathname, buff, sizeof(buff));
+ if (linklen < 0) {
+ failure_start(file, line, "Can't read symlink %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ buff[linklen] = '\0';
+ if (strcmp(buff, contents) != 0)
+ return (0);
+ return (1);
+#endif
+}
+
+/* Assert that path is a symlink that (optionally) contains contents. */
+int
+assertion_is_symlink(const char *file, int line,
+ const char *path, const char *contents)
+{
+ if (is_symlink(file, line, path, contents))
+ return (1);
+ if (contents)
+ failure_start(file, line, "File %s is not a symlink to %s",
+ path, contents);
+ else
+ failure_start(file, line, "File %s is not a symlink", path);
+ failure_finish(NULL);
+ return (0);
+}
+
+
+/* Create a directory and report any errors. */
+int
+assertion_make_dir(const char *file, int line, const char *dirname, int mode)
+{
+ assertion_count(file, line);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ (void)mode; /* UNUSED */
+ if (0 == _mkdir(dirname))
+ return (1);
+#else
+ if (0 == mkdir(dirname, mode))
+ return (1);
+#endif
+ failure_start(file, line, "Could not create directory %s", dirname);
+ failure_finish(NULL);
+ return(0);
+}
+
+/* Create a file with the specified contents and report any failures. */
+int
+assertion_make_file(const char *file, int line,
+ const char *path, int mode, const char *contents)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* TODO: Rework this to set file mode as well. */
+ FILE *f;
+ (void)mode; /* UNUSED */
+ assertion_count(file, line);
+ f = fopen(path, "wb");
+ if (f == NULL) {
+ failure_start(file, line, "Could not create file %s", path);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (contents != NULL) {
+ if (strlen(contents)
+ != fwrite(contents, 1, strlen(contents), f)) {
+ fclose(f);
+ failure_start(file, line,
+ "Could not write file %s", path);
+ failure_finish(NULL);
+ return (0);
+ }
+ }
+ fclose(f);
+ return (1);
+#else
+ int fd;
+ assertion_count(file, line);
+ fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644);
+ if (fd < 0) {
+ failure_start(file, line, "Could not create %s", path);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (contents != NULL) {
+ if ((ssize_t)strlen(contents)
+ != write(fd, contents, strlen(contents))) {
+ close(fd);
+ failure_start(file, line, "Could not write to %s", path);
+ failure_finish(NULL);
+ return (0);
+ }
+ }
+ close(fd);
+ return (1);
+#endif
+}
+
+/* Create a hardlink and report any failures. */
+int
+assertion_make_hardlink(const char *file, int line,
+ const char *newpath, const char *linkto)
+{
+ int succeeded;
+
+ assertion_count(file, line);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ succeeded = my_CreateHardLinkA(newpath, linkto);
+#elif HAVE_LINK
+ succeeded = !link(linkto, newpath);
+#else
+ succeeded = 0;
+#endif
+ if (succeeded)
+ return (1);
+ failure_start(file, line, "Could not create hardlink");
+ logprintf(" New link: %s\n", newpath);
+ logprintf(" Old name: %s\n", linkto);
+ failure_finish(NULL);
+ return(0);
+}
+
+/* Create a symlink and report any failures. */
+int
+assertion_make_symlink(const char *file, int line,
+ const char *newpath, const char *linkto)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ int targetIsDir = 0; /* TODO: Fix this */
+ assertion_count(file, line);
+ if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir))
+ return (1);
+#elif HAVE_SYMLINK
+ assertion_count(file, line);
+ if (0 == symlink(linkto, newpath))
+ return (1);
+#endif
+ failure_start(file, line, "Could not create symlink");
+ logprintf(" New link: %s\n", newpath);
+ logprintf(" Old name: %s\n", linkto);
+ failure_finish(NULL);
+ return(0);
+}
+
+/* Set umask, report failures. */
+int
+assertion_umask(const char *file, int line, int mask)
+{
+ assertion_count(file, line);
+ (void)file; /* UNUSED */
+ (void)line; /* UNUSED */
+ umask(mask);
+ return (1);
+}
+
+/*
+ *
+ * UTILITIES for use by tests.
+ *
+ */
+
+/*
+ * Check whether platform supports symlinks. This is intended
+ * for tests to use in deciding whether to bother testing symlink
+ * support; if the platform doesn't support symlinks, there's no point
+ * in checking whether the program being tested can create them.
+ *
+ * Note that the first time this test is called, we actually go out to
+ * disk to create and verify a symlink. This is necessary because
+ * symlink support is actually a property of a particular filesystem
+ * and can thus vary between directories on a single system. After
+ * the first call, this returns the cached result from memory, so it's
+ * safe to call it as often as you wish.
+ */
+int
+canSymlink(void)
+{
+ /* Remember the test result */
+ static int value = 0, tested = 0;
+ if (tested)
+ return (value);
+
+ ++tested;
+ assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a");
+ /* Note: Cygwin has its own symlink() emulation that does not
+ * use the Win32 CreateSymbolicLink() function. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0)
+ && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0");
+#elif HAVE_SYMLINK
+ value = (0 == symlink("canSymlink.0", "canSymlink.1"))
+ && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0");
+#endif
+ return (value);
+}
+
+/*
+ * Can this platform run the gzip program?
+ */
+/* Platform-dependent options for hiding the output of a subcommand. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */
+#else
+static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */
+#endif
+int
+canGzip(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("gzip -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the gunzip program?
+ */
+int
+canGunzip(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("gunzip -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Sleep as needed; useful for verifying disk timestamp changes by
+ * ensuring that the wall-clock time has actually changed before we
+ * go back to re-read something from disk.
+ */
+void
+sleepUntilAfter(time_t t)
+{
+ while (t >= time(NULL))
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ Sleep(500);
+#else
+ sleep(1);
+#endif
+}
+
/*
* Call standard system() call, but build up the command line using
* sprintf() conventions.
@@ -634,6 +1576,8 @@ systemf(const char *fmt, ...)
va_start(ap, fmt);
vsprintf(buff, fmt, ap);
+ if (verbosity > VERBOSITY_FULL)
+ logprintf("Cmd: %s\n", buff);
r = system(buff);
va_end(ap);
return (r);
@@ -652,112 +1596,263 @@ slurpfile(size_t * sizep, const char *fmt, ...)
va_list ap;
char *p;
ssize_t bytes_read;
- int fd;
+ FILE *f;
int r;
va_start(ap, fmt);
vsprintf(filename, fmt, ap);
va_end(ap);
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
+ f = fopen(filename, "rb");
+ if (f == NULL) {
/* Note: No error; non-existent file is okay here. */
return (NULL);
}
- r = fstat(fd, &st);
+ r = fstat(fileno(f), &st);
if (r != 0) {
- fprintf(stderr, "Can't stat file %s\n", filename);
- close(fd);
+ logprintf("Can't stat file %s\n", filename);
+ fclose(f);
return (NULL);
}
- p = malloc(st.st_size + 1);
+ p = malloc((size_t)st.st_size + 1);
if (p == NULL) {
- fprintf(stderr, "Can't allocate %ld bytes of memory to read file %s\n", (long int)st.st_size, filename);
- close(fd);
+ logprintf("Can't allocate %ld bytes of memory to read file %s\n",
+ (long int)st.st_size, filename);
+ fclose(f);
return (NULL);
}
- bytes_read = read(fd, p, st.st_size);
+ bytes_read = fread(p, 1, (size_t)st.st_size, f);
if (bytes_read < st.st_size) {
- fprintf(stderr, "Can't read file %s\n", filename);
- close(fd);
+ logprintf("Can't read file %s\n", filename);
+ fclose(f);
free(p);
return (NULL);
}
p[st.st_size] = '\0';
if (sizep != NULL)
*sizep = (size_t)st.st_size;
- close(fd);
+ fclose(f);
return (p);
}
+/* Read a uuencoded file from the reference directory, decode, and
+ * write the result into the current directory. */
+#define UUDECODE(c) (((c) - 0x20) & 0x3f)
+void
+extract_reference_file(const char *name)
+{
+ char buff[1024];
+ FILE *in, *out;
+
+ sprintf(buff, "%s/%s.uu", refdir, name);
+ in = fopen(buff, "r");
+ failure("Couldn't open reference file %s", buff);
+ assert(in != NULL);
+ if (in == NULL)
+ return;
+ /* Read up to and including the 'begin' line. */
+ for (;;) {
+ if (fgets(buff, sizeof(buff), in) == NULL) {
+ /* TODO: This is a failure. */
+ return;
+ }
+ if (memcmp(buff, "begin ", 6) == 0)
+ break;
+ }
+ /* Now, decode the rest and write it. */
+ /* Not a lot of error checking here; the input better be right. */
+ out = fopen(name, "wb");
+ while (fgets(buff, sizeof(buff), in) != NULL) {
+ char *p = buff;
+ int bytes;
+
+ if (memcmp(buff, "end", 3) == 0)
+ break;
+
+ bytes = UUDECODE(*p++);
+ while (bytes > 0) {
+ int n = 0;
+ /* Write out 1-3 bytes from that. */
+ if (bytes > 0) {
+ n = UUDECODE(*p++) << 18;
+ n |= UUDECODE(*p++) << 12;
+ fputc(n >> 16, out);
+ --bytes;
+ }
+ if (bytes > 0) {
+ n |= UUDECODE(*p++) << 6;
+ fputc((n >> 8) & 0xFF, out);
+ --bytes;
+ }
+ if (bytes > 0) {
+ n |= UUDECODE(*p++);
+ fputc(n & 0xFF, out);
+ --bytes;
+ }
+ }
+ }
+ fclose(out);
+ fclose(in);
+}
+
/*
- * "list.h" is automatically generated; it just has a lot of lines like:
- * DEFINE_TEST(function_name)
- * It's used above to declare all of the test functions.
- * We reuse it here to define a list of all tests (functions and names).
+ *
+ * TEST management
+ *
*/
+
+/*
+ * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has
+ * a line like
+ * DEFINE_TEST(test_function)
+ * for each test.
+ */
+
+/* Use "list.h" to declare all of the test functions. */
#undef DEFINE_TEST
-#define DEFINE_TEST(n) { n, #n },
-struct { void (*func)(void); const char *name; } tests[] = {
+#define DEFINE_TEST(name) void name(void);
+#include "list.h"
+
+/* Use "list.h" to create a list of all tests (functions and names). */
+#undef DEFINE_TEST
+#define DEFINE_TEST(n) { n, #n, 0 },
+struct { void (*func)(void); const char *name; int failures; } tests[] = {
#include "list.h"
};
/*
- * Each test is run in a private work dir. Those work dirs
- * do have consistent and predictable names, in case a group
- * of tests need to collaborate. However, there is no provision
- * for requiring that tests run in a certain order.
+ * Summarize repeated failures in the just-completed test.
*/
-static int test_run(int i, const char *tmpdir)
+static void
+test_summarize(const char *filename, int failed)
{
- int failures_before = failures;
+ unsigned int i;
- if (!quiet_flag) {
- printf("%d: %s\n", i, tests[i].name);
+ switch (verbosity) {
+ case VERBOSITY_SUMMARY_ONLY:
+ printf(failed ? "E" : ".");
fflush(stdout);
+ break;
+ case VERBOSITY_PASSFAIL:
+ printf(failed ? "FAIL\n" : "ok\n");
+ break;
}
- /*
- * Always explicitly chdir() in case the last test moved us to
- * a strange place.
- */
- if (chdir(tmpdir)) {
- fprintf(stderr,
- "ERROR: Couldn't chdir to temp dir %s\n",
- tmpdir);
- exit(1);
+ log_console = (verbosity == VERBOSITY_LIGHT_REPORT);
+
+ for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
+ if (failed_lines[i].count > 1 && !failed_lines[i].skip)
+ logprintf("%s:%d: Summary: Failed %d times\n",
+ filename, i, failed_lines[i].count);
}
- /* Create a temp directory for this specific test. */
- if (mkdir(tests[i].name, 0755)) {
+ /* Clear the failure history for the next file. */
+ memset(failed_lines, 0, sizeof(failed_lines));
+}
+
+/*
+ * Actually run a single test, with appropriate setup and cleanup.
+ */
+static int
+test_run(int i, const char *tmpdir)
+{
+ char logfilename[64];
+ int failures_before = failures;
+ int oldumask;
+
+ switch (verbosity) {
+ case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */
+ break;
+ case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */
+ printf("%3d: %-50s", i, tests[i].name);
+ fflush(stdout);
+ break;
+ default: /* Title of test, details will follow */
+ printf("%3d: %s\n", i, tests[i].name);
+ }
+
+ /* Chdir to the top-level work directory. */
+ if (!assertChdir(tmpdir)) {
fprintf(stderr,
- "ERROR: Couldn't create temp dir ``%s''\n",
- tests[i].name);
+ "ERROR: Can't chdir to top work dir %s\n", tmpdir);
exit(1);
}
- /* Chdir() to that work directory. */
- if (chdir(tests[i].name)) {
+ /* Create a log file for this test. */
+ sprintf(logfilename, "%s.log", tests[i].name);
+ logfile = fopen(logfilename, "w");
+ fprintf(logfile, "%s\n\n", tests[i].name);
+ /* Chdir() to a work dir for this specific test. */
+ if (!assertMakeDir(tests[i].name, 0755)
+ || !assertChdir(tests[i].name)) {
fprintf(stderr,
- "ERROR: Couldn't chdir to temp dir ``%s''\n",
- tests[i].name);
+ "ERROR: Can't chdir to work dir %s/%s\n",
+ tmpdir, tests[i].name);
exit(1);
}
/* Explicitly reset the locale before each test. */
setlocale(LC_ALL, "C");
- /* Run the actual test. */
+ /* Record the umask before we run the test. */
+ umask(oldumask = umask(0));
+ /*
+ * Run the actual test.
+ */
(*tests[i].func)();
- /* Summarize the results of this test. */
- summarize();
- /* If there were no failures, we can remove the work dir. */
- if (failures == failures_before) {
- if (!keep_temp_files && chdir(tmpdir) == 0) {
+ /*
+ * Clean up and report afterwards.
+ */
+ /* Restore umask */
+ umask(oldumask);
+ /* Reset locale. */
+ setlocale(LC_ALL, "C");
+ /* Reset directory. */
+ if (!assertChdir(tmpdir)) {
+ fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n",
+ tmpdir);
+ exit(1);
+ }
+ /* Report per-test summaries. */
+ tests[i].failures = failures - failures_before;
+ test_summarize(test_filename, tests[i].failures);
+ /* Close the per-test log file. */
+ fclose(logfile);
+ logfile = NULL;
+ /* If there were no failures, we can remove the work dir and logfile. */
+ if (tests[i].failures == 0) {
+ if (!keep_temp_files && assertChdir(tmpdir)) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Make sure not to leave empty directories.
+ * Sometimes a processing of closing files used by tests
+ * is not done, then rmdir will be failed and it will
+ * leave a empty test directory. So we should wait a few
+ * seconds and retry rmdir. */
+ int r, t;
+ for (t = 0; t < 10; t++) {
+ if (t > 0)
+ Sleep(1000);
+ r = systemf("rmdir /S /Q %s", tests[i].name);
+ if (r == 0)
+ break;
+ }
+ systemf("del %s", logfilename);
+#else
systemf("rm -rf %s", tests[i].name);
+ systemf("rm %s", logfilename);
+#endif
}
}
/* Return appropriate status. */
- return (failures == failures_before ? 0 : 1);
+ return (tests[i].failures);
}
-static void usage(const char *program)
+/*
+ *
+ *
+ * MAIN and support routines.
+ *
+ *
+ */
+
+static void
+usage(const char *program)
{
static const int limit = sizeof(tests) / sizeof(tests[0]);
int i;
@@ -783,92 +1878,129 @@ static void usage(const char *program)
exit(1);
}
-#define UUDECODE(c) (((c) - 0x20) & 0x3f)
-
-void
-extract_reference_file(const char *name)
+static char *
+get_refdir(const char *d)
{
- char buff[1024];
- FILE *in, *out;
+ char tried[512] = { '\0' };
+ char buff[128];
+ char *pwd, *p;
+
+ /* If a dir was specified, try that */
+ if (d != NULL) {
+ pwd = NULL;
+ snprintf(buff, sizeof(buff), "%s", d);
+ p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+ if (p != NULL) goto success;
+ strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+ strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+ goto failure;
+ }
- sprintf(buff, "%s/%s.uu", refdir, name);
- in = fopen(buff, "r");
- failure("Couldn't open reference file %s", buff);
- assert(in != NULL);
- if (in == NULL)
- return;
- /* Read up to and including the 'begin' line. */
- for (;;) {
- if (fgets(buff, sizeof(buff), in) == NULL) {
- /* TODO: This is a failure. */
- return;
- }
- if (memcmp(buff, "begin ", 6) == 0)
- break;
+ /* Get the current dir. */
+ pwd = getcwd(NULL, 0);
+ while (pwd[strlen(pwd) - 1] == '\n')
+ pwd[strlen(pwd) - 1] = '\0';
+
+ /* Look for a known file. */
+ snprintf(buff, sizeof(buff), "%s", pwd);
+ p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+ if (p != NULL) goto success;
+ strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+ strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+ snprintf(buff, sizeof(buff), "%s/test", pwd);
+ p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+ if (p != NULL) goto success;
+ strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+ strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+#if defined(LIBRARY)
+ snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
+#else
+ snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
+#endif
+ p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+ if (p != NULL) goto success;
+ strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+ strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+ if (memcmp(pwd, "/usr/obj", 8) == 0) {
+ snprintf(buff, sizeof(buff), "%s", pwd + 8);
+ p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+ if (p != NULL) goto success;
+ strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+ strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+ snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
+ p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+ if (p != NULL) goto success;
+ strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+ strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
}
- /* Now, decode the rest and write it. */
- /* Not a lot of error checking here; the input better be right. */
- out = fopen(name, "w");
- while (fgets(buff, sizeof(buff), in) != NULL) {
- char *p = buff;
- int bytes;
- if (memcmp(buff, "end", 3) == 0)
- break;
+failure:
+ printf("Unable to locate known reference file %s\n", KNOWNREF);
+ printf(" Checked following directories:\n%s\n", tried);
+#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
+ DebugBreak();
+#endif
+ exit(1);
- bytes = UUDECODE(*p++);
- while (bytes > 0) {
- int n = 0;
- /* Write out 1-3 bytes from that. */
- if (bytes > 0) {
- n = UUDECODE(*p++) << 18;
- n |= UUDECODE(*p++) << 12;
- fputc(n >> 16, out);
- --bytes;
- }
- if (bytes > 0) {
- n |= UUDECODE(*p++) << 6;
- fputc((n >> 8) & 0xFF, out);
- --bytes;
- }
- if (bytes > 0) {
- n |= UUDECODE(*p++);
- fputc(n & 0xFF, out);
- --bytes;
- }
- }
- }
- fclose(out);
- fclose(in);
+success:
+ free(p);
+ free(pwd);
+ return strdup(buff);
}
-
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
static const int limit = sizeof(tests) / sizeof(tests[0]);
- int i, tests_run = 0, tests_failed = 0, opt;
+ int i, tests_run = 0, tests_failed = 0, option;
time_t now;
char *refdir_alloc = NULL;
- char *progname, *p;
+ const char *progname;
+ const char *tmp, *option_arg, *p;
char tmpdir[256];
char tmpdir_timestamp[256];
+ (void)argc; /* UNUSED */
+
+#if defined(HAVE__CrtSetReportMode)
+ /* To stop to run the default invalid parameter handler. */
+ _set_invalid_parameter_handler(invalid_parameter_handler);
+ /* Disable annoying assertion message box. */
+ _CrtSetReportMode(_CRT_ASSERT, 0);
+#endif
+
/*
* Name of this program, used to build root of our temp directory
* tree.
*/
progname = p = argv[0];
while (*p != '\0') {
- if (*p == '/')
+ /* Support \ or / dir separators for Windows compat. */
+ if (*p == '/' || *p == '\\')
progname = p + 1;
++p;
}
#ifdef PROGRAM
/* Get the target program from environment, if available. */
- testprog = getenv(ENVBASE);
+ testprogfile = getenv(ENVBASE);
#endif
+ if (getenv("TMPDIR") != NULL)
+ tmp = getenv("TMPDIR");
+ else if (getenv("TMP") != NULL)
+ tmp = getenv("TMP");
+ else if (getenv("TEMP") != NULL)
+ tmp = getenv("TEMP");
+ else if (getenv("TEMPDIR") != NULL)
+ tmp = getenv("TEMPDIR");
+ else
+ tmp = "/tmp";
+
/* Allow -d to be controlled through the environment. */
if (getenv(ENVBASE "_DEBUG") != NULL)
dump_on_failure = 1;
@@ -877,46 +2009,92 @@ int main(int argc, char **argv)
refdir = getenv(ENVBASE "_TEST_FILES");
/*
- * Parse options.
+ * Parse options, without using getopt(), which isn't available
+ * on all platforms.
*/
- while ((opt = getopt(argc, argv, "dkp:qr:v")) != -1) {
- switch (opt) {
- case 'd':
- dump_on_failure = 1;
- break;
- case 'k':
- keep_temp_files = 1;
+ ++argv; /* Skip program name */
+ while (*argv != NULL) {
+ if (**argv != '-')
break;
- case 'p':
+ p = *argv++;
+ ++p; /* Skip '-' */
+ while (*p != '\0') {
+ option = *p++;
+ option_arg = NULL;
+ /* If 'opt' takes an argument, parse that. */
+ if (option == 'p' || option == 'r') {
+ if (*p != '\0')
+ option_arg = p;
+ else if (*argv == NULL) {
+ fprintf(stderr,
+ "Option -%c requires argument.\n",
+ option);
+ usage(progname);
+ } else
+ option_arg = *argv++;
+ p = ""; /* End of this option word. */
+ }
+
+ /* Now, handle the option. */
+ switch (option) {
+ case 'd':
+ dump_on_failure = 1;
+ break;
+ case 'k':
+ keep_temp_files = 1;
+ break;
+ case 'p':
#ifdef PROGRAM
- testprog = optarg;
+ testprogfile = option_arg;
#else
- usage(progname);
+ fprintf(stderr, "-p option not permitted\n");
+ usage(progname);
#endif
- break;
- case 'q':
- quiet_flag++;
- break;
- case 'r':
- refdir = optarg;
- break;
- case 'v':
- verbose = 1;
- break;
- case '?':
- default:
- usage(progname);
+ break;
+ case 'q':
+ verbosity--;
+ break;
+ case 'r':
+ refdir = option_arg;
+ break;
+ case 'v':
+ verbosity++;
+ break;
+ default:
+ fprintf(stderr, "Unrecognized option '%c'\n",
+ option);
+ usage(progname);
+ }
}
}
- argc -= optind;
- argv += optind;
/*
* Sanity-check that our options make sense.
*/
#ifdef PROGRAM
- if (testprog == NULL)
+ if (testprogfile == NULL) {
+ fprintf(stderr, "Program executable required\n");
usage(progname);
+ }
+
+ {
+ char *testprg;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Command.com sometimes rejects '/' separators. */
+ testprg = strdup(testprogfile);
+ for (i = 0; testprg[i] != '\0'; i++) {
+ if (testprg[i] == '/')
+ testprg[i] = '\\';
+ }
+ testprogfile = testprg;
+#endif
+ /* Quote the name that gets put into shell command lines. */
+ testprg = malloc(strlen(testprogfile) + 3);
+ strcpy(testprg, "\"");
+ strcat(testprg, testprogfile);
+ strcat(testprg, "\"");
+ testprog = testprg;
+ }
#endif
/*
@@ -925,40 +2103,37 @@ int main(int argc, char **argv)
* to make it easier to track the results of multiple tests.
*/
now = time(NULL);
- for (i = 0; i < 1000; i++) {
+ for (i = 0; ; i++) {
strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
"%Y-%m-%dT%H.%M.%S",
localtime(&now));
- sprintf(tmpdir, "/tmp/%s.%s-%03d", progname, tmpdir_timestamp, i);
- if (mkdir(tmpdir,0755) == 0)
+ sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
+ tmpdir_timestamp, i);
+ if (assertMakeDir(tmpdir,0755))
break;
- if (errno == EEXIST)
- continue;
- fprintf(stderr, "ERROR: Unable to create temp directory %s\n",
- tmpdir);
- exit(1);
+ if (i >= 999) {
+ fprintf(stderr,
+ "ERROR: Unable to create temp directory %s\n",
+ tmpdir);
+ exit(1);
+ }
}
/*
* If the user didn't specify a directory for locating
- * reference files, use the current directory for that.
+ * reference files, try to find the reference files in
+ * the "usual places."
*/
- if (refdir == NULL) {
- systemf("/bin/pwd > %s/refdir", tmpdir);
- refdir = refdir_alloc = slurpfile(NULL, "%s/refdir", tmpdir);
- p = refdir + strlen(refdir);
- while (p[-1] == '\n') {
- --p;
- *p = '\0';
- }
- systemf("rm %s/refdir", tmpdir);
- }
+ refdir = refdir_alloc = get_refdir(refdir);
/*
* Banner with basic information.
*/
- if (!quiet_flag) {
- printf("Running tests in: %s\n", tmpdir);
+ printf("\n");
+ printf("If tests fail or crash, details will be in:\n");
+ printf(" %s\n", tmpdir);
+ printf("\n");
+ if (verbosity > VERBOSITY_SUMMARY_ONLY) {
printf("Reference files will be read from: %s\n", refdir);
#ifdef PROGRAM
printf("Running tests on: %s\n", testprog);
@@ -966,12 +2141,15 @@ int main(int argc, char **argv)
printf("Exercising: ");
fflush(stdout);
printf("%s\n", EXTRA_VERSION);
+ } else {
+ printf("Running ");
+ fflush(stdout);
}
/*
* Run some or all of the individual tests.
*/
- if (argc == 0) {
+ if (*argv == NULL) {
/* Default: Run all tests. */
for (i = 0; i < limit; i++) {
if (test_run(i, tmpdir))
@@ -980,15 +2158,30 @@ int main(int argc, char **argv)
}
} else {
while (*(argv) != NULL) {
- i = atoi(*argv);
- if (**argv < '0' || **argv > '9' || i < 0 || i >= limit) {
- printf("*** INVALID Test %s\n", *argv);
- usage(progname);
+ if (**argv >= '0' && **argv <= '9') {
+ i = atoi(*argv);
+ if (i < 0 || i >= limit) {
+ printf("*** INVALID Test %s\n", *argv);
+ free(refdir_alloc);
+ usage(progname);
+ /* usage() never returns */
+ }
} else {
- if (test_run(i, tmpdir))
- tests_failed++;
- tests_run++;
+ for (i = 0; i < limit; ++i) {
+ if (strcmp(*argv, tests[i].name) == 0)
+ break;
+ }
+ if (i >= limit) {
+ printf("*** INVALID Test ``%s''\n",
+ *argv);
+ free(refdir_alloc);
+ usage(progname);
+ /* usage() never returns */
+ }
}
+ if (test_run(i, tmpdir))
+ tests_failed++;
+ tests_run++;
argv++;
}
}
@@ -996,20 +2189,38 @@ int main(int argc, char **argv)
/*
* Report summary statistics.
*/
- if (!quiet_flag) {
+ if (verbosity > VERBOSITY_SUMMARY_ONLY) {
printf("\n");
- printf("%d of %d tests reported failures\n",
- tests_failed, tests_run);
- printf(" Total of %d assertions checked.\n", assertions);
- printf(" Total of %d assertions failed.\n", failures);
- printf(" Total of %d assertions skipped.\n", skips);
+ printf("Totals:\n");
+ printf(" Tests run: %8d\n", tests_run);
+ printf(" Tests failed: %8d\n", tests_failed);
+ printf(" Assertions checked:%8d\n", assertions);
+ printf(" Assertions failed: %8d\n", failures);
+ printf(" Skips reported: %8d\n", skips);
+ }
+ if (failures) {
+ printf("\n");
+ printf("Failing tests:\n");
+ for (i = 0; i < limit; ++i) {
+ if (tests[i].failures)
+ printf(" %d: %s (%d failures)\n", i,
+ tests[i].name, tests[i].failures);
+ }
+ printf("\n");
+ printf("Details for failing tests: %s\n", tmpdir);
+ printf("\n");
+ } else {
+ if (verbosity == VERBOSITY_SUMMARY_ONLY)
+ printf("\n");
+ printf("%d tests passed, no failures\n", tests_run);
}
free(refdir_alloc);
/* If the final tmpdir is empty, we can remove it. */
/* This should be the usual case when all tests succeed. */
+ assertChdir("..");
rmdir(tmpdir);
- return (tests_failed);
+ return (tests_failed ? 1 : 0);
}
diff --git a/archivers/libarchive/files/tar/test/test.h b/archivers/libarchive/files/tar/test/test.h
index 30321e845d6..54c8b8b10c9 100644
--- a/archivers/libarchive/files/tar/test/test.h
+++ b/archivers/libarchive/files/tar/test/test.h
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.bin/tar/test/test.h,v 1.3 2008/06/15 10:07:54 kientzle Exp $
+ * $FreeBSD: src/usr.bin/tar/test/test.h,v 1.4 2008/08/21 07:04:57 kientzle Exp $
*/
/* Every test program should #include "test.h" as the first thing. */
@@ -33,39 +33,95 @@
*/
#if defined(HAVE_CONFIG_H)
/* Most POSIX platforms use the 'configure' script to build config.h */
-#include "../../config.h"
+#include "config.h"
#elif defined(__FreeBSD__)
/* Building as part of FreeBSD system requires a pre-built config.h. */
-#include "../config_freebsd.h"
-#elif defined(_WIN32)
+#include "config_freebsd.h"
+#elif defined(_WIN32) && !defined(__CYGWIN__)
/* Win32 can't run the 'configure' script. */
-#include "../config_windows.h"
+#include "config_windows.h"
#else
/* Warn if the library hasn't been (automatically or manually) configured. */
#error Oops: No config.h and no pre-built configuration in test.h.
#endif
+#include <sys/types.h> /* Windows requires this before sys/stat.h */
+#include <sys/stat.h>
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
+#if HAVE_DIRENT_H
#include <dirent.h>
+#endif
+#ifdef HAVE_DIRECT_H
+#include <direct.h>
+#define dirent direct
+#endif
#include <errno.h>
#include <fcntl.h>
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/stat.h>
-#ifndef _WIN32
+#include <time.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <wchar.h>
-
-#ifdef USE_DMALLOC
-#include <dmalloc.h>
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
#endif
-/* No non-FreeBSD platform will have __FBSDID, so just define it here. */
-#ifdef __FreeBSD__
-#include <sys/cdefs.h> /* For __FBSDID */
+/*
+ * System-specific tweaks. We really want to minimize these
+ * as much as possible, since they make it harder to understand
+ * the mainline code.
+ */
+
+/* Windows (including Visual Studio and MinGW but not Cygwin) */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include "../bsdtar_windows.h"
+#if !defined(__BORLANDC__)
+#define strdup _strdup
+#endif
+#define LOCALE_DE "deu"
#else
-#define __FBSDID(a) /* null */
+#define LOCALE_DE "de_DE.UTF-8"
+#endif
+
+/* Visual Studio */
+#ifdef _MSC_VER
+#define snprintf sprintf_s
+#endif
+
+/* Cygwin */
+#if defined(__CYGWIN__)
+/* Cygwin-1.7.x is lazy about populating nlinks, so don't
+ * expect it to be accurate. */
+# define NLINKS_INACCURATE_FOR_DIRS
+#endif
+
+/* Haiku OS */
+#if defined(__HAIKU__)
+/* Haiku has typedefs in stdint.h (needed for int64_t) */
+#include <stdint.h>
+#endif
+
+/* Get a real definition for __FBSDID if we can */
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+
+/* If not, define it so as to avoid dangling semicolons. */
+#ifndef __FBSDID
+#define __FBSDID(a) struct _undefined_hack
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
#endif
/*
@@ -75,38 +131,83 @@
#define DEFINE_TEST(name) void name(void); void name(void)
/* An implementation of the standard assert() macro */
-#define assert(e) test_assert(__FILE__, __LINE__, (e), #e, NULL)
-
+#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL)
+/* chdir() and error if it fails */
+#define assertChdir(path) \
+ assertion_chdir(__FILE__, __LINE__, path)
/* Assert two integers are the same. Reports value of each one if not. */
-#define assertEqualInt(v1,v2) \
- test_assert_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
-
+#define assertEqualInt(v1,v2) \
+ assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
/* Assert two strings are the same. Reports value of each one if not. */
#define assertEqualString(v1,v2) \
- test_assert_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
+ assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
/* As above, but v1 and v2 are wchar_t * */
#define assertEqualWString(v1,v2) \
- test_assert_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
+ assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
/* As above, but raw blocks of bytes. */
#define assertEqualMem(v1, v2, l) \
- test_assert_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL)
+ assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL)
/* Assert two files are the same; allow printf-style expansion of second name.
* See below for comments about variable arguments here...
*/
#define assertEqualFile \
- test_setup(__FILE__, __LINE__);test_assert_equal_file
+ assertion_setup(__FILE__, __LINE__);assertion_equal_file
/* Assert that a file is empty; supports printf-style arguments. */
#define assertEmptyFile \
- test_setup(__FILE__, __LINE__);test_assert_empty_file
+ assertion_setup(__FILE__, __LINE__);assertion_empty_file
+/* Assert that a file is not empty; supports printf-style arguments. */
+#define assertNonEmptyFile \
+ assertion_setup(__FILE__, __LINE__);assertion_non_empty_file
+#define assertFileAtime(pathname, sec, nsec) \
+ assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec)
+#define assertFileAtimeRecent(pathname) \
+ assertion_file_atime_recent(__FILE__, __LINE__, pathname)
+#define assertFileBirthtime(pathname, sec, nsec) \
+ assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec)
+#define assertFileBirthtimeRecent(pathname) \
+ assertion_file_birthtime_recent(__FILE__, __LINE__, pathname)
/* Assert that a file exists; supports printf-style arguments. */
#define assertFileExists \
- test_setup(__FILE__, __LINE__);test_assert_file_exists
+ assertion_setup(__FILE__, __LINE__);assertion_file_exists
/* Assert that a file exists; supports printf-style arguments. */
#define assertFileNotExists \
- test_setup(__FILE__, __LINE__);test_assert_file_not_exists
+ assertion_setup(__FILE__, __LINE__);assertion_file_not_exists
/* Assert that file contents match a string; supports printf-style arguments. */
#define assertFileContents \
- test_setup(__FILE__, __LINE__);test_assert_file_contents
+ assertion_setup(__FILE__, __LINE__);assertion_file_contents
+#define assertFileMtime(pathname, sec, nsec) \
+ assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
+#define assertFileMtimeRecent(pathname) \
+ assertion_file_mtime_recent(__FILE__, __LINE__, pathname)
+#define assertFileNLinks(pathname, nlinks) \
+ assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
+#define assertFileSize(pathname, size) \
+ assertion_file_size(__FILE__, __LINE__, pathname, size)
+#define assertTextFileContents \
+ assertion_setup(__FILE__, __LINE__);assertion_text_file_contents
+#define assertFileContainsLinesAnyOrder(pathname, lines) \
+ assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines)
+#define assertIsDir(pathname, mode) \
+ assertion_is_dir(__FILE__, __LINE__, pathname, mode)
+#define assertIsHardlink(path1, path2) \
+ assertion_is_hardlink(__FILE__, __LINE__, path1, path2)
+#define assertIsNotHardlink(path1, path2) \
+ assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2)
+#define assertIsReg(pathname, mode) \
+ assertion_is_reg(__FILE__, __LINE__, pathname, mode)
+#define assertIsSymlink(pathname, contents) \
+ assertion_is_symlink(__FILE__, __LINE__, pathname, contents)
+/* Create a directory, report error if it fails. */
+#define assertMakeDir(dirname, mode) \
+ assertion_make_dir(__FILE__, __LINE__, dirname, mode)
+#define assertMakeFile(path, mode, contents) \
+ assertion_make_file(__FILE__, __LINE__, path, mode, contents)
+#define assertMakeHardlink(newfile, oldfile) \
+ assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
+#define assertMakeSymlink(newfile, linkto) \
+ assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
+#define assertUmask(mask) \
+ assertion_umask(__FILE__, __LINE__, mask)
/*
* This would be simple with C99 variadic macros, but I don't want to
@@ -115,26 +216,61 @@
* but effective.
*/
#define skipping \
- test_setup(__FILE__, __LINE__);test_skipping
+ assertion_setup(__FILE__, __LINE__);test_skipping
/* Function declarations. These are defined in test_utility.c. */
void failure(const char *fmt, ...);
-void test_setup(const char *, int);
+int assertion_assert(const char *, int, int, const char *, void *);
+int assertion_chdir(const char *, int, const char *);
+int assertion_empty_file(const char *, ...);
+int assertion_equal_file(const char *, const char *, ...);
+int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *);
+int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *);
+int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
+int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
+int assertion_file_atime(const char *, int, const char *, long, long);
+int assertion_file_atime_recent(const char *, int, const char *);
+int assertion_file_birthtime(const char *, int, const char *, long, long);
+int assertion_file_birthtime_recent(const char *, int, const char *);
+int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **);
+int assertion_file_contents(const void *, int, const char *, ...);
+int assertion_file_exists(const char *, ...);
+int assertion_file_mtime(const char *, int, const char *, long, long);
+int assertion_file_mtime_recent(const char *, int, const char *);
+int assertion_file_nlinks(const char *, int, const char *, int);
+int assertion_file_not_exists(const char *, ...);
+int assertion_file_size(const char *, int, const char *, long);
+int assertion_is_dir(const char *, int, const char *, int);
+int assertion_is_hardlink(const char *, int, const char *, const char *);
+int assertion_is_not_hardlink(const char *, int, const char *, const char *);
+int assertion_is_reg(const char *, int, const char *, int);
+int assertion_is_symlink(const char *, int, const char *, const char *);
+int assertion_make_dir(const char *, int, const char *, int);
+int assertion_make_file(const char *, int, const char *, int, const char *);
+int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
+int assertion_make_symlink(const char *, int, const char *newpath, const char *);
+int assertion_non_empty_file(const char *, ...);
+int assertion_text_file_contents(const char *buff, const char *f);
+int assertion_umask(const char *, int, int);
+void assertion_setup(const char *, int);
+
void test_skipping(const char *fmt, ...);
-int test_assert(const char *, int, int, const char *, void *);
-int test_assert_empty_file(const char *, ...);
-int test_assert_equal_file(const char *, const char *, ...);
-int test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
-int test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
-int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
-int test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *);
-int test_assert_file_contents(const void *, int, const char *, ...);
-int test_assert_file_exists(const char *, ...);
-int test_assert_file_not_exists(const char *, ...);
/* Like sprintf, then system() */
int systemf(const char * fmt, ...);
+/* Delay until time() returns a value after this. */
+void sleepUntilAfter(time_t);
+
+/* Return true if this platform can create symlinks. */
+int canSymlink(void);
+
+/* Return true if this platform can run the "gzip" program. */
+int canGzip(void);
+
+/* Return true if this platform can run the "gunzip" program. */
+int canGunzip(void);
+
/* Suck file into string allocated via malloc(). Call free() when done. */
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
char *slurpfile(size_t *, const char *fmt, ...);
@@ -147,4 +283,7 @@ void extract_reference_file(const char *);
*/
/* Pathname of exe to be tested. */
-char *testprog;
+const char *testprogfile;
+/* Name of exe to use in printf-formatted command strings. */
+/* On Windows, this includes leading/trailing quotes. */
+const char *testprog;
diff --git a/archivers/libarchive/files/tar/test/test_0.c b/archivers/libarchive/files/tar/test/test_0.c
index 36c8b1ebe1f..c9277da16bc 100644
--- a/archivers/libarchive/files/tar/test/test_0.c
+++ b/archivers/libarchive/files/tar/test/test_0.c
@@ -29,13 +29,18 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_0.c,v 1.2 2008/05/26 17:10:10 kien
* 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?!", testprog);
- if (!assertEqualInt(0, stat(testprog, &st)))
+ if (!assertEqualInt(0, stat(testprogfile, &st)))
exit(1);
failure("%s is not executable?!", testprog);
@@ -46,9 +51,9 @@ DEFINE_TEST(test_0)
* Try to succesfully run the program; this requires that
* we know some option that will succeed.
*/
- if (0 == systemf("%s --version >/dev/null", testprog)) {
+ if (0 == systemf("%s --version >" DEV_NULL, testprog)) {
/* This worked. */
- } else if (0 == systemf("%s -W version >/dev/null", testprog)) {
+ } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) {
/* This worked. */
} else {
failure("Unable to successfully run any of the following:\n"
diff --git a/archivers/libarchive/files/tar/test/test_basic.c b/archivers/libarchive/files/tar/test/test_basic.c
index fff51123019..4dc7cf6364f 100644
--- a/archivers/libarchive/files/tar/test/test_basic.c
+++ b/archivers/libarchive/files/tar/test/test_basic.c
@@ -27,20 +27,19 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_basic.c,v 1.2 2008/05/26 17:10:10
static void
-basic_tar(const char *target, const char *pack_options, const char *unpack_options)
+basic_tar(const char *target, const char *pack_options,
+ const char *unpack_options, const char *flist)
{
- struct stat st, st2;
- char buff[128];
int r;
- assertEqualInt(0, mkdir(target, 0775));
+ assertMakeDir(target, 0775);
/* Use the tar program to create an archive. */
- r = systemf("%s cf - %s `cat filelist` >%s/archive 2>%s/pack.err", testprog, pack_options, target, target);
+ r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target);
failure("Error invoking %s cf -", testprog, pack_options);
assertEqualInt(r, 0);
- chdir(target);
+ assertChdir(target);
/* Verify that nothing went to stderr. */
assertEmptyFile("pack.err");
@@ -60,99 +59,57 @@ basic_tar(const char *target, const char *pack_options, const char *unpack_optio
*/
/* Regular file with 2 links. */
- r = lstat("file", &st);
- failure("Failed to stat file %s/file, errno=%d", target, errno);
- assertEqualInt(r, 0);
- if (r == 0) {
- assert(S_ISREG(st.st_mode));
- assertEqualInt(0644, st.st_mode & 0777);
- assertEqualInt(10, st.st_size);
- failure("file %s/file", target);
- assertEqualInt(2, st.st_nlink);
- }
+ assertIsReg("file", -1);
+ assertFileSize("file", 10);
+ failure("%s", target);
+ assertFileNLinks("file", 2);
/* Another name for the same file. */
- r = lstat("linkfile", &st2);
- failure("Failed to stat file %s/linkfile, errno=%d", target, errno);
- assertEqualInt(r, 0);
- if (r == 0) {
- assert(S_ISREG(st2.st_mode));
- assertEqualInt(0644, st2.st_mode & 0777);
- assertEqualInt(10, st2.st_size);
- failure("file %s/linkfile", target);
- assertEqualInt(2, st2.st_nlink);
- /* Verify that the two are really hardlinked. */
- assertEqualInt(st.st_dev, st2.st_dev);
- failure("%s/linkfile and %s/file aren't really hardlinks", target, target);
- assertEqualInt(st.st_ino, st2.st_ino);
- }
+ assertIsReg("linkfile", -1);
+ assertFileSize("linkfile", 10);
+ assertFileNLinks("linkfile", 2);
+ assertIsHardlink("file", "linkfile");
/* Symlink */
- r = lstat("symlink", &st);
- failure("Failed to stat file %s/symlink, errno=%d", target, errno);
- assertEqualInt(r, 0);
- if (r == 0) {
- failure("symlink should be a symlink; actual mode is %o",
- st.st_mode);
- assert(S_ISLNK(st.st_mode));
- if (S_ISLNK(st.st_mode)) {
- r = readlink("symlink", buff, sizeof(buff));
- assertEqualInt(r, 4);
- buff[r] = '\0';
- assertEqualString(buff, "file");
- }
- }
+ if (canSymlink())
+ assertIsSymlink("symlink", "file");
/* dir */
- r = lstat("dir", &st);
- if (r == 0) {
- assertEqualInt(r, 0);
- assert(S_ISDIR(st.st_mode));
- assertEqualInt(0775, st.st_mode & 0777);
- }
-
- chdir("..");
+ assertIsDir("dir", 0775);
+ assertChdir("..");
}
DEFINE_TEST(test_basic)
{
- int fd;
- int filelist;
- int oldumask;
+ FILE *f;
+ const char *flist;
- oldumask = umask(0);
-
- /*
- * Create an assortment of files on disk.
- */
- filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+ assertUmask(0);
/* File with 10 bytes content. */
- fd = open("file", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(10, write(fd, "123456789", 10));
- close(fd);
- write(filelist, "file\n", 5);
+ f = fopen("file", "wb");
+ assert(f != NULL);
+ assertEqualInt(10, fwrite("123456789", 1, 10, f));
+ fclose(f);
/* hardlink to above file. */
- assertEqualInt(0, link("file", "linkfile"));
- write(filelist, "linkfile\n", 9);
+ assertMakeHardlink("linkfile", "file");
+ assertIsHardlink("file", "linkfile");
/* Symlink to above file. */
- assertEqualInt(0, symlink("file", "symlink"));
- write(filelist, "symlink\n", 8);
+ if (canSymlink())
+ assertMakeSymlink("symlink", "file");
/* Directory. */
- assertEqualInt(0, mkdir("dir", 0775));
- write(filelist, "dir\n", 4);
- /* All done. */
- close(filelist);
+ assertMakeDir("dir", 0775);
+ if (canSymlink())
+ flist = "file linkfile symlink dir";
+ else
+ flist = "file linkfile dir";
/* Archive/dearchive with a variety of options. */
- basic_tar("copy", "", "");
+ basic_tar("copy", "", "", flist);
/* tar doesn't handle cpio symlinks correctly */
/* basic_tar("copy_odc", "--format=odc", ""); */
- basic_tar("copy_ustar", "--format=ustar", "");
-
- umask(oldumask);
+ basic_tar("copy_ustar", "--format=ustar", "", flist);
}
diff --git a/archivers/libarchive/files/tar/test/test_copy.c b/archivers/libarchive/files/tar/test/test_copy.c
index b2eef8cf791..69112900e53 100644
--- a/archivers/libarchive/files/tar/test/test_copy.c
+++ b/archivers/libarchive/files/tar/test/test_copy.c
@@ -23,7 +23,110 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_copy.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_copy.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
+
+#if defined(__CYGWIN__)
+# include <limits.h>
+# include <sys/cygwin.h>
+#endif
+
+/*
+ * Try to figure out how deep we can go in our tests. Assumes that
+ * the first call to this function has the longest starting cwd (which
+ * is currently "<testdir>/original"). This is mostly to work around
+ * limits in our Win32 support.
+ *
+ * Background: On Posix systems, PATH_MAX is merely a limit on the
+ * length of the string passed into a system call. By repeatedly
+ * calling chdir(), you can work with arbitrarily long paths on such
+ * systems. In contrast, Win32 APIs apply PATH_MAX limits to the full
+ * absolute path, so the permissible length of a system call argument
+ * varies with the cwd. Some APIs actually enforce limits
+ * significantly less than PATH_MAX to ensure that you can create
+ * files within the current working directory. The Win32 limits also
+ * apply to Cygwin before 1.7.
+ *
+ * Someday, I want to convert the Win32 support to use newer
+ * wide-character paths with '\\?\' prefix, which has a 32k PATH_MAX
+ * instead of the rather anemic 260 character limit of the older
+ * system calls. Then we can drop this mess (unless we want to
+ * continue to special-case Cygwin 1.5 and earlier).
+ */
+static int
+compute_loop_max(void)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ static int LOOP_MAX = 0;
+ char buf[MAX_PATH];
+ size_t cwdlen;
+
+ if (LOOP_MAX == 0) {
+ assert(_getcwd(buf, MAX_PATH) != NULL);
+ cwdlen = strlen(buf);
+ /* 12 characters = length of 8.3 filename */
+ /* 4 characters = length of "/../" used in symlink tests */
+ /* 1 character = length of extra "/" separator */
+ LOOP_MAX = MAX_PATH - (int)cwdlen - 12 - 4 - 1;
+ }
+ return LOOP_MAX;
+#elif defined(__CYGWIN__) && !defined(HAVE_CYGWIN_CONV_PATH)
+ static int LOOP_MAX = 0;
+ if (LOOP_MAX == 0) {
+ char wbuf[PATH_MAX];
+ char pbuf[PATH_MAX];
+ size_t wcwdlen;
+ size_t pcwdlen;
+ size_t cwdlen;
+ assert(getcwd(pbuf, PATH_MAX) != NULL);
+ pcwdlen = strlen(pbuf);
+ cygwin_conv_to_full_win32_path(pbuf, wbuf);
+ wcwdlen = strlen(wbuf);
+ cwdlen = ((wcwdlen > pcwdlen) ? wcwdlen : pcwdlen);
+ /* Cygwin helper needs an extra few characters. */
+ LOOP_MAX = PATH_MAX - (int)cwdlen - 12 - 4 - 4;
+ }
+ return LOOP_MAX;
+#else
+ /* cygwin-1.7 ends up here, along with "normal" unix */
+ return 200; /* restore pre-r278 depth */
+#endif
+}
+
+/* filenames[i] is a distinctive filename of length i. */
+/* To simplify interpreting failures, each filename ends with a
+ * decimal integer which is the length of the filename. E.g., A
+ * filename ending in "_92" is 92 characters long. To detect errors
+ * which drop or misplace characters, the filenames use a repeating
+ * "abcdefghijklmnopqrstuvwxyz..." pattern. */
+static char *filenames[201];
+
+static void
+compute_filenames(void)
+{
+ char buff[250];
+ size_t i,j;
+
+ filenames[0] = strdup("");
+ filenames[1] = strdup("1");
+ filenames[2] = strdup("a2");
+ for (i = 3; i < sizeof(filenames)/sizeof(filenames[0]); ++i) {
+ /* Fill with "abcdefghij..." */
+ for (j = 0; j < i; ++j)
+ buff[j] = 'a' + (j % 26);
+ buff[j--] = '\0';
+ /* Work from the end to fill in the number portion. */
+ buff[j--] = '0' + (i % 10);
+ if (i > 9) {
+ buff[j--] = '0' + ((i / 10) % 10);
+ if (i > 99)
+ buff[j--] = '0' + (i / 100);
+ }
+ buff[j] = '_';
+ /* Guard against obvious screwups in the above code. */
+ assertEqualInt(strlen(buff), i);
+ filenames[i] = strdup(buff);
+ }
+}
static void
create_tree(void)
@@ -31,208 +134,145 @@ create_tree(void)
char buff[260];
char buff2[260];
int i;
- int fd;
-
- assertEqualInt(0, mkdir("original", 0775));
- chdir("original");
- assertEqualInt(0, mkdir("f", 0775));
- assertEqualInt(0, mkdir("l", 0775));
- assertEqualInt(0, mkdir("m", 0775));
- assertEqualInt(0, mkdir("s", 0775));
- assertEqualInt(0, mkdir("d", 0775));
-
- for (i = 0; i < 200; i++) {
- buff[0] = 'f';
- buff[1] = '/';
- /* Create a file named "f/abcdef..." */
- buff[i + 2] = 'a' + (i % 26);
- buff[i + 3] = '\0';
- fd = open(buff, O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(i + 3, write(fd, buff, strlen(buff)));
- close(fd);
+ int LOOP_MAX;
+
+ compute_filenames();
+
+ /* Log that we'll be omitting some checks. */
+ if (!canSymlink()) {
+ skipping("Symlink checks");
+ }
+
+ assertMakeDir("original", 0775);
+ assertEqualInt(0, chdir("original"));
+ LOOP_MAX = compute_loop_max();
+
+ assertMakeDir("f", 0775);
+ assertMakeDir("l", 0775);
+ assertMakeDir("m", 0775);
+ assertMakeDir("s", 0775);
+ assertMakeDir("d", 0775);
+
+ for (i = 1; i < LOOP_MAX; i++) {
+ failure("Internal sanity check failed: i = %d", i);
+ assert(filenames[i] != NULL);
+
+ sprintf(buff, "f/%s", filenames[i]);
+ assertMakeFile(buff, 0777, buff);
/* Create a link named "l/abcdef..." to the above. */
- strcpy(buff2, buff);
- buff2[0] = 'l';
- assertEqualInt(0, link(buff, buff2));
+ sprintf(buff2, "l/%s", filenames[i]);
+ assertMakeHardlink(buff2, buff);
/* Create a link named "m/abcdef..." to the above. */
- strcpy(buff2, buff);
- buff2[0] = 'm';
- assertEqualInt(0, link(buff, buff2));
-
- /* Create a symlink named "s/abcdef..." to the above. */
- strcpy(buff2 + 3, buff);
- buff[0] = 's';
- buff2[0] = '.';
- buff2[1] = '.';
- buff2[2] = '/';
- assertEqualInt(0, symlink(buff2, buff));
-
+ sprintf(buff2, "m/%s", filenames[i]);
+ assertMakeHardlink(buff2, buff);
+
+ if (canSymlink()) {
+ /* Create a symlink named "s/abcdef..." to the above. */
+ sprintf(buff, "s/%s", filenames[i]);
+ sprintf(buff2, "../f/%s", filenames[i]);
+ failure("buff=\"%s\" buff2=\"%s\"", buff, buff2);
+ assertMakeSymlink(buff, buff2);
+ }
/* Create a dir named "d/abcdef...". */
buff[0] = 'd';
- assertEqualInt(0, mkdir(buff, 0775));
+ failure("buff=\"%s\"", buff);
+ assertMakeDir(buff, 0775);
}
- chdir("..");
+ assertEqualInt(0, chdir(".."));
}
-#define LIMIT_NONE 0
-#define LIMIT_USTAR 1
+#define LIMIT_NONE 200
+#define LIMIT_USTAR 100
static void
-verify_tree(int limit)
+verify_tree(size_t limit)
{
- struct stat st, st2;
- char filename[260];
char name1[260];
char name2[260];
- char contents[260];
- int i, j, r;
- int fd;
- int len;
- const char *p, *dp;
- DIR *d;
- struct dirent *de;
+ size_t i, LOOP_MAX;
- /* Generate the names we know should be there and verify them. */
- for (i = 1; i < 200; i++) {
- /* Generate a base name of the correct length. */
- for (j = 0; j < i; ++j)
- filename[j] = 'a' + (j % 26);
-#if 0
- for (n = i; n > 0; n /= 10)
- filename[--j] = '0' + (n % 10);
-#endif
- filename[i] = '\0';
+ LOOP_MAX = compute_loop_max();
+ /* Generate the names we know should be there and verify them. */
+ for (i = 1; i < LOOP_MAX; i++) {
/* Verify a file named "f/abcdef..." */
- strcpy(name1, "f/");
- strcat(name1, filename);
- if (limit != LIMIT_USTAR || strlen(filename) <= 100) {
- fd = open(name1, O_RDONLY);
- failure("Couldn't open \"%s\": %s",
- name1, strerror(errno));
- if (assert(fd >= 0)) {
- len = read(fd, contents, i + 10);
- close(fd);
- assertEqualInt(len, i + 2);
- /* Verify contents of 'contents' */
- contents[len] = '\0';
- failure("Each test file contains its own name");
- assertEqualString(name1, contents);
- /* stat() for dev/ino for next check */
- assertEqualInt(0, lstat(name1, &st));
- }
+ sprintf(name1, "f/%s", filenames[i]);
+ if (i <= limit) {
+ assertFileExists(name1);
+ assertFileContents(name1, strlen(name1), name1);
}
- /*
- * ustar allows 100 chars for links, and we have
- * "original/" as part of the name, so the link
- * names here can't exceed 91 chars.
- */
- strcpy(name2, "l/");
- strcat(name2, filename);
- if (limit != LIMIT_USTAR || strlen(name2) <= 100) {
+ sprintf(name2, "l/%s", filenames[i]);
+ if (i + 2 <= limit) {
/* Verify hardlink "l/abcdef..." */
- assertEqualInt(0, (r = lstat(name2, &st2)));
- if (r == 0) {
- assertEqualInt(st2.st_dev, st.st_dev);
- assertEqualInt(st2.st_ino, st.st_ino);
- }
-
- /* Verify hardlink "m_abcdef..." */
+ assertIsHardlink(name1, name2);
+ /* Verify hardlink "m/abcdef..." */
name2[0] = 'm';
- assertEqualInt(0, (r = lstat(name2, &st2)));
- if (r == 0) {
- assertEqualInt(st2.st_dev, st.st_dev);
- assertEqualInt(st2.st_ino, st.st_ino);
- }
+ assertIsHardlink(name1, name2);
}
- /*
- * Symlink text doesn't include the 'original/' prefix,
- * so the limit here is 100 characters.
- */
- /* Verify symlink "s/abcdef..." */
- strcpy(name2, "../s/");
- strcat(name2, filename);
- if (limit != LIMIT_USTAR || strlen(name2) <= 100) {
- /* This is a symlink. */
- failure("Couldn't stat %s (length %d)",
- filename, strlen(filename));
- if (assertEqualInt(0, lstat(name2 + 3, &st2))) {
- assert(S_ISLNK(st2.st_mode));
- /* This is a symlink to the file above. */
- failure("Couldn't stat %s", name2 + 3);
- if (assertEqualInt(0, stat(name2 + 3, &st2))) {
- assertEqualInt(st2.st_dev, st.st_dev);
- assertEqualInt(st2.st_ino, st.st_ino);
- }
- }
+ if (canSymlink()) {
+ /* Verify symlink "s/abcdef..." */
+ sprintf(name1, "s/%s", filenames[i]);
+ sprintf(name2, "../f/%s", filenames[i]);
+ if (strlen(name2) <= limit)
+ assertIsSymlink(name1, name2);
}
/* Verify dir "d/abcdef...". */
- strcpy(name1, "d/");
- strcat(name1, filename);
- if (limit != LIMIT_USTAR || strlen(filename) < 100) {
- /* This is a dir. */
- failure("Couldn't stat %s (length %d)",
- name1, strlen(filename));
- if (assertEqualInt(0, lstat(name1, &st2))) {
- if (assert(S_ISDIR(st2.st_mode))) {
- /* TODO: opendir/readdir this
- * directory and make sure
- * it's empty.
- */
- }
+ sprintf(name1, "d/%s", filenames[i]);
+ if (i + 1 <= limit) { /* +1 for trailing slash */
+ if (assertIsDir(name1, -1)) {
+ /* TODO: opendir/readdir this
+ * directory and make sure
+ * it's empty.
+ */
}
}
}
- /* Now make sure nothing is there that shouldn't be. */
- for (dp = "dflms"; *dp != '\0'; ++dp) {
- char dir[2];
- dir[0] = *dp; dir[1] = '\0';
- d = opendir(dir);
- while ((de = readdir(d)) != NULL) {
- p = de->d_name;
- switch(dp[0]) {
- case 'l': case 'm':
- if (limit == LIMIT_USTAR) {
- failure("strlen(p) = %d", strlen(p));
- assert(strlen(p) <= 100);
- }
- case 'd':
- if (limit == LIMIT_USTAR) {
+#if !defined(_WIN32) || defined(__CYGWIN__)
+ {
+ const char *dp;
+ /* Now make sure nothing is there that shouldn't be. */
+ for (dp = "dflms"; *dp != '\0'; ++dp) {
+ DIR *d;
+ struct dirent *de;
+ char dir[2];
+ dir[0] = *dp; dir[1] = '\0';
+ d = opendir(dir);
+ failure("Unable to open dir '%s'", dir);
+ if (!assert(d != NULL))
+ continue;
+ while ((de = readdir(d)) != NULL) {
+ char *p = de->d_name;
+ if (p[0] == '.')
+ continue;
+ switch(dp[0]) {
+ case 'l': case 'm': case 'd':
failure("strlen(p)=%d", strlen(p));
- assert(strlen(p) < 100);
- }
- case 'f': case 's':
- if (limit == LIMIT_USTAR) {
+ assert(strlen(p) < limit);
+ assertEqualString(p,
+ filenames[strlen(p)]);
+ break;
+ case 'f': case 's':
failure("strlen(p)=%d", strlen(p));
- assert(strlen(p) < 101);
- }
- /* Our files have very particular filename patterns. */
- if (p[0] != '.' || (p[1] != '.' && p[1] != '\0')) {
- for (i = 0; p[i] != '\0' && i < 200; i++) {
- failure("i=%d, p[i]='%c' 'a'+(i%%26)='%c'", i, p[i], 'a' + (i % 26));
- assertEqualInt(p[i], 'a' + (i % 26));
- }
- assert(p[i] == '\0');
+ assert(strlen(p) < limit + 1);
+ assertEqualString(p,
+ filenames[strlen(p)]);
+ break;
+ default:
+ failure("File %s shouldn't be here", p);
+ assert(0);
}
- break;
- case '.':
- assert(p[1] == '\0' || (p[1] == '.' && p[2] == '\0'));
- break;
- default:
- failure("File %s shouldn't be here", p);
- assert(0);
}
+ closedir(d);
}
- closedir(d);
}
+#endif
}
static void
@@ -240,7 +280,13 @@ copy_basic(void)
{
int r;
- assertEqualInt(0, mkdir("plain", 0775));
+ /* NOTE: for proper operation on cygwin-1.5 and windows, the
+ * length of the name of the directory below, "plain", must be
+ * less than or equal to the lengthe of the name of the original
+ * directory, "original" This restriction derives from the
+ * extremely limited pathname lengths on those platforms.
+ */
+ assertMakeDir("plain", 0775);
assertEqualInt(0, chdir("plain"));
/*
@@ -276,7 +322,13 @@ copy_ustar(void)
const char *target = "ustar";
int r;
- assertEqualInt(0, mkdir(target, 0775));
+ /* NOTE: for proper operation on cygwin-1.5 and windows, the
+ * length of the name of the directory below, "ustar", must be
+ * less than or equal to the lengthe of the name of the original
+ * directory, "original" This restriction derives from the
+ * extremely limited pathname lengths on those platforms.
+ */
+ assertMakeDir(target, 0775);
assertEqualInt(0, chdir(target));
/*
@@ -303,17 +355,13 @@ copy_ustar(void)
assertEmptyFile("unpack.err");
assertEmptyFile("unpack.out");
- chdir("original");
verify_tree(LIMIT_USTAR);
- chdir("../..");
+ assertEqualInt(0, chdir("../.."));
}
DEFINE_TEST(test_copy)
{
- int oldumask;
-
- oldumask = umask(0);
-
+ assertUmask(0);
create_tree(); /* Create sample files in "original" dir. */
/* Test simple "tar -c | tar -x" pipeline copy. */
@@ -321,6 +369,4 @@ DEFINE_TEST(test_copy)
/* Same, but constrain to ustar format. */
copy_ustar();
-
- umask(oldumask);
}
diff --git a/archivers/libarchive/files/tar/test/test_empty_mtree.c b/archivers/libarchive/files/tar/test/test_empty_mtree.c
new file mode 100644
index 00000000000..6f8a5e91aa1
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_empty_mtree.c
@@ -0,0 +1,45 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD$");
+
+/*
+ * Regression test: We used to get a bogus error message when we
+ * asked tar to copy entries out of an empty archive. See
+ * Issue 51 on libarchive.googlecode.com for details.
+ */
+DEFINE_TEST(test_empty_mtree)
+{
+ int r;
+
+ assertMakeFile("test1.mtree", 0777, "#mtree\n");
+
+ r = systemf("%s cf test1.tar @test1.mtree >test1.out 2>test1.err",
+ testprog);
+ failure("Error invoking %s cf", testprog);
+ assertEqualInt(r, 0);
+ assertEmptyFile("test1.out");
+ assertEmptyFile("test1.err");
+}
diff --git a/archivers/libarchive/files/tar/test/test_getdate.c b/archivers/libarchive/files/tar/test/test_getdate.c
index d75119cc33a..eac571049fe 100644
--- a/archivers/libarchive/files/tar/test/test_getdate.c
+++ b/archivers/libarchive/files/tar/test/test_getdate.c
@@ -25,14 +25,56 @@
#include "test.h"
__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_getdate.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
+#include <time.h>
+
/*
* Verify that the getdate() function works.
*/
-time_t get_date(const char *);
+time_t get_date(time_t, const char *);
DEFINE_TEST(test_getdate)
{
- assertEqualInt(0, get_date("Jan 1, 1970 UTC"));
+ time_t now = time(NULL);
+
+ assertEqualInt(get_date(now, "Jan 1, 1970 UTC"), 0);
+ assertEqualInt(get_date(now, "7:12:18-0530 4 May 1983"), 420900138);
+ assertEqualInt(get_date(now, "2004/01/29 513 mest"), 1075345980);
+ assertEqualInt(get_date(now, "99/02/17 7pm utc"), 919278000);
+ assertEqualInt(get_date(now, "02/17/99 7:11am est"), 919253460);
+ /* It's important that we handle ctime() format. */
+ assertEqualInt(get_date(now, "Sun Feb 22 17:38:26 PST 2009"),
+ 1235353106);
+ /* Basic relative offsets. */
+ /* If we use the actual current time as the reference, then
+ * these tests break around DST changes, so it's actually
+ * important to use a specific reference time here. */
+ assertEqualInt(get_date(0, "tomorrow"), 24 * 60 * 60);
+ assertEqualInt(get_date(0, "yesterday"), - 24 * 60 * 60);
+ assertEqualInt(get_date(0, "now + 1 hour"), 60 * 60);
+ assertEqualInt(get_date(0, "now + 1 hour + 1 minute"), 60 * 60 + 60);
+ /* Repeat the above for a different start time. */
+ now = 1231113600; /* Jan 5, 2009 00:00 UTC */
+ assertEqualInt(get_date(0, "Jan 5, 2009 00:00 UTC"), now);
+ assertEqualInt(get_date(now, "tomorrow"), now + 24 * 60 * 60);
+ assertEqualInt(get_date(now, "yesterday"), now - 24 * 60 * 60);
+ assertEqualInt(get_date(now, "now + 1 hour"), now + 60 * 60);
+ assertEqualInt(get_date(now, "now + 1 hour + 1 minute"),
+ now + 60 * 60 + 60);
+ assertEqualInt(get_date(now, "tomorrow 5:16am UTC"),
+ now + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60);
+ assertEqualInt(get_date(now, "UTC 5:16am tomorrow"),
+ now + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60);
+
+ /* Jan 5, 2009 was a Monday. */
+ assertEqualInt(get_date(now, "monday UTC"), now);
+ assertEqualInt(get_date(now, "sunday UTC"), now + 6 * 24 * 60 * 60);
+ assertEqualInt(get_date(now, "tuesday UTC"), now + 24 * 60 * 60);
+ /* "next tuesday" is one week after "tuesday" */
+ assertEqualInt(get_date(now, "UTC next tuesday"),
+ now + 8 * 24 * 60 * 60);
+ /* "last tuesday" is one week before "tuesday" */
+ assertEqualInt(get_date(now, "last tuesday UTC"),
+ now - 6 * 24 * 60 * 60);
/* TODO: Lots more tests here. */
}
diff --git a/archivers/libarchive/files/tar/test/test_help.c b/archivers/libarchive/files/tar/test/test_help.c
index 163e2127f26..3bb517d00cd 100644
--- a/archivers/libarchive/files/tar/test/test_help.c
+++ b/archivers/libarchive/files/tar/test/test_help.c
@@ -51,6 +51,7 @@ DEFINE_TEST(test_help)
/* 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. */
@@ -67,6 +68,7 @@ DEFINE_TEST(test_help)
/* -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");
@@ -74,6 +76,7 @@ DEFINE_TEST(test_help)
/* -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");
diff --git a/archivers/libarchive/files/tar/test/test_option_T_upper.c b/archivers/libarchive/files/tar/test/test_option_T_upper.c
new file mode 100644
index 00000000000..3d2a8b1e2a5
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_option_T_upper.c
@@ -0,0 +1,188 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
+
+static int
+touch(const char *fn, int fail)
+{
+ FILE *f = fopen(fn, "w");
+ if (fail) {
+ failure("Couldn't create file '%s', errno=%d (%s)\n",
+ fn, errno, strerror(errno));
+ if (!assert(f != NULL))
+ return (0); /* Failure. */
+ } else {
+ if (f == NULL)
+ return (0); /* Soft failure. */
+ }
+ fclose(f);
+ return (1); /* Success */
+}
+
+DEFINE_TEST(test_option_T_upper)
+{
+ FILE *f;
+ int r;
+ struct stat st;
+ int gnarlyFilesSupported;
+
+ /* Create a simple dir heirarchy; bail if anything fails. */
+ if (!assertMakeDir("d1", 0755)) return;
+ if (!assertMakeDir("d1/d2", 0755)) return;
+ if (!touch("f", 1)) return;
+ if (!touch("d1/f1", 1)) return;
+ if (!touch("d1/f2", 1)) return;
+ if (!touch("d1/d2/f3", 1)) return;
+ if (!touch("d1/d2/f4", 1)) return;
+ if (!touch("d1/d2/f5", 1)) return;
+ if (!touch("d1/d2/f6", 1)) return;
+ /* Some platforms don't permit such things; just skip it. */
+ gnarlyFilesSupported = touch("d1/d2/f\x0a", 0);
+
+ /* Populate a file list */
+ f = fopen("filelist", "w+");
+ if (!assert(f != NULL))
+ return;
+ /* Use a variety of text line endings. */
+ fprintf(f, "f\x0d"); /* CR */
+ fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */
+ fprintf(f, "d1/d2/f4\x0a"); /* NL */
+ fprintf(f, "d1/d2/f6"); /* EOF */
+ fclose(f);
+
+ /* Populate a second file list */
+ f = fopen("filelist2", "w+");
+ if (!assert(f != NULL))
+ return;
+ /* Use null-terminated names. */
+ fprintf(f, "d1/d2/f3");
+ fwrite("\0", 1, 1, f);
+ fprintf(f, "d1/d2/f5");
+ fwrite("\0", 1, 1, f);
+ if (gnarlyFilesSupported) {
+ fprintf(f, "d1/d2/f\x0a");
+ fwrite("\0", 1, 1, f);
+ }
+ fclose(f);
+
+ /* Use -c -T to archive up the files. */
+ r = systemf("%s -c -f test1.tar -T filelist > test1.out 2> test1.err",
+ testprog);
+ assert(r == 0);
+ assertEmptyFile("test1.out");
+ assertEmptyFile("test1.err");
+
+ /* Use -x -T to dearchive the files */
+ if (!assertMakeDir("test1", 0755)) return;
+ systemf("%s -x -f test1.tar -T filelist -C test1"
+ " > test1b.out 2> test1b.err", testprog);
+ assertEmptyFile("test1b.out");
+ assertEmptyFile("test1b.err");
+
+ /* Verify the files were extracted. */
+ assertFileExists("test1/f");
+ assertFileExists("test1/d1/f1");
+ assertFileNotExists("test1/d1/f2");
+ assertFileNotExists("test1/d1/d2/f3");
+ assertFileExists("test1/d1/d2/f4");
+ assertFileNotExists("test1/d1/d2/f5");
+ assertFileExists("test1/d1/d2/f6");
+ if (gnarlyFilesSupported) {
+ assertFileNotExists("test1/d1/d2/f\x0a");
+ }
+
+ /* Use -r -T to add more files to the archive. */
+ systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err",
+ testprog);
+ assertEmptyFile("test2.out");
+ assertEmptyFile("test2.err");
+
+ /* Use -x without -T to dearchive the files (ensure -r worked) */
+ if (!assertMakeDir("test3", 0755)) return;
+ systemf("%s -x -f test1.tar -C test3"
+ " > test3.out 2> test3.err", testprog);
+ assertEmptyFile("test3.out");
+ assertEmptyFile("test3.err");
+ /* Verify the files were extracted.*/
+ assertFileExists("test3/f");
+ assertFileExists("test3/d1/f1");
+ assertFileNotExists("test3/d1/f2");
+ assertFileExists("test3/d1/d2/f3");
+ assertFileExists("test3/d1/d2/f4");
+ assertFileExists("test3/d1/d2/f5");
+ assertFileExists("test3/d1/d2/f6");
+ if (gnarlyFilesSupported) {
+ assertFileExists("test3/d1/d2/f\x0a");
+ }
+
+ /* Use -x -T to dearchive the files (verify -x -T together) */
+ if (!assertMakeDir("test2", 0755)) return;
+ systemf("%s -x -f test1.tar -T filelist -C test2"
+ " > test2b.out 2> test2b.err", testprog);
+ assertEmptyFile("test2b.out");
+ assertEmptyFile("test2b.err");
+ /* Verify the files were extracted.*/
+ assertFileExists("test2/f");
+ assertFileExists("test2/d1/f1");
+ assertFileNotExists("test2/d1/f2");
+ assertFileNotExists("test2/d1/d2/f3");
+ assertFileExists("test2/d1/d2/f4");
+ assertFileNotExists("test2/d1/d2/f5");
+ assertFileExists("test2/d1/d2/f6");
+ if (gnarlyFilesSupported) {
+ assertFileNotExists("test2/d1/d2/f\x0a");
+ }
+
+ assertMakeDir("test4", 0755);
+ assertMakeDir("test4_out", 0755);
+ assertMakeDir("test4_out2", 0755);
+ assertMakeDir("test4/d1", 0755);
+ assertEqualInt(1, touch("test4/d1/foo", 0));
+
+ /* Does bsdtar support -s option ? */
+ systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err",
+ testprog);
+ assertEqualInt(0, stat("check.err", &st));
+ if (st.st_size == 0) {
+ systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out",
+ testprog, testprog);
+ assertEmptyFile("test4_out/test4/d1/bar");
+ systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out",
+ testprog, testprog);
+ assertEmptyFile("test4_out/test4/d2/foo");
+ systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst",
+ testprog, testprog);
+ assertEmptyFile("test4.lst");
+ systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2",
+ testprog, testprog);
+ assertEmptyFile("test4_out2/test4/d1/bar");
+ } else {
+ skipping("bsdtar does not support -s option on this platform");
+ }
+
+ /* TODO: Include some use of -C directory-changing within the filelist. */
+ /* I'm pretty sure -C within the filelist is broken on extract. */
+}
diff --git a/archivers/libarchive/files/tar/test/test_option_q.c b/archivers/libarchive/files/tar/test/test_option_q.c
new file mode 100644
index 00000000000..68867b52a82
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_option_q.c
@@ -0,0 +1,129 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:08 kientzle Exp $");
+
+DEFINE_TEST(test_option_q)
+{
+ FILE *f;
+ int r;
+
+ /*
+ * Create an archive with several different versions of the
+ * same files. By default, the last version will overwrite
+ * any earlier versions. The -q/--fast-read option will
+ * stop early, so we can verify -q/--fast-read by seeing
+ * which version of each file actually ended up being
+ * extracted. This also exercises -r mode, since that's
+ * what we use to build up the test archive.
+ */
+
+ f = fopen("foo", "w");
+ assert(f != NULL);
+ fprintf(f, "foo1");
+ fclose(f);
+
+ assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
+
+ f = fopen("foo", "w");
+ assert(f != NULL);
+ fprintf(f, "foo2");
+ fclose(f);
+
+ assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
+
+ f = fopen("bar", "w");
+ assert(f != NULL);
+ fprintf(f, "bar1");
+ fclose(f);
+
+ assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
+
+ f = fopen("foo", "w");
+ assert(f != NULL);
+ fprintf(f, "foo3");
+ fclose(f);
+
+ assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
+
+ f = fopen("bar", "w");
+ assert(f != NULL);
+ fprintf(f, "bar2");
+ fclose(f);
+
+ assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
+
+ /*
+ * Now, try extracting from the test archive with various
+ * combinations of -q.
+ */
+
+ /* Test 1: -q foo should only extract the first foo. */
+ assertMakeDir("test1", 0755);
+ assertChdir("test1");
+ r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err",
+ testprog);
+ failure("Fatal error trying to use -q option");
+ if (!assertEqualInt(0, r))
+ return;
+
+ assertFileContents("foo1", 4, "foo");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ assertChdir("..");
+
+ /* Test 2: -q foo bar should extract up to the first bar. */
+ assertMakeDir("test2", 0755);
+ assertChdir("test2");
+ assertEqualInt(0,
+ systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog));
+ assertFileContents("foo2", 4, "foo");
+ assertFileContents("bar1", 4, "bar");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ assertChdir("..");
+
+ /* Test 3: Same as test 2, but use --fast-read spelling. */
+ assertMakeDir("test3", 0755);
+ assertChdir("test3");
+ assertEqualInt(0,
+ systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog));
+ assertFileContents("foo2", 4, "foo");
+ assertFileContents("bar1", 4, "bar");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ assertChdir("..");
+
+ /* Test 4: Without -q, should extract everything. */
+ assertMakeDir("test4", 0755);
+ assertChdir("test4");
+ assertEqualInt(0,
+ systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog));
+ assertFileContents("foo3", 4, "foo");
+ assertFileContents("bar2", 4, "bar");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ assertChdir("..");
+}
diff --git a/archivers/libarchive/files/tar/test/test_option_r.c b/archivers/libarchive/files/tar/test/test_option_r.c
new file mode 100644
index 00000000000..516a8307936
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_option_r.c
@@ -0,0 +1,117 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD$");
+
+/*
+ * Also see test_option_q for additional validation of -r support.
+ */
+DEFINE_TEST(test_option_r)
+{
+ char buff[15];
+ char *p0, *p1;
+ size_t s;
+ FILE *f;
+ int r;
+
+ /* Create a file */
+ f = fopen("f1", "w");
+ if (!assert(f != NULL))
+ return;
+ assertEqualInt(3, fwrite("abc", 1, 3, f));
+ fclose(f);
+
+ /* Archive that one file. */
+ r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog);
+ failure("Error invoking %s cf archive.tar f1", testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify that nothing went to stdout or stderr. */
+ assertEmptyFile("step1.out");
+ assertEmptyFile("step1.err");
+
+
+ /* Do some basic validation of the constructed archive. */
+ p0 = slurpfile(&s, "archive.tar");
+ if (!assert(p0 != NULL))
+ return;
+ if (!assert(s >= 2048)) {
+ free(p0);
+ return;
+ }
+ assertEqualMem(p0 + 0, "f1", 3);
+ assertEqualMem(p0 + 512, "abc", 3);
+ assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
+ assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
+
+ /* Edit that file */
+ f = fopen("f1", "w");
+ if (!assert(f != NULL))
+ return;
+ assertEqualInt(3, fwrite("123", 1, 3, f));
+ fclose(f);
+
+ /* Update the archive. */
+ r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog);
+ failure("Error invoking %s rf archive.tar f1", testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify that nothing went to stdout or stderr. */
+ assertEmptyFile("step2.out");
+ assertEmptyFile("step2.err");
+
+ /* Do some basic validation of the constructed archive. */
+ p1 = slurpfile(&s, "archive.tar");
+ if (!assert(p1 != NULL)) {
+ free(p0);
+ return;
+ }
+ assert(s >= 3072);
+ /* Verify first entry is unchanged. */
+ assertEqualMem(p0, p1, 1024);
+ /* Verify that second entry is correct. */
+ assertEqualMem(p1 + 1024, "f1", 3);
+ assertEqualMem(p1 + 1536, "123", 3);
+ /* Verify end-of-archive marker. */
+ assertEqualMem(p1 + 2048, "\0\0\0\0\0\0\0\0", 8);
+ assertEqualMem(p1 + 2560, "\0\0\0\0\0\0\0\0", 8);
+ free(p0);
+ free(p1);
+
+ /* Unpack both items */
+ assertMakeDir("step3", 0775);
+ assertChdir("step3");
+ r = systemf("%s xf ../archive.tar", testprog);
+ failure("Error invoking %s xf archive.tar", testprog);
+ assertEqualInt(r, 0);
+
+ /* Verify that the second one overwrote the first. */
+ f = fopen("f1", "r");
+ if (assert(f != NULL)) {
+ assertEqualInt(3, fread(buff, 1, 3, f));
+ assertEqualMem(buff, "123", 3);
+ fclose(f);
+ }
+}
diff --git a/archivers/libarchive/files/tar/test/test_option_s.c b/archivers/libarchive/files/tar/test/test_option_s.c
new file mode 100644
index 00000000000..8eb415e1cea
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_option_s.c
@@ -0,0 +1,107 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
+
+static int
+mkfile(const char *fn, const char *contents)
+{
+ FILE *f = fopen(fn, "w");
+ failure("Couldn't create file '%s', errno=%d (%s)\n",
+ fn, errno, strerror(errno));
+ if (!assert(f != NULL))
+ return (1); /* Failure. */
+ if (contents != NULL)
+ assertEqualInt(strlen(contents),
+ fwrite(contents, 1, strlen(contents), f));
+ assertEqualInt(0, fclose(f));
+ return (0); /* Success */
+}
+
+DEFINE_TEST(test_option_s)
+{
+ struct stat st;
+
+ /* Create a sample file heirarchy. */
+ assertMakeDir("in", 0755);
+ assertMakeDir("in/d1", 0755);
+ assertEqualInt(0, mkfile("in/d1/foo", "foo"));
+ assertEqualInt(0, mkfile("in/d1/bar", "bar"));
+
+ /* Does bsdtar support -s option ? */
+ systemf("%s -cf - -s /foo/bar/ in/d1/foo > NUL 2> check.err",
+ testprog);
+ assertEqualInt(0, stat("check.err", &st));
+ if (st.st_size != 0) {
+ skipping("%s does not support -s option on this platform",
+ testprog);
+ return;
+ }
+
+ /*
+ * Test 1: Filename substitution when creating archives.
+ */
+ assertMakeDir("test1", 0755);
+ systemf("%s -cf - -s /foo/bar/ in/d1/foo | %s -xf - -C test1",
+ testprog, testprog);
+ assertFileContents("foo", 3, "test1/in/d1/bar");
+ systemf("%s -cf - -s /d1/d2/ in/d1/foo | %s -xf - -C test1",
+ testprog, testprog);
+ assertFileContents("foo", 3, "test1/in/d2/foo");
+
+
+ /*
+ * Test 2: Basic substitution when extracting archive.
+ */
+ assertMakeDir("test2", 0755);
+ systemf("%s -cf - in/d1/foo | %s -xf - -s /foo/bar/ -C test2",
+ testprog, testprog);
+ assertFileContents("foo", 3, "test2/in/d1/bar");
+
+ /*
+ * Test 3: Files with empty names shouldn't be archived.
+ */
+ systemf("%s -cf - -s ,in/d1/foo,, in/d1/foo | %s -tvf - > in.lst",
+ testprog, testprog);
+ assertEmptyFile("in.lst");
+
+ /*
+ * Test 4: Multiple substitutions when extracting archive.
+ */
+ assertMakeDir("test4", 0755);
+ systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}baz} -C test4",
+ testprog, testprog);
+ assertFileContents("foo", 3, "test4/in/d1/bar");
+ assertFileContents("bar", 3, "test4/in/d1/baz");
+
+ /*
+ * Test 5: Name-switching substitutions when extracting archive.
+ */
+ assertMakeDir("test5", 0755);
+ systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}foo} -C test5",
+ testprog, testprog);
+ assertFileContents("foo", 3, "test5/in/d1/bar");
+ assertFileContents("bar", 3, "test5/in/d1/foo");
+}
diff --git a/archivers/libarchive/files/tar/test/test_patterns.c b/archivers/libarchive/files/tar/test/test_patterns.c
index e7b1679fd9d..fee98be9b27 100644
--- a/archivers/libarchive/files/tar/test/test_patterns.c
+++ b/archivers/libarchive/files/tar/test/test_patterns.c
@@ -1,4 +1,5 @@
/*-
+ * Copyright (c) 2009 Michihiro NAKAJIMA
* Copyright (c) 2003-2007 Tim Kientzle
* All rights reserved.
*
@@ -23,25 +24,161 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_patterns.c,v 1.6 2008/08/21 22:28:00 kientzle Exp $");
DEFINE_TEST(test_patterns)
{
- int fd, r;
+ FILE *f;
+ int r;
+ const char *reffile2 = "test_patterns_2.tar";
+ const char *reffile3 = "test_patterns_3.tar";
+ const char *reffile4 = "test_patterns_4.tar";
+
+ const char *tar2aExpected[] = {
+ "/tmp/foo/bar/",
+ "/tmp/foo/bar/baz",
+ NULL
+ };
/*
* Test basic command-line pattern handling.
*/
/*
+ * Test 1: Files on the command line that don't get matched
+ * didn't produce an error.
+ *
* John Baldwin reported this problem in PR bin/121598
*/
- fd = open("foo", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- close(fd);
- r = systemf("%s zcfv tar1.tgz foo > tar1a.out 2> tar1a.err", testprog);
+ f = fopen("foo", "w");
+ assert(f != NULL);
+ fclose(f);
+ r = systemf("%s cfv tar1.tgz foo > tar1a.out 2> tar1a.err", testprog);
assertEqualInt(r, 0);
- r = systemf("%s zxfv tar1.tgz foo bar > tar1b.out 2> tar1b.err", testprog);
+ r = systemf("%s xv --no-same-owner -f tar1.tgz foo bar > tar1b.out 2> tar1b.err", testprog);
failure("tar should return non-zero because a file was given on the command line that's not in the archive");
assert(r != 0);
+
+ /*
+ * Test 2: Check basic matching of full paths that start with /
+ */
+ extract_reference_file(reffile2);
+
+ r = systemf("%s tf %s /tmp/foo/bar > tar2a.out 2> tar2a.err",
+ testprog, reffile2);
+ assertEqualInt(r, 0);
+ assertFileContainsLinesAnyOrder("tar2a.out", tar2aExpected);
+ assertEmptyFile("tar2a.err");
+
+ /*
+ * Test 3 archive has some entries starting with '/' and some not.
+ */
+ extract_reference_file(reffile3);
+
+ /* Test 3a: Pattern tmp/foo/bar should not match /tmp/foo/bar */
+ r = systemf("%s x --no-same-owner -f %s tmp/foo/bar > tar3a.out 2> tar3a.err",
+ testprog, reffile3);
+ assert(r != 0);
+ assertEmptyFile("tar3a.out");
+
+ /* Test 3b: Pattern /tmp/foo/baz should not match tmp/foo/baz */
+ assertNonEmptyFile("tar3a.err");
+ /* Again, with the '/' */
+ r = systemf("%s x --no-same-owner -f %s /tmp/foo/baz > tar3b.out 2> tar3b.err",
+ testprog, reffile3);
+ assert(r != 0);
+ assertEmptyFile("tar3b.out");
+ assertNonEmptyFile("tar3b.err");
+
+ /* Test 3c: ./tmp/foo/bar should not match /tmp/foo/bar */
+ r = systemf("%s x --no-same-owner -f %s ./tmp/foo/bar > tar3c.out 2> tar3c.err",
+ testprog, reffile3);
+ assert(r != 0);
+ assertEmptyFile("tar3c.out");
+ assertNonEmptyFile("tar3c.err");
+
+ /* Test 3d: ./tmp/foo/baz should match tmp/foo/baz */
+ r = systemf("%s x --no-same-owner -f %s ./tmp/foo/baz > tar3d.out 2> tar3d.err",
+ testprog, reffile3);
+ assertEqualInt(r, 0);
+ assertEmptyFile("tar3d.out");
+ assertEmptyFile("tar3d.err");
+ assertFileExists("tmp/foo/baz/bar");
+
+ /*
+ * Test 4 archive has some entries starting with windows drive letters
+ * such as 'c:\', '//./c:/' or '//?/c:/'.
+ */
+ extract_reference_file(reffile4);
+
+ r = systemf("%s x --no-same-owner -f %s -C tmp > tar4.out 2> tar4.err",
+ testprog, reffile4);
+ assert(r != 0);
+ assertEmptyFile("tar4.out");
+ assertNonEmptyFile("tar4.err");
+
+ for (r = 1; r <= 54; r++) {
+ char file_a[] = "tmp/fileXX";
+ char file_b1[] = "tmp/server/share/fileXX";
+ char file_b2[] = "tmp/server\\share\\fileXX";
+ char file_c[] = "tmp/../fileXX";
+ char *filex;
+ int xsize;
+
+ switch (r) {
+ case 15: case 18:
+ /*
+ * Including server and share names.
+ * //?/UNC/server/share/file15
+ * //?/unc/server/share/file18
+ */
+ filex = file_b1;
+ xsize = sizeof(file_b1);
+ break;
+ case 35: case 38: case 52:
+ /*
+ * Including server and share names.
+ * \\?\UNC\server\share\file35
+ * \\?\unc\server\share\file38
+ * \/?/uNc/server\share\file52
+ */
+ filex = file_b2;
+ xsize = sizeof(file_b2);
+ break;
+ default:
+ filex = file_a;
+ xsize = sizeof(file_a);
+ break;
+ }
+ filex[xsize-3] = '0' + r / 10;
+ filex[xsize-2] = '0' + r % 10;
+ switch (r) {
+ case 5: case 6: case 17: case 20: case 25:
+ case 26: case 37: case 40: case 43: case 54:
+ /*
+ * Not extracted patterns.
+ * D:../file05
+ * c:../../file06
+ * //?/UNC/../file17
+ * //?/unc/../file20
+ * z:..\file25
+ * c:..\..\file26
+ * \\?\UNC\..\file37
+ * \\?\unc\..\file40
+ * c:../..\file43
+ * \/?\UnC\../file54
+ */
+ assertFileNotExists(filex);
+ filex = file_c;
+ xsize = sizeof(file_c);
+ filex[xsize-3] = '0' + r / 10;
+ filex[xsize-2] = '0' + r % 10;
+ assertFileNotExists(filex);
+ break;
+ default:
+ /* Extracted patterns. */
+ assertFileExists(filex);
+ break;
+ }
+ }
}
diff --git a/archivers/libarchive/files/tar/test/test_patterns_2.tar.uu b/archivers/libarchive/files/tar/test/test_patterns_2.tar.uu
new file mode 100644
index 00000000000..eba2daece09
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_patterns_2.tar.uu
@@ -0,0 +1,231 @@
+begin 644 test_patterns_2.tar
+M+W1M<"]F;V\O````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#<U-2``,#`Q-S4P(``P,#`P,#`@`#`P,#`P,#`P,#`P
+M(#$Q,#4Q,C$R-C4V(#`Q,C0T,0`@-0``````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
+M````````````````````````````````````=VAE96P`````````````````
+M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````O=&UP+V9O;R]B87(O````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````,#`P-S4U(``P,#$W-3`@`#`P
+M,#`P,"``,#`P,#`P,#`P,#`@,3$P-3$R,3(V-3,@,#$S,C`R`"`U````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````'5S=&%R`#`P=&EM``````````````````````````````````````!W
+M:&5E;````````````````````````````````````#`P,#`P,"``,#`P,#`P
+M(```````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````"]T;7`O9F]O+V)A
+M>@``````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`V-#0@`#`P,3<U,"``,#`P,#`P(``P,#`P,#`P,#`P,"`Q,3`U,3(Q,C8U
+M-B`P,3,Q,C8`(#``````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#!T:6T`````````````````
+M`````````````````````'=H965L````````````````````````````````
+M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````+W1M<"]F;V\O8F%R+V)A>@``````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#8T-"``,#`Q-S4P(``P,#`P,#`@`#`P,#`P
+M,#`P,#`P(#$Q,#4Q,C$R-C4S(#`Q,S8V-P`@,```````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,'1I;0``````````````````````````````````````=VAE96P`````````
+M```````````````````````````P,#`P,#`@`#`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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+9````````````````````````````````````
+`
+end
diff --git a/archivers/libarchive/files/tar/test/test_patterns_3.tar.uu b/archivers/libarchive/files/tar/test/test_patterns_3.tar.uu
new file mode 100644
index 00000000000..de60b8dc8e1
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_patterns_3.tar.uu
@@ -0,0 +1,231 @@
+begin 644 test_patterns_3.tar
+M+W1M<"]F;V\O8F%R+P``````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#<U-2``,#`Q-S4P(``P,#`P,#`@`#`P,#`P,#`P,#`P
+M(#$Q,#4S,C`W-34R(#`Q,S(P-@`@-0``````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
+M````````````````````````````````````=VAE96P`````````````````
+M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````O=&UP+V9O;R]B87(O8F%Z+P``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````,#`P-S4U(``P,#$W-3`@`#`P
+M,#`P,"``,#`P,#`P,#`P,#`@,3$P-3,R,#<U-3(@,#$S-S8R`"`U````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````'5S=&%R`#`P=&EM``````````````````````````````````````!W
+M:&5E;````````````````````````````````````#`P,#`P,"``,#`P,#`P
+M(```````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````'1M<"]F;V\O8F%Z
+M+P``````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`W-34@`#`P,3<U,"``,#`P,#`P(``P,#`P,#`P,#`P,"`Q,3`U,S(P-S4V
+M,"`P,3,Q,S8`(#4`````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#!T:6T`````````````````
+M`````````````````````'=H965L````````````````````````````````
+M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````=&UP+V9O;R]B87HO8F%R+P``````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#<U-2``,#`Q-S4P(``P,#`P,#`@`#`P,#`P
+M,#`P,#`P(#$Q,#4S,C`W-38P(#`Q,S<P,@`@-0``````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,'1I;0``````````````````````````````````````=VAE96P`````````
+M```````````````````````````P,#`P,#`@`#`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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+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````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+9````````````````````````````````````
+`
+end
diff --git a/archivers/libarchive/files/tar/test/test_patterns_4.tar.uu b/archivers/libarchive/files/tar/test/test_patterns_4.tar.uu
new file mode 100644
index 00000000000..240af208934
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_patterns_4.tar.uu
@@ -0,0 +1,641 @@
+begin 644 test_patterns_4.tar
+M+V9I;&4P,0``````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P
+M(#$Q,34P-C<T-C0R(#`Q,#,S-@`@,```````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,```````
+M````````````````````````````````````````````````````````````
+M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````O+BXO9FEL93`R````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P
+M,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$P-34R`"`P````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````'5S=&%R`#`P````````````````````````````````````````````
+M`````````````````````````````````````````#`P,#`P,"``,#`P,#`P
+M(```````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````"\N+B\N+B]F:6QE
+M,#,`````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T
+M,B`P,3`W-C8`(#``````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#``````````````````````
+M````````````````````````````````````````````````````````````
+M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````8SHO9FEL93`T````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P
+M,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,#4W-@`@,```````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,```````````````````````````````````````````````````````````
+M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````!$.BXN+V9I;&4P-0``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````,#`P-C0T(``P,#$W
+M-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$P-C<T`"`P
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````'5S=&%R`#`P````````````````````````````````````
+M`````````````````````````````````````````````````#`P,#`P,"``
+M,#`P,#`P(```````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````&,Z+BXO
+M+BXO9FEL93`V````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U
+M,#8W-#8T,B`P,3$Q-#<`(#``````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````=7-T87(`,#``````````````
+M````````````````````````````````````````````````````````````
+M````````````,#`P,#`P(``P,#`P,#`@````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````0SHO+BXO9FEL93`W````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@
+M`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,#<U-``@,```````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````````````!U
+M<W1A<@`P,```````````````````````````````````````````````````
+M```````````````````````````````````P,#`P,#`@`#`P,#`P,"``````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````!A.B\N+B\N+B]F:6QE,#@`
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````,#`P-C0T
+M(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q
+M,C(V`"`P````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````'5S=&%R`#`P````````````````````````````
+M`````````````````````````````````````````````````````````#`P
+M,#`P,"``,#`P,#`P(```````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`"\O+B]C.B]F:6QE,#D`````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P
+M,"`Q,3$U,#8W-#8T,B`P,3$P-S8`(#``````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````=7-T87(`,#``````
+M````````````````````````````````````````````````````````````
+M````````````````````,#`P,#`P(``P,#`P,#`@````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````+R\N+T,Z+RXN+V9I;&4Q,```````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P
+M,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,3(T,0`@,```````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````!U<W1A<@`P,```````````````````````````````````````````
+M```````````````````````````````````````````P,#`P,#`@`#`P,#`P
+M,"``````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````````O+S\O8SHO9FEL
+M93$Q````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V
+M-#(@,#$Q,3$P`"`P````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````'5S=&%R`#`P````````````````````
+M````````````````````````````````````````````````````````````
+M`````#`P,#`P,"``,#`P,#`P(```````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````"\O/R]#.B\N+B]F:6QE,3(`````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P
+M,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$R-C0`(#``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````=7-T87(`
+M,#``````````````````````````````````````````````````````````
+M````````````````````````````,#`P,#`P(``P,#`P,#`@````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````+R\O+V,Z+V9I;&4Q,P``````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````#`P,#8T-"``,#`Q
+M-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,3`W,@`@
+M,```````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````!U<W1A<@`P,```````````````````````````````````
+M```````````````````````````````````````````````````P,#`P,#`@
+M`#`P,#`P,"``````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````O+R\O
+M0SHO+R\O+V9I;&4Q-```````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q
+M-3`V-S0V-#(@,#$Q,S(W`"`P````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````'5S=&%R`#`P````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#`P,"``,#`P,#`P(```````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````"\O/R]53D,O<V5R=F5R+W-H87)E+V9I;&4Q-0``````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q
+M(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3,V,S4`(#``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M=7-T87(`,#``````````````````````````````````````````````````
+M````````````````````````````````````,#`P,#`P(``P,#`P,#`@````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````+R\_+U5.0R]F:6QE,38`
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````#`P,#8T
+M-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q
+M,3(R-@`@,```````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````!U<W1A<@`P,```````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`P,#`@`#`P,#`P,"``````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```O+S\O54Y#+RXN+V9I;&4Q-P``````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P
+M,#`@,3$Q-3`V-S0V-#(@,#$Q-#0R`"`P````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````'5S=&%R`#`P````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#`P,"``,#`P,#`P(```````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````"\O/R]U;F,O<V5R=F5R+W-H87)E+V9I;&4Q
+M.```````````````````````````````````````````````````````````
+M```````````````````````````````````````P,#`V-#0@`#`P,3<U,2``
+M,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,30P,#``(#``````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````=7-T87(`,#``````````````````````````````````````````
+M````````````````````````````````````````````,#`P,#`P(``P,#`P
+M,#`@````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````+R\_+W5N8R]F
+M:6QE,3D`````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T
+M-C0R(#`Q,3,W,0`@,```````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````!U<W1A<@`P,```````````````````
+M````````````````````````````````````````````````````````````
+M```````P,#`P,#`@`#`P,#`P,"``````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````O+S\O=6YC+RXN+V9I;&4R,```````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P
+M,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q-3<T`"`P````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````'5S=&%R
+M`#`P````````````````````````````````````````````````````````
+M`````````````````````````````#`P,#`P,"``,#`P,#`P(```````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````%QF:6QE,C$`````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````````P,#`V-#0@`#`P
+M,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3`T,34`
+M(#``````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````=7-T87(`,#``````````````````````````````````
+M````````````````````````````````````````````````````,#`P,#`P
+M(``P,#`P,#`@````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````7"XN
+M7&9I;&4R,@``````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q
+M,34P-C<T-C0R(#`Q,#<P-@`@,```````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````!U<W1A<@`P,```````````
+M````````````````````````````````````````````````````````````
+M```````````````P,#`P,#`@`#`P,#`P,"``````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````!<+BY<+BY<9FEL93(S````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U
+M,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,3<W`"`P````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`'5S=&%R`#`P````````````````````````````````````````````````
+M`````````````````````````````````````#`P,#`P,"``,#`P,#`P(```
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````$,Z7&9I;&4R-```````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````P,#`V
+M-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P
+M,3`V,34`(#``````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````=7-T87(`,#``````````````````````````
+M````````````````````````````````````````````````````````````
+M,#`P,#`P(``P,#`P,#`@````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````>CHN+EQF:6QE,C4`````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P
+M,#`P(#$Q,34P-C<T-C0R(#`Q,3`T,0`@,```````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````!U<W1A<@`P,```
+M````````````````````````````````````````````````````````````
+M```````````````````````P,#`P,#`@`#`P,#`P,"``````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````!C.BXN7"XN7&9I;&4R-@``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````,#`P-C0T(``P,#$W-3$@
+M`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,S`S`"`P````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````'5S=&%R`#`P````````````````````````````````````````
+M`````````````````````````````````````````````#`P,#`P,"``,#`P
+M,#`P(```````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````%HZ7"XN7&9I
+M;&4R-P``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W
+M-#8T,B`P,3$Q,S<`(#``````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````=7-T87(`,#``````````````````
+M````````````````````````````````````````````````````````````
+M````````,#`P,#`P(``P,#`P,#`@````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````0SI<+BY<+BY<9FEL93(X````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P
+M,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,30P,0`@,```````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````````!U<W1A
+M<@`P,```````````````````````````````````````````````````````
+M```````````````````````````````P,#`P,#`@`#`P,#`P,"``````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````!<7"Y<8SI<9FEL93(Y````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````,#`P-C0T(``P
+M,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,S8T
+M`"`P````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````'5S=&%R`#`P````````````````````````````````
+M`````````````````````````````````````````````````````#`P,#`P
+M,"``,#`P,#`P(```````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````````%Q<
+M+EQ#.EPN+EQF:6QE,S``````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q
+M,3$U,#8W-#8T,B`P,3$V,#0`(#``````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````=7-T87(`,#``````````
+M````````````````````````````````````````````````````````````
+M````````````````,#`P,#`P(``P,#`P,#`@````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````7%P_7&,Z7&9I;&4S,0``````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W
+M-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,3,W-@`@,```````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``!U<W1A<@`P,```````````````````````````````````````````````
+M```````````````````````````````````````P,#`P,#`@`#`P,#`P,"``
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!<7#]<1#I<+BY<9FEL
+M93,R````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````,#`P
+M-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@
+M,#$Q-C,P`"`P````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````'5S=&%R`#`P````````````````````````
+M````````````````````````````````````````````````````````````
+M`#`P,#`P,"``,#`P,#`P(```````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````%Q<7%QC.EQF:6QE,S,`````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P
+M,#`P,"`Q,3$U,#8W-#8T,B`P,3$T,S4`(#``````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````=7-T87(`,#``
+M````````````````````````````````````````````````````````````
+M````````````````````````,#`P,#`P(``P,#`P,#`@````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````7%Q<7$,Z7%Q<7%QF:6QE,S0`````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````#`P,#8T-"``,#`Q-S4Q
+M(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,C$U-@`@,```
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````!U<W1A<@`P,```````````````````````````````````````
+M```````````````````````````````````````````````P,#`P,#`@`#`P
+M,#`P,"``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!<7#]<54Y#
+M7'-E<G9E<EQS:&%R95QF:6QE,S4`````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V
+M-S0V-#(@,#$T,C4U`"`P````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````'5S=&%R`#`P````````````````
+M````````````````````````````````````````````````````````````
+M`````````#`P,#`P,"``,#`P,#`P(```````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````%Q</UQ53D-<9FEL93,V````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P
+M,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$U,30`(#``````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````=7-T
+M87(`,#``````````````````````````````````````````````````````
+M````````````````````````````````,#`P,#`P(``P,#`P,#`@````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````7%P_7%5.0UPN+EQF:6QE,S<`
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````#`P,#8T-"``
+M,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,C`P
+M-0`@,```````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````!U<W1A<@`P,```````````````````````````````
+M```````````````````````````````````````````````````````P,#`P
+M,#`@`#`P,#`P,"``````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````````````!<
+M7#]<=6YC7'-E<G9E<EQS:&%R95QF:6QE,S@`````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@
+M,3$Q-3`V-S0V-#(@,#$T-#(P`"`P````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````'5S=&%R`#`P````````
+M````````````````````````````````````````````````````````````
+M`````````````````#`P,#`P,"``,#`P,#`P(```````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````%Q</UQU;F-<9FEL93,Y````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q
+M-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$V-3<`(#``````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````=7-T87(`,#``````````````````````````````````````````````
+M````````````````````````````````````````,#`P,#`P(``P,#`P,#`@
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````7%P_7'5N8UPN+EQF
+M:6QE-#``````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````````#`P
+M,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R
+M(#`Q,C$S-P`@,```````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````!U<W1A<@`P,```````````````````````
+M````````````````````````````````````````````````````````````
+M```P,#`P,#`@`#`P,#`P,"``````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````!<+BXO9FEL930Q````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P
+M,#`P,#`@,3$Q-3`V-S0V-#(@,#$P-C,R`"`P````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````'5S=&%R`#`P
+M````````````````````````````````````````````````````````````
+M`````````````````````````#`P,#`P,"``,#`P,#`P(```````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````%PN+B\N+EQF:6QE-#(`````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````P,#`V-#0@`#`P,3<U
+M,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$Q,C,`(#``
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````=7-T87(`,#``````````````````````````````````````
+M````````````````````````````````````````````````,#`P,#`P(``P
+M,#`P,#`@````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````8SHN+B\N
+M+EQF:6QE-#,`````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P
+M-C<T-C0R(#`Q,3(R-0`@,```````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````!U<W1A<@`P,```````````````
+M````````````````````````````````````````````````````````````
+M```````````P,#`P,#`@`#`P,#`P,"``````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````!#.B\N+EQF:6QE-#0`````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``
+M,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,#,R`"`P````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````````'5S
+M=&%R`#`P````````````````````````````````````````````````````
+M`````````````````````````````````#`P,#`P,"``,#`P,#`P(```````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````$0Z7"XN+RXN7&9I;&4T-0``
+M````````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````P,#`V-#0@
+M`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$S
+M,C0`(#``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````=7-T87(`,#``````````````````````````````
+M````````````````````````````````````````````````````````,#`P
+M,#`P(``P,#`P,#`@````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M7"\N+V,Z7&9I;&4T-@``````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P
+M(#$Q,34P-C<T-C0R(#`Q,3(S,0`@,```````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,```````
+M````````````````````````````````````````````````````````````
+M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````!<7"XO0SI<+BY<9FEL930W````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P
+M,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q-3,W`"`P````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````'5S=&%R`#`P````````````````````````````````````````````
+M`````````````````````````````````````````#`P,#`P,"``,#`P,#`P
+M(```````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````%PO/UQC.B]F:6QE
+M-#@`````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T
+M,B`P,3$R-30`(#``````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#``````````````````````
+M````````````````````````````````````````````````````````````
+M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````7%P_+T0Z+RXN7&9I;&4T.0``````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P
+M,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,34P-@`@,```````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,```````````````````````````````````````````````````````````
+M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````!<+R]<1#I<9FEL934P````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````,#`P-C0T(``P,#$W
+M-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,C0S`"`P
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````'5S=&%R`#`P````````````````````````````````````
+M`````````````````````````````````````````````````#`P,#`P,"``
+M,#`P,#`P(```````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````%Q<+R]C
+M.EPO+UQ<9FEL934Q````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U
+M,#8W-#8T,B`P,3$W,S$`(#``````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````=7-T87(`,#``````````````
+M````````````````````````````````````````````````````````````
+M````````````,#`P,#`P(``P,#`P,#`@````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````7"\_+W5.8R]S97)V97)<<VAA<F5<9FEL934R````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@
+M`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q-#$T-0`@,```````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````````````!U
+M<W1A<@`P,```````````````````````````````````````````````````
+M```````````````````````````````````P,#`P,#`@`#`P,#`P,"``````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````!<7#\O54YC7&9I;&4U,P``
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````,#`P-C0T
+M(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q
+M-#<V`"`P````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````'5S=&%R`#`P````````````````````````````
+M`````````````````````````````````````````````````````````#`P
+M,#`P,"``,#`P,#`P(```````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`%PO/UQ5;D-<+BXO9FEL934T````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P
+M,"`Q,3$U,#8W-#8T,B`P,3$W,3(`(#``````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````=7-T87(`,#``````
+M````````````````````````````````````````````````````````````
+M````````````````````,#`P,#`P(``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````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+'````````````
+`
+end
diff --git a/archivers/libarchive/files/tar/test/test_stdio.c b/archivers/libarchive/files/tar/test/test_stdio.c
index d770cf11f40..b95a4e30542 100644
--- a/archivers/libarchive/files/tar/test/test_stdio.c
+++ b/archivers/libarchive/files/tar/test/test_stdio.c
@@ -27,27 +27,27 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_stdio.c,v 1.2 2008/05/26 17:10:10
DEFINE_TEST(test_stdio)
{
- int fd;
- int filelist;
- int oldumask;
+ FILE *filelist;
+ char *p;
+ size_t s;
int r;
- oldumask = umask(0);
+ assertUmask(0);
/*
* Create a couple of files on disk.
*/
- filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
/* File */
- fd = open("f", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- write(fd, "f\n", 2);
- close(fd);
- write(filelist, "f\n", 2);
+ assertMakeFile("f", 0755, "abc");
/* Link to above file. */
- assertEqualInt(0, link("f", "l"));
- write(filelist, "l\n", 2);
- close(filelist);
+ assertMakeHardlink("l", "f");
+
+ /* Create file list (text mode here) */
+ filelist = fopen("filelist", "w");
+ assert(filelist != NULL);
+ fprintf(filelist, "f\n");
+ fprintf(filelist, "l\n");
+ fclose(filelist);
/*
* Archive/dearchive with a variety of options, verifying
@@ -111,7 +111,10 @@ DEFINE_TEST(test_stdio)
/* 'xvOf' should generate list on stderr, file contents on stdout. */
r = systemf("%s xvOf archive >xvOf.out 2>xvOf.err", testprog);
assertEqualInt(r, 0);
- /* TODO: Verify xvOf.out */
+ /* Verify xvOf.out is the file contents */
+ p = slurpfile(&s, "xvOf.out");
+ assert(s = 3);
+ assertEqualMem(p, "abc", 3);
/* TODO: Verify xvf.err */
/* 'xvf -' should generate list on stderr, empty stdout. */
@@ -119,6 +122,4 @@ DEFINE_TEST(test_stdio)
assertEqualInt(r, 0);
assertEmptyFile("xvf-.out");
/* TODO: Verify xvf-.err */
-
- umask(oldumask);
}
diff --git a/archivers/libarchive/files/tar/test/test_strip_components.c b/archivers/libarchive/files/tar/test/test_strip_components.c
new file mode 100644
index 00000000000..c9028a4d766
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_strip_components.c
@@ -0,0 +1,109 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/10 05:24:13 kientzle Exp $");
+
+static int
+touch(const char *fn)
+{
+ FILE *f = fopen(fn, "w");
+ failure("Couldn't create file '%s', errno=%d (%s)\n",
+ fn, errno, strerror(errno));
+ if (!assert(f != NULL))
+ return (0); /* Failure. */
+ fclose(f);
+ return (1); /* Success */
+}
+
+DEFINE_TEST(test_strip_components)
+{
+ assertMakeDir("d0", 0755);
+ assertChdir("d0");
+ assertMakeDir("d1", 0755);
+ assertMakeDir("d1/d2", 0755);
+ assertMakeDir("d1/d2/d3", 0755);
+ assertEqualInt(1, touch("d1/d2/f1"));
+ assertMakeHardlink("l1", "d1/d2/f1");
+ assertMakeHardlink("d1/l2", "d1/d2/f1");
+ if (canSymlink()) {
+ assertMakeSymlink("s1", "d1/d2/f1");
+ assertMakeSymlink("d1/s2", "d2/f1");
+ }
+ assertChdir("..");
+
+ assertEqualInt(0, systemf("%s -cf test.tar d0", testprog));
+
+ assertMakeDir("target", 0755);
+ assertEqualInt(0, systemf("%s -x -C target --strip-components 2 "
+ "-f test.tar", testprog));
+
+ failure("d0/ is too short and should not get restored");
+ assertFileNotExists("target/d0");
+ failure("d0/d1/ is too short and should not get restored");
+ assertFileNotExists("target/d1");
+ failure("d0/d1/s2 is a symlink to something that won't be extracted");
+ /* If platform supports symlinks, target/s2 is a broken symlink. */
+ /* If platform does not support symlink, target/s2 doesn't exist. */
+ assertFileNotExists("target/s2");
+ if (canSymlink())
+ assertIsSymlink("target/s2", "d2/f1");
+ failure("d0/d1/d2 should be extracted");
+ assertIsDir("target/d2", -1);
+
+ /*
+ * This next is a complicated case. d0/l1, d0/d1/l2, and
+ * d0/d1/d2/f1 are all hardlinks to the same file; d0/l1 can't
+ * be extracted with --strip-components=2 and the other two
+ * can. Remember that tar normally stores the first file with
+ * a body and the other as hardlink entries to the first
+ * appearance. So the final result depends on the order in
+ * which these three names get archived. If d0/l1 is first,
+ * none of the three can be restored. If either of the longer
+ * names are first, then the two longer ones can both be
+ * restored.
+ *
+ * The tree-walking code used by bsdtar always visits files
+ * before subdirectories, so bsdtar's behavior is fortunately
+ * deterministic: d0/l1 will always get stored first and the
+ * other two will be stored as hardlinks to d0/l1. Since
+ * d0/l1 can't be extracted, none of these three will be
+ * extracted.
+ *
+ * It may be worth extending this test to force a particular
+ * archiving order so as to exercise both of the cases described
+ * above.
+ *
+ * Of course, this is all totally different for cpio and newc
+ * formats because the hardlink management is different.
+ * TODO: Rename this to test_strip_components_tar and create
+ * parallel tests for cpio and newc formats.
+ */
+ failure("d0/l1 is too short and should not get restored");
+ assertFileNotExists("target/l1");
+ failure("d0/d1/l2 is a hardlink to file whose name was too short");
+ assertFileNotExists("target/l2");
+ failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
+ assertFileNotExists("target/d2/f1");
+}
diff --git a/archivers/libarchive/files/tar/test/test_symlink_dir.c b/archivers/libarchive/files/tar/test/test_symlink_dir.c
new file mode 100644
index 00000000000..aa80ba68e31
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_symlink_dir.c
@@ -0,0 +1,160 @@
+/*-
+ * 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"
+__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_symlink_dir.c,v 1.1 2008/09/14 02:16:04 kientzle Exp $");
+
+/*
+ * tar -x -P should follow existing symlinks for dirs, but not other
+ * content. Plain tar -x should remove symlinks when they're in the
+ * way of a dir extraction.
+ */
+
+static int
+mkfile(const char *name, int mode, const char *contents, size_t size)
+{
+ FILE *f = fopen(name, "wb");
+ size_t written;
+
+ (void)mode; /* UNUSED */
+ if (f == NULL)
+ return (-1);
+ written = fwrite(contents, 1, size, f);
+ fclose(f);
+ if (size != written)
+ return (-1);
+ return (0);
+}
+
+DEFINE_TEST(test_symlink_dir)
+{
+ assertUmask(0);
+
+ assertMakeDir("source", 0755);
+ assertEqualInt(0, mkfile("source/file", 0755, "a", 1));
+ assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2));
+ assertMakeDir("source/dir", 0755);
+ assertMakeDir("source/dir/d", 0755);
+ assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3));
+ assertMakeDir("source/dir2", 0755);
+ assertMakeDir("source/dir2/d2", 0755);
+ assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4));
+ assertMakeDir("source/dir3", 0755);
+ assertMakeDir("source/dir3/d3", 0755);
+ assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5));
+
+ assertEqualInt(0,
+ systemf("%s -cf test.tar -C source dir dir2 dir3 file file2",
+ testprog));
+
+ /*
+ * Extract with -x and without -P.
+ */
+ assertMakeDir("dest1", 0755);
+ /* "dir" is a symlink to an existing "dest1/real_dir" */
+ assertMakeDir("dest1/real_dir", 0755);
+ if (canSymlink()) {
+ assertMakeSymlink("dest1/dir", "real_dir");
+ /* "dir2" is a symlink to a non-existing "real_dir2" */
+ assertMakeSymlink("dest1/dir2", "real_dir2");
+ } else {
+ skipping("some symlink checks");
+ }
+ /* "dir3" is a symlink to an existing "non_dir3" */
+ assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6));
+ if (canSymlink())
+ assertMakeSymlink("dest1/dir3", "non_dir3");
+ /* "file" is a symlink to existing "real_file" */
+ assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7));
+ if (canSymlink()) {
+ assertMakeSymlink("dest1/file", "real_file");
+ /* "file2" is a symlink to non-existing "real_file2" */
+ assertMakeSymlink("dest1/file2", "real_file2");
+ }
+ assertEqualInt(0, systemf("%s -xf test.tar -C dest1", testprog));
+
+ /* dest1/dir symlink should be replaced */
+ failure("symlink to dir was followed when it shouldn't be");
+ assertIsDir("dest1/dir", -1);
+ /* dest1/dir2 symlink should be replaced */
+ failure("Broken symlink wasn't replaced with dir");
+ assertIsDir("dest1/dir2", -1);
+ /* dest1/dir3 symlink should be replaced */
+ failure("Symlink to non-dir wasn't replaced with dir");
+ assertIsDir("dest1/dir3", -1);
+ /* dest1/file symlink should be replaced */
+ failure("Symlink to existing file should be replaced");
+ assertIsReg("dest1/file", -1);
+ /* dest1/file2 symlink should be replaced */
+ failure("Symlink to non-existing file should be replaced");
+ assertIsReg("dest1/file2", -1);
+
+ /*
+ * Extract with both -x and -P
+ */
+ assertMakeDir("dest2", 0755);
+ /* "dir" is a symlink to existing "real_dir" */
+ assertMakeDir("dest2/real_dir", 0755);
+ if (canSymlink())
+ assertMakeSymlink("dest2/dir", "real_dir");
+ /* "dir2" is a symlink to a non-existing "real_dir2" */
+ if (canSymlink())
+ assertMakeSymlink("dest2/dir2", "real_dir2");
+ /* "dir3" is a symlink to an existing "non_dir3" */
+ assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8));
+ if (canSymlink())
+ assertMakeSymlink("dest2/dir3", "non_dir3");
+ /* "file" is a symlink to existing "real_file" */
+ assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9));
+ if (canSymlink())
+ assertMakeSymlink("dest2/file", "real_file");
+ /* "file2" is a symlink to non-existing "real_file2" */
+ if (canSymlink())
+ assertMakeSymlink("dest2/file2", "real_file2");
+ assertEqualInt(0, systemf("%s -xPf test.tar -C dest2", testprog));
+
+ /* dest2/dir symlink should be followed */
+ if (canSymlink()) {
+ assertIsSymlink("dest2/dir", "real_dir");
+ assertIsDir("dest2/real_dir", -1);
+ }
+
+ /* Contents of 'dir' should be restored */
+ assertIsDir("dest2/dir/d", -1);
+ assertIsReg("dest2/dir/f", -1);
+ assertFileSize("dest2/dir/f", 3);
+ /* dest2/dir2 symlink should be removed */
+ failure("Broken symlink wasn't replaced with dir");
+ assertIsDir("dest2/dir2", -1);
+ /* dest2/dir3 symlink should be removed */
+ failure("Symlink to non-dir wasn't replaced with dir");
+ assertIsDir("dest2/dir3", -1);
+ /* dest2/file symlink should be removed;
+ * even -P shouldn't follow symlinks for files */
+ failure("Symlink to existing file should be removed");
+ assertIsReg("dest2/file", -1);
+ /* dest2/file2 symlink should be removed */
+ failure("Symlink to non-existing file should be removed");
+ assertIsReg("dest2/file2", -1);
+}
diff --git a/archivers/libarchive/files/tar/test/test_version.c b/archivers/libarchive/files/tar/test/test_version.c
index 6ed656d8024..42472d1bc26 100644
--- a/archivers/libarchive/files/tar/test/test_version.c
+++ b/archivers/libarchive/files/tar/test/test_version.c
@@ -51,8 +51,9 @@ DEFINE_TEST(test_version)
q = p = slurpfile(&s, "version.stdout");
/* Version message should start with name of program, then space. */
assert(s > 6);
- failure("Version: %s", p);
- assertEqualMem(q, "bsdtar ", 7);
+ failure("Version must start with 'bsdtar': ``%s''", p);
+ if (!assertEqualMem(q, "bsdtar ", 7))
+ return;
q += 7; s -= 7;
/* Version number is a series of digits and periods. */
while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
@@ -60,22 +61,22 @@ DEFINE_TEST(test_version)
--s;
}
/* Version number terminated by space. */
- failure("Version: %s", p);
+ failure("No space after bsdtar version: ``%s''", p);
assert(s > 1);
/* Skip a single trailing a,b,c, or d. */
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
++q;
- failure("Version: %s", p);
+ failure("No space after bsdtar version: ``%s''", p);
assert(*q == ' ');
++q; --s;
/* Separator. */
- failure("Version: %s", p);
+ failure("No `-' between bsdtar and libarchive versions: ``%s''", p);
assertEqualMem(q, "- ", 2);
q += 2; s -= 2;
/* libarchive name and version number */
- failure("Version: %s", p);
+ failure("Not long enough for libarchive version: ``%s''", p);
assert(s > 11);
- failure("Version: %s", p);
+ failure("Libarchive version must start with `libarchive': ``%s''", p);
assertEqualMem(q, "libarchive ", 11);
q += 11; s -= 11;
/* Version number is a series of digits and periods. */
@@ -86,8 +87,11 @@ DEFINE_TEST(test_version)
/* Skip a single trailing a,b,c, or d. */
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
++q;
- /* All terminated by a newline. */
+ /* All terminated by end-of-line. */
assert(s >= 1);
+ /* Skip an optional CR character (e.g., Windows) */
+ failure("Version output must end with \\n or \\r\\n");
+ if (*q == '\r') { ++q; --s; }
assertEqualMem(q, "\n", 1);
free(p);
}
diff --git a/archivers/libarchive/files/tar/test/test_windows.c b/archivers/libarchive/files/tar/test/test_windows.c
new file mode 100644
index 00000000000..a2d0c214b95
--- /dev/null
+++ b/archivers/libarchive/files/tar/test/test_windows.c
@@ -0,0 +1,323 @@
+/*-
+ * Copyright (c) 2009 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"
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+
+static void
+mkfile(const char *name)
+{
+ FILE *f;
+
+ f = fopen(name, "wb");
+ assert(f != NULL);
+ assertEqualInt(5, fwrite("01234", 1, 5, f));
+ fclose(f);
+}
+
+static void
+mkfullpath(char **path1, char **path2, const char *tpath, int type)
+{
+ char *fp1 = NULL, *fp2 = NULL, *p1 = NULL, *p2 = NULL;
+ size_t l;
+
+ /*
+ * Get full path name of "tpath"
+ */
+ l = GetFullPathNameA(tpath, 0, NULL, NULL);
+ assert(0 != l);
+ fp1 = malloc(l);
+ assert(NULL != fp1);
+ fp2 = malloc(l*2);
+ assert(NULL != fp2);
+ l = GetFullPathNameA(tpath, l, fp1, NULL);
+ if ((type & 0x01) == 0) {
+ for (p1 = fp1; *p1 != '\0'; p1++)
+ if (*p1 == '\\')
+ *p1 = '/';
+ }
+
+ switch(type) {
+ case 0: /* start with "/" */
+ case 1: /* start with "\" */
+ /* strip "c:" */
+ memmove(fp1, fp1 + 2, l - 2);
+ fp1[l -2] = '\0';
+ p1 = fp1 + 1;
+ break;
+ case 2: /* start with "c:/" */
+ case 3: /* start with "c:\" */
+ p1 = fp1 + 3;
+ break;
+ case 4: /* start with "//./c:/" */
+ case 5: /* start with "\\.\c:\" */
+ case 6: /* start with "//?/c:/" */
+ case 7: /* start with "\\?\c:\" */
+ p1 = malloc(l + 4 + 1);
+ assert(NULL != p1);
+ if (type & 0x1)
+ memcpy(p1, "\\\\.\\", 4);
+ else
+ memcpy(p1, "//./", 4);
+ if (type == 6 || type == 7)
+ p1[2] = '?';
+ memcpy(p1 + 4, fp1, l);
+ p1[l + 4] = '\0';
+ free(fp1);
+ fp1 = p1;
+ p1 = fp1 + 7;
+ break;
+ }
+
+ /*
+ * Strip leading drive names and converting "\" to "\\"
+ */
+ p2 = fp2;
+ while (*p1 != '\0') {
+ if (*p1 == '\\')
+ *p2 = '/';
+ else
+ *p2 = *p1;
+ ++p1;
+ ++p2;
+ }
+ *p2++ = '\r';
+ *p2++ = '\n';
+ *p2 = '\0';
+
+ *path1 = fp1;
+ *path2 = fp2;
+}
+
+static const char *list1[] = {"aaa/", "aaa/file1", "aaa/xxa/", "aaa/xxb/",
+ "aaa/zzc/", "aaa/zzc/file1", "aaa/xxb/file1", "aaa/xxa/file1",
+ "aab/", "aac/", "abb/", "abc/", "abd/", NULL};
+static const char *list2[] = {"bbb/", "bbb/file1", "bbb/xxa/", "bbb/xxb/",
+ "bbb/zzc/", "bbb/zzc/file1", "bbb/xxb/file1", "bbb/xxa/file1", "bbc/",
+ "bbd/", "bcc/", "bcd/", "bce/", NULL};
+static const char *list3[] = {"aac/", "abc/", "bbc/", "bcc/", "ccc/", NULL};
+static const char *list4[] = {"fff/abca", "fff/acca", NULL};
+static const char *list5[] = {"aaa/file1", "aaa/xxa/", "aaa/xxa/file1",
+ "aaa/xxb/", "aaa/xxb/file1", "aaa/zzc/", "aaa/zzc/file1", NULL};
+static const char *list6[] = {"fff/abca", "fff/acca", "aaa/xxa/",
+ "aaa/xxa/file1", "aaa/xxb/", "aaa/xxb/file1", NULL};
+#endif /* _WIN32 && !__CYGWIN__ */
+
+DEFINE_TEST(test_windows)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char *fp1, *fp2;
+
+ /*
+ * Preparre tests.
+ * Create directories and files.
+ */
+ assertMakeDir("tmp", 0775);
+ assertChdir("tmp");
+
+ assertMakeDir("aaa", 0775);
+ assertMakeDir("aaa/xxa", 0775);
+ assertMakeDir("aaa/xxb", 0775);
+ assertMakeDir("aaa/zzc", 0775);
+ mkfile("aaa/file1");
+ mkfile("aaa/xxa/file1");
+ mkfile("aaa/xxb/file1");
+ mkfile("aaa/zzc/file1");
+ assertMakeDir("aab", 0775);
+ assertMakeDir("aac", 0775);
+ assertMakeDir("abb", 0775);
+ assertMakeDir("abc", 0775);
+ assertMakeDir("abd", 0775);
+ assertMakeDir("bbb", 0775);
+ assertMakeDir("bbb/xxa", 0775);
+ assertMakeDir("bbb/xxb", 0775);
+ assertMakeDir("bbb/zzc", 0775);
+ mkfile("bbb/file1");
+ mkfile("bbb/xxa/file1");
+ mkfile("bbb/xxb/file1");
+ mkfile("bbb/zzc/file1");
+ assertMakeDir("bbc", 0775);
+ assertMakeDir("bbd", 0775);
+ assertMakeDir("bcc", 0775);
+ assertMakeDir("bcd", 0775);
+ assertEqualInt(0, _mkdir("bce"));
+ assertEqualInt(0, _mkdir("ccc"));
+ assertEqualInt(0, _mkdir("fff"));
+ mkfile("fff/aaaa");
+ mkfile("fff/abba");
+ mkfile("fff/abca");
+ mkfile("fff/acba");
+ mkfile("fff/acca");
+
+ /*
+ * Test1: Command line pattern matching.
+ */
+ assertEqualInt(0,
+ systemf("%s -cf ../archive1.tar a*", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive1.tar > ../list1", testprog));
+ assertFileContainsLinesAnyOrder("../list1", list1);
+
+ assertEqualInt(0,
+ systemf("%s -cf ../archive2.tar b*", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive2.tar > ../list2", testprog));
+ assertFileContainsLinesAnyOrder("../list2", list2);
+
+ assertEqualInt(0,
+ systemf("%s -cf ../archive3.tar ??c", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive3.tar > ../list3", testprog));
+ assertFileContainsLinesAnyOrder("../list3", list3);
+
+ assertEqualInt(0,
+ systemf("%s -cf ../archive3b.tar *c", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive3b.tar > ../list3b", testprog));
+ assertFileContainsLinesAnyOrder("../list3b", list3);
+
+ assertEqualInt(0,
+ systemf("%s -cf ../archive4.tar fff/a?ca", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive4.tar > ../list4", testprog));
+ assertFileContainsLinesAnyOrder("../list4", list4);
+
+ assertEqualInt(0,
+ systemf("%s -cf ../archive5.tar aaa\\*", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive5.tar > ../list5", testprog));
+ assertFileContainsLinesAnyOrder("../list5", list5);
+
+ assertEqualInt(0,
+ systemf("%s -cf ../archive6.tar fff\\a?ca aaa\\xx*", testprog));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive6.tar > ../list6", testprog));
+ assertFileContainsLinesAnyOrder("../list6", list6);
+
+ /*
+ * Test2: Archive the file start with drive letters.
+ */
+ /* Test2a: start with "/" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 0);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive10.tar %s > ../out10 2> ../err10",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive10.tar > ../list10", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list10");
+ free(fp1);
+ free(fp2);
+
+ /* Test2b: start with "\" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 1);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive11.tar %s > ../out11 2> ../err11",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive11.tar > ../list11", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list11");
+ free(fp1);
+ free(fp2);
+
+ /* Test2c: start with "c:/" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 2);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive12.tar %s > ../out12 2> ../err12",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive12.tar > ../list12", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list12");
+ free(fp1);
+ free(fp2);
+
+ /* Test2d: start with "c:\" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 3);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive13.tar %s > ../out13 2> ../err13",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive13.tar > ../list13", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list13");
+ free(fp1);
+ free(fp2);
+
+ /* Test2e: start with "//./c:/" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 4);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive14.tar %s > ../out14 2> ../err14",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive14.tar > ../list14", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list14");
+ free(fp1);
+ free(fp2);
+
+ /* Test2f: start with "\\.\c:\" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 5);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive15.tar %s > ../out15 2> ../err15",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive15.tar > ../list15", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list15");
+ free(fp1);
+ free(fp2);
+
+ /* Test2g: start with "//?/c:/" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 6);
+ failure("fp1=%s, fp2=%s", fp1, fp2);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive16.tar %s > ../out16 2> ../err16",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive16.tar > ../list16", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list16");
+ free(fp1);
+ free(fp2);
+
+ /* Test2h: start with "\\?\c:\" */
+ mkfullpath(&fp1, &fp2, "aaa/file1", 7);
+ failure("fp1=%s, fp2=%s", fp1, fp2);
+ assertEqualInt(0,
+ systemf("%s -cf ../archive17.tar %s > ../out17 2> ../err17",
+ testprog, fp1));
+ assertEqualInt(0,
+ systemf("%s -tf ../archive17.tar > ../list17", testprog));
+ /* Check drive letters have been stripped. */
+ assertFileContents(fp2, strlen(fp2), "../list17");
+ free(fp1);
+ free(fp2);
+#else
+ skipping("Windows specific test");
+#endif /* _WIN32 && !__CYGWIN__ */
+}
diff --git a/archivers/libarchive/files/tar/tree.c b/archivers/libarchive/files/tar/tree.c
index 23e64e3da06..6504ebf7d06 100644
--- a/archivers/libarchive/files/tar/tree.c
+++ b/archivers/libarchive/files/tar/tree.c
@@ -18,6 +18,7 @@
* 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.
@@ -43,11 +44,14 @@
* regular dir or via fchdir(2) for a symlink).
*/
#include "bsdtar_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/tree.c,v 1.8 2007/03/11 10:36:42 kientzle Exp $");
+__FBSDID("$FreeBSD: src/usr.bin/tar/tree.c,v 1.9 2008/11/27 05:49:52 kientzle Exp $");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
+#ifdef HAVE_DIRECT_H
+#include <direct.h>
+#endif
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
@@ -66,6 +70,9 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/tree.c,v 1.8 2007/03/11 10:36:42 kientzle Ex
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__)
+#include <windows.h>
+#endif
#include "tree.h"
@@ -76,21 +83,38 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/tree.c,v 1.8 2007/03/11 10:36:42 kientzle Ex
*/
struct tree_entry {
+ int depth;
struct tree_entry *next;
struct tree_entry *parent;
char *name;
size_t dirname_length;
dev_t dev;
ino_t ino;
- int fd;
int flags;
+ /* How to return back to the parent of a symlink. */
+#ifdef HAVE_FCHDIR
+ int symlink_parent_fd;
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ char *symlink_parent_path;
+#else
+#error fchdir function required.
+#endif
};
/* Definitions for tree_entry.flags bitmap. */
#define isDir 1 /* This entry is a regular directory. */
#define isDirLink 2 /* This entry is a symbolic link to a directory. */
-#define needsPreVisit 4 /* This entry needs to be previsited. */
-#define needsPostVisit 8 /* This entry needs to be postvisited. */
+#define needsFirstVisit 4 /* This is an initial entry. */
+#define needsDescent 8 /* This entry needs to be previsited. */
+#define needsOpen 16 /* This is a directory that needs to be opened. */
+#define needsAscent 32 /* This entry needs to be postvisited. */
+
+/*
+ * On Windows, "first visit" is handled as a pattern to be handed to
+ * _findfirst(). This is consistent with Windows conventions that
+ * file patterns are handled within the application. On Posix,
+ * "first visit" is just returned to the client.
+ */
/*
* Local data for this package.
@@ -98,17 +122,28 @@ struct tree_entry {
struct tree {
struct tree_entry *stack;
struct tree_entry *current;
+#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__)
+ HANDLE d;
+ BY_HANDLE_FILE_INFORMATION fileInfo;
+#define INVALID_DIR_HANDLE INVALID_HANDLE_VALUE
+ WIN32_FIND_DATA _findData;
+ WIN32_FIND_DATA *findData;
+#else
DIR *d;
- int initialDirFd;
+#define INVALID_DIR_HANDLE NULL
+ struct dirent *de;
+#endif
int flags;
int visit_type;
int tree_errno; /* Error code from last failed operation. */
+ /* Dynamically-sized buffer for holding path */
char *buff;
- const char *basename;
size_t buff_length;
- size_t path_length;
- size_t dirname_length;
+
+ const char *basename; /* Last path element */
+ size_t dirname_length; /* Leading dir length */
+ size_t path_length; /* Total path length */
int depth;
int openCount;
@@ -119,10 +154,17 @@ struct tree {
};
/* Definitions for tree.flags bitmap. */
-#define needsReturn 8 /* Marks first entry as not having been returned yet. */
-#define hasStat 16 /* The st entry is set. */
-#define hasLstat 32 /* The lst entry is set. */
+#define hasStat 16 /* The st entry is valid. */
+#define hasLstat 32 /* The lst entry is valid. */
+#define hasFileInfo 64 /* The Windows fileInfo entry is valid. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static int
+tree_dir_next_windows(struct tree *t, const char *pattern);
+#else
+static int
+tree_dir_next_posix(struct tree *t);
+#endif
#ifdef HAVE_DIRENT_D_NAMLEN
/* BSD extension; avoids need for a strlen() call. */
@@ -131,25 +173,32 @@ struct tree {
#define D_NAMELEN(dp) (strlen((dp)->d_name))
#endif
-#if 0
#include <stdio.h>
void
tree_dump(struct tree *t, FILE *out)
{
+ char buff[300];
struct tree_entry *te;
fprintf(out, "\tdepth: %d\n", t->depth);
fprintf(out, "\tbuff: %s\n", t->buff);
- fprintf(out, "\tpwd: "); fflush(stdout); system("pwd");
- fprintf(out, "\taccess: %s\n", t->basename);
+ fprintf(out, "\tpwd: %s\n", getcwd(buff, sizeof(buff)));
+ fprintf(out, "\tbasename: %s\n", t->basename);
fprintf(out, "\tstack:\n");
for (te = t->stack; te != NULL; te = te->next) {
- fprintf(out, "\t\tte->name: %s%s%s\n", te->name,
- te->flags & needsPreVisit ? "" : " *",
- t->current == te ? " (current)" : "");
+ fprintf(out, "\t\t%s%d:\"%s\" %s%s%s%s%s%s\n",
+ t->current == te ? "*" : " ",
+ te->depth,
+ te->name,
+ te->flags & needsFirstVisit ? "V" : "",
+ te->flags & needsDescent ? "D" : "",
+ te->flags & needsOpen ? "O" : "",
+ te->flags & needsAscent ? "A" : "",
+ te->flags & isDirLink ? "L" : "",
+ (t->current == te && t->d) ? "+" : ""
+ );
}
}
-#endif
/*
* Add a directory path to the current stack.
@@ -162,20 +211,29 @@ tree_push(struct tree *t, const char *path)
te = malloc(sizeof(*te));
memset(te, 0, sizeof(*te));
te->next = t->stack;
+ te->parent = t->current;
+ if (te->parent)
+ te->depth = te->parent->depth + 1;
t->stack = te;
- te->fd = -1;
+#ifdef HAVE_FCHDIR
+ te->symlink_parent_fd = -1;
te->name = strdup(path);
- te->flags = needsPreVisit | needsPostVisit;
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ te->symlink_parent_path = NULL;
+ te->name = strdup(path);
+#endif
+ te->flags = needsDescent | needsOpen | needsAscent;
te->dirname_length = t->dirname_length;
}
/*
- * Append a name to the current path.
+ * Append a name to the current dir path.
*/
static void
tree_append(struct tree *t, const char *name, size_t name_length)
{
char *p;
+ size_t size_needed;
if (t->buff != NULL)
t->buff[t->dirname_length] = '\0';
@@ -184,12 +242,16 @@ tree_append(struct tree *t, const char *name, size_t name_length)
name_length--;
/* Resize pathname buffer as needed. */
- while (name_length + 1 + t->dirname_length >= t->buff_length) {
- t->buff_length *= 2;
+ size_needed = name_length + 1 + t->dirname_length;
+ if (t->buff_length < size_needed) {
if (t->buff_length < 1024)
t->buff_length = 1024;
+ while (t->buff_length < size_needed)
+ t->buff_length *= 2;
t->buff = realloc(t->buff, t->buff_length);
}
+ if (t->buff == NULL)
+ abort();
p = t->buff + t->dirname_length;
t->path_length = t->dirname_length + name_length;
/* Add a separating '/' if it's needed. */
@@ -197,7 +259,11 @@ tree_append(struct tree *t, const char *name, size_t name_length)
*p++ = '/';
t->path_length ++;
}
+#if HAVE_STRNCPY_S
+ strncpy_s(p, t->buff_length - (p - t->buff), name, name_length);
+#else
strncpy(p, name, name_length);
+#endif
p[name_length] = '\0';
t->basename = p;
}
@@ -208,39 +274,95 @@ tree_append(struct tree *t, const char *name, size_t name_length)
struct tree *
tree_open(const char *path)
{
+#ifdef HAVE_FCHDIR
struct tree *t;
t = malloc(sizeof(*t));
memset(t, 0, sizeof(*t));
- tree_append(t, path, strlen(path));
- t->initialDirFd = open(".", O_RDONLY);
- /*
- * During most of the traversal, items are set up and then
- * returned immediately from tree_next(). That doesn't work
- * for the very first entry, so we set a flag for this special
- * case.
- */
- t->flags = needsReturn;
+ /* First item is set up a lot like a symlink traversal. */
+ tree_push(t, path);
+ t->stack->flags = needsFirstVisit | isDirLink | needsAscent;
+ t->stack->symlink_parent_fd = open(".", O_RDONLY);
+ t->openCount++;
+ t->d = INVALID_DIR_HANDLE;
+ return (t);
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ struct tree *t;
+ char *cwd = _getcwd(NULL, 0);
+ char *pathname = strdup(path), *p, *base;
+
+ if (pathname == NULL)
+ abort();
+ for (p = pathname; *p != '\0'; ++p) {
+ if (*p == '\\')
+ *p = '/';
+ }
+ base = pathname;
+
+ t = malloc(sizeof(*t));
+ memset(t, 0, sizeof(*t));
+ /* First item is set up a lot like a symlink traversal. */
+ /* printf("Looking for wildcard in %s\n", path); */
+ /* TODO: wildcard detection here screws up on \\?\c:\ UNC names */
+ if (strchr(base, '*') || strchr(base, '?')) {
+ // It has a wildcard in it...
+ // Separate the last element.
+ p = strrchr(base, '/');
+ if (p != NULL) {
+ *p = '\0';
+ chdir(base);
+ tree_append(t, base, p - base);
+ t->dirname_length = t->path_length;
+ base = p + 1;
+ }
+ }
+ tree_push(t, base);
+ free(pathname);
+ t->stack->flags = needsFirstVisit | isDirLink | needsAscent;
+ t->stack->symlink_parent_path = cwd;
+ t->d = INVALID_DIR_HANDLE;
return (t);
+#endif
}
/*
* We've finished a directory; ascend back to the parent.
*/
-static void
+static int
tree_ascend(struct tree *t)
{
struct tree_entry *te;
+ int r = 0;
te = t->stack;
t->depth--;
if (te->flags & isDirLink) {
- fchdir(te->fd);
- close(te->fd);
+#ifdef HAVE_FCHDIR
+ if (fchdir(te->symlink_parent_fd) != 0) {
+ t->tree_errno = errno;
+ r = TREE_ERROR_FATAL;
+ }
+ close(te->symlink_parent_fd);
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ if (SetCurrentDirectory(te->symlink_parent_path) == 0) {
+ t->tree_errno = errno;
+ r = TREE_ERROR_FATAL;
+ }
+ free(te->symlink_parent_path);
+ te->symlink_parent_path = NULL;
+#endif
t->openCount--;
} else {
- chdir("..");
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (SetCurrentDirectory("..") == 0) {
+#else
+ if (chdir("..") != 0) {
+#endif
+ t->tree_errno = errno;
+ r = TREE_ERROR_FATAL;
+ }
}
+ return (r);
}
/*
@@ -251,16 +373,18 @@ tree_pop(struct tree *t)
{
struct tree_entry *te;
- t->buff[t->dirname_length] = '\0';
+ if (t->buff)
+ t->buff[t->dirname_length] = '\0';
if (t->stack == t->current && t->current != NULL)
t->current = t->current->parent;
te = t->stack;
t->stack = te->next;
t->dirname_length = te->dirname_length;
- t->basename = t->buff + t->dirname_length;
- /* Special case: starting dir doesn't skip leading '/'. */
- if (t->dirname_length > 0)
- t->basename++;
+ if (t->buff) {
+ t->basename = t->buff + t->dirname_length;
+ while (t->basename[0] == '/')
+ t->basename++;
+ }
free(te->name);
free(te);
}
@@ -271,84 +395,179 @@ tree_pop(struct tree *t)
int
tree_next(struct tree *t)
{
- struct dirent *de = NULL;
-
- /* Handle the startup case by returning the initial entry. */
- if (t->flags & needsReturn) {
- t->flags &= ~needsReturn;
- return (t->visit_type = TREE_REGULAR);
+ int r;
+
+ /* If we're called again after a fatal error, that's an API
+ * violation. Just crash now. */
+ if (t->visit_type == TREE_ERROR_FATAL) {
+ fprintf(stderr, "Unable to continue traversing"
+ " directory heirarchy after a fatal error.");
+ abort();
}
while (t->stack != NULL) {
/* If there's an open dir, get the next entry from there. */
- while (t->d != NULL) {
- de = readdir(t->d);
- if (de == NULL) {
- closedir(t->d);
- t->d = NULL;
- } else if (de->d_name[0] == '.'
- && de->d_name[1] == '\0') {
- /* Skip '.' */
- } else if (de->d_name[0] == '.'
- && de->d_name[1] == '.'
- && de->d_name[2] == '\0') {
- /* Skip '..' */
- } else {
- /*
- * Append the path to the current path
- * and return it.
- */
- tree_append(t, de->d_name, D_NAMELEN(de));
- t->flags &= ~hasLstat;
- t->flags &= ~hasStat;
- return (t->visit_type = TREE_REGULAR);
- }
+ if (t->d != INVALID_DIR_HANDLE) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ r = tree_dir_next_windows(t, NULL);
+#else
+ r = tree_dir_next_posix(t);
+#endif
+ if (r == 0)
+ continue;
+ return (r);
}
- /* If the current dir needs to be visited, set it up. */
- if (t->stack->flags & needsPreVisit) {
+ if (t->stack->flags & needsFirstVisit) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char *d = t->stack->name;
+ t->stack->flags &= ~needsFirstVisit;
+ if (strchr(d, '*') || strchr(d, '?')) {
+ r = tree_dir_next_windows(t, d);
+ if (r == 0)
+ continue;
+ return (r);
+ }
+ // Not a pattern, handle it as-is...
+#endif
+ /* Top stack item needs a regular visit. */
+ t->current = t->stack;
+ tree_append(t, t->stack->name, strlen(t->stack->name));
+ //t->dirname_length = t->path_length;
+ //tree_pop(t);
+ t->stack->flags &= ~needsFirstVisit;
+ return (t->visit_type = TREE_REGULAR);
+ } else if (t->stack->flags & needsDescent) {
+ /* Top stack item is dir to descend into. */
t->current = t->stack;
tree_append(t, t->stack->name, strlen(t->stack->name));
- t->stack->flags &= ~needsPreVisit;
+ t->stack->flags &= ~needsDescent;
/* If it is a link, set up fd for the ascent. */
if (t->stack->flags & isDirLink) {
- t->stack->fd = open(".", O_RDONLY);
+#ifdef HAVE_FCHDIR
+ t->stack->symlink_parent_fd = open(".", O_RDONLY);
t->openCount++;
if (t->openCount > t->maxOpenCount)
t->maxOpenCount = t->openCount;
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ t->stack->symlink_parent_path = _getcwd(NULL, 0);
+#endif
}
t->dirname_length = t->path_length;
- if (chdir(t->stack->name) != 0) {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (t->path_length == 259 || !SetCurrentDirectory(t->stack->name) != 0)
+#else
+ if (chdir(t->stack->name) != 0)
+#endif
+ {
/* chdir() failed; return error */
tree_pop(t);
t->tree_errno = errno;
return (t->visit_type = TREE_ERROR_DIR);
}
t->depth++;
- t->d = opendir(".");
- if (t->d == NULL) {
- tree_ascend(t); /* Undo "chdir" */
+ return (t->visit_type = TREE_POSTDESCENT);
+ } else if (t->stack->flags & needsOpen) {
+ t->stack->flags &= ~needsOpen;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ r = tree_dir_next_windows(t, "*");
+#else
+ r = tree_dir_next_posix(t);
+#endif
+ if (r == 0)
+ continue;
+ return (r);
+ } else if (t->stack->flags & needsAscent) {
+ /* Top stack item is dir and we're done with it. */
+ r = tree_ascend(t);
+ tree_pop(t);
+ t->visit_type = r != 0 ? r : TREE_POSTASCENT;
+ return (t->visit_type);
+ } else {
+ /* Top item on stack is dead. */
+ tree_pop(t);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ }
+ }
+ return (t->visit_type = 0);
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static int
+tree_dir_next_windows(struct tree *t, const char *pattern)
+{
+ const char *name;
+ size_t namelen;
+ int r;
+
+ for (;;) {
+ if (pattern != NULL) {
+ t->d = FindFirstFile(pattern, &t->_findData);
+ if (t->d == INVALID_DIR_HANDLE) {
+ r = tree_ascend(t); /* Undo "chdir" */
tree_pop(t);
t->tree_errno = errno;
- return (t->visit_type = TREE_ERROR_DIR);
+ t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
+ return (t->visit_type);
}
- t->flags &= ~hasLstat;
- t->flags &= ~hasStat;
- t->basename = ".";
- return (t->visit_type = TREE_POSTDESCENT);
+ t->findData = &t->_findData;
+ pattern = NULL;
+ } else if (!FindNextFile(t->d, &t->_findData)) {
+ FindClose(t->d);
+ t->d = INVALID_DIR_HANDLE;
+ t->findData = NULL;
+ return (0);
}
+ name = t->findData->cFileName;
+ namelen = strlen(name);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ if (name[0] == '.' && name[1] == '\0')
+ continue;
+ if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
+ continue;
+ tree_append(t, name, namelen);
+ return (t->visit_type = TREE_REGULAR);
+ }
+}
+#else
+static int
+tree_dir_next_posix(struct tree *t)
+{
+ int r;
+ const char *name;
+ size_t namelen;
- /* We've done everything necessary for the top stack entry. */
- if (t->stack->flags & needsPostVisit) {
- tree_ascend(t);
+ if (t->d == NULL) {
+ if ((t->d = opendir(".")) == NULL) {
+ r = tree_ascend(t); /* Undo "chdir" */
tree_pop(t);
- t->flags &= ~hasLstat;
- t->flags &= ~hasStat;
- return (t->visit_type = TREE_POSTASCENT);
+ t->tree_errno = errno;
+ t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
+ return (t->visit_type);
}
}
- return (t->visit_type = 0);
+ for (;;) {
+ t->de = readdir(t->d);
+ if (t->de == NULL) {
+ closedir(t->d);
+ t->d = INVALID_DIR_HANDLE;
+ return (0);
+ }
+ name = t->de->d_name;
+ namelen = D_NAMELEN(t->de);
+ t->flags &= ~hasLstat;
+ t->flags &= ~hasStat;
+ if (name[0] == '.' && name[1] == '\0')
+ continue;
+ if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
+ continue;
+ tree_append(t, name, namelen);
+ return (t->visit_type = TREE_REGULAR);
+ }
}
+#endif
/*
* Return error code.
@@ -385,25 +604,51 @@ const struct stat *
tree_current_stat(struct tree *t)
{
if (!(t->flags & hasStat)) {
- if (stat(t->basename, &t->st) != 0)
+ if (stat(tree_current_access_path(t), &t->st) != 0)
return NULL;
t->flags |= hasStat;
}
return (&t->st);
}
+#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__)
+const BY_HANDLE_FILE_INFORMATION *
+tree_current_file_information(struct tree *t)
+{
+ if (!(t->flags & hasFileInfo)) {
+ HANDLE h = CreateFile(tree_current_access_path(t),
+ 0, 0, NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
+ NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ return NULL;
+ if (!GetFileInformationByHandle(h, &t->fileInfo)) {
+ CloseHandle(h);
+ return NULL;
+ }
+ CloseHandle(h);
+ t->flags |= hasFileInfo;
+ }
+ return (&t->fileInfo);
+}
+#endif
/*
* Get the lstat() data for the entry just returned from tree_next().
*/
const struct stat *
tree_current_lstat(struct tree *t)
{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ return (tree_current_stat(t));
+#else
if (!(t->flags & hasLstat)) {
- if (lstat(t->basename, &t->lst) != 0)
+ if (lstat(tree_current_access_path(t), &t->lst) != 0)
return NULL;
t->flags |= hasLstat;
}
return (&t->lst);
+#endif
}
/*
@@ -412,8 +657,14 @@ tree_current_lstat(struct tree *t)
int
tree_current_is_dir(struct tree *t)
{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (t->findData)
+ return (t->findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+ if (tree_current_file_information(t))
+ return (t->fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+ return (0);
+#else
const struct stat *st;
-
/*
* If we already have lstat() info, then try some
* cheap tests to determine if this is a dir.
@@ -438,6 +689,7 @@ tree_current_is_dir(struct tree *t)
return 0;
/* Use the definitive test. Hopefully this is cached. */
return (S_ISDIR(st->st_mode));
+#endif
}
/*
@@ -448,6 +700,11 @@ tree_current_is_dir(struct tree *t)
int
tree_current_is_physical_dir(struct tree *t)
{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (tree_current_is_physical_link(t))
+ return (0);
+ return (tree_current_is_dir(t));
+#else
const struct stat *st;
/*
@@ -471,6 +728,7 @@ tree_current_is_physical_dir(struct tree *t)
return 0;
/* Use the definitive test. Hopefully this is cached. */
return (S_ISDIR(st->st_mode));
+#endif
}
/*
@@ -479,10 +737,21 @@ tree_current_is_physical_dir(struct tree *t)
int
tree_current_is_physical_link(struct tree *t)
{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#ifndef IO_REPARSE_TAG_SYMLINK
+/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */
+#define IO_REPARSE_TAG_SYMLINK 0xA000000CL
+#endif
+ if (t->findData)
+ return ((t->findData->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
+ && (t->findData->dwReserved0 == IO_REPARSE_TAG_SYMLINK));
+ return (0);
+#else
const struct stat *st = tree_current_lstat(t);
if (st == NULL)
return 0;
return (S_ISLNK(st->st_mode));
+#endif
}
/*
@@ -530,13 +799,23 @@ tree_close(struct tree *t)
/* Release anything remaining in the stack. */
while (t->stack != NULL)
tree_pop(t);
- if (t->buff)
- free(t->buff);
- /* chdir() back to where we started. */
+ free(t->buff);
+ /* TODO: Ensure that premature close() resets cwd */
+#if 0
+#ifdef HAVE_FCHDIR
if (t->initialDirFd >= 0) {
- fchdir(t->initialDirFd);
+ int s = fchdir(t->initialDirFd);
+ (void)s; /* UNUSED */
close(t->initialDirFd);
t->initialDirFd = -1;
}
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ if (t->initialDir != NULL) {
+ SetCurrentDir(t->initialDir);
+ free(t->initialDir);
+ t->initialDir = NULL;
+ }
+#endif
+#endif
free(t);
}
diff --git a/archivers/libarchive/files/tar/tree.h b/archivers/libarchive/files/tar/tree.h
index a32a15f8f32..9a7e0d30744 100644
--- a/archivers/libarchive/files/tar/tree.h
+++ b/archivers/libarchive/files/tar/tree.h
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.bin/tar/tree.h,v 1.3 2007/01/09 08:12:17 kientzle Exp $
+ * $FreeBSD: src/usr.bin/tar/tree.h,v 1.4 2008/11/27 05:49:52 kientzle Exp $
*/
/*-
@@ -36,8 +36,7 @@
* * Supports very deep logical traversals. The fts package
* uses "non-chdir" approach for logical traversals. This
* package does use a chdir approach for logical traversals
- * and can therefore handle pathnames much longer than
- * PATH_MAX.
+ * and can therefore handle pathnames much longer than PATH_MAX.
* * Supports deep physical traversals "out of the box."
* Due to the memory optimizations above, there's no need to
* limit dir names to 32k.
@@ -53,23 +52,32 @@ struct tree *tree_open(const char * /* pathname */);
void tree_close(struct tree *);
/*
- * tree_next() returns Zero if there is no next entry, non-zero if there is.
- * Note that directories are potentially visited three times. The first
- * time as "regular" file. If tree_descend() is invoked at that time,
- * the directory is added to a work list and will be visited two more
- * times: once just after descending into the directory and again
- * just after ascending back to the parent.
+ * tree_next() returns Zero if there is no next entry, non-zero if
+ * there is. Note that directories are visited three times.
+ * Directories are always visited first as part of enumerating their
+ * parent; that is a "regular" visit. If tree_descend() is invoked at
+ * that time, the directory is added to a work list and will
+ * subsequently be visited two more times: once just after descending
+ * into the directory ("postdescent") and again just after ascending
+ * back to the parent ("postascent").
*
- * TREE_ERROR is returned if the descent failed (because the
+ * TREE_ERROR_DIR is returned if the descent failed (because the
* directory couldn't be opened, for instance). This is returned
- * instead of TREE_PREVISIT/TREE_POSTVISIT.
+ * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a
+ * fatal error, but it does imply that the relevant subtree won't be
+ * visited. TREE_ERROR_FATAL is returned for an error that left the
+ * traversal completely hosed. Right now, this is only returned for
+ * chdir() failures during ascent.
*/
#define TREE_REGULAR 1
#define TREE_POSTDESCENT 2
#define TREE_POSTASCENT 3
#define TREE_ERROR_DIR -1
+#define TREE_ERROR_FATAL -2
+
int tree_next(struct tree *);
+/* Errno value associated with the last traversal error. */
int tree_errno(struct tree *);
/*
@@ -85,16 +93,32 @@ void tree_descend(struct tree *);
* Return information about the current entry.
*/
+/* Current depth in the traversal. */
int tree_current_depth(struct tree *);
+
/*
- * The current full pathname, length of the full pathname,
- * and a name that can be used to access the file.
- * Because tree does use chdir extensively, the access path is
- * almost never the same as the full current path.
+ * The current full pathname, length of the full pathname, and a name
+ * that can be used to access the file. Because tree does use chdir
+ * extensively, the access path is almost never the same as the full
+ * current path.
+ *
+ * TODO: Flesh out this interface to provide other information. In
+ * particular, Windows can provide file size, mode, and some permission
+ * information without invoking stat() at all.
+ *
+ * TODO: On platforms that support it, use openat()-style operations
+ * to eliminate the chdir() operations entirely while still supporting
+ * arbitrarily deep traversals. This makes access_path troublesome to
+ * support, of course, which means we'll need a rich enough interface
+ * that clients can function without it. (In particular, we'll need
+ * tree_current_open() that returns an open file descriptor.)
+ *
+ * TODO: Provide tree_current_archive_entry().
*/
const char *tree_current_path(struct tree *);
size_t tree_current_pathlen(struct tree *);
const char *tree_current_access_path(struct tree *);
+
/*
* Request the lstat() or stat() data for the current path. Since the
* tree package needs to do some of this anyway, and caches the
@@ -103,7 +127,9 @@ const char *tree_current_access_path(struct tree *);
*/
const struct stat *tree_current_stat(struct tree *);
const struct stat *tree_current_lstat(struct tree *);
-/* The following tests may use mechanisms much faster than stat()/lstat(). */
+
+/* The following functions use tricks to avoid a certain number of
+ * stat()/lstat() calls. */
/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */
int tree_current_is_physical_dir(struct tree *);
/* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */
diff --git a/archivers/libarchive/files/tar/util.c b/archivers/libarchive/files/tar/util.c
index ee1e40dbf2d..f7232744ec0 100644
--- a/archivers/libarchive/files/tar/util.c
+++ b/archivers/libarchive/files/tar/util.c
@@ -24,7 +24,7 @@
*/
#include "bsdtar_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.20 2008/06/09 14:03:55 cperciva Exp $");
+__FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.23 2008/12/15 06:00:25 kientzle Exp $");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
@@ -36,9 +36,15 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.20 2008/06/09 14:03:55 cperciva E
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
+#ifdef HAVE_IO_H
+#include <io.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>
@@ -46,122 +52,163 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.20 2008/06/09 14:03:55 cperciva E
#ifdef HAVE_STRING_H
#include <string.h>
#endif
+#ifdef HAVE_WCTYPE_H
+#include <wctype.h>
+#else
+/* If we don't have wctype, we need to hack up some version of iswprint(). */
+#define iswprint isprint
+#endif
#include "bsdtar.h"
+#include "err.h"
-static void bsdtar_vwarnc(struct bsdtar *, int code,
- const char *fmt, va_list ap);
+static size_t bsdtar_expand_char(char *, size_t, char);
+static const char *strip_components(const char *path, int elements);
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define read _read
+#endif
+
+/* TODO: Hack up a version of mbtowc for platforms with no wide
+ * character support at all. I think the following might suffice,
+ * but it needs careful testing.
+ * #if !HAVE_MBTOWC
+ * #define mbtowc(wcp, p, n) ((*wcp = *p), 1)
+ * #endif
+ */
/*
* Print a string, taking care with any non-printable characters.
+ *
+ * Note that we use a stack-allocated buffer to receive the formatted
+ * string if we can. This is partly performance (avoiding a call to
+ * malloc()), partly out of expedience (we have to call vsnprintf()
+ * before malloc() anyway to find out how big a buffer we need; we may
+ * as well point that first call at a small local buffer in case it
+ * works), but mostly for safety (so we can use this to print messages
+ * about out-of-memory conditions).
*/
void
safe_fprintf(FILE *f, const char *fmt, ...)
{
- char *buff;
- char *buff_heap;
- int buff_length;
- int length;
+ char fmtbuff_stack[256]; /* Place to format the printf() string. */
+ char outbuff[256]; /* Buffer for outgoing characters. */
+ char *fmtbuff_heap; /* If fmtbuff_stack is too small, we use malloc */
+ char *fmtbuff; /* Pointer to fmtbuff_stack or fmtbuff_heap. */
+ int fmtbuff_length;
+ int length, n;
va_list ap;
- char *p;
+ const char *p;
unsigned i;
- char buff_stack[256];
- char copy_buff[256];
+ wchar_t wc;
+ char try_wc;
/* Use a stack-allocated buffer if we can, for speed and safety. */
- buff_heap = NULL;
- buff_length = sizeof(buff_stack);
- buff = buff_stack;
+ fmtbuff_heap = NULL;
+ fmtbuff_length = sizeof(fmtbuff_stack);
+ fmtbuff = fmtbuff_stack;
+ /* Try formatting into the stack buffer. */
va_start(ap, fmt);
- length = vsnprintf(buff, buff_length, fmt, ap);
+ length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap);
va_end(ap);
- /* If the result is too large, allocate a buffer on the heap. */
- if (length >= buff_length) {
- buff_length = length+1;
- buff_heap = malloc(buff_length);
- /* Failsafe: use the truncated string if malloc fails. */
- if (buff_heap != NULL) {
- buff = buff_heap;
+
+ /* If the result was too large, allocate a buffer on the heap. */
+ if (length >= fmtbuff_length) {
+ fmtbuff_length = length+1;
+ fmtbuff_heap = malloc(fmtbuff_length);
+
+ /* Reformat the result into the heap buffer if we can. */
+ if (fmtbuff_heap != NULL) {
+ fmtbuff = fmtbuff_heap;
va_start(ap, fmt);
- length = vsnprintf(buff, buff_length, fmt, ap);
+ length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap);
va_end(ap);
+ } else {
+ /* Leave fmtbuff pointing to the truncated
+ * string in fmtbuff_stack. */
+ length = sizeof(fmtbuff_stack) - 1;
}
}
+ /* Note: mbrtowc() has a cleaner API, but mbtowc() seems a bit
+ * more portable, so we use that here instead. */
+ n = mbtowc(NULL, NULL, 1); /* Reset the shift state. */
+
/* Write data, expanding unprintable characters. */
- p = buff;
+ p = fmtbuff;
i = 0;
+ try_wc = 1;
while (*p != '\0') {
- unsigned char c = *p++;
-
- if (isprint(c) && c != '\\')
- copy_buff[i++] = c;
- else {
- copy_buff[i++] = '\\';
- switch (c) {
- case '\a': copy_buff[i++] = 'a'; break;
- case '\b': copy_buff[i++] = 'b'; break;
- case '\f': copy_buff[i++] = 'f'; break;
- case '\n': copy_buff[i++] = 'n'; break;
-#if '\r' != '\n'
- /* On some platforms, \n and \r are the same. */
- case '\r': copy_buff[i++] = 'r'; break;
-#endif
- case '\t': copy_buff[i++] = 't'; break;
- case '\v': copy_buff[i++] = 'v'; break;
- case '\\': copy_buff[i++] = '\\'; break;
- default:
- sprintf(copy_buff + i, "%03o", c);
- i += 3;
+
+ /* Convert to wide char, test if the wide
+ * char is printable in the current locale. */
+ if (try_wc && (n = mbtowc(&wc, p, length)) != -1) {
+ length -= n;
+ if (iswprint(wc) && wc != L'\\') {
+ /* Printable, copy the bytes through. */
+ while (n-- > 0)
+ outbuff[i++] = *p++;
+ } else {
+ /* Not printable, format the bytes. */
+ while (n-- > 0)
+ i += (unsigned)bsdtar_expand_char(
+ outbuff, i, *p++);
}
+ } else {
+ /* After any conversion failure, don't bother
+ * trying to convert the rest. */
+ i += (unsigned)bsdtar_expand_char(outbuff, i, *p++);
+ try_wc = 0;
}
- /* If our temp buffer is full, dump it and keep going. */
- if (i > (sizeof(copy_buff) - 8)) {
- copy_buff[i++] = '\0';
- fprintf(f, "%s", copy_buff);
+ /* If our output buffer is full, dump it and keep going. */
+ if (i > (sizeof(outbuff) - 20)) {
+ outbuff[i] = '\0';
+ fprintf(f, "%s", outbuff);
i = 0;
}
}
- copy_buff[i++] = '\0';
- fprintf(f, "%s", copy_buff);
+ outbuff[i] = '\0';
+ fprintf(f, "%s", outbuff);
- /* If we allocated a heap-based buffer, free it now. */
- if (buff_heap != NULL)
- free(buff_heap);
+ /* If we allocated a heap-based formatting buffer, free it now. */
+ if (fmtbuff_heap != NULL)
+ free(fmtbuff_heap);
}
-static void
-bsdtar_vwarnc(struct bsdtar *bsdtar, int code, const char *fmt, va_list ap)
-{
- fprintf(stderr, "%s: ", bsdtar->progname);
- vfprintf(stderr, fmt, ap);
- if (code != 0)
- fprintf(stderr, ": %s", strerror(code));
- fprintf(stderr, "\n");
-}
-
-void
-bsdtar_warnc(struct bsdtar *bsdtar, int code, const char *fmt, ...)
+/*
+ * Render an arbitrary sequence of bytes into printable ASCII characters.
+ */
+static size_t
+bsdtar_expand_char(char *buff, size_t offset, char c)
{
- va_list ap;
+ size_t i = offset;
- va_start(ap, fmt);
- bsdtar_vwarnc(bsdtar, code, fmt, ap);
- va_end(ap);
-}
-
-void
-bsdtar_errc(struct bsdtar *bsdtar, int eval, int code, const char *fmt, ...)
-{
- va_list ap;
+ if (isprint((unsigned char)c) && c != '\\')
+ buff[i++] = c;
+ else {
+ buff[i++] = '\\';
+ switch (c) {
+ case '\a': buff[i++] = 'a'; break;
+ case '\b': buff[i++] = 'b'; break;
+ case '\f': buff[i++] = 'f'; break;
+ case '\n': buff[i++] = 'n'; break;
+#if '\r' != '\n'
+ /* On some platforms, \n and \r are the same. */
+ case '\r': buff[i++] = 'r'; break;
+#endif
+ case '\t': buff[i++] = 't'; break;
+ case '\v': buff[i++] = 'v'; break;
+ case '\\': buff[i++] = '\\'; break;
+ default:
+ sprintf(buff + i, "%03o", 0xFF & (int)c);
+ i += 3;
+ }
+ }
- va_start(ap, fmt);
- bsdtar_vwarnc(bsdtar, code, fmt, ap);
- va_end(ap);
- exit(eval);
+ return (i - offset);
}
int
@@ -184,7 +231,7 @@ yes(const char *fmt, ...)
buff[l] = 0;
for (p = buff; *p != '\0'; p++) {
- if (isspace(0xff & (int)*p))
+ if (isspace((unsigned char)*p))
continue;
switch(*p) {
case 'y': case 'Y':
@@ -199,95 +246,6 @@ yes(const char *fmt, ...)
return (0);
}
-/*
- * Read lines from file and do something with each one. If option_null
- * is set, lines are terminated with zero bytes; otherwise, they're
- * terminated with newlines.
- *
- * This uses a self-sizing buffer to handle arbitrarily-long lines.
- * If the "process" function returns non-zero for any line, this
- * function will return non-zero after attempting to process all
- * remaining lines.
- */
-int
-process_lines(struct bsdtar *bsdtar, const char *pathname,
- int (*process)(struct bsdtar *, const char *))
-{
- FILE *f;
- char *buff, *buff_end, *line_start, *line_end, *p;
- size_t buff_length, new_buff_length, bytes_read, bytes_wanted;
- int separator;
- int ret;
-
- separator = bsdtar->option_null ? '\0' : '\n';
- ret = 0;
-
- if (strcmp(pathname, "-") == 0)
- f = stdin;
- else
- f = fopen(pathname, "r");
- if (f == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Couldn't open %s", pathname);
- buff_length = 8192;
- buff = malloc(buff_length);
- if (buff == NULL)
- bsdtar_errc(bsdtar, 1, ENOMEM, "Can't read %s", pathname);
- line_start = line_end = buff_end = buff;
- for (;;) {
- /* Get some more data into the buffer. */
- bytes_wanted = buff + buff_length - buff_end;
- bytes_read = fread(buff_end, 1, bytes_wanted, f);
- buff_end += bytes_read;
- /* Process all complete lines in the buffer. */
- while (line_end < buff_end) {
- if (*line_end == separator) {
- *line_end = '\0';
- if ((*process)(bsdtar, line_start) != 0)
- ret = -1;
- line_start = line_end + 1;
- line_end = line_start;
- } else
- line_end++;
- }
- if (feof(f))
- break;
- if (ferror(f))
- bsdtar_errc(bsdtar, 1, errno,
- "Can't read %s", pathname);
- if (line_start > buff) {
- /* Move a leftover fractional line to the beginning. */
- memmove(buff, line_start, buff_end - line_start);
- buff_end -= line_start - buff;
- line_end -= line_start - buff;
- line_start = buff;
- } else {
- /* Line is too big; enlarge the buffer. */
- new_buff_length = buff_length * 2;
- if (new_buff_length <= buff_length)
- bsdtar_errc(bsdtar, 1, ENOMEM,
- "Line too long in %s", pathname);
- buff_length = new_buff_length;
- p = realloc(buff, buff_length);
- if (p == NULL)
- bsdtar_errc(bsdtar, 1, ENOMEM,
- "Line too long in %s", pathname);
- buff_end = p + (buff_end - buff);
- line_end = p + (line_end - buff);
- line_start = buff = p;
- }
- }
- /* At end-of-file, handle the final line. */
- if (line_end > line_start) {
- *line_end = '\0';
- if ((*process)(bsdtar, line_start) != 0)
- ret = -1;
- }
- free(buff);
- if (f != stdin)
- fclose(f);
- return (ret);
-}
-
/*-
* The logic here for -C <dir> attempts to avoid
* chdir() as long as possible. For example:
@@ -304,6 +262,8 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
* This way, programs that build tar command lines don't have to worry
* about -C with non-existent directories; such requests will only
* fail if the directory must be accessed.
+ *
+ * TODO: Make this handle Windows paths correctly.
*/
void
set_chdir(struct bsdtar *bsdtar, const char *newdir)
@@ -329,7 +289,7 @@ set_chdir(struct bsdtar *bsdtar, const char *newdir)
free(old_pending);
}
if (bsdtar->pending_chdir == NULL)
- bsdtar_errc(bsdtar, 1, errno, "No memory");
+ lafe_errc(1, errno, "No memory");
}
void
@@ -339,13 +299,52 @@ do_chdir(struct bsdtar *bsdtar)
return;
if (chdir(bsdtar->pending_chdir) != 0) {
- bsdtar_errc(bsdtar, 1, 0, "could not chdir to '%s'\n",
+ lafe_errc(1, 0, "could not chdir to '%s'\n",
bsdtar->pending_chdir);
}
free(bsdtar->pending_chdir);
bsdtar->pending_chdir = NULL;
}
+static const char *
+strip_components(const char *p, int elements)
+{
+ /* Skip as many elements as necessary. */
+ while (elements > 0) {
+ switch (*p++) {
+ case '/':
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ case '\\': /* Support \ path sep on Windows ONLY. */
+#endif
+ elements--;
+ break;
+ case '\0':
+ /* Path is too short, skip it. */
+ return (NULL);
+ }
+ }
+
+ /* Skip any / characters. This handles short paths that have
+ * additional / termination. This also handles the case where
+ * the logic above stops in the middle of a duplicate //
+ * sequence (which would otherwise get converted to an
+ * absolute path). */
+ for (;;) {
+ switch (*p) {
+ case '/':
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ case '\\': /* Support \ path sep on Windows ONLY. */
+#endif
+ ++p;
+ break;
+ case '\0':
+ return (NULL);
+ default:
+ return (p);
+ }
+ }
+}
+
/*
* Handle --strip-components and any future path-rewriting options.
* Returns non-zero if the pathname should not be extracted.
@@ -358,13 +357,13 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
const char *name = archive_entry_pathname(entry);
#if HAVE_REGEX_H
char *subst_name;
-#endif
int r;
+#endif
#if HAVE_REGEX_H
r = apply_substitution(bsdtar, name, &subst_name, 0);
if (r == -1) {
- bsdtar_warnc(bsdtar, 0, "Invalid substituion, skipping entry");
+ lafe_warnc(0, "Invalid substitution, skipping entry");
return 1;
}
if (r == 1) {
@@ -380,7 +379,7 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
if (archive_entry_hardlink(entry)) {
r = apply_substitution(bsdtar, archive_entry_hardlink(entry), &subst_name, 1);
if (r == -1) {
- bsdtar_warnc(bsdtar, 0, "Invalid substituion, skipping entry");
+ lafe_warnc(0, "Invalid substitution, skipping entry");
return 1;
}
if (r == 1) {
@@ -391,7 +390,7 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
if (archive_entry_symlink(entry) != NULL) {
r = apply_substitution(bsdtar, archive_entry_symlink(entry), &subst_name, 1);
if (r == -1) {
- bsdtar_warnc(bsdtar, 0, "Invalid substituion, skipping entry");
+ lafe_warnc(0, "Invalid substitution, skipping entry");
return 1;
}
if (r == 1) {
@@ -402,42 +401,88 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
#endif
/* Strip leading dir names as per --strip-components option. */
- if ((r = bsdtar->strip_components) > 0) {
- const char *p = name;
-
- while (r > 0) {
- switch (*p++) {
- case '/':
- r--;
- name = p;
- break;
- case '\0':
- /* Path is too short, skip it. */
+ if (bsdtar->strip_components > 0) {
+ const char *linkname = archive_entry_hardlink(entry);
+
+ name = strip_components(name, bsdtar->strip_components);
+ if (name == NULL)
+ return (1);
+
+ if (linkname != NULL) {
+ linkname = strip_components(linkname,
+ bsdtar->strip_components);
+ if (linkname == NULL)
return (1);
- }
+ archive_entry_copy_hardlink(entry, linkname);
}
- while (*name == '/')
- ++name;
- if (*name == '\0')
- return (1);
}
- /* Strip redundant leading '/' characters. */
- while (name[0] == '/' && name[1] == '/')
- name++;
-
- /* Strip leading '/' unless user has asked us not to. */
- if (name[0] == '/' && !bsdtar->option_absolute_paths) {
- /* Generate a warning the first time this happens. */
- if (!bsdtar->warned_lead_slash) {
- bsdtar_warnc(bsdtar, 0,
- "Removing leading '/' from member names");
+ /* By default, don't write or restore absolute pathnames. */
+ if (!bsdtar->option_absolute_paths) {
+ const char *rp, *p = name;
+ int slashonly = 1;
+
+ /* 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;
+ slashonly = 0;
+ }
+ 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;
+ slashonly = 0;
+ }
+ /* Remove leading "/../", "//", etc. */
+ while (p[0] == '/' || p[0] == '\\') {
+ if (p[1] == '.' && p[2] == '.' &&
+ (p[3] == '/' || p[3] == '\\')) {
+ p += 3; /* Remove "/..", leave "/"
+ * for next pass. */
+ slashonly = 0;
+ } else
+ p += 1; /* Remove "/". */
+ }
+ } while (rp != p);
+
+ if (p != name && !bsdtar->warned_lead_slash) {
+ /* Generate a warning the first time this happens. */
+ if (slashonly)
+ lafe_warnc(0,
+ "Removing leading '%c' from member names",
+ name[0]);
+ else
+ lafe_warnc(0,
+ "Removing leading drive letter from "
+ "member names");
bsdtar->warned_lead_slash = 1;
}
- name++;
- /* Special case: Stripping leading '/' from "/" yields ".". */
- if (*name == '\0')
+
+ /* Special case: Stripping everything yields ".". */
+ if (*p == '\0')
name = ".";
+ else
+ name = p;
+ } else {
+ /* Strip redundant leading '/' characters. */
+ while (name[0] == '/' && name[1] == '/')
+ name++;
}
/* Safely replace name in archive_entry. */
@@ -450,6 +495,28 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
}
/*
+ * It would be nice to just use printf() for formatting large numbers,
+ * but the compatibility problems are quite a headache. Hence the
+ * following simple utility function.
+ */
+const char *
+tar_i64toa(int64_t n0)
+{
+ static char buff[24];
+ 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;
+}
+
+/*
* Like strcmp(), but try to be a little more aware of the fact that
* we're comparing two paths. Right now, it just handles leading
* "./" and trailing '/' specially, so that "a/b/" == "./a/b"
@@ -459,6 +526,9 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
* TODO: Publish the path normalization routines in libarchive so
* that bsdtar can normalize paths and use fast strcmp() instead
* of this.
+ *
+ * Note: This is currently only used within write.c, so should
+ * not handle \ path separators.
*/
int
diff --git a/archivers/libarchive/files/tar/write.c b/archivers/libarchive/files/tar/write.c
index 1a6e9289abe..fcf6eecfce4 100644
--- a/archivers/libarchive/files/tar/write.c
+++ b/archivers/libarchive/files/tar/write.c
@@ -24,14 +24,11 @@
*/
#include "bsdtar_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.70 2008/05/26 17:10:10 kientzle Exp $");
+__FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.79 2008/11/27 05:49:52 kientzle Exp $");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
-#ifdef HAVE_SYS_ACL_H
-#include <sys/acl.h>
-#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
@@ -44,27 +41,38 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.70 2008/05/26 17:10:10 kientzle
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
-#ifdef HAVE_EXT2FS_EXT2_FS_H
-#include <ext2fs/ext2_fs.h>
-#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_FNMATCH_H
-#include <fnmatch.h>
-#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_LINUX_FS_H
#include <linux/fs.h> /* for Linux file flags */
#endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h> /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+/* This header exists but is broken on Cygwin. */
+#include <ext2fs/ext2_fs.h>
+#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -77,8 +85,13 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.70 2008/05/26 17:10:10 kientzle
#endif
#include "bsdtar.h"
+#include "err.h"
+#include "line_reader.h"
#include "tree.h"
+/* Size of buffer for holding file data prior to writing. */
+#define FILEDATABUFLEN 65536
+
/* Fixed size of uname/gname caches. */
#define name_cache_size 101
@@ -113,36 +126,38 @@ static int append_archive_filename(struct bsdtar *,
struct archive *, const char *fname);
static void archive_names_from_file(struct bsdtar *bsdtar,
struct archive *a);
-static int archive_names_from_file_helper(struct bsdtar *bsdtar,
- const char *line);
-static int copy_file_data(struct bsdtar *bsdtar,
- struct archive *a, struct archive *ina);
-static void create_cleanup(struct bsdtar *);
-static void free_cache(struct name_cache *cache);
-static const char * lookup_gname(struct bsdtar *bsdtar, gid_t gid);
-static int lookup_gname_helper(struct bsdtar *bsdtar,
- const char **name, id_t gid);
-static const char * lookup_uname(struct bsdtar *bsdtar, uid_t uid);
-static int lookup_uname_helper(struct bsdtar *bsdtar,
- const char **name, id_t uid);
+static int copy_file_data(struct bsdtar *, struct archive *a,
+ struct archive *ina, struct archive_entry *);
static int new_enough(struct bsdtar *, const char *path,
const struct stat *);
-static void setup_acls(struct bsdtar *, struct archive_entry *,
- const char *path);
-static void setup_xattrs(struct bsdtar *, struct archive_entry *,
- const char *path);
+static void report_write(struct bsdtar *, struct archive *,
+ struct archive_entry *, int64_t progress);
static void test_for_append(struct bsdtar *);
static void write_archive(struct archive *, struct bsdtar *);
-static void write_entry(struct bsdtar *, struct archive *,
- const struct stat *, const char *pathname,
- const char *accpath);
static void write_entry_backend(struct bsdtar *, struct archive *,
- struct archive_entry *, int);
+ struct archive_entry *);
static int write_file_data(struct bsdtar *, struct archive *,
- int fd);
+ struct archive_entry *, int fd);
static void write_hierarchy(struct bsdtar *, struct archive *,
const char *);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+/* Not a full lseek() emulation, but enough for our needs here. */
+static int
+seek_file(int fd, int64_t offset, int whence)
+{
+ LARGE_INTEGER distance;
+ (void)whence; /* UNUSED */
+ distance.QuadPart = offset;
+ return (SetFilePointerEx((HANDLE)_get_osfhandle(fd),
+ distance, NULL, FILE_BEGIN) ? 1 : -1);
+}
+#define open _open
+#define close _close
+#define read _read
+#define lseek seek_file
+#endif
+
void
tar_mode_c(struct bsdtar *bsdtar)
{
@@ -150,10 +165,7 @@ tar_mode_c(struct bsdtar *bsdtar)
int r;
if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL)
- bsdtar_errc(bsdtar, 1, 0, "no files or directories specified");
-
- /* We want to catch SIGINFO and SIGUSR1. */
- siginfo_init(bsdtar);
+ lafe_errc(1, 0, "no files or directories specified");
a = archive_write_new();
@@ -168,7 +180,7 @@ tar_mode_c(struct bsdtar *bsdtar)
fprintf(stderr, "Can't use format %s: %s\n",
bsdtar->create_format,
archive_error_string(a));
- usage(bsdtar);
+ usage();
}
/*
@@ -189,43 +201,40 @@ tar_mode_c(struct bsdtar *bsdtar)
} else {
switch (bsdtar->create_compression) {
case 0:
- archive_write_set_compression_none(a);
+ r = archive_write_set_compression_none(a);
break;
-#ifdef HAVE_LIBBZ2
case 'j': case 'y':
- archive_write_set_compression_bzip2(a);
+ r = archive_write_set_compression_bzip2(a);
+ break;
+ case 'J':
+ r = archive_write_set_compression_xz(a);
+ break;
+ case OPTION_LZMA:
+ archive_write_set_compression_lzma(a);
break;
-#endif
-#ifdef HAVE_LIBZ
case 'z':
- archive_write_set_compression_gzip(a);
+ r = archive_write_set_compression_gzip(a);
break;
-#endif
case 'Z':
- archive_write_set_compression_compress(a);
+ r = archive_write_set_compression_compress(a);
break;
default:
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Unrecognized compression option -%c",
bsdtar->create_compression);
}
+ if (r != ARCHIVE_OK) {
+ lafe_errc(1, 0,
+ "Unsupported compression option -%c",
+ bsdtar->create_compression);
+ }
}
- r = archive_write_open_file(a, bsdtar->filename);
- if (r != ARCHIVE_OK)
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
-
+ if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar);
-
- if (bsdtar->option_totals) {
- fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n",
- (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a));
- }
-
- archive_write_finish(a);
-
- /* Restore old SIGINFO + SIGUSR1 handlers. */
- siginfo_done(bsdtar);
}
/*
@@ -235,7 +244,7 @@ tar_mode_c(struct bsdtar *bsdtar)
void
tar_mode_r(struct bsdtar *bsdtar)
{
- off_t end_offset;
+ int64_t end_offset;
int format;
struct archive *a;
struct archive_entry *entry;
@@ -244,14 +253,15 @@ tar_mode_r(struct bsdtar *bsdtar)
/* Sanity-test some arguments and the file. */
test_for_append(bsdtar);
- /* We want to catch SIGINFO and SIGUSR1. */
- siginfo_init(bsdtar);
-
format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
+#if defined(__BORLANDC__)
+ bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT);
+#else
bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666);
+#endif
if (bsdtar->fd < 0)
- bsdtar_errc(bsdtar, 1, errno,
+ lafe_errc(1, errno,
"Cannot open %s", bsdtar->filename);
a = archive_read_new();
@@ -260,14 +270,14 @@ tar_mode_r(struct bsdtar *bsdtar)
archive_read_support_format_gnutar(a);
r = archive_read_open_fd(a, bsdtar->fd, 10240);
if (r != ARCHIVE_OK)
- bsdtar_errc(bsdtar, 1, archive_errno(a),
+ lafe_errc(1, archive_errno(a),
"Can't read archive %s: %s", bsdtar->filename,
archive_error_string(a));
while (0 == archive_read_next_header(a, &entry)) {
if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) {
archive_read_finish(a);
close(bsdtar->fd);
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Cannot append to compressed archive.");
}
/* Keep going until we hit end-of-archive */
@@ -296,7 +306,7 @@ tar_mode_r(struct bsdtar *bsdtar)
format &= ARCHIVE_FORMAT_BASE_MASK;
if (format != (int)(archive_format(a) & ARCHIVE_FORMAT_BASE_MASK)
&& format != ARCHIVE_FORMAT_EMPTY) {
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Format %s is incompatible with the archive %s.",
bsdtar->create_format, bsdtar->filename);
}
@@ -312,17 +322,15 @@ tar_mode_r(struct bsdtar *bsdtar)
format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
archive_write_set_format(a, format);
}
- lseek(bsdtar->fd, end_offset, SEEK_SET); /* XXX check return val XXX */
- archive_write_open_fd(a, bsdtar->fd); /* XXX check return val XXX */
+ if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
+ lafe_errc(1, errno, "Could not seek to archive end");
+ if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar); /* XXX check return val XXX */
- if (bsdtar->option_totals) {
- fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n",
- (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a));
- }
-
- archive_write_finish(a);
close(bsdtar->fd);
bsdtar->fd = -1;
}
@@ -330,7 +338,7 @@ tar_mode_r(struct bsdtar *bsdtar)
void
tar_mode_u(struct bsdtar *bsdtar)
{
- off_t end_offset;
+ int64_t end_offset;
struct archive *a;
struct archive_entry *entry;
int format;
@@ -345,12 +353,9 @@ tar_mode_u(struct bsdtar *bsdtar)
/* Sanity-test some arguments and the file. */
test_for_append(bsdtar);
- /* We want to catch SIGINFO and SIGUSR1. */
- siginfo_init(bsdtar);
-
bsdtar->fd = open(bsdtar->filename, O_RDWR);
if (bsdtar->fd < 0)
- bsdtar_errc(bsdtar, 1, errno,
+ lafe_errc(1, errno,
"Cannot open %s", bsdtar->filename);
a = archive_read_new();
@@ -360,7 +365,7 @@ tar_mode_u(struct bsdtar *bsdtar)
if (archive_read_open_fd(a, bsdtar->fd,
bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Can't open %s: %s", bsdtar->filename,
archive_error_string(a));
}
@@ -370,7 +375,7 @@ tar_mode_u(struct bsdtar *bsdtar)
if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) {
archive_read_finish(a);
close(bsdtar->fd);
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Cannot append to compressed archive.");
}
add_dir_list(bsdtar, archive_entry_pathname(entry),
@@ -400,18 +405,15 @@ tar_mode_u(struct bsdtar *bsdtar)
bsdtar->bytes_per_block);
} else
archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
- lseek(bsdtar->fd, end_offset, SEEK_SET);
- ftruncate(bsdtar->fd, end_offset);
- archive_write_open_fd(a, bsdtar->fd);
+ if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
+ lafe_errc(1, errno, "Could not seek to archive end");
+ if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar);
- if (bsdtar->option_totals) {
- fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n",
- (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a));
- }
-
- archive_write_finish(a);
close(bsdtar->fd);
bsdtar->fd = -1;
@@ -434,10 +436,17 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
const char *arg;
struct archive_entry *entry, *sparse_entry;
+ /* Allocate a buffer for file data. */
+ if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL)
+ lafe_errc(1, 0, "cannot allocate memory");
+
if ((bsdtar->resolver = archive_entry_linkresolver_new()) == NULL)
- bsdtar_errc(bsdtar, 1, 0, "cannot create link resolver");
+ lafe_errc(1, 0, "cannot create link resolver");
archive_entry_linkresolver_set_strategy(bsdtar->resolver,
archive_format(a));
+ if ((bsdtar->diskreader = archive_read_disk_new()) == NULL)
+ lafe_errc(1, 0, "Cannot create read_disk object");
+ archive_read_disk_set_standard_lookup(bsdtar->diskreader);
if (bsdtar->names_from_file != NULL)
archive_names_from_file(bsdtar, a);
@@ -450,10 +459,10 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
bsdtar->argv++;
arg = *bsdtar->argv;
if (arg == NULL) {
- bsdtar_warnc(bsdtar, 1, 0,
+ lafe_warnc(0, "%s",
"Missing argument for -C");
bsdtar->return_value = 1;
- return;
+ goto cleanup;
}
}
set_chdir(bsdtar, arg);
@@ -473,18 +482,31 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
entry = NULL;
archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry);
while (entry != NULL) {
- int fd = -1;
- write_entry_backend(bsdtar, a, entry, fd);
+ write_entry_backend(bsdtar, a, entry);
archive_entry_free(entry);
entry = NULL;
archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry);
}
- create_cleanup(bsdtar);
if (archive_write_close(a)) {
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ lafe_warnc(0, "%s", archive_error_string(a));
bsdtar->return_value = 1;
}
+
+cleanup:
+ /* Free file data buffer. */
+ free(bsdtar->buff);
+ archive_entry_linkresolver_free(bsdtar->resolver);
+ bsdtar->resolver = NULL;
+ archive_read_finish(bsdtar->diskreader);
+ bsdtar->diskreader = NULL;
+
+ if (bsdtar->option_totals) {
+ fprintf(stderr, "Total bytes written: %s\n",
+ tar_i64toa(archive_position_compressed(a)));
+ }
+
+ archive_write_finish(a);
}
/*
@@ -494,36 +516,34 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
* cause the next line to be a directory to pass to chdir(). If
* --null is specified, then a line "-C" is just another filename.
*/
-void
+static void
archive_names_from_file(struct bsdtar *bsdtar, struct archive *a)
{
- bsdtar->archive = a;
+ struct lafe_line_reader *lr;
+ const char *line;
bsdtar->next_line_is_dir = 0;
- process_lines(bsdtar, bsdtar->names_from_file,
- archive_names_from_file_helper);
+
+ lr = lafe_line_reader(bsdtar->names_from_file, bsdtar->option_null);
+ while ((line = lafe_line_reader_next(lr)) != NULL) {
+ if (bsdtar->next_line_is_dir) {
+ set_chdir(bsdtar, line);
+ bsdtar->next_line_is_dir = 0;
+ } else if (!bsdtar->option_null && strcmp(line, "-C") == 0)
+ bsdtar->next_line_is_dir = 1;
+ else {
+ if (*line != '/')
+ do_chdir(bsdtar); /* Handle a deferred -C */
+ write_hierarchy(bsdtar, a, line);
+ }
+ }
+ lafe_line_reader_free(lr);
if (bsdtar->next_line_is_dir)
- bsdtar_errc(bsdtar, 1, errno,
+ lafe_errc(1, errno,
"Unexpected end of filename list; "
"directory expected after -C");
}
-static int
-archive_names_from_file_helper(struct bsdtar *bsdtar, const char *line)
-{
- if (bsdtar->next_line_is_dir) {
- set_chdir(bsdtar, line);
- bsdtar->next_line_is_dir = 0;
- } else if (!bsdtar->option_null && strcmp(line, "-C") == 0)
- bsdtar->next_line_is_dir = 1;
- else {
- if (*line != '/')
- do_chdir(bsdtar); /* Handle a deferred -C */
- write_hierarchy(bsdtar, bsdtar->archive, line);
- }
- return (0);
-}
-
/*
* Copy from specified archive to current archive. Returns non-zero
* for write errors (which force us to terminate the entire archiving
@@ -545,15 +565,15 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
archive_read_support_format_all(ina);
archive_read_support_compression_all(ina);
if (archive_read_open_file(ina, filename, 10240)) {
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(ina));
+ lafe_warnc(0, "%s", archive_error_string(ina));
bsdtar->return_value = 1;
return (0);
}
rc = append_archive(bsdtar, a, ina);
- if (archive_errno(ina)) {
- bsdtar_warnc(bsdtar, 0, "Error reading archive %s: %s",
+ if (rc != ARCHIVE_OK) {
+ lafe_warnc(0, "Error reading archive %s: %s",
filename, archive_error_string(ina));
bsdtar->return_value = 1;
}
@@ -572,7 +592,7 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
if (!new_enough(bsdtar, archive_entry_pathname(in_entry),
archive_entry_stat(in_entry)))
continue;
- if (excluded(bsdtar, archive_entry_pathname(in_entry)))
+ if (lafe_excluded(bsdtar->matching, archive_entry_pathname(in_entry)))
continue;
if (bsdtar->option_interactive &&
!yes("copy '%s'", archive_entry_pathname(in_entry)))
@@ -580,15 +600,13 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
if (bsdtar->verbose)
safe_fprintf(stderr, "a %s",
archive_entry_pathname(in_entry));
- siginfo_setinfo(bsdtar, "copying",
- archive_entry_pathname(in_entry),
- archive_entry_size(in_entry));
- siginfo_printinfo(bsdtar, 0);
+ if (need_report())
+ report_write(bsdtar, a, in_entry, 0);
e = archive_write_header(a, in_entry);
if (e != ARCHIVE_OK) {
if (!bsdtar->verbose)
- bsdtar_warnc(bsdtar, 0, "%s: %s",
+ lafe_warnc(0, "%s: %s",
archive_entry_pathname(in_entry),
archive_error_string(a));
else
@@ -600,7 +618,7 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
if (e >= ARCHIVE_WARN) {
if (archive_entry_size(in_entry) == 0)
archive_read_data_skip(ina);
- else if (copy_file_data(bsdtar, a, ina))
+ else if (copy_file_data(bsdtar, a, ina, in_entry))
exit(1);
}
@@ -614,24 +632,27 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
/* Helper function to copy data between archives. */
static int
-copy_file_data(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
+copy_file_data(struct bsdtar *bsdtar, struct archive *a,
+ struct archive *ina, struct archive_entry *entry)
{
- char buff[64*1024];
ssize_t bytes_read;
ssize_t bytes_written;
- off_t progress = 0;
+ int64_t progress = 0;
- bytes_read = archive_read_data(ina, buff, sizeof(buff));
+ bytes_read = archive_read_data(ina, bsdtar->buff, FILEDATABUFLEN);
while (bytes_read > 0) {
- siginfo_printinfo(bsdtar, progress);
+ if (need_report())
+ report_write(bsdtar, a, entry, progress);
- bytes_written = archive_write_data(a, buff, bytes_read);
+ bytes_written = archive_write_data(a, bsdtar->buff,
+ bytes_read);
if (bytes_written < bytes_read) {
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ lafe_warnc(0, "%s", archive_error_string(a));
return (-1);
}
progress += bytes_written;
- bytes_read = archive_read_data(ina, buff, sizeof(buff));
+ bytes_read = archive_read_data(ina, bsdtar->buff,
+ FILEDATABUFLEN);
}
return (0);
@@ -643,153 +664,240 @@ copy_file_data(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
static void
write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
{
+ struct archive_entry *entry = NULL, *spare_entry = NULL;
struct tree *tree;
char symlink_mode = bsdtar->symlink_mode;
dev_t first_dev = 0;
int dev_recorded = 0;
int tree_ret;
-#ifdef __linux
- int fd, r;
- unsigned long fflags;
-#endif
tree = tree_open(path);
if (!tree) {
- bsdtar_warnc(bsdtar, errno, "%s: Cannot open", path);
+ lafe_warnc(errno, "%s: Cannot open", path);
bsdtar->return_value = 1;
return;
}
- while ((tree_ret = tree_next(tree))) {
+ while ((tree_ret = tree_next(tree)) != 0) {
+ int r;
const char *name = tree_current_path(tree);
- const struct stat *st = NULL, *lst = NULL;
+ const struct stat *st = NULL; /* info to use for this entry */
+ const struct stat *lst = NULL; /* lstat() information */
int descend;
- if (tree_ret == TREE_ERROR_DIR)
- bsdtar_warnc(bsdtar, errno, "%s: Couldn't visit directory", name);
+ if (tree_ret == TREE_ERROR_FATAL)
+ lafe_errc(1, tree_errno(tree),
+ "%s: Unable to continue traversing directory tree",
+ name);
+ if (tree_ret == TREE_ERROR_DIR) {
+ lafe_warnc(errno,
+ "%s: Couldn't visit directory", name);
+ bsdtar->return_value = 1;
+ }
if (tree_ret != TREE_REGULAR)
continue;
+
+ /*
+ * If this file/dir is excluded by a filename
+ * pattern, skip it.
+ */
+ if (lafe_excluded(bsdtar->matching, name))
+ continue;
+
+ /*
+ * Get lstat() info from the tree library.
+ */
lst = tree_current_lstat(tree);
if (lst == NULL) {
/* Couldn't lstat(); must not exist. */
- bsdtar_warnc(bsdtar, errno, "%s: Cannot stat", name);
-
- /*
- * Report an error via the exit code if the failed
- * path is a prefix of what the user provided via
- * the command line. (Testing for string equality
- * here won't work due to trailing '/' characters.)
- */
- if (memcmp(name, path, strlen(name)) == 0)
- bsdtar->return_value = 1;
-
+ lafe_warnc(errno, "%s: Cannot stat", name);
+ /* Return error if files disappear during traverse. */
+ bsdtar->return_value = 1;
continue;
}
- if (S_ISLNK(lst->st_mode))
+
+ /*
+ * Distinguish 'L'/'P'/'H' symlink following.
+ */
+ switch(symlink_mode) {
+ case 'H':
+ /* 'H': After the first item, rest like 'P'. */
+ symlink_mode = 'P';
+ /* 'H': First item (from command line) like 'L'. */
+ /* FALLTHROUGH */
+ case 'L':
+ /* 'L': Do descend through a symlink to dir. */
+ descend = tree_current_is_dir(tree);
+ /* 'L': Follow symlinks to files. */
+ archive_read_disk_set_symlink_logical(bsdtar->diskreader);
+ /* 'L': Archive symlinks as targets, if we can. */
st = tree_current_stat(tree);
- /* Default: descend into any dir or symlink to dir. */
- /* We'll adjust this later on. */
- descend = 0;
- if ((st != NULL) && S_ISDIR(st->st_mode))
- descend = 1;
- if ((lst != NULL) && S_ISDIR(lst->st_mode))
- descend = 1;
+ if (st != NULL)
+ break;
+ /* If stat fails, we have a broken symlink;
+ * in that case, don't follow the link. */
+ /* FALLTHROUGH */
+ default:
+ /* 'P': Don't descend through a symlink to dir. */
+ descend = tree_current_is_physical_dir(tree);
+ /* 'P': Don't follow symlinks to files. */
+ archive_read_disk_set_symlink_physical(bsdtar->diskreader);
+ /* 'P': Archive symlinks as symlinks. */
+ st = lst;
+ break;
+ }
/*
- * If user has asked us not to cross mount points,
- * then don't descend into into a dir on a different
- * device.
+ * Are we about to cross to a new filesystem?
*/
if (!dev_recorded) {
+ /* This is the initial file system. */
first_dev = lst->st_dev;
dev_recorded = 1;
- }
- if (bsdtar->option_dont_traverse_mounts) {
- if (lst != NULL && lst->st_dev != first_dev)
- descend = 0;
+ } else if (lst->st_dev == first_dev) {
+ /* The starting file system is always acceptable. */
+ } else if (descend == 0) {
+ /* We're not descending, so no need to check. */
+ } else if (bsdtar->option_dont_traverse_mounts) {
+ /* User has asked us not to cross mount points. */
+ descend = 0;
+ } else {
+ /* We're prepared to cross a mount point. */
+
+ /* XXX TODO: check whether this filesystem is
+ * synthetic and/or local. Add a new
+ * --local-only option to skip non-local
+ * filesystems. Skip synthetic filesystems
+ * regardless.
+ *
+ * The results should be cached, since
+ * tree.c doesn't usually visit a directory
+ * and the directory contents together. A simple
+ * move-to-front list should perform quite well.
+ *
+ * This is going to be heavily OS dependent:
+ * FreeBSD's statfs() in conjunction with getvfsbyname()
+ * provides all of this; NetBSD's statvfs() does
+ * most of it; other systems will vary.
+ */
}
/*
- * If this file/dir is flagged "nodump" and we're
- * honoring such flags, skip this file/dir.
+ * In -u mode, check that the file is newer than what's
+ * already in the archive; in all modes, obey --newerXXX flags.
*/
-#ifdef HAVE_CHFLAGS
- if (bsdtar->option_honor_nodump &&
- (lst->st_flags & UF_NODUMP))
+ if (!new_enough(bsdtar, name, st))
continue;
+
+ archive_entry_free(entry);
+ entry = archive_entry_new();
+
+ archive_entry_set_pathname(entry, name);
+ archive_entry_copy_sourcepath(entry,
+ tree_current_access_path(tree));
+
+ /* Populate the archive_entry with metadata from the disk. */
+ /* XXX TODO: Arrange to open a regular file before
+ * calling this so we can pass in an fd and shorten
+ * the race to query metadata. The linkify dance
+ * makes this more complex than it might sound. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* TODO: tree.c uses stat(), which is badly broken
+ * on Windows. To fix this, we should
+ * deprecate tree_current_stat() and provide a new
+ * call tree_populate_entry(t, entry). This call
+ * would use stat() internally on POSIX and
+ * GetInfoByFileHandle() internally on Windows.
+ * This would be another step towards a tree-walker
+ * that can be integrated deep into libarchive.
+ * For now, just set st to NULL on Windows;
+ * archive_read_disk_entry_from_file() should
+ * be smart enough to use platform-appropriate
+ * ways to probe file information.
+ */
+ st = NULL;
#endif
+ r = archive_read_disk_entry_from_file(bsdtar->diskreader,
+ entry, -1, st);
+ if (r != ARCHIVE_OK)
+ lafe_warnc(archive_errno(bsdtar->diskreader),
+ "%s", archive_error_string(bsdtar->diskreader));
+ if (r < ARCHIVE_WARN)
+ continue;
+
+ /* XXX TODO: Just use flag data from entry; avoid the
+ * duplicate check here. */
-#ifdef __linux
/*
- * Linux has a nodump flag too but to read it
- * we have to open() the file/dir and do an ioctl on it...
+ * If this file/dir is flagged "nodump" and we're
+ * honoring such flags, skip this file/dir.
*/
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+ /* BSD systems store flags in struct stat */
if (bsdtar->option_honor_nodump &&
- ((fd = open(name, O_RDONLY|O_NONBLOCK)) >= 0) &&
- ((r = ioctl(fd, EXT2_IOC_GETFLAGS, &fflags)),
- close(fd), r) >= 0 &&
- (fflags & EXT2_NODUMP_FL))
+ (lst->st_flags & UF_NODUMP))
continue;
#endif
- /*
- * If this file/dir is excluded by a filename
- * pattern, skip it.
- */
- if (excluded(bsdtar, name))
- continue;
+#if defined(EXT2_IOC_GETFLAGS) && defined(EXT2_NODUMP_FL)
+ /* Linux uses ioctl to read flags. */
+ if (bsdtar->option_honor_nodump) {
+ int fd = open(name, O_RDONLY | O_NONBLOCK);
+ if (fd >= 0) {
+ unsigned long fflags;
+ int r = ioctl(fd, EXT2_IOC_GETFLAGS, &fflags);
+ close(fd);
+ if (r >= 0 && (fflags & EXT2_NODUMP_FL))
+ continue;
+ }
+ }
+#endif
/*
* If the user vetoes this file/directory, skip it.
+ * We want this to be fairly late; if some other
+ * check would veto this file, we shouldn't bother
+ * the user with it.
*/
if (bsdtar->option_interactive &&
!yes("add '%s'", name))
continue;
- /*
- * If this is a dir, decide whether or not to recurse.
- */
- if (bsdtar->option_no_subdirs)
- descend = 0;
+ /* Note: if user vetoes, we won't descend. */
+ if (descend && !bsdtar->option_no_subdirs)
+ tree_descend(tree);
/*
- * Distinguish 'L'/'P'/'H' symlink following.
+ * Rewrite the pathname to be archived. If rewrite
+ * fails, skip the entry.
*/
- switch(symlink_mode) {
- case 'H':
- /* 'H': After the first item, rest like 'P'. */
- symlink_mode = 'P';
- /* 'H': First item (from command line) like 'L'. */
- /* FALLTHROUGH */
- case 'L':
- /* 'L': Do descend through a symlink to dir. */
- /* 'L': Archive symlink to file as file. */
- lst = tree_current_stat(tree);
- /* If stat fails, we have a broken symlink;
- * in that case, archive the link as such. */
- if (lst == NULL)
- lst = tree_current_lstat(tree);
- break;
- default:
- /* 'P': Don't descend through a symlink to dir. */
- if (!S_ISDIR(lst->st_mode))
- descend = 0;
- /* 'P': Archive symlink to file as symlink. */
- /* lst = tree_current_lstat(tree); */
- break;
- }
+ if (edit_pathname(bsdtar, entry))
+ continue;
- if (descend)
- tree_descend(tree);
+ /* Display entry as we process it.
+ * This format is required by SUSv2. */
+ if (bsdtar->verbose)
+ safe_fprintf(stderr, "a %s",
+ archive_entry_pathname(entry));
- /*
- * Write the entry. Note that write_entry() handles
- * pathname editing and newness testing.
- */
- write_entry(bsdtar, a, lst, name,
- tree_current_access_path(tree));
+ /* Non-regular files get archived with zero size. */
+ if (archive_entry_filetype(entry) != AE_IFREG)
+ archive_entry_set_size(entry, 0);
+
+ archive_entry_linkify(bsdtar->resolver, &entry, &spare_entry);
+
+ while (entry != NULL) {
+ write_entry_backend(bsdtar, a, entry);
+ archive_entry_free(entry);
+ entry = spare_entry;
+ spare_entry = NULL;
+ }
+
+ if (bsdtar->verbose)
+ fprintf(stderr, "\n");
}
+ archive_entry_free(entry);
tree_close(tree);
}
@@ -798,16 +906,17 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
*/
static void
write_entry_backend(struct bsdtar *bsdtar, struct archive *a,
- struct archive_entry *entry, int fd)
+ struct archive_entry *entry)
{
+ int fd = -1;
int e;
- if (fd == -1 && archive_entry_size(entry) > 0) {
+ if (archive_entry_size(entry) > 0) {
const char *pathname = archive_entry_sourcepath(entry);
fd = open(pathname, O_RDONLY);
if (fd == -1) {
if (!bsdtar->verbose)
- bsdtar_warnc(bsdtar, errno,
+ lafe_warnc(errno,
"%s: could not open file", pathname);
else
fprintf(stderr, ": %s", strerror(errno));
@@ -818,7 +927,7 @@ write_entry_backend(struct bsdtar *bsdtar, struct archive *a,
e = archive_write_header(a, entry);
if (e != ARCHIVE_OK) {
if (!bsdtar->verbose)
- bsdtar_warnc(bsdtar, 0, "%s: %s",
+ lafe_warnc(0, "%s: %s",
archive_entry_pathname(entry),
archive_error_string(a));
else
@@ -835,499 +944,79 @@ write_entry_backend(struct bsdtar *bsdtar, struct archive *a,
* that case, just skip the write.
*/
if (e >= ARCHIVE_WARN && fd >= 0 && archive_entry_size(entry) > 0) {
- if (write_file_data(bsdtar, a, fd))
+ if (write_file_data(bsdtar, a, entry, fd))
exit(1);
- close(fd);
}
-}
-
-/*
- * Add a single filesystem object to the archive.
- */
-static void
-write_entry(struct bsdtar *bsdtar, struct archive *a, const struct stat *st,
- const char *pathname, const char *accpath)
-{
- struct archive_entry *entry, *sparse_entry;
- int fd;
-#ifdef __linux
- int r;
- unsigned long stflags;
-#endif
- static char linkbuffer[PATH_MAX+1];
-
- fd = -1;
- entry = archive_entry_new();
-
- archive_entry_set_pathname(entry, pathname);
- archive_entry_copy_sourcepath(entry, accpath);
/*
- * Rewrite the pathname to be archived. If rewrite
- * fails, skip the entry.
+ * If we opened a file, close it now even if there was an error
+ * which made us decide not to write the archive body.
*/
- if (edit_pathname(bsdtar, entry))
- goto abort;
-
- /*
- * In -u mode, check that the file is newer than what's
- * already in the archive; in all modes, obey --newerXXX flags.
- */
- if (!new_enough(bsdtar, archive_entry_pathname(entry), st))
- goto abort;
-
- /* Display entry as we process it. This format is required by SUSv2. */
- if (bsdtar->verbose)
- safe_fprintf(stderr, "a %s", archive_entry_pathname(entry));
-
- /* Read symbolic link information. */
- if ((st->st_mode & S_IFMT) == S_IFLNK) {
- int lnklen;
-
- lnklen = readlink(accpath, linkbuffer, PATH_MAX);
- if (lnklen < 0) {
- if (!bsdtar->verbose)
- bsdtar_warnc(bsdtar, errno,
- "%s: Couldn't read symbolic link",
- pathname);
- else
- safe_fprintf(stderr,
- ": Couldn't read symbolic link: %s",
- strerror(errno));
- goto cleanup;
- }
- linkbuffer[lnklen] = 0;
- archive_entry_set_symlink(entry, linkbuffer);
- }
-
- /* Look up username and group name. */
- archive_entry_set_uname(entry, lookup_uname(bsdtar, st->st_uid));
- archive_entry_set_gname(entry, lookup_gname(bsdtar, st->st_gid));
-
-#ifdef HAVE_CHFLAGS
- if (st->st_flags != 0)
- archive_entry_set_fflags(entry, st->st_flags, 0);
-#endif
-
-#ifdef __linux
- if ((S_ISREG(st->st_mode) || S_ISDIR(st->st_mode)) &&
- ((fd = open(accpath, O_RDONLY|O_NONBLOCK)) >= 0) &&
- ((r = ioctl(fd, EXT2_IOC_GETFLAGS, &stflags)), close(fd), (fd = -1), r) >= 0 &&
- stflags) {
- archive_entry_set_fflags(entry, stflags, 0);
- }
-#endif
-
- archive_entry_copy_stat(entry, st);
- setup_acls(bsdtar, entry, accpath);
- setup_xattrs(bsdtar, entry, accpath);
-
- /* Non-regular files get archived with zero size. */
- if (!S_ISREG(st->st_mode))
- archive_entry_set_size(entry, 0);
-
- /* Record what we're doing, for the benefit of SIGINFO / SIGUSR1. */
- siginfo_setinfo(bsdtar, "adding", archive_entry_pathname(entry),
- archive_entry_size(entry));
- archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry);
-
- /* Handle SIGINFO / SIGUSR1 request if one was made. */
- siginfo_printinfo(bsdtar, 0);
-
- while (entry != NULL) {
- write_entry_backend(bsdtar, a, entry, fd);
- fd = -1;
- archive_entry_free(entry);
- entry = sparse_entry;
- sparse_entry = NULL;
- }
-
-cleanup:
- if (bsdtar->verbose)
- fprintf(stderr, "\n");
-
-abort:
if (fd >= 0)
close(fd);
+}
- archive_entry_free(entry);
+static void
+report_write(struct bsdtar *bsdtar, struct archive *a,
+ struct archive_entry *entry, int64_t progress)
+{
+ uint64_t comp, uncomp;
+ if (bsdtar->verbose)
+ fprintf(stderr, "\n");
+ comp = archive_position_compressed(a);
+ uncomp = archive_position_uncompressed(a);
+ fprintf(stderr, "In: %d files, %s bytes;",
+ archive_file_count(a), tar_i64toa(uncomp));
+ fprintf(stderr,
+ " Out: %s bytes, compression %d%%\n",
+ tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
+ /* Can't have two calls to tar_i64toa() pending, so split the output. */
+ safe_fprintf(stderr, "Current: %s (%s",
+ archive_entry_pathname(entry),
+ tar_i64toa(progress));
+ fprintf(stderr, "/%s bytes)\n",
+ tar_i64toa(archive_entry_size(entry)));
}
-/* Helper function to copy file to archive, with stack-allocated buffer. */
+/* Helper function to copy file to archive. */
static int
-write_file_data(struct bsdtar *bsdtar, struct archive *a, int fd)
+write_file_data(struct bsdtar *bsdtar, struct archive *a,
+ struct archive_entry *entry, int fd)
{
- char buff[64*1024];
ssize_t bytes_read;
ssize_t bytes_written;
- off_t progress = 0;
-
- /* XXX TODO: Allocate buffer on heap and store pointer to
- * it in bsdtar structure; arrange cleanup as well. XXX */
+ int64_t progress = 0;
- bytes_read = read(fd, buff, sizeof(buff));
+ bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
while (bytes_read > 0) {
- siginfo_printinfo(bsdtar, progress);
+ if (need_report())
+ report_write(bsdtar, a, entry, progress);
- bytes_written = archive_write_data(a, buff, bytes_read);
+ bytes_written = archive_write_data(a, bsdtar->buff,
+ bytes_read);
if (bytes_written < 0) {
/* Write failed; this is bad */
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ lafe_warnc(0, "%s", archive_error_string(a));
return (-1);
}
if (bytes_written < bytes_read) {
/* Write was truncated; warn but continue. */
- bsdtar_warnc(bsdtar, 0,
- "Truncated write; file may have grown while being archived.");
+ lafe_warnc(0,
+ "%s: Truncated write; file may have grown while being archived.",
+ archive_entry_pathname(entry));
return (0);
}
progress += bytes_written;
- bytes_read = read(fd, buff, sizeof(buff));
+ bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
}
return 0;
}
-
-static void
-create_cleanup(struct bsdtar *bsdtar)
-{
- free_cache(bsdtar->uname_cache);
- bsdtar->uname_cache = NULL;
- free_cache(bsdtar->gname_cache);
- bsdtar->gname_cache = NULL;
-}
-
-#ifdef HAVE_POSIX_ACL
-static void setup_acl(struct bsdtar *bsdtar,
- struct archive_entry *entry, const char *accpath,
- int acl_type, int archive_entry_acl_type);
-
-static void
-setup_acls(struct bsdtar *bsdtar, struct archive_entry *entry,
- const char *accpath)
-{
- archive_entry_acl_clear(entry);
-
- setup_acl(bsdtar, entry, accpath,
- ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
- /* Only directories can have default ACLs. */
- if (S_ISDIR(archive_entry_mode(entry)))
- setup_acl(bsdtar, entry, accpath,
- ACL_TYPE_DEFAULT, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT);
-}
-
-static void
-setup_acl(struct bsdtar *bsdtar, struct archive_entry *entry,
- const char *accpath, int acl_type, int archive_entry_acl_type)
-{
- acl_t acl;
- acl_tag_t acl_tag;
- acl_entry_t acl_entry;
- acl_permset_t acl_permset;
- int s, ae_id, ae_tag, ae_perm;
- const char *ae_name;
-
- /* Retrieve access ACL from file. */
- acl = acl_get_file(accpath, acl_type);
- if (acl != NULL) {
- s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry);
- while (s == 1) {
- ae_id = -1;
- ae_name = NULL;
-
- acl_get_tag_type(acl_entry, &acl_tag);
- if (acl_tag == ACL_USER) {
- ae_id = (int)*(uid_t *)acl_get_qualifier(acl_entry);
- ae_name = lookup_uname(bsdtar, ae_id);
- ae_tag = ARCHIVE_ENTRY_ACL_USER;
- } else if (acl_tag == ACL_GROUP) {
- ae_id = (int)*(gid_t *)acl_get_qualifier(acl_entry);
- ae_name = lookup_gname(bsdtar, ae_id);
- ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
- } else if (acl_tag == ACL_MASK) {
- ae_tag = ARCHIVE_ENTRY_ACL_MASK;
- } else if (acl_tag == ACL_USER_OBJ) {
- ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
- } else if (acl_tag == ACL_GROUP_OBJ) {
- ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
- } else if (acl_tag == ACL_OTHER) {
- ae_tag = ARCHIVE_ENTRY_ACL_OTHER;
- } else {
- /* Skip types that libarchive can't support. */
- continue;
- }
-
- acl_get_permset(acl_entry, &acl_permset);
- ae_perm = 0;
- /*
- * acl_get_perm() is spelled differently on different
- * platforms; see bsdtar_platform.h for details.
- */
- if (ACL_GET_PERM(acl_permset, ACL_EXECUTE))
- ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE;
- if (ACL_GET_PERM(acl_permset, ACL_READ))
- ae_perm |= ARCHIVE_ENTRY_ACL_READ;
- if (ACL_GET_PERM(acl_permset, ACL_WRITE))
- ae_perm |= ARCHIVE_ENTRY_ACL_WRITE;
-
- archive_entry_acl_add_entry(entry,
- archive_entry_acl_type, ae_perm, ae_tag,
- ae_id, ae_name);
-
- s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
- }
- acl_free(acl);
- }
-}
-#else
-static void
-setup_acls(struct bsdtar *bsdtar, struct archive_entry *entry,
- const char *accpath)
-{
- (void)bsdtar;
- (void)entry;
- (void)accpath;
-}
-#endif
-
-#if HAVE_LISTXATTR && HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR
-
-static void
-setup_xattr(struct bsdtar *bsdtar, struct archive_entry *entry,
- const char *accpath, const char *name)
-{
- size_t size;
- void *value = NULL;
- char symlink_mode = bsdtar->symlink_mode;
-
- if (symlink_mode == 'H')
- size = getxattr(accpath, name, NULL, 0);
- else
- size = lgetxattr(accpath, name, NULL, 0);
-
- if (size == -1) {
- bsdtar_warnc(bsdtar, errno, "Couldn't get extended attribute");
- return;
- }
-
- if (size > 0 && (value = malloc(size)) == NULL) {
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
- return;
- }
-
- if (symlink_mode == 'H')
- size = getxattr(accpath, name, value, size);
- else
- size = lgetxattr(accpath, name, value, size);
-
- if (size == -1) {
- bsdtar_warnc(bsdtar, errno, "Couldn't get extended attribute");
- return;
- }
-
- archive_entry_xattr_add_entry(entry, name, value, size);
-
- free(value);
-}
-
-/*
- * Linux extended attribute support
- */
-static void
-setup_xattrs(struct bsdtar *bsdtar, struct archive_entry *entry,
- const char *accpath)
-{
- char *list, *p;
- size_t list_size;
- char symlink_mode = bsdtar->symlink_mode;
-
- if (symlink_mode == 'H')
- list_size = listxattr(accpath, NULL, 0);
- else
- list_size = llistxattr(accpath, NULL, 0);
-
- if (list_size == -1) {
- bsdtar_warnc(bsdtar, errno,
- "Couldn't list extended attributes");
- return;
- } else if (list_size == 0)
- return;
-
- if ((list = malloc(list_size)) == NULL) {
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
- return;
- }
-
- if (symlink_mode == 'H')
- list_size = listxattr(accpath, list, list_size);
- else
- list_size = llistxattr(accpath, list, list_size);
-
- if (list_size == -1) {
- bsdtar_warnc(bsdtar, errno,
- "Couldn't list extended attributes");
- free(list);
- return;
- }
-
- for (p = list; (p - list) < list_size; p += strlen(p) + 1) {
- if (strncmp(p, "system.", 7) == 0 ||
- strncmp(p, "xfsroot.", 8) == 0)
- continue;
-
- setup_xattr(bsdtar, entry, accpath, p);
- }
-
- free(list);
-}
-
-#else
-
-/*
- * Generic (stub) extended attribute support.
- */
-static void
-setup_xattrs(struct bsdtar *bsdtar, struct archive_entry *entry,
- const char *accpath)
-{
- (void)bsdtar; /* UNUSED */
- (void)entry; /* UNUSED */
- (void)accpath; /* UNUSED */
-}
-
-#endif
-
-static void
-free_cache(struct name_cache *cache)
-{
- size_t i;
-
- if (cache != NULL) {
- for (i = 0; i < cache->size; i++) {
- if (cache->cache[i].name != NULL &&
- cache->cache[i].name != NO_NAME)
- free((void *)(uintptr_t)cache->cache[i].name);
- }
- free(cache);
- }
-}
-
-/*
- * Lookup uid/gid from uname/gname, return NULL if no match.
- */
-static const char *
-lookup_name(struct bsdtar *bsdtar, struct name_cache **name_cache_variable,
- int (*lookup_fn)(struct bsdtar *, const char **, id_t), id_t id)
-{
- struct name_cache *cache;
- const char *name;
- int slot;
-
-
- if (*name_cache_variable == NULL) {
- *name_cache_variable = malloc(sizeof(struct name_cache));
- if (*name_cache_variable == NULL)
- bsdtar_errc(bsdtar, 1, ENOMEM, "No more memory");
- memset(*name_cache_variable, 0, sizeof(struct name_cache));
- (*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++;
- if (cache->cache[slot].name == NO_NAME)
- return (NULL);
- return (cache->cache[slot].name);
- }
- if (cache->cache[slot].name != NO_NAME)
- free((void *)(uintptr_t)cache->cache[slot].name);
- cache->cache[slot].name = NULL;
- }
-
- if (lookup_fn(bsdtar, &name, id) == 0) {
- if (name == NULL || name[0] == '\0') {
- /* Cache the negative response. */
- cache->cache[slot].name = NO_NAME;
- cache->cache[slot].id = id;
- } else {
- 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 bsdtar *bsdtar, uid_t uid)
-{
- return (lookup_name(bsdtar, &bsdtar->uname_cache,
- &lookup_uname_helper, (id_t)uid));
-}
-
-static int
-lookup_uname_helper(struct bsdtar *bsdtar, const char **name, id_t id)
-{
- struct passwd *pwent;
-
- (void)bsdtar; /* UNUSED */
-
- errno = 0;
- pwent = getpwuid((uid_t)id);
- if (pwent == NULL) {
- *name = NULL;
- if (errno != 0)
- bsdtar_warnc(bsdtar, errno, "getpwuid(%d) failed", id);
- return (errno);
- }
-
- *name = pwent->pw_name;
- return (0);
-}
-
-static const char *
-lookup_gname(struct bsdtar *bsdtar, gid_t gid)
-{
- return (lookup_name(bsdtar, &bsdtar->gname_cache,
- &lookup_gname_helper, (id_t)gid));
-}
-
-static int
-lookup_gname_helper(struct bsdtar *bsdtar, const char **name, id_t id)
-{
- struct group *grent;
-
- (void)bsdtar; /* UNUSED */
-
- errno = 0;
- grent = getgrgid((gid_t)id);
- if (grent == NULL) {
- *name = NULL;
- if (errno != 0)
- bsdtar_warnc(bsdtar, errno, "getgrgid(%d) failed", id);
- return (errno);
- }
-
- *name = grent->gr_name;
- return (0);
-}
-
/*
* Test if the specified file is new enough to include in the archive.
*/
-int
+static int
new_enough(struct bsdtar *bsdtar, const char *path, const struct stat *st)
{
struct archive_dir_entry *p;
@@ -1398,11 +1087,11 @@ add_dir_list(struct bsdtar *bsdtar, const char *path,
p = malloc(sizeof(*p));
if (p == NULL)
- bsdtar_errc(bsdtar, 1, ENOMEM, "Can't read archive directory");
+ lafe_errc(1, ENOMEM, "Can't read archive directory");
p->name = strdup(path);
if (p->name == NULL)
- bsdtar_errc(bsdtar, 1, ENOMEM, "Can't read archive directory");
+ lafe_errc(1, ENOMEM, "Can't read archive directory");
p->mtime_sec = mtime_sec;
p->mtime_nsec = mtime_nsec;
p->next = NULL;
@@ -1414,25 +1103,32 @@ add_dir_list(struct bsdtar *bsdtar, const char *path,
}
}
-void
+static void
test_for_append(struct bsdtar *bsdtar)
{
struct stat s;
if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL)
- bsdtar_errc(bsdtar, 1, 0, "no files or directories specified");
+ lafe_errc(1, 0, "no files or directories specified");
if (bsdtar->filename == NULL)
- bsdtar_errc(bsdtar, 1, 0, "Cannot append to stdout.");
+ lafe_errc(1, 0, "Cannot append to stdout.");
if (bsdtar->create_compression != 0)
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Cannot append to %s with compression", bsdtar->filename);
if (stat(bsdtar->filename, &s) != 0)
return;
if (!S_ISREG(s.st_mode) && !S_ISBLK(s.st_mode))
- bsdtar_errc(bsdtar, 1, 0,
+ lafe_errc(1, 0,
"Cannot append to %s: not a regular file.",
bsdtar->filename);
+
+/* Is this an appropriate check here on Windows? */
+/*
+ if (GetFileType(handle) != FILE_TYPE_DISK)
+ lafe_errc(1, 0, "Cannot append");
+*/
+
}