From owner-svn-src-head@FreeBSD.ORG Fri Apr 17 03:36:08 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5213E106566C; Fri, 17 Apr 2009 03:36:08 +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 3F94A8FC08; Fri, 17 Apr 2009 03:36:08 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n3H3a86q006147; Fri, 17 Apr 2009 03:36:08 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n3H3a72i006136; Fri, 17 Apr 2009 03:36:07 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <200904170336.n3H3a72i006136@svn.freebsd.org> From: Tim Kientzle Date: Fri, 17 Apr 2009 03:36:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r191187 - in head/usr.bin/tar: . test X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Apr 2009 03:36:08 -0000 Author: kientzle Date: Fri Apr 17 03:36:07 2009 New Revision: 191187 URL: http://svn.freebsd.org/changeset/base/191187 Log: Merge from libarchive.googlecode.com: Numerous Windows-specific build tweaks. Modified: head/usr.bin/tar/bsdtar_platform.h head/usr.bin/tar/test/main.c head/usr.bin/tar/test/test.h head/usr.bin/tar/test/test_0.c head/usr.bin/tar/test/test_basic.c head/usr.bin/tar/test/test_copy.c head/usr.bin/tar/test/test_patterns.c head/usr.bin/tar/test/test_strip_components.c head/usr.bin/tar/test/test_symlink_dir.c head/usr.bin/tar/tree.c Modified: head/usr.bin/tar/bsdtar_platform.h ============================================================================== --- head/usr.bin/tar/bsdtar_platform.h Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/bsdtar_platform.h Fri Apr 17 03:36:07 2009 (r191187) @@ -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) Modified: head/usr.bin/tar/test/main.c ============================================================================== --- head/usr.bin/tar/test/main.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/main.c Fri Apr 17 03:36:07 2009 (r191187) @@ -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 *fm #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 *t /* 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. Modified: head/usr.bin/tar/test/test.h ============================================================================== --- head/usr.bin/tar/test/test.h Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test.h Fri Apr 17 03:36:07 2009 (r191187) @@ -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 #else #define dirent direct @@ -58,7 +58,7 @@ #include #include #include -#ifndef _WIN32 +#if !defined(_WIN32) || defined(__CYGWIN__) #include #endif #include @@ -67,12 +67,16 @@ #include #endif -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ #ifdef __FreeBSD__ #include /* 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. Modified: head/usr.bin/tar/test/test_0.c ============================================================================== --- head/usr.bin/tar/test/test_0.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test_0.c Fri Apr 17 03:36:07 2009 (r191187) @@ -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" Modified: head/usr.bin/tar/test/test_basic.c ============================================================================== --- head/usr.bin/tar/test/test_basic.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test_basic.c Fri Apr 17 03:36:07 2009 (r191187) @@ -31,7 +31,7 @@ basic_tar(const char *target, const char 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 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 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 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 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 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"; Modified: head/usr.bin/tar/test/test_copy.c ============================================================================== --- head/usr.bin/tar/test/test_copy.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test_copy.c Fri Apr 17 03:36:07 2009 (r191187) @@ -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. Modified: head/usr.bin/tar/test/test_patterns.c ============================================================================== --- head/usr.bin/tar/test/test_patterns.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test_patterns.c Fri Apr 17 03:36:07 2009 (r191187) @@ -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"; Modified: head/usr.bin/tar/test/test_strip_components.c ============================================================================== --- head/usr.bin/tar/test/test_strip_components.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test_strip_components.c Fri Apr 17 03:36:07 2009 (r191187) @@ -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()"); Modified: head/usr.bin/tar/test/test_symlink_dir.c ============================================================================== --- head/usr.bin/tar/test/test_symlink_dir.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/test/test_symlink_dir.c Fri Apr 17 03:36:07 2009 (r191187) @@ -48,7 +48,7 @@ mkfile(const char *name, int mode, const 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. */ Modified: head/usr.bin/tar/tree.c ============================================================================== --- head/usr.bin/tar/tree.c Fri Apr 17 02:52:23 2009 (r191186) +++ head/usr.bin/tar/tree.c Fri Apr 17 03:36:07 2009 (r191187) @@ -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 *pa 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); }