From owner-svn-src-all@FreeBSD.ORG Sun Dec 21 00:13:51 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3BA4F1065675; Sun, 21 Dec 2008 00:13:51 +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 2A9608FC14; Sun, 21 Dec 2008 00:13:51 +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 mBL0DpD0017777; Sun, 21 Dec 2008 00:13:51 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBL0Dpgs017776; Sun, 21 Dec 2008 00:13:51 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <200812210013.mBL0Dpgs017776@svn.freebsd.org> From: Tim Kientzle Date: Sun, 21 Dec 2008 00:13:51 +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: r186366 - head/lib/libarchive/test X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Dec 2008 00:13:51 -0000 Author: kientzle Date: Sun Dec 21 00:13:50 2008 New Revision: 186366 URL: http://svn.freebsd.org/changeset/base/186366 Log: Teach get_refdir() about FreeBSD's /usr/obj convention. In development, I run libarchive_test frequently by hand and it gets tedious having to specify a suitable -r path all of the time. Modified: head/lib/libarchive/test/main.c Modified: head/lib/libarchive/test/main.c ============================================================================== --- head/lib/libarchive/test/main.c Sat Dec 20 22:11:31 2008 (r186365) +++ head/lib/libarchive/test/main.c Sun Dec 21 00:13:50 2008 (r186366) @@ -846,48 +846,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)