Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Feb 2010 01:35:28 +0000 (UTC)
From:      Tim Kientzle <kientzle@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r203590 - head/usr.bin/tar
Message-ID:  <201002070135.o171ZSrM098925@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kientzle
Date: Sun Feb  7 01:35:28 2010
New Revision: 203590
URL: http://svn.freebsd.org/changeset/base/203590

Log:
  Style & Portability:  Use archive_entry methods to examine
  file information, change some functions to static, remove
  some unused headers.

Modified:
  head/usr.bin/tar/read.c
  head/usr.bin/tar/write.c

Modified: head/usr.bin/tar/read.c
==============================================================================
--- head/usr.bin/tar/read.c	Sun Feb  7 01:26:45 2010	(r203589)
+++ head/usr.bin/tar/read.c	Sun Feb  7 01:35:28 2010	(r203590)
@@ -29,11 +29,6 @@ __FBSDID("$FreeBSD$");
 #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
@@ -346,7 +341,6 @@ read_archive(struct bsdtar *bsdtar, char
 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;
@@ -354,8 +348,6 @@ list_item_verbose(struct bsdtar *bsdtar,
 	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
@@ -371,12 +363,13 @@ list_item_verbose(struct bsdtar *bsdtar,
 		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);
@@ -390,7 +383,8 @@ list_item_verbose(struct bsdtar *bsdtar,
 		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);
 	}
@@ -400,37 +394,30 @@ list_item_verbose(struct bsdtar *bsdtar,
 	 * 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;
+	tim = archive_entry_mtime(entry);
+#define HALF_YEAR (time_t)365 * 86400 / 2
 #if defined(_WIN32) && !defined(__CYGWIN__)
-	/* Windows' strftime function does not support %e format. */
-	if (abs(tim - now) > (365/2)*86400)
-		fmt = bsdtar->day_first ? "%d %b  %Y" : "%b %d  %Y";
-	else
-		fmt = bsdtar->day_first ? "%d %b %H:%M" : "%b %d %H:%M";
+#define DAY_FMT  "%d"  /* Windows' strftime function does not support %e format. */
 #else
-	if (abs(tim - now) > (365/2)*86400)
-		fmt = bsdtar->day_first ? "%e %b  %Y" : "%b %e  %Y";
-	else
-		fmt = bsdtar->day_first ? "%e %b %H:%M" : "%b %e %H:%M";
+#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 ? 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));
@@ -439,6 +426,6 @@ list_item_verbose(struct bsdtar *bsdtar,
 	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));
 }

Modified: head/usr.bin/tar/write.c
==============================================================================
--- head/usr.bin/tar/write.c	Sun Feb  7 01:26:45 2010	(r203589)
+++ head/usr.bin/tar/write.c	Sun Feb  7 01:35:28 2010	(r203590)
@@ -44,9 +44,6 @@ __FBSDID("$FreeBSD$");
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
-#ifdef HAVE_FNMATCH_H
-#include <fnmatch.h>
-#endif
 #ifdef HAVE_GRP_H
 #include <grp.h>
 #endif
@@ -514,7 +511,7 @@ cleanup:
  * 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;
@@ -679,7 +676,7 @@ write_hierarchy(struct bsdtar *bsdtar, s
 		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; /* info to use for this entry */
@@ -882,7 +879,7 @@ write_hierarchy(struct bsdtar *bsdtar, s
 			    archive_entry_pathname(entry));
 
 		/* Non-regular files get archived with zero size. */
-		if (!S_ISREG(st->st_mode))
+		if (archive_entry_filetype(entry) != AE_IFREG)
 			archive_entry_set_size(entry, 0);
 
 		archive_entry_linkify(bsdtar->resolver, &entry, &spare_entry);
@@ -1016,7 +1013,7 @@ write_file_data(struct bsdtar *bsdtar, s
 /*
  * 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;
@@ -1103,7 +1100,7 @@ add_dir_list(struct bsdtar *bsdtar, cons
 	}
 }
 
-void
+static void
 test_for_append(struct bsdtar *bsdtar)
 {
 	struct stat s;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002070135.o171ZSrM098925>