summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-07-24 22:13:44 +0000
committerkientzle <kientzle@FreeBSD.org>2004-07-24 22:13:44 +0000
commit4eaecd41f31309b86bf7e73c017f01bd2f1f14b4 (patch)
treeba108286e4e711cdf3753c7ced91e04bee859848 /usr.bin/tar
parent353438ef29b01ce945860c223820b7e6afab99ed (diff)
downloadFreeBSD-src-4eaecd41f31309b86bf7e73c017f01bd2f1f14b4.zip
FreeBSD-src-4eaecd41f31309b86bf7e73c017f01bd2f1f14b4.tar.gz
A bunch of stuff from Christoph Mellon:
* Whitespace fixes * Check some malloc calls * Simplify long_help formatting * Spell "LINUX" -> "linux" * A few other miscellaneous style improvements
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/bsdtar.c89
-rw-r--r--usr.bin/tar/bsdtar.h2
-rw-r--r--usr.bin/tar/bsdtar_platform.h2
-rw-r--r--usr.bin/tar/fts.c2
-rw-r--r--usr.bin/tar/matching.c2
-rw-r--r--usr.bin/tar/read.c31
-rw-r--r--usr.bin/tar/write.c23
7 files changed, 77 insertions, 74 deletions
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c
index 3a0b001..c35fa78 100644
--- a/usr.bin/tar/bsdtar.c
+++ b/usr.bin/tar/bsdtar.c
@@ -74,7 +74,7 @@ static char ** rewrite_argv(struct bsdtar *,
* non-option. Otherwise, GNU getopt() permutes the arguments and
* screws up -C processing.
*/
-const char *tar_opts = "+Bb:C:cF:f:HhjkLlmnOoPprtT:UuvW:wX:xyZz";
+static const char *tar_opts = "+Bb:C:cF:f:HhjkLlmnOoPprtT:UuvW:wX:xyZz";
/*
* Most of these long options are deliberately not documented. They
@@ -100,7 +100,7 @@ const char *tar_opts = "+Bb:C:cF:f:HhjkLlmnOoPprtT:UuvW:wX:xyZz";
#define OPTION_NULL 7
#define OPTION_ONE_FILE_SYSTEM 8
-const struct option tar_longopts[] = {
+static const struct option tar_longopts[] = {
{ "absolute-paths", no_argument, NULL, 'P' },
{ "append", no_argument, NULL, 'r' },
{ "block-size", required_argument, NULL, 'b' },
@@ -201,7 +201,7 @@ main(int argc, char **argv)
bsdtar->argc = argc;
/* Process all remaining arguments now. */
- while ((opt = bsdtar_getopt(bsdtar, tar_opts, &option)) != -1) {
+ while ((opt = bsdtar_getopt(bsdtar, tar_opts, &option)) != -1) {
switch (opt) {
case 'B': /* GNU tar */
/* libarchive doesn't need this; just ignore it. */
@@ -441,8 +441,8 @@ main(int argc, char **argv)
only_mode(bsdtar, mode, buff, "cru");
}
- bsdtar->argc -= optind;
- bsdtar->argv += optind;
+ bsdtar->argc -= optind;
+ bsdtar->argv += optind;
switch(mode) {
case 'c':
@@ -497,7 +497,7 @@ only_mode(struct bsdtar *bsdtar, char mode,
* It is used to determine which option letters have trailing arguments.
*/
char **
-rewrite_argv(struct bsdtar *bsdtar, int *argc, char ** src_argv,
+rewrite_argv(struct bsdtar *bsdtar, int *argc, char **src_argv,
const char *optstring)
{
char **new_argv, **dest_argv;
@@ -565,35 +565,33 @@ usage(struct bsdtar *bsdtar)
exit(1);
}
-static const char *long_help_msg[] = {
- "First option must be a mode specifier:\n",
- " -c Create -r Add/Replace -t List -u Update -x Extract\n",
- "Common Options:\n",
- " -b # Use # 512-byte records per I/O block\n",
- " -f <filename> Location of archive (default " _PATH_DEFTAPE ")\n",
- " -v Verbose\n",
- " -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",
- " -F {ustar|pax|cpio|shar} Select archive format\n",
+static const char *long_help_msg =
+ "First option must be a mode specifier:\n"
+ " -c Create -r Add/Replace -t List -u Update -x Extract\n"
+ "Common Options:\n"
+ " -b # Use # 512-byte records per I/O block\n"
+ " -f <filename> Location of archive (default " _PATH_DEFTAPE ")\n"
+ " -v Verbose\n"
+ " -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"
+ " -F {ustar|pax|cpio|shar} Select archive format\n"
#ifdef HAVE_GETOPT_LONG
- " --exclude <pattern> Skip files that match pattern\n",
+ " --exclude <pattern> Skip files that match pattern\n"
#else
- " -W exclude=<pattern> Skip files that match pattern\n",
+ " -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",
- " <patterns> If specified, list only entries that match\n",
- "Extract: %p -x [options] [<patterns>]\n",
- " <patterns> If specified, extract only entries that match\n",
- " -k Keep (don't overwrite) existing files\n",
- " -m Don't restore modification times\n",
- " -O Write entries to stdout, don't restore to disk\n",
- " -p Restore permissions (including ACLs, owner, file flags)\n",
- NULL
-};
+ " C=<dir> Change to <dir> before processing remaining files\n"
+ " @<archive> Add entries from <archive> to output\n"
+ "List: %p -t [options] [<patterns>]\n"
+ " <patterns> If specified, list only entries that match\n"
+ "Extract: %p -x [options] [<patterns>]\n"
+ " <patterns> If specified, extract only entries that match\n"
+ " -k Keep (don't overwrite) existing files\n"
+ " -m Don't restore modification times\n"
+ " -O Write entries to stdout, don't restore to disk\n"
+ " -p Restore permissions (including ACLs, owner, file flags)\n";
/*
@@ -611,32 +609,25 @@ long_help(struct bsdtar *bsdtar)
{
const char *prog;
const char *p;
- const char **msg;
prog = bsdtar->progname;
fflush(stderr);
- if (strcmp(prog,"bsdtar")!=0)
- p = "(bsdtar)";
- else
- p = "";
+ p = (strcmp(prog,"bsdtar")!=0) ? "(bsdtar)" : "";
fprintf(stdout, "%s%s: manipulate archive files\n", prog, p);
- for (msg = long_help_msg; *msg != NULL; msg++) {
- for (p = *msg; p != NULL; p++) {
- if (*p == '\0')
- break;
- else if (*p == '%') {
- if (p[1] == 'p') {
- fputs(prog, stdout);
- p++;
- } else
- putchar('%');
+ for (p = long_help_msg; *p != '\0'; p++) {
+ if (*p == '%') {
+ if (p[1] == 'p') {
+ fputs(prog, stdout);
+ p++;
} else
- putchar(*p);
- }
+ putchar('%');
+ } else
+ putchar(*p);
}
+ fprintf(stdout, "\n%s\n", archive_version());
fflush(stderr);
}
diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h
index b52e5f1..a77ae47c 100644
--- a/usr.bin/tar/bsdtar.h
+++ b/usr.bin/tar/bsdtar.h
@@ -81,7 +81,7 @@ struct bsdtar {
char warned_lead_slash; /* Already displayed warning */
char next_line_is_dir; /* Used for -C parsing in -cT */
- /*
+ /*
* Data for various subsystems. Full definitions are located in
* the file where they are used.
*/
diff --git a/usr.bin/tar/bsdtar_platform.h b/usr.bin/tar/bsdtar_platform.h
index 752423b..a91cd9c 100644
--- a/usr.bin/tar/bsdtar_platform.h
+++ b/usr.bin/tar/bsdtar_platform.h
@@ -73,7 +73,7 @@
#endif
/* Linux */
-#ifdef LINUX
+#ifdef linux
#define _FILE_OFFSET_BITS 64 /* For a 64-bit off_t */
#include <stdint.h> /* for uintmax_t */
#define BSDTAR_FILESIZE_TYPE uintmax_t
diff --git a/usr.bin/tar/fts.c b/usr.bin/tar/fts.c
index 6cdc4d3..07bf972c 100644
--- a/usr.bin/tar/fts.c
+++ b/usr.bin/tar/fts.c
@@ -55,7 +55,7 @@ static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
#include "bsdtar_platform.h" /* bsdtar: need platform-specific definitions. */
__FBSDID("$FreeBSD$");
-#ifdef LINUX /* bsdtar: translate certain system calls to Linux names. */
+#ifdef linux /* bsdtar: translate certain system calls to Linux names. */
#define _open open
#define _close close
#define _fstat fstat
diff --git a/usr.bin/tar/matching.c b/usr.bin/tar/matching.c
index d73c5e5..ff0daee 100644
--- a/usr.bin/tar/matching.c
+++ b/usr.bin/tar/matching.c
@@ -43,7 +43,7 @@ struct match {
struct matching {
struct match *exclusions;
int exclusions_count;
- struct match *inclusions;
+ struct match *inclusions;
int inclusions_count;
int inclusions_unmatched_count;
};
diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c
index 34be304..2c71a76 100644
--- a/usr.bin/tar/read.c
+++ b/usr.bin/tar/read.c
@@ -65,17 +65,17 @@ tar_mode_x(struct bsdtar *bsdtar)
/*
* Handle 'x' and 't' modes.
*/
-void
+static void
read_archive(struct bsdtar *bsdtar, char mode)
{
struct archive *a;
struct archive_entry *entry;
int r;
- while (*bsdtar->argv) {
+ while (*bsdtar->argv) {
include(bsdtar, *bsdtar->argv);
bsdtar->argv++;
- }
+ }
if (bsdtar->names_from_file != NULL)
include_from_file(bsdtar, bsdtar->names_from_file);
@@ -232,7 +232,6 @@ list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
fprintf(out, "%s %d ", tmp, st->st_nlink);
/* Use uname if it's present, else uid. */
- w = 0;
p = archive_entry_uname(entry);
if (p && *p) {
sprintf(tmp, "%s ", p);
@@ -245,14 +244,13 @@ list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
fprintf(out, "%-*s", (int)bsdtar->u_width, tmp);
/* Use gname if it's present, else gid. */
- w = 0;
p = archive_entry_gname(entry);
- if (p && *p) {
+ if (p != NULL && p[0] != '\0') {
fprintf(out, "%s", p);
- w += strlen(p);
+ w = strlen(p);
} else {
sprintf(tmp, "%d", st->st_gid);
- w += strlen(tmp);
+ w = strlen(tmp);
fprintf(out, "%s", tmp);
}
@@ -304,7 +302,7 @@ struct security {
* generate warnings as appropriate, return non-zero to prevent
* this entry from being extracted.
*/
-int
+static int
security_problem(struct bsdtar *bsdtar, struct archive_entry *entry)
{
struct stat st;
@@ -355,8 +353,12 @@ security_problem(struct bsdtar *bsdtar, struct archive_entry *entry)
pn = name;
if (bsdtar->security == NULL) {
bsdtar->security = malloc(sizeof(*bsdtar->security));
+ if (bsdtar->security == NULL)
+ bsdtar_errc(bsdtar, 1, errno, "No Memory");
bsdtar->security->path_size = MAXPATHLEN + 1;
bsdtar->security->path = malloc(bsdtar->security->path_size);
+ if (bsdtar->security->path == NULL)
+ bsdtar_errc(bsdtar, 1, errno, "No Memory");
}
if (strlen(name) >= bsdtar->security->path_size) {
free(bsdtar->security->path);
@@ -390,12 +392,16 @@ security_problem(struct bsdtar *bsdtar, struct archive_entry *entry)
"Removing symlink %s",
bsdtar->security->path);
}
- unlink(bsdtar->security->path);
+ if (unlink(bsdtar->security->path))
+ bsdtar_errc(bsdtar, 1, errno,
+ "Unlink failed");
/* Symlink gone. No more problem! */
return (0);
} else if (bsdtar->option_unlink_first) {
/* User asked us to remove problems. */
- unlink(bsdtar->security->path);
+ if (unlink(bsdtar->security->path))
+ bsdtar_errc(bsdtar, 1, errno,
+ "Unlink failed");
} else {
bsdtar_warnc(bsdtar, 0,
"Cannot extract %s through symlink %s",
@@ -413,8 +419,7 @@ static void
cleanup_security(struct bsdtar *bsdtar)
{
if (bsdtar->security != NULL) {
- if (bsdtar->security->path != NULL)
- free(bsdtar->security->path);
+ free(bsdtar->security->path);
free(bsdtar->security);
}
}
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index c8cac23..787b734 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#ifdef LINUX
+#ifdef linux
#include <ext2fs/ext2_fs.h>
#include <sys/ioctl.h>
#endif
@@ -412,7 +412,11 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
pending_dir =
malloc(old_len + 1 + strlen(arg));
+ if (pending_dir == NULL)
+ bsdtar_errc(bsdtar, 1, errno,
+ "No Memory");
strcpy(pending_dir, old_pending);
+ free(old_pending);
if (pending_dir[old_len - 1] != '/') {
pending_dir[old_len] = '/';
old_len ++;
@@ -421,9 +425,12 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
} else {
/* Easy case: no previously-saved dir. */
pending_dir = strdup(arg);
+ if (pending_dir == NULL)
+ bsdtar_errc(bsdtar, 1, errno,
+ "No Memory");
}
} else {
- if (pending_dir &&
+ if (pending_dir != NULL &&
(*arg != '/' || (*arg == '@' && arg[1] != '/'))) {
/* Handle a deferred -C */
if (chdir(pending_dir)) {
@@ -565,7 +572,7 @@ write_heirarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
FTSENT *ftsent;
int ftsoptions;
char *fts_argv[2];
-#ifdef LINUX
+#ifdef linux
int fd, r;
unsigned long fflags;
#endif
@@ -635,7 +642,7 @@ write_heirarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
}
#endif
-#ifdef LINUX
+#ifdef linux
/*
* Linux has a nodump flag too but to read it
* we have to open() the dir and do an ioctl on it...
@@ -704,7 +711,7 @@ write_heirarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
break;
#endif
-#ifdef LINUX
+#ifdef linux
/*
* Linux has a nodump flag too but to read it
* we have to open() the file and do an ioctl on it...
@@ -771,7 +778,7 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st,
struct archive_entry *entry;
int e;
int fd;
-#ifdef LINUX
+#ifdef linux
int r;
unsigned long stflags;
#endif
@@ -842,7 +849,7 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st,
archive_entry_set_fflags(entry, st->st_flags, 0);
#endif
-#ifdef LINUX
+#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), r) >= 0 &&
@@ -851,7 +858,7 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st,
}
#endif
- archive_entry_copy_stat(entry, st);
+ archive_entry_copy_stat(entry, st);
setup_acls(bsdtar, entry, accpath);
/*
OpenPOWER on IntegriCloud