]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
IFC: libarchive_test now understands FreeBSD's /usr/obj convention.
authorTim Kientzle <kientzle@gmail.com>
Sat, 27 Dec 2008 22:03:55 +0000 (17:03 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 27 Dec 2008 22:03:55 +0000 (17:03 -0500)
SVN-Revision: 286

libarchive/test/main.c

index e39aa38099858f43fb633bebc8bbe3296dd4d9b2..9cdadd4e73097a35f92f57163e3e8bef621c2d16 100644 (file)
@@ -45,7 +45,7 @@
 #define        EXTRA_DUMP(x)   archive_error_string((struct archive *)(x))
 #define        EXTRA_VERSION   archive_version()
 #define KNOWNREF       "test_compat_gtar_1.tgz.uu"
-__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.15 2008/12/08 17:22:44 kientzle Exp $");
+__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.17 2008/12/21 00:13:50 kientzle Exp $");
 
 /*
  * "list.h" is simply created by "grep DEFINE_TEST"; it has
@@ -867,48 +867,59 @@ extract_reference_file(const char *name)
 static char *
 get_refdir(const char *tmpdir)
 {
-       char *ref, *p;
+       char tried[512] = { '\0' };
+       char buff[128];
+       char *pwd, *p;
 
        /* Get the current dir. */
        systemf("/bin/pwd > %s/refdir", tmpdir);
-       ref = slurpfile(NULL, "%s/refdir", tmpdir);
-       p = ref + strlen(ref);
-       while (p[-1] == '\n') {
-               --p;
-               *p = '\0';
-       }
+       pwd = slurpfile(NULL, "%s/refdir", tmpdir);
+       while (pwd[strlen(pwd) - 1] == '\n')
+               pwd[strlen(pwd) - 1] = '\0';
+       printf("PWD: %s\n", pwd);
        systemf("rm %s/refdir", tmpdir);
+
        /* Look for a known file. */
-       p = slurpfile(NULL, "%s/%s", ref, KNOWNREF);
-       if (p != NULL) {
-               free(p);
-               return (ref);
-       }
-       p = slurpfile(NULL, "%s/test/%s", ref, KNOWNREF);
-       if (p != NULL) {
-               free(p);
-               p = malloc(strlen(ref) + strlen("/test") + 1);
-               strcpy(p, ref);
-               strcat(p, "/test");
-               free(ref);
-               return (p);
-       }
-       p = slurpfile(NULL, "%s/%s/test/%s", ref, LIBRARY, KNOWNREF);
-       if (p != NULL) {
-               free(p);
-               p = malloc(strlen(ref) + 1 + strlen(LIBRARY) + strlen("/test") + 1);
-               strcpy(p, ref);
-               strcat(p, "/");
-               strcat(p, LIBRARY);
-               strcat(p, "/test");
-               free(ref);
-               return (p);
+       snprintf(buff, sizeof(buff), "%s", pwd);
+       p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+       if (p != NULL) goto success;
+       strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+       strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+       snprintf(buff, sizeof(buff), "%s/test", pwd);
+       p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+       if (p != NULL) goto success;
+       strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+       strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+       snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
+       p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+       if (p != NULL) goto success;
+       strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+       strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+       if (memcmp(pwd, "/usr/obj", 8) == 0) {
+               snprintf(buff, sizeof(buff), "%s", pwd + 8);
+               p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+               if (p != NULL) goto success;
+               strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+               strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
+
+               snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
+               p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
+               if (p != NULL) goto success;
+               strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
+               strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
        }
+
        printf("Unable to locate known reference file %s\n", KNOWNREF);
-       printf("  Checked directory %s\n", ref);
-       printf("  Checked directory %s/test\n", ref);
-       printf("  Checked directory %s/%s/test\n", ref, LIBRARY);
+       printf("  Checked following directories:\n%s\n", tried);
        exit(1);
+
+success:
+       free(p);
+       free(pwd);
+       return strdup(buff);
 }
 
 int main(int argc, char **argv)