summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2010-02-06 19:44:37 +0000
committerkientzle <kientzle@FreeBSD.org>2010-02-06 19:44:37 +0000
commitcf5d23cf839d0495d58c838df8a357c7f7118d23 (patch)
treef9ab85cc7e89bc1457423f42955a33ef3b4a81a5
parent4304f61e8ffb49b9ac4ee95f97b8f5ce3696e05f (diff)
downloadFreeBSD-src-cf5d23cf839d0495d58c838df8a357c7f7118d23.zip
FreeBSD-src-cf5d23cf839d0495d58c838df8a357c7f7118d23.tar.gz
Diff reduction compared to portable bsdtar 2.8: Move the
program name into a global, which eliminates an extra argument from a lot of places.
-rw-r--r--usr.bin/tar/Makefile2
-rw-r--r--usr.bin/tar/bsdtar.c89
-rw-r--r--usr.bin/tar/bsdtar.h7
-rw-r--r--usr.bin/tar/cmdline.c13
-rw-r--r--usr.bin/tar/err.c74
-rw-r--r--usr.bin/tar/err.h43
-rw-r--r--usr.bin/tar/matching.c15
-rw-r--r--usr.bin/tar/read.c21
-rw-r--r--usr.bin/tar/siginfo.c7
-rw-r--r--usr.bin/tar/subst.c43
-rw-r--r--usr.bin/tar/util.c58
-rw-r--r--usr.bin/tar/write.c83
12 files changed, 271 insertions, 184 deletions
diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile
index 7234845..c035372 100644
--- a/usr.bin/tar/Makefile
+++ b/usr.bin/tar/Makefile
@@ -3,7 +3,7 @@
PROG= bsdtar
BSDTAR_VERSION_STRING=2.7.0
-SRCS= bsdtar.c cmdline.c getdate.c matching.c read.c siginfo.c subst.c tree.c util.c write.c
+SRCS= bsdtar.c cmdline.c err.c getdate.c matching.c read.c siginfo.c subst.c tree.c util.c write.c
DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ}
LDADD= -larchive -lbz2 -lz -lmd
.if ${MK_OPENSSL} != "no"
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c
index cd6fa63..0d86edb 100644
--- a/usr.bin/tar/bsdtar.c
+++ b/usr.bin/tar/bsdtar.c
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
#endif
#include "bsdtar.h"
+#include "err.h"
/*
* Per POSIX.1-1988, tar defaults to reading/writing archives to/from
@@ -84,7 +85,7 @@ __FBSDID("$FreeBSD$");
/* External function to parse a date/time string (from getdate.y) */
time_t get_date(time_t, const char *);
-static void long_help(struct bsdtar *);
+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);
@@ -120,25 +121,25 @@ main(int argc, char **argv)
_set_fmode(_O_BINARY);
#endif
- /* Need bsdtar->progname before calling bsdtar_warnc. */
+ /* Need bsdtar_progname before calling bsdtar_warnc. */
if (*argv == NULL)
- bsdtar->progname = "bsdtar";
+ bsdtar_progname = "bsdtar";
else {
#if defined(_WIN32) && !defined(__CYGWIN__)
- bsdtar->progname = strrchr(*argv, '\\');
+ bsdtar_progname = strrchr(*argv, '\\');
#else
- bsdtar->progname = strrchr(*argv, '/');
+ bsdtar_progname = strrchr(*argv, '/');
#endif
- if (bsdtar->progname != NULL)
- bsdtar->progname++;
+ if (bsdtar_progname != NULL)
+ bsdtar_progname++;
else
- bsdtar->progname = *argv;
+ bsdtar_progname = *argv;
}
time(&now);
if (setlocale(LC_ALL, "") == NULL)
- bsdtar_warnc(bsdtar, 0, "Failed to set default locale");
+ bsdtar_warnc(0, "Failed to set default locale");
#if defined(HAVE_NL_LANGINFO) && defined(HAVE_D_MD_ORDER)
bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd');
#endif
@@ -186,7 +187,7 @@ main(int argc, char **argv)
case 'b': /* SUSv2 */
t = atoi(bsdtar->optarg);
if (t <= 0 || t > 1024)
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Argument to -b is out of range (1..1024)");
bsdtar->bytes_per_block = 512 * t;
break;
@@ -204,7 +205,7 @@ main(int argc, char **argv)
break;
case OPTION_EXCLUDE: /* GNU tar */
if (exclude(bsdtar, bsdtar->optarg))
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Couldn't exclude %s\n", bsdtar->optarg);
break;
case OPTION_FORMAT: /* GNU tar, others */
@@ -227,7 +228,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 */
@@ -250,34 +251,34 @@ main(int argc, char **argv)
* when transforming archives.
*/
if (include(bsdtar, bsdtar->optarg))
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Failed to add %s to inclusion list",
bsdtar->optarg);
break;
case 'j': /* GNU tar */
#if HAVE_LIBBZ2
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
#else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"bzip2 compression not supported by this version of bsdtar");
- usage(bsdtar);
+ usage();
#endif
break;
case 'J': /* GNU tar 1.21 and later */
#if HAVE_LIBLZMA
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
#else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"xz compression not supported by this version of bsdtar");
- usage(bsdtar);
+ usage();
#endif
break;
case 'k': /* GNU tar */
@@ -296,14 +297,14 @@ main(int argc, char **argv)
case OPTION_LZMA:
#if HAVE_LIBLZMA
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
#else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"lzma compression not supported by this version of bsdtar");
- usage(bsdtar);
+ usage();
#endif
break;
case 'm': /* SUSv2 */
@@ -326,7 +327,7 @@ main(int argc, char **argv)
{
struct stat st;
if (stat(bsdtar->optarg, &st) != 0)
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't open file %s", bsdtar->optarg);
bsdtar->newer_ctime_sec = st.st_ctime;
bsdtar->newer_ctime_nsec =
@@ -340,7 +341,7 @@ main(int argc, char **argv)
{
struct stat st;
if (stat(bsdtar->optarg, &st) != 0)
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't open file %s", bsdtar->optarg);
bsdtar->newer_mtime_sec = st.st_mtime;
bsdtar->newer_mtime_nsec =
@@ -411,9 +412,9 @@ main(int argc, char **argv)
#if HAVE_REGEX_H
add_substitution(bsdtar, bsdtar->optarg);
#else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"-s is not supported by this version of bsdtar");
- usage(bsdtar);
+ usage();
#endif
break;
case OPTION_SAME_OWNER: /* GNU tar */
@@ -458,7 +459,7 @@ main(int argc, char **argv)
break;
case 'X': /* GNU tar */
if (exclude_from_file(bsdtar, bsdtar->optarg))
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"failed to process exclusions from file %s",
bsdtar->optarg);
break;
@@ -468,19 +469,19 @@ main(int argc, char **argv)
case 'y': /* FreeBSD version of GNU tar */
#if HAVE_LIBBZ2
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
#else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"bzip2 compression not supported by this version of bsdtar");
- usage(bsdtar);
+ usage();
#endif
break;
case 'Z': /* GNU tar */
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
@@ -488,21 +489,21 @@ main(int argc, char **argv)
case 'z': /* GNU tar, star, many others */
#if HAVE_LIBZ
if (bsdtar->create_compression != '\0')
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
#else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"gzip compression not supported by this version of bsdtar");
- usage(bsdtar);
+ usage();
#endif
break;
case OPTION_USE_COMPRESS_PROGRAM:
bsdtar->compress_program = bsdtar->optarg;
break;
default:
- usage(bsdtar);
+ usage();
}
}
@@ -512,13 +513,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,
+ bsdtar_errc(1, 0,
"Must specify one of -c, -r, -t, -u, -x");
/* Check boolean options only permitted in certain modes. */
@@ -598,7 +599,7 @@ main(int argc, char **argv)
#endif
if (bsdtar->return_value != 0)
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Error exit delayed from previous errors.");
return (bsdtar->return_value);
}
@@ -607,7 +608,7 @@ static void
set_mode(struct bsdtar *bsdtar, char opt)
{
if (bsdtar->mode != '\0' && bsdtar->mode != opt)
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Can't specify both -%c and -%c", opt, bsdtar->mode);
bsdtar->mode = opt;
}
@@ -619,18 +620,18 @@ 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,
+ bsdtar_errc(1, 0,
"Option %s is not permitted in mode -%c",
opt, bsdtar->mode);
}
void
-usage(struct bsdtar *bsdtar)
+usage(void)
{
const char *p;
- p = bsdtar->progname;
+ p = bsdtar_progname;
fprintf(stderr, "Usage:\n");
fprintf(stderr, " List: %s -tf <archive-filename>\n", p);
@@ -685,12 +686,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 = bsdtar_progname;
fflush(stderr);
diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h
index f0f3e54..2d70b7e 100644
--- a/usr.bin/tar/bsdtar.h
+++ b/usr.bin/tar/bsdtar.h
@@ -78,7 +78,6 @@ struct bsdtar {
/* Miscellaneous state information */
struct archive *archive;
- const char *progname;
int argc;
char **argv;
const char *optarg;
@@ -134,11 +133,7 @@ enum {
OPTION_VERSION
};
-
-void bsdtar_errc(struct bsdtar *, int _eval, int _code,
- const char *fmt, ...) __LA_DEAD;
int bsdtar_getopt(struct bsdtar *);
-void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
void cleanup_exclusions(struct bsdtar *);
void do_chdir(struct bsdtar *);
int edit_pathname(struct bsdtar *, struct archive_entry *);
@@ -164,7 +159,7 @@ 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/usr.bin/tar/cmdline.c b/usr.bin/tar/cmdline.c
index efaeafd..dfe7cf6 100644
--- a/usr.bin/tar/cmdline.c
+++ b/usr.bin/tar/cmdline.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#endif
#include "bsdtar.h"
+#include "err.h"
/*
* Short options for tar. Please keep this sorted.
@@ -220,7 +221,7 @@ bsdtar_getopt(struct bsdtar *bsdtar)
if (p[1] == ':') {
bsdtar->optarg = *bsdtar->argv;
if (bsdtar->optarg == NULL) {
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Option %c requires an argument",
opt);
return ('?');
@@ -287,7 +288,7 @@ bsdtar_getopt(struct bsdtar *bsdtar)
/* Otherwise, pick up the next word. */
opt_word = *bsdtar->argv;
if (opt_word == NULL) {
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Option -%c requires an argument",
opt);
return ('?');
@@ -338,13 +339,13 @@ bsdtar_getopt(struct bsdtar *bsdtar)
/* Fail if there wasn't a unique match. */
if (match == NULL) {
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Option %s%s is not supported",
long_prefix, opt_word);
return ('?');
}
if (match2 != NULL) {
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Ambiguous option %s%s (matches --%s and --%s)",
long_prefix, opt_word, match->name, match2->name);
return ('?');
@@ -356,7 +357,7 @@ bsdtar_getopt(struct bsdtar *bsdtar)
if (bsdtar->optarg == NULL) {
bsdtar->optarg = *bsdtar->argv;
if (bsdtar->optarg == NULL) {
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Option %s%s requires an argument",
long_prefix, match->name);
return ('?');
@@ -367,7 +368,7 @@ bsdtar_getopt(struct bsdtar *bsdtar)
} else {
/* Argument forbidden: fail if there is one. */
if (bsdtar->optarg != NULL) {
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Option %s%s does not allow an argument",
long_prefix, match->name);
return ('?');
diff --git a/usr.bin/tar/err.c b/usr.bin/tar/err.c
new file mode 100644
index 0000000..3770561
--- /dev/null
+++ b/usr.bin/tar/err.c
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "bsdtar_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "err.h"
+
+const char *bsdtar_progname;
+
+static void
+bsdtar_vwarnc(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(int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bsdtar_vwarnc(code, fmt, ap);
+ va_end(ap);
+}
+
+void
+bsdtar_errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bsdtar_vwarnc(code, fmt, ap);
+ va_end(ap);
+ exit(eval);
+}
diff --git a/usr.bin/tar/err.h b/usr.bin/tar/err.h
new file mode 100644
index 0000000..84ed3f4
--- /dev/null
+++ b/usr.bin/tar/err.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger
+ * 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 LAFE_ERR_H
+#define LAFE_ERR_H
+
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+ (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
+#define __LA_DEAD __attribute__((__noreturn__))
+#else
+#define __LA_DEAD
+#endif
+
+extern const char *bsdtar_progname;
+
+void bsdtar_warnc(int code, const char *fmt, ...);
+void bsdtar_errc(int eval, int code, const char *fmt, ...) __LA_DEAD;
+
+#endif
diff --git a/usr.bin/tar/matching.c b/usr.bin/tar/matching.c
index 36bc84b..c5fe094 100644
--- a/usr.bin/tar/matching.c
+++ b/usr.bin/tar/matching.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#endif
#include "bsdtar.h"
+#include "err.h"
struct match {
struct match *next;
@@ -53,7 +54,7 @@ struct matching {
};
-static void add_pattern(struct bsdtar *, struct match **list,
+static void add_pattern(struct match **list,
const char *pattern);
static int bsdtar_fnmatch(const char *p, const char *s);
static void initialize_matching(struct bsdtar *);
@@ -80,7 +81,7 @@ exclude(struct bsdtar *bsdtar, const char *pattern)
if (bsdtar->matching == NULL)
initialize_matching(bsdtar);
matching = bsdtar->matching;
- add_pattern(bsdtar, &(matching->exclusions), pattern);
+ add_pattern(&(matching->exclusions), pattern);
matching->exclusions_count++;
return (0);
}
@@ -99,7 +100,7 @@ include(struct bsdtar *bsdtar, const char *pattern)
if (bsdtar->matching == NULL)
initialize_matching(bsdtar);
matching = bsdtar->matching;
- add_pattern(bsdtar, &(matching->inclusions), pattern);
+ add_pattern(&(matching->inclusions), pattern);
matching->inclusions_count++;
matching->inclusions_unmatched_count++;
return (0);
@@ -112,13 +113,13 @@ include_from_file(struct bsdtar *bsdtar, const char *pathname)
}
static void
-add_pattern(struct bsdtar *bsdtar, struct match **list, const char *pattern)
+add_pattern(struct match **list, const char *pattern)
{
struct match *match;
match = malloc(sizeof(*match) + strlen(pattern) + 1);
if (match == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
strcpy(match->pattern, pattern);
/* Both "foo/" and "foo" should match "foo/bar". */
if (match->pattern[strlen(match->pattern)-1] == '/')
@@ -242,7 +243,7 @@ initialize_matching(struct bsdtar *bsdtar)
{
bsdtar->matching = malloc(sizeof(*bsdtar->matching));
if (bsdtar->matching == NULL)
- bsdtar_errc(bsdtar, 1, errno, "No memory");
+ bsdtar_errc(1, errno, "No memory");
memset(bsdtar->matching, 0, sizeof(*bsdtar->matching));
}
@@ -272,7 +273,7 @@ unmatched_inclusions_warn(struct bsdtar *bsdtar, const char *msg)
while (p != NULL) {
if (p->matches == 0) {
bsdtar->return_value = 1;
- bsdtar_warnc(bsdtar, 0, "%s: %s",
+ bsdtar_warnc(0, "%s: %s",
p->pattern, msg);
}
p = p->next;
diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c
index 0756cd8..ec80db8 100644
--- a/usr.bin/tar/read.c
+++ b/usr.bin/tar/read.c
@@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
#endif
#include "bsdtar.h"
+#include "err.h"
static void list_item_verbose(struct bsdtar *, FILE *,
struct archive_entry *);
@@ -128,11 +129,11 @@ read_archive(struct bsdtar *bsdtar, char mode)
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, 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",
+ bsdtar_errc(1, 0, "Error opening archive: %s",
archive_error_string(a));
do_chdir(bsdtar);
@@ -146,9 +147,9 @@ read_archive(struct bsdtar *bsdtar, char mode)
if (mode == 'x' && bsdtar->option_chroot) {
#if HAVE_CHROOT
if (chroot(".") != 0)
- bsdtar_errc(bsdtar, 1, errno, "Can't chroot to \".\"");
+ bsdtar_errc(1, errno, "Can't chroot to \".\"");
#else
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"chroot isn't supported on this platform");
#endif
}
@@ -163,12 +164,12 @@ read_archive(struct bsdtar *bsdtar, char mode)
if (r == ARCHIVE_EOF)
break;
if (r < ARCHIVE_OK)
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ bsdtar_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...");
+ bsdtar_warnc(0, "Retrying...");
continue;
}
if (r == ARCHIVE_FATAL)
@@ -232,17 +233,17 @@ 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",
+ bsdtar_warnc(0, "%s",
archive_error_string(a));
}
if (r == ARCHIVE_RETRY) {
fprintf(out, "\n");
- bsdtar_warnc(bsdtar, 0, "%s",
+ bsdtar_warnc(0, "%s",
archive_error_string(a));
}
if (r == ARCHIVE_FATAL) {
fprintf(out, "\n");
- bsdtar_warnc(bsdtar, 0, "%s",
+ bsdtar_warnc(0, "%s",
archive_error_string(a));
bsdtar->return_value = 1;
break;
@@ -297,7 +298,7 @@ read_archive(struct bsdtar *bsdtar, char mode)
r = archive_read_close(a);
if (r != ARCHIVE_OK)
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ bsdtar_warnc(0, "%s", archive_error_string(a));
if (r <= ARCHIVE_WARN)
bsdtar->return_value = 1;
diff --git a/usr.bin/tar/siginfo.c b/usr.bin/tar/siginfo.c
index e0881ac..b6b64f1 100644
--- a/usr.bin/tar/siginfo.c
+++ b/usr.bin/tar/siginfo.c
@@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include "bsdtar.h"
+#include "err.h"
/* Is there a pending SIGINFO or SIGUSR1? */
static volatile sig_atomic_t siginfo_received = 0;
@@ -73,7 +74,7 @@ siginfo_init(struct bsdtar *bsdtar)
/* Allocate space for internal structure. */
if ((bsdtar->siginfo = malloc(sizeof(struct siginfo_data))) == NULL)
- bsdtar_errc(bsdtar, 1, errno, "malloc failed");
+ bsdtar_errc(1, errno, "malloc failed");
/* Set the strings to NULL so that free() is safe. */
bsdtar->siginfo->path = bsdtar->siginfo->oper = NULL;
@@ -99,9 +100,9 @@ siginfo_setinfo(struct bsdtar *bsdtar, const char * oper, const char * path,
/* Duplicate strings and store entry size. */
if ((bsdtar->siginfo->oper = strdup(oper)) == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Cannot strdup");
+ bsdtar_errc(1, errno, "Cannot strdup");
if ((bsdtar->siginfo->path = strdup(path)) == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Cannot strdup");
+ bsdtar_errc(1, errno, "Cannot strdup");
bsdtar->siginfo->size = size;
}
diff --git a/usr.bin/tar/subst.c b/usr.bin/tar/subst.c
index 13464cd..44fd87b 100644
--- a/usr.bin/tar/subst.c
+++ b/usr.bin/tar/subst.c
@@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$");
#if HAVE_REGEX_H
#include "bsdtar.h"
+#include "err.h"
#include <errno.h>
#include <regex.h>
@@ -56,7 +57,7 @@ init_substitution(struct bsdtar *bsdtar)
bsdtar->substitution = subst = malloc(sizeof(*subst));
if (subst == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
subst->first_rule = subst->last_rule = NULL;
}
@@ -76,7 +77,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");
+ bsdtar_errc(1, errno, "Out of memory");
rule->next = NULL;
if (subst->last_rule == NULL)
@@ -86,32 +87,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");
+ bsdtar_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");
+ bsdtar_errc(1, 0, "Invalid replacement string");
pattern = malloc(end_pattern - rule_text);
if (pattern == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_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);
+ bsdtar_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");
+ bsdtar_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");
+ bsdtar_errc(1, errno, "Out of memory");
memcpy(rule->result, start_subst, end_pattern - start_subst);
rule->result[end_pattern - start_subst] = '\0';
@@ -134,13 +135,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);
+ bsdtar_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 +153,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");
+ bsdtar_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 +162,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 +174,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");
+ bsdtar_errc(1, errno, "Out of memory");
memcpy(new_str, *str, old_len);
strcpy(new_str + old_len, append);
free(*str);
@@ -206,12 +207,12 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
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 +224,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 +236,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 +252,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 +261,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/usr.bin/tar/util.c b/usr.bin/tar/util.c
index 7b2da48..82a018f 100644
--- a/usr.bin/tar/util.c
+++ b/usr.bin/tar/util.c
@@ -54,9 +54,8 @@ __FBSDID("$FreeBSD$");
#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);
@@ -203,37 +202,6 @@ bsdtar_expand_char(char *buff, size_t offset, char c)
return (i - offset);
}
-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, ...)
-{
- va_list ap;
-
- 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;
-
- va_start(ap, fmt);
- bsdtar_vwarnc(bsdtar, code, fmt, ap);
- va_end(ap);
- exit(eval);
-}
-
int
yes(const char *fmt, ...)
{
@@ -297,11 +265,11 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
else
f = fopen(pathname, "r");
if (f == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Couldn't open %s", pathname);
+ bsdtar_errc(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);
+ bsdtar_errc(1, ENOMEM, "Can't read %s", pathname);
line_start = line_end = buff_end = buff;
for (;;) {
/* Get some more data into the buffer. */
@@ -322,7 +290,7 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
if (feof(f))
break;
if (ferror(f))
- bsdtar_errc(bsdtar, 1, errno,
+ bsdtar_errc(1, errno,
"Can't read %s", pathname);
if (line_start > buff) {
/* Move a leftover fractional line to the beginning. */
@@ -334,12 +302,12 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
/* Line is too big; enlarge the buffer. */
new_buff_length = buff_length * 2;
if (new_buff_length <= buff_length)
- bsdtar_errc(bsdtar, 1, ENOMEM,
+ bsdtar_errc(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,
+ bsdtar_errc(1, ENOMEM,
"Line too long in %s", pathname);
buff_end = p + (buff_end - buff);
line_end = p + (line_end - buff);
@@ -399,7 +367,7 @@ set_chdir(struct bsdtar *bsdtar, const char *newdir)
free(old_pending);
}
if (bsdtar->pending_chdir == NULL)
- bsdtar_errc(bsdtar, 1, errno, "No memory");
+ bsdtar_errc(1, errno, "No memory");
}
void
@@ -409,7 +377,7 @@ do_chdir(struct bsdtar *bsdtar)
return;
if (chdir(bsdtar->pending_chdir) != 0) {
- bsdtar_errc(bsdtar, 1, 0, "could not chdir to '%s'\n",
+ bsdtar_errc(1, 0, "could not chdir to '%s'\n",
bsdtar->pending_chdir);
}
free(bsdtar->pending_chdir);
@@ -459,7 +427,7 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
#if HAVE_REGEX_H
r = apply_substitution(bsdtar, name, &subst_name, 0);
if (r == -1) {
- bsdtar_warnc(bsdtar, 0, "Invalid substitution, skipping entry");
+ bsdtar_warnc(0, "Invalid substitution, skipping entry");
return 1;
}
if (r == 1) {
@@ -475,7 +443,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 substitution, skipping entry");
+ bsdtar_warnc(0, "Invalid substitution, skipping entry");
return 1;
}
if (r == 1) {
@@ -486,7 +454,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 substitution, skipping entry");
+ bsdtar_warnc(0, "Invalid substitution, skipping entry");
return 1;
}
if (r == 1) {
@@ -560,11 +528,11 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
if (p != name && !bsdtar->warned_lead_slash) {
/* Generate a warning the first time this happens. */
if (slashonly)
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Removing leading '%c' from member names",
name[0]);
else
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"Removing leading drive letter from "
"member names");
bsdtar->warned_lead_slash = 1;
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index efc94de..78e555c 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -86,6 +86,7 @@ __FBSDID("$FreeBSD$");
#include "bsdtar.h"
#include "tree.h"
+#include "err.h"
/* Size of buffer for holding file data prior to writing. */
#define FILEDATABUFLEN 65536
@@ -146,7 +147,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");
+ bsdtar_errc(1, 0, "no files or directories specified");
a = archive_write_new();
@@ -161,7 +162,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();
}
/*
@@ -206,16 +207,16 @@ tar_mode_c(struct bsdtar *bsdtar)
archive_write_set_compression_compress(a);
break;
default:
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_errc(1, 0,
"Unrecognized compression option -%c",
bsdtar->create_compression);
}
}
if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, archive_error_string(a));
if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, archive_error_string(a));
write_archive(a, bsdtar);
}
@@ -239,7 +240,7 @@ tar_mode_r(struct bsdtar *bsdtar)
bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666);
if (bsdtar->fd < 0)
- bsdtar_errc(bsdtar, 1, errno,
+ bsdtar_errc(1, errno,
"Cannot open %s", bsdtar->filename);
a = archive_read_new();
@@ -248,14 +249,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),
+ bsdtar_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,
+ bsdtar_errc(1, 0,
"Cannot append to compressed archive.");
}
/* Keep going until we hit end-of-archive */
@@ -284,7 +285,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,
+ bsdtar_errc(1, 0,
"Format %s is incompatible with the archive %s.",
bsdtar->create_format, bsdtar->filename);
}
@@ -302,9 +303,9 @@ tar_mode_r(struct bsdtar *bsdtar)
}
lseek(bsdtar->fd, end_offset, SEEK_SET); /* XXX check return val XXX */
if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, archive_error_string(a));
if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, archive_error_string(a));
write_archive(a, bsdtar); /* XXX check return val XXX */
@@ -332,7 +333,7 @@ tar_mode_u(struct bsdtar *bsdtar)
bsdtar->fd = open(bsdtar->filename, O_RDWR);
if (bsdtar->fd < 0)
- bsdtar_errc(bsdtar, 1, errno,
+ bsdtar_errc(1, errno,
"Cannot open %s", bsdtar->filename);
a = archive_read_new();
@@ -342,7 +343,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,
+ bsdtar_errc(1, 0,
"Can't open %s: %s", bsdtar->filename,
archive_error_string(a));
}
@@ -352,7 +353,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,
+ bsdtar_errc(1, 0,
"Cannot append to compressed archive.");
}
add_dir_list(bsdtar, archive_entry_pathname(entry),
@@ -385,9 +386,9 @@ tar_mode_u(struct bsdtar *bsdtar)
lseek(bsdtar->fd, end_offset, SEEK_SET);
ftruncate(bsdtar->fd, end_offset);
if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, archive_error_string(a));
if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
- bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, archive_error_string(a));
write_archive(a, bsdtar);
@@ -418,14 +419,14 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
/* Allocate a buffer for file data. */
if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL)
- bsdtar_errc(bsdtar, 1, 0, "cannot allocate memory");
+ bsdtar_errc(1, 0, "cannot allocate memory");
if ((bsdtar->resolver = archive_entry_linkresolver_new()) == NULL)
- bsdtar_errc(bsdtar, 1, 0, "cannot create link resolver");
+ bsdtar_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)
- bsdtar_errc(bsdtar, 1, 0, "Cannot create read_disk object");
+ bsdtar_errc(1, 0, "Cannot create read_disk object");
archive_read_disk_set_standard_lookup(bsdtar->diskreader);
if (bsdtar->names_from_file != NULL)
@@ -439,7 +440,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
bsdtar->argv++;
arg = *bsdtar->argv;
if (arg == NULL) {
- bsdtar_warnc(bsdtar, 1, 0,
+ bsdtar_warnc(1, 0,
"Missing argument for -C");
bsdtar->return_value = 1;
goto cleanup;
@@ -474,7 +475,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
}
if (archive_write_close(a)) {
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ bsdtar_warnc(0, "%s", archive_error_string(a));
bsdtar->return_value = 1;
}
@@ -513,7 +514,7 @@ archive_names_from_file(struct bsdtar *bsdtar, struct archive *a)
process_lines(bsdtar, bsdtar->names_from_file,
archive_names_from_file_helper);
if (bsdtar->next_line_is_dir)
- bsdtar_errc(bsdtar, 1, errno,
+ bsdtar_errc(1, errno,
"Unexpected end of filename list; "
"directory expected after -C");
}
@@ -555,7 +556,7 @@ 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));
+ bsdtar_warnc(0, "%s", archive_error_string(ina));
bsdtar->return_value = 1;
return (0);
}
@@ -563,7 +564,7 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
rc = append_archive(bsdtar, a, ina);
if (archive_errno(ina)) {
- bsdtar_warnc(bsdtar, 0, "Error reading archive %s: %s",
+ bsdtar_warnc(0, "Error reading archive %s: %s",
filename, archive_error_string(ina));
bsdtar->return_value = 1;
}
@@ -598,7 +599,7 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
e = archive_write_header(a, in_entry);
if (e != ARCHIVE_OK) {
if (!bsdtar->verbose)
- bsdtar_warnc(bsdtar, 0, "%s: %s",
+ bsdtar_warnc(0, "%s: %s",
archive_entry_pathname(in_entry),
archive_error_string(a));
else
@@ -637,7 +638,7 @@ copy_file_data(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
bytes_written = archive_write_data(a, bsdtar->buff,
bytes_read);
if (bytes_written < bytes_read) {
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ bsdtar_warnc(0, "%s", archive_error_string(a));
return (-1);
}
progress += bytes_written;
@@ -664,7 +665,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
tree = tree_open(path);
if (!tree) {
- bsdtar_warnc(bsdtar, errno, "%s: Cannot open", path);
+ bsdtar_warnc(errno, "%s: Cannot open", path);
bsdtar->return_value = 1;
return;
}
@@ -677,11 +678,11 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
int descend;
if (tree_ret == TREE_ERROR_FATAL)
- bsdtar_errc(bsdtar, 1, tree_errno(tree),
+ bsdtar_errc(1, tree_errno(tree),
"%s: Unable to continue traversing directory tree",
name);
if (tree_ret == TREE_ERROR_DIR) {
- bsdtar_warnc(bsdtar, errno,
+ bsdtar_warnc(errno,
"%s: Couldn't visit directory", name);
bsdtar->return_value = 1;
}
@@ -701,7 +702,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
lst = tree_current_lstat(tree);
if (lst == NULL) {
/* Couldn't lstat(); must not exist. */
- bsdtar_warnc(bsdtar, errno, "%s: Cannot stat", name);
+ bsdtar_warnc(errno, "%s: Cannot stat", name);
/* Return error if files disappear during traverse. */
bsdtar->return_value = 1;
continue;
@@ -774,7 +775,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
r = archive_read_disk_entry_from_file(bsdtar->diskreader,
entry, -1, st);
if (r != ARCHIVE_OK)
- bsdtar_warnc(bsdtar, archive_errno(bsdtar->diskreader),
+ bsdtar_warnc(archive_errno(bsdtar->diskreader),
archive_error_string(bsdtar->diskreader));
if (r < ARCHIVE_WARN)
continue;
@@ -875,7 +876,7 @@ write_entry_backend(struct bsdtar *bsdtar, struct archive *a,
fd = open(pathname, O_RDONLY);
if (fd == -1) {
if (!bsdtar->verbose)
- bsdtar_warnc(bsdtar, errno,
+ bsdtar_warnc(errno,
"%s: could not open file", pathname);
else
fprintf(stderr, ": %s", strerror(errno));
@@ -886,7 +887,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",
+ bsdtar_warnc(0, "%s: %s",
archive_entry_pathname(entry),
archive_error_string(a));
else
@@ -933,12 +934,12 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a,
bytes_read);
if (bytes_written < 0) {
/* Write failed; this is bad */
- bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ bsdtar_warnc(0, "%s", archive_error_string(a));
return (-1);
}
if (bytes_written < bytes_read) {
/* Write was truncated; warn but continue. */
- bsdtar_warnc(bsdtar, 0,
+ bsdtar_warnc(0,
"%s: Truncated write; file may have grown while being archived.",
archive_entry_pathname(entry));
return (0);
@@ -1023,11 +1024,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");
+ bsdtar_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");
+ bsdtar_errc(1, ENOMEM, "Can't read archive directory");
p->mtime_sec = mtime_sec;
p->mtime_nsec = mtime_nsec;
p->next = NULL;
@@ -1045,19 +1046,19 @@ 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");
+ bsdtar_errc(1, 0, "no files or directories specified");
if (bsdtar->filename == NULL)
- bsdtar_errc(bsdtar, 1, 0, "Cannot append to stdout.");
+ bsdtar_errc(1, 0, "Cannot append to stdout.");
if (bsdtar->create_compression != 0)
- bsdtar_errc(bsdtar, 1, 0,
+ bsdtar_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,
+ bsdtar_errc(1, 0,
"Cannot append to %s: not a regular file.",
bsdtar->filename);
}
OpenPOWER on IntegriCloud