From 0429b2a941faba569b2f97a81f8ca0eeb652b12c Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Thu, 18 Jun 2009 01:11:18 -0400 Subject: [PATCH] Make bsdtar_test and bsdcpio_test aware of TMPDIR/TMP/TEMPDIR environment variables. SVN-Revision: 1170 --- cpio/test/main.c | 15 ++++++++++++++- tar/test/main.c | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cpio/test/main.c b/cpio/test/main.c index 08a010b70..e8b8a3d61 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -990,6 +990,7 @@ int main(int argc, char **argv) char *testprg; #endif const char *opt_arg, *progname, *p; + char *tmp; char tmpdir[256]; char tmpdir_timestamp[256]; @@ -1018,6 +1019,17 @@ int main(int argc, char **argv) testprog = getenv(ENVBASE); #endif + if (getenv("TMPDIR") != NULL) + tmp = getenv("TMPDIR"); + else if (getenv("TMP") != NULL) + tmp = getenv("TMP"); + else if (getenv("TEMP") != NULL) + tmp = getenv("TEMP"); + else if (getenv("TEMPDIR") != NULL) + tmp = getenv("TEMPDIR"); + else + tmp = "/tmp"; + /* Allow -d to be controlled through the environment. */ if (getenv(ENVBASE "_DEBUG") != NULL) dump_on_failure = 1; @@ -1112,7 +1124,8 @@ int main(int argc, char **argv) strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), "%Y-%m-%dT%H.%M.%S", localtime(&now)); - sprintf(tmpdir, "/tmp/%s.%s-%03d", progname, tmpdir_timestamp, i); + sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, + tmpdir_timestamp, i); if (mkdir(tmpdir,0755) == 0) break; if (errno == EEXIST) diff --git a/tar/test/main.c b/tar/test/main.c index 5bf93de9f..5ca1c45bf 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -908,6 +908,7 @@ int main(int argc, char **argv) char *testprg; #endif const char *opt_arg, *progname, *p; + char *tmp; char tmpdir[256]; char tmpdir_timestamp[256]; @@ -930,6 +931,17 @@ int main(int argc, char **argv) testprog = getenv(ENVBASE); #endif + if (getenv("TMPDIR") != NULL) + tmp = getenv("TMPDIR"); + else if (getenv("TMP") != NULL) + tmp = getenv("TMP"); + else if (getenv("TEMP") != NULL) + tmp = getenv("TEMP"); + else if (getenv("TEMPDIR") != NULL) + tmp = getenv("TEMPDIR"); + else + tmp = "/tmp"; + /* Allow -d to be controlled through the environment. */ if (getenv(ENVBASE "_DEBUG") != NULL) dump_on_failure = 1; @@ -1025,7 +1037,8 @@ int main(int argc, char **argv) strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), "%Y-%m-%dT%H.%M.%S", localtime(&now)); - sprintf(tmpdir, "/tmp/%s.%s-%03d", progname, tmpdir_timestamp, i); + sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, + tmpdir_timestamp, i); if (mkdir(tmpdir,0755) == 0) break; if (errno == EEXIST) -- 2.47.3