Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Feb 2010 01:26:45 +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: r203589 - head/usr.bin/tar
Message-ID:  <201002070126.o171Qj6u096977@svn.freebsd.org>

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

Log:
  Various portability workarounds for non-FreeBSD platforms.

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

Modified: head/usr.bin/tar/bsdtar.c
==============================================================================
--- head/usr.bin/tar/bsdtar.c	Sun Feb  7 01:22:55 2010	(r203588)
+++ head/usr.bin/tar/bsdtar.c	Sun Feb  7 01:26:45 2010	(r203589)
@@ -82,6 +82,10 @@ __FBSDID("$FreeBSD$");
 #define	_PATH_DEFTAPE "/dev/tape"
 #endif
 
+#ifdef __MINGW32__
+int _CRT_glob = 0; /* Disable broken CRT globbing. */
+#endif
+
 #if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1))
 static volatile int siginfo_occurred;
 

Modified: head/usr.bin/tar/write.c
==============================================================================
--- head/usr.bin/tar/write.c	Sun Feb  7 01:22:55 2010	(r203588)
+++ head/usr.bin/tar/write.c	Sun Feb  7 01:26:45 2010	(r203589)
@@ -139,6 +139,23 @@ static int		 write_file_data(struct bsdt
 static void		 write_hierarchy(struct bsdtar *, struct archive *,
 			     const char *);
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+/* Not a full lseek() emulation, but enough for our needs here. */
+static int
+seek_file(int fd, int64_t offset, int whence)
+{
+	LARGE_INTEGER distance;
+	(void)whence; /* UNUSED */
+	distance.QuadPart = offset;
+	return (SetFilePointerEx((HANDLE)_get_osfhandle(fd),
+		distance, NULL, FILE_BEGIN) ? 1 : -1);
+}
+#define open _open
+#define close _close
+#define read _read
+#define lseek seek_file
+#endif
+
 void
 tar_mode_c(struct bsdtar *bsdtar)
 {
@@ -236,7 +253,11 @@ tar_mode_r(struct bsdtar *bsdtar)
 
 	format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
 
+#if defined(__BORLANDC__)
+	bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT);
+#else
 	bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666);
+#endif
 	if (bsdtar->fd < 0)
 		bsdtar_errc(1, errno,
 		    "Cannot open %s", bsdtar->filename);
@@ -451,12 +472,7 @@ write_archive(struct archive *a, struct 
 				    arg + 1) != 0)
 					break;
 			} else
-#if defined(_WIN32) && !defined(__CYGWIN__)
-				write_hierarchy_win(bsdtar, a, arg,
-				    write_hierarchy);
-#else
 				write_hierarchy(bsdtar, a, arg);
-#endif
 		}
 		bsdtar->argv++;
 	}
@@ -786,6 +802,22 @@ write_hierarchy(struct bsdtar *bsdtar, s
 		 * calling this so we can pass in an fd and shorten
 		 * the race to query metadata.  The linkify dance
 		 * makes this more complex than it might sound. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+		/* TODO: tree.c uses stat(), which is badly broken
+		 * on Windows.  To fix this, we should
+		 * deprecate tree_current_stat() and provide a new
+		 * call tree_populate_entry(t, entry).  This call
+		 * would use stat() internally on POSIX and
+		 * GetInfoByFileHandle() internally on Windows.
+		 * This would be another step towards a tree-walker
+		 * that can be integrated deep into libarchive.
+		 * For now, just set st to NULL on Windows;
+		 * archive_read_disk_entry_from_file() should
+		 * be smart enough to use platform-appropriate
+		 * ways to probe file information.
+		 */
+		st = NULL;
+#endif
 		r = archive_read_disk_entry_from_file(bsdtar->diskreader,
 		    entry, -1, st);
 		if (r != ARCHIVE_OK)
@@ -801,7 +833,7 @@ write_hierarchy(struct bsdtar *bsdtar, s
 		 * If this file/dir is flagged "nodump" and we're
 		 * honoring such flags, skip this file/dir.
 		 */
-#ifdef HAVE_STRUCT_STAT_ST_FLAGS
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
 		/* BSD systems store flags in struct stat */
 		if (bsdtar->option_honor_nodump &&
 		    (lst->st_flags & UF_NODUMP))
@@ -1092,4 +1124,11 @@ test_for_append(struct bsdtar *bsdtar)
 		bsdtar_errc(1, 0,
 		    "Cannot append to %s: not a regular file.",
 		    bsdtar->filename);
+
+/* Is this an appropriate check here on Windows? */
+/*
+	if (GetFileType(handle) != FILE_TYPE_DISK)
+		bsdtar_errc(1, 0, "Cannot append");
+*/
+
 }



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