summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2009-04-17 03:36:07 +0000
committerkientzle <kientzle@FreeBSD.org>2009-04-17 03:36:07 +0000
commit1d7225113365f424ee3017bc92cd954156fb6b0f (patch)
tree209743ef1faf839b48a6d5c8b1eefaef05654532 /usr.bin/tar
parent3b75ab9db91434d792b4f5c69eedcf87a6dfbd62 (diff)
downloadFreeBSD-src-1d7225113365f424ee3017bc92cd954156fb6b0f.zip
FreeBSD-src-1d7225113365f424ee3017bc92cd954156fb6b0f.tar.gz
Merge from libarchive.googlecode.com: Numerous Windows-specific build tweaks.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/bsdtar_platform.h4
-rw-r--r--usr.bin/tar/test/main.c18
-rw-r--r--usr.bin/tar/test/test.h12
-rw-r--r--usr.bin/tar/test/test_0.c2
-rw-r--r--usr.bin/tar/test/test_basic.c14
-rw-r--r--usr.bin/tar/test/test_copy.c4
-rw-r--r--usr.bin/tar/test/test_patterns.c2
-rw-r--r--usr.bin/tar/test/test_strip_components.c2
-rw-r--r--usr.bin/tar/test/test_symlink_dir.c12
-rw-r--r--usr.bin/tar/tree.c40
10 files changed, 58 insertions, 52 deletions
diff --git a/usr.bin/tar/bsdtar_platform.h b/usr.bin/tar/bsdtar_platform.h
index 828eb38..fb14442 100644
--- a/usr.bin/tar/bsdtar_platform.h
+++ b/usr.bin/tar/bsdtar_platform.h
@@ -164,7 +164,9 @@
#define __LA_DEAD
#endif
-#ifdef _WIN32
+#if defined(__CYGWIN__)
+#include "bsdtar_cygwin.h"
+#elif defined(_WIN32) /* && !__CYGWIN__ */
#include "bsdtar_windows.h"
#else
#define bsdtar_is_privileged(bsdtar) (bsdtar->user_uid == 0)
diff --git a/usr.bin/tar/test/main.c b/usr.bin/tar/test/main.c
index 968cb35..041b7a0 100644
--- a/usr.bin/tar/test/main.c
+++ b/usr.bin/tar/test/main.c
@@ -56,11 +56,7 @@ __FBSDID("$FreeBSD$");
*/
#undef DEFINE_TEST
#define DEFINE_TEST(name) void name(void);
-#ifdef LIST_H
-#include LIST_H
-#else
#include "list.h"
-#endif
/* Interix doesn't define these in a standard header. */
#if __INTERIX__
@@ -754,11 +750,7 @@ slurpfile(size_t * sizep, const char *fmt, ...)
#undef DEFINE_TEST
#define DEFINE_TEST(n) { n, #n },
struct { void (*func)(void); const char *name; } tests[] = {
-#ifdef LIST_H
- #include LIST_H
-#else
#include "list.h"
-#endif
};
/*
@@ -809,7 +801,7 @@ static int test_run(int i, const char *tmpdir)
/* If there were no failures, we can remove the work dir. */
if (failures == failures_before) {
if (!keep_temp_files && chdir(tmpdir) == 0) {
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
systemf("rmdir /S /Q %s", tests[i].name);
#else
systemf("rm -rf %s", tests[i].name);
@@ -912,7 +904,7 @@ int main(int argc, char **argv)
int i, tests_run = 0, tests_failed = 0, opt;
time_t now;
char *refdir_alloc = NULL;
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
char *testprg;
#endif
const char *opt_arg, *progname, *p;
@@ -921,8 +913,10 @@ int main(int argc, char **argv)
(void)argc; /* UNUSED */
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
/* Make sure open() function will be used with a binary mode. */
+ /* on cygwin, we need something similar, but instead link against */
+ /* a special startup object, binmode.o */
_set_fmode(_O_BINARY);
#endif
/*
@@ -1014,7 +1008,7 @@ int main(int argc, char **argv)
if (testprog == NULL)
usage(progname);
#endif
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
/*
* command.com cannot accept the command used '/' with drive
* name such as c:/xxx/command.exe when use '|' pipe handling.
diff --git a/usr.bin/tar/test/test.h b/usr.bin/tar/test/test.h
index 27a6935..6a1e1e8 100644
--- a/usr.bin/tar/test/test.h
+++ b/usr.bin/tar/test/test.h
@@ -37,7 +37,7 @@
#elif defined(__FreeBSD__)
/* Building as part of FreeBSD system requires a pre-built config.h. */
#include "config_freebsd.h"
-#elif defined(_WIN32)
+#elif defined(_WIN32) && !defined(__CYGWIN__)
/* Win32 can't run the 'configure' script. */
#include "config_windows.h"
#else
@@ -45,7 +45,7 @@
#error Oops: No config.h and no pre-built configuration in test.h.
#endif
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
#include <dirent.h>
#else
#define dirent direct
@@ -58,7 +58,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h>
#endif
#include <wchar.h>
@@ -67,12 +67,16 @@
#include <dmalloc.h>
#endif
-/* No non-FreeBSD platform will have __FBSDID, so just define it here. */
#ifdef __FreeBSD__
#include <sys/cdefs.h> /* For __FBSDID */
#else
+/* Some non-FreeBSD platforms such as newlib-derived ones like
+ * cygwin, have __FBSDID, so this definition must be guarded.
+ */
+#ifndef __FBSDID
#define __FBSDID(a) /* null */
#endif
+#endif
/*
* Redefine DEFINE_TEST for use in defining the test functions.
diff --git a/usr.bin/tar/test/test_0.c b/usr.bin/tar/test/test_0.c
index 1bafc05..d224daa 100644
--- a/usr.bin/tar/test/test_0.c
+++ b/usr.bin/tar/test/test_0.c
@@ -29,7 +29,7 @@ __FBSDID("$FreeBSD$");
* This first test does basic sanity checks on the environment. For
* most of these, we just exit on failure.
*/
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
#define DEV_NULL "/dev/null"
#else
#define DEV_NULL "NUL"
diff --git a/usr.bin/tar/test/test_basic.c b/usr.bin/tar/test/test_basic.c
index b454723..3fad754 100644
--- a/usr.bin/tar/test/test_basic.c
+++ b/usr.bin/tar/test/test_basic.c
@@ -31,7 +31,7 @@ basic_tar(const char *target, const char *pack_options,
const char *unpack_options, const char *flist)
{
struct stat st, st2;
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
char buff[128];
#endif
int r;
@@ -39,7 +39,7 @@ basic_tar(const char *target, const char *pack_options,
assertEqualInt(0, mkdir(target, 0775));
/* Use the tar program to create an archive. */
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
r = systemf("%s cf - %s `cat %s` >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target);
#else
r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target);
@@ -72,7 +72,7 @@ basic_tar(const char *target, const char *pack_options,
assertEqualInt(r, 0);
if (r == 0) {
assert(S_ISREG(st.st_mode));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(0644, st.st_mode & 0777);
#else
assertEqualInt(0600, st.st_mode & 0700);
@@ -88,7 +88,7 @@ basic_tar(const char *target, const char *pack_options,
assertEqualInt(r, 0);
if (r == 0) {
assert(S_ISREG(st2.st_mode));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(0644, st2.st_mode & 0777);
#else
assertEqualInt(0600, st2.st_mode & 0700);
@@ -102,7 +102,7 @@ basic_tar(const char *target, const char *pack_options,
assertEqualInt(st.st_ino, st2.st_ino);
}
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
/* Symlink */
r = lstat("symlink", &st);
failure("Failed to stat file %s/symlink, errno=%d", target, errno);
@@ -125,7 +125,7 @@ basic_tar(const char *target, const char *pack_options,
if (r == 0) {
assertEqualInt(r, 0);
assert(S_ISDIR(st.st_mode));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(0775, st.st_mode & 0777);
#else
assertEqualInt(0700, st.st_mode & 0700);
@@ -170,7 +170,7 @@ DEFINE_TEST(test_basic)
/* All done. */
close(filelist);
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
flist = "filelist";
#else
flist = "file linkfile symlink dir";
diff --git a/usr.bin/tar/test/test_copy.c b/usr.bin/tar/test/test_copy.c
index 9aff916..120d9f3 100644
--- a/usr.bin/tar/test/test_copy.c
+++ b/usr.bin/tar/test/test_copy.c
@@ -64,7 +64,7 @@ create_tree(void)
buff2[0] = 'm';
assertEqualInt(0, link(buff, buff2));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
/* Create a symlink named "s/abcdef..." to the above. */
strcpy(buff2 + 3, buff);
buff[0] = 's';
@@ -156,7 +156,7 @@ verify_tree(int limit)
}
}
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
/*
* Symlink text doesn't include the 'original/' prefix,
* so the limit here is 100 characters.
diff --git a/usr.bin/tar/test/test_patterns.c b/usr.bin/tar/test/test_patterns.c
index 9d9cc60..66a4ecf 100644
--- a/usr.bin/tar/test/test_patterns.c
+++ b/usr.bin/tar/test/test_patterns.c
@@ -61,7 +61,7 @@ DEFINE_TEST(test_patterns)
r = systemf("%s tf %s /tmp/foo/bar > tar2a.out 2> tar2a.err",
testprog, reffile2);
assertEqualInt(r, 0);
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
p = "/tmp/foo/bar/\n/tmp/foo/bar/baz\n";
#else
p = "/tmp/foo/bar/\r\n/tmp/foo/bar/baz\r\n";
diff --git a/usr.bin/tar/test/test_strip_components.c b/usr.bin/tar/test/test_strip_components.c
index 6fc4b30..38e0e48 100644
--- a/usr.bin/tar/test/test_strip_components.c
+++ b/usr.bin/tar/test/test_strip_components.c
@@ -64,7 +64,7 @@ DEFINE_TEST(test_strip_components)
failure("d0/d1/ is too short and should not get restored");
assertEqualInt(-1, lstat("target/d1", &st));
failure("d0/d1/s2 is a symlink to something that won't be extracted");
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(-1, stat("target/s2", &st));
#else
skipping("symlink with stat()");
diff --git a/usr.bin/tar/test/test_symlink_dir.c b/usr.bin/tar/test/test_symlink_dir.c
index d5c493d..356f17c 100644
--- a/usr.bin/tar/test/test_symlink_dir.c
+++ b/usr.bin/tar/test/test_symlink_dir.c
@@ -48,7 +48,7 @@ mkfile(const char *name, int mode, const char *contents, ssize_t size)
DEFINE_TEST(test_symlink_dir)
{
struct stat st;
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
struct stat st2;
#endif
int oldumask;
@@ -78,7 +78,7 @@ DEFINE_TEST(test_symlink_dir)
assertEqualInt(0, mkdir("dest1", 0755));
/* "dir" is a symlink to an existing "real_dir" */
assertEqualInt(0, mkdir("dest1/real_dir", 0755));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(0, symlink("real_dir", "dest1/dir"));
/* "dir2" is a symlink to a non-existing "real_dir2" */
assertEqualInt(0, symlink("real_dir2", "dest1/dir2"));
@@ -91,7 +91,7 @@ DEFINE_TEST(test_symlink_dir)
/* "file" is a symlink to existing "real_file" */
assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7));
assertEqualInt(0, symlink("real_file", "dest1/file"));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
/* "file2" is a symlink to non-existing "real_file2" */
assertEqualInt(0, symlink("real_file2", "dest1/file2"));
#else
@@ -126,7 +126,7 @@ DEFINE_TEST(test_symlink_dir)
assertEqualInt(0, mkdir("dest2", 0755));
/* "dir" is a symlink to existing "real_dir" */
assertEqualInt(0, mkdir("dest2/real_dir", 0755));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(0, symlink("real_dir", "dest2/dir"));
/* "dir2" is a symlink to a non-existing "real_dir2" */
assertEqualInt(0, symlink("real_dir2", "dest2/dir2"));
@@ -139,7 +139,7 @@ DEFINE_TEST(test_symlink_dir)
/* "file" is a symlink to existing "real_file" */
assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9));
assertEqualInt(0, symlink("real_file", "dest2/file"));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
/* "file2" is a symlink to non-existing "real_file2" */
assertEqualInt(0, symlink("real_file2", "dest2/file2"));
#else
@@ -150,7 +150,7 @@ DEFINE_TEST(test_symlink_dir)
/* dest2/dir symlink should be followed */
assertEqualInt(0, lstat("dest2/dir", &st));
failure("tar -xP removed symlink instead of following it");
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__CYGWIN__)
if (assert(S_ISLNK(st.st_mode))) {
/* Only verify what the symlink points to if it
* really is a symlink. */
diff --git a/usr.bin/tar/tree.c b/usr.bin/tar/tree.c
index f47330b..f70b6d5 100644
--- a/usr.bin/tar/tree.c
+++ b/usr.bin/tar/tree.c
@@ -82,9 +82,12 @@ struct tree_entry {
size_t dirname_length;
dev_t dev;
ino_t ino;
+#ifdef HAVE_FCHDIR
int fd;
-#ifdef _WIN32
+#elif defined(_WIN32) && !defined(__CYGWIN__)
char *fullpath;
+#else
+#error fchdir function required.
#endif
int flags;
};
@@ -102,8 +105,9 @@ struct tree {
struct tree_entry *stack;
struct tree_entry *current;
DIR *d;
+#ifdef HAVE_FCHDIR
int initialDirFd;
-#ifdef _WIN32
+#elif defined(_WIN32) && !defined(__CYGWIN__)
char *initialDir;
#endif
int flags;
@@ -169,8 +173,9 @@ tree_push(struct tree *t, const char *path)
memset(te, 0, sizeof(*te));
te->next = t->stack;
t->stack = te;
+#ifdef HAVE_FCHDIR
te->fd = -1;
-#ifdef _WIN32
+#elif defined(_WIN32) && !defined(__CYGWIN__)
te->fullpath = NULL;
#endif
te->name = strdup(path);
@@ -222,10 +227,10 @@ tree_open(const char *path)
t = malloc(sizeof(*t));
memset(t, 0, sizeof(*t));
tree_append(t, path, strlen(path));
+#ifdef HAVE_FCHDIR
t->initialDirFd = open(".", O_RDONLY);
-#ifdef _WIN32
- if (t->initialDirFd >= 0)
- t->initialDir = getcwd(NULL, 0);
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ t->initialDir = getcwd(NULL, 0);
#endif
/*
* During most of the traversal, items are set up and then
@@ -254,16 +259,15 @@ tree_ascend(struct tree *t)
t->tree_errno = errno;
r = TREE_ERROR_FATAL;
}
-#endif
-#ifdef _WIN32
- if (te->fullpath != NULL && chdir(te->fullpath) != 0) {
+ close(te->fd);
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ if (chdir(te->fullpath) != 0) {
t->tree_errno = errno;
r = TREE_ERROR_FATAL;
}
free(te->fullpath);
te->fullpath = NULL;
#endif
- close(te->fd);
t->openCount--;
} else {
if (chdir("..") != 0) {
@@ -354,8 +358,9 @@ tree_next(struct tree *t)
t->stack->flags &= ~needsPreVisit;
/* If it is a link, set up fd for the ascent. */
if (t->stack->flags & isDirLink) {
+#ifdef HAVE_FCHDIR
t->stack->fd = open(".", O_RDONLY);
-#ifdef _WIN32
+#elif defined(_WIN32) && !defined(__CYGWIN__)
t->stack->fullpath = getcwd(NULL, 0);
#endif
t->openCount++;
@@ -580,17 +585,18 @@ tree_close(struct tree *t)
if (t->buff)
free(t->buff);
/* chdir() back to where we started. */
- if (t->initialDirFd >= 0) {
#ifdef HAVE_FCHDIR
+ if (t->initialDirFd >= 0) {
fchdir(t->initialDirFd);
-#endif
-#ifdef _WIN32
+ close(t->initialDirFd);
+ t->initialDirFd = -1;
+ }
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ if (t->initialDir != NULL) {
chdir(t->initialDir);
free(t->initialDir);
t->initialDir = NULL;
-#endif
- close(t->initialDirFd);
- t->initialDirFd = -1;
}
+#endif
free(t);
}
OpenPOWER on IntegriCloud