From: Tim Kientzle Date: Fri, 25 Jul 2008 22:24:02 +0000 (-0400) Subject: Make ad-hoc use of the test program a little simpler by X-Git-Tag: v2.6.0~135 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=12cb13f152bf6cfcb431ee428bba622d37124abd;p=thirdparty%2Flibarchive.git Make ad-hoc use of the test program a little simpler by searching a few standard locations for the reference files and aborting if we can't find them. SVN-Revision: 157 --- diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 83d3147d9..f8d4ebd8d 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -40,9 +40,11 @@ * The next few lines are the only differences. */ #undef PROGRAM /* Testing a library, not a program. */ +#define LIBRARY "libarchive" #define ENVBASE "LIBARCHIVE" /* Prefix for environment variables. */ #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.13 2008/06/15 10:35:22 kientzle Exp $"); /* @@ -841,6 +843,52 @@ extract_reference_file(const char *name) fclose(in); } +static char * +get_refdir(const char *tmpdir) +{ + char *ref, *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'; + } + 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); + } + 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); + exit(1); +} int main(int argc, char **argv) { @@ -940,18 +988,11 @@ int main(int argc, char **argv) /* * If the user didn't specify a directory for locating - * reference files, use the current directory for that. + * reference files, try to find the reference files in + * the "usual places." */ - if (refdir == NULL) { - systemf("/bin/pwd > %s/refdir", tmpdir); - refdir = refdir_alloc = slurpfile(NULL, "%s/refdir", tmpdir); - p = refdir + strlen(refdir); - while (p[-1] == '\n') { - --p; - *p = '\0'; - } - systemf("rm %s/refdir", tmpdir); - } + if (refdir == NULL) + refdir = refdir_alloc = get_refdir(tmpdir); /* * Banner with basic information.