From owner-svn-src-all@FreeBSD.ORG Sat Nov 13 05:50:49 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B4AA9106566C; Sat, 13 Nov 2010 05:50:49 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9FCB58FC0A; Sat, 13 Nov 2010 05:50:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oAD5onxL037211; Sat, 13 Nov 2010 05:50:49 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oAD5on3V037198; Sat, 13 Nov 2010 05:50:49 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <201011130550.oAD5on3V037198@svn.freebsd.org> From: Tim Kientzle Date: Sat, 13 Nov 2010 05:50:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r215228 - stable/8/usr.bin/tar X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Nov 2010 05:50:49 -0000 Author: kientzle Date: Sat Nov 13 05:50:49 2010 New Revision: 215228 URL: http://svn.freebsd.org/changeset/base/215228 Log: MFC r203557: Move program name into a global, eliminate an extra argument from the error-reporting routines. Added: stable/8/usr.bin/tar/err.c - copied unchanged from r203557, head/usr.bin/tar/err.c stable/8/usr.bin/tar/err.h - copied unchanged from r203557, head/usr.bin/tar/err.h Modified: stable/8/usr.bin/tar/Makefile stable/8/usr.bin/tar/bsdtar.c stable/8/usr.bin/tar/bsdtar.h stable/8/usr.bin/tar/cmdline.c stable/8/usr.bin/tar/matching.c stable/8/usr.bin/tar/read.c stable/8/usr.bin/tar/siginfo.c stable/8/usr.bin/tar/subst.c stable/8/usr.bin/tar/util.c stable/8/usr.bin/tar/write.c Directory Properties: stable/8/usr.bin/tar/ (props changed) Modified: stable/8/usr.bin/tar/Makefile ============================================================================== --- stable/8/usr.bin/tar/Makefile Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/Makefile Sat Nov 13 05:50:49 2010 (r215228) @@ -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} ${LIBLZMA} LDADD= -larchive -lbz2 -lz -lmd -llzma .if ${MK_OPENSSL} != "no" Modified: stable/8/usr.bin/tar/bsdtar.c ============================================================================== --- stable/8/usr.bin/tar/bsdtar.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/bsdtar.c Sat Nov 13 05:50:49 2010 (r215228) @@ -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 \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); Modified: stable/8/usr.bin/tar/bsdtar.h ============================================================================== --- stable/8/usr.bin/tar/bsdtar.h Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/bsdtar.h Sat Nov 13 05:50:49 2010 (r215228) @@ -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 Modified: stable/8/usr.bin/tar/cmdline.c ============================================================================== --- stable/8/usr.bin/tar/cmdline.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/cmdline.c Sat Nov 13 05:50:49 2010 (r215228) @@ -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 ('?'); Copied: stable/8/usr.bin/tar/err.c (from r203557, head/usr.bin/tar/err.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/8/usr.bin/tar/err.c Sat Nov 13 05:50:49 2010 (r215228, copy of r203557, head/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 +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#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); +} Copied: stable/8/usr.bin/tar/err.h (from r203557, head/usr.bin/tar/err.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/8/usr.bin/tar/err.h Sat Nov 13 05:50:49 2010 (r215228, copy of r203557, head/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 Modified: stable/8/usr.bin/tar/matching.c ============================================================================== --- stable/8/usr.bin/tar/matching.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/matching.c Sat Nov 13 05:50:49 2010 (r215228) @@ -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 cha 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 cha 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, } 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 *bsdta { 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 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; Modified: stable/8/usr.bin/tar/read.c ============================================================================== --- stable/8/usr.bin/tar/read.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/read.c Sat Nov 13 05:50:49 2010 (r215228) @@ -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 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 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 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 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 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; Modified: stable/8/usr.bin/tar/siginfo.c ============================================================================== --- stable/8/usr.bin/tar/siginfo.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/siginfo.c Sat Nov 13 05:50:49 2010 (r215228) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #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, c /* 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; } Modified: stable/8/usr.bin/tar/subst.c ============================================================================== --- stable/8/usr.bin/tar/subst.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/subst.c Sat Nov 13 05:50:49 2010 (r215228) @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #if HAVE_REGEX_H #include "bsdtar.h" +#include "err.h" #include #include @@ -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, 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, 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, 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, c 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, c } 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, ch 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 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 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 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 } - 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 } if (got_match) - realloc_strcat(bsdtar, result, name); + realloc_strcat(result, name); if (print_match) fprintf(stderr, "%s >> %s\n", path, *result); Modified: stable/8/usr.bin/tar/util.c ============================================================================== --- stable/8/usr.bin/tar/util.c Sat Nov 13 05:43:58 2010 (r215227) +++ stable/8/usr.bin/tar/util.c Sat Nov 13 05:50:49 2010 (r215228) @@ -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 of 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, con 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, con 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, con /* 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 c 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, str #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, str 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"); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***