diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2010-09-24 18:54:37 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2010-09-24 19:25:06 +0100 |
commit | c9c0ac7d362fd19214c2c5e5bb7dcd9059950887 (patch) | |
tree | 6e5b1b2888baaf0bdb3b65d91d5f6f5bbef22f9c /fish | |
parent | 840536ea5a0568296dfd3e483442c76b93c5a949 (diff) | |
download | libguestfs-c9c0ac7d362fd19214c2c5e5bb7dcd9059950887.tar.gz libguestfs-c9c0ac7d362fd19214c2c5e5bb7dcd9059950887.tar.xz libguestfs-c9c0ac7d362fd19214c2c5e5bb7dcd9059950887.zip |
Allow $TMPDIR to override most temporary directory uses.
Be more consistent in allowing the user to override use of the
temporary directory by specifying $TMPDIR. Also prefer P_tmpdir
macro (defined in <stdio.h>) if that is defined, rather than
hard-coding "/tmp" for the fallback location.
Diffstat (limited to 'fish')
-rw-r--r-- | fish/edit.c | 2 | ||||
-rw-r--r-- | fish/fish.c | 2 | ||||
-rw-r--r-- | fish/fish.h | 5 | ||||
-rw-r--r-- | fish/hexedit.c | 2 | ||||
-rw-r--r-- | fish/more.c | 2 |
5 files changed, 9 insertions, 4 deletions
diff --git a/fish/edit.c b/fish/edit.c index 4c06e86e..58b4a598 100644 --- a/fish/edit.c +++ b/fish/edit.c @@ -34,7 +34,7 @@ int run_edit (const char *cmd, int argc, char *argv[]) { - char filename[] = "/tmp/guestfishXXXXXX"; + TMP_TEMPLATE_ON_STACK (filename); char buf[256]; const char *editor; struct stat oldstat, newstat; diff --git a/fish/fish.c b/fish/fish.c index 43798458..6aadd560 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -1561,7 +1561,7 @@ file_in (const char *arg) static char * file_in_heredoc (const char *endmarker) { - static const char template[] = "/tmp/heredocXXXXXX"; + TMP_TEMPLATE_ON_STACK (template); file_in_tmpfile = strdup (template); if (file_in_tmpfile == NULL) { perror ("strdup"); diff --git a/fish/fish.h b/fish/fish.h index b941c493..23403575 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -47,6 +47,11 @@ #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) +#define TMP_TEMPLATE_ON_STACK(var) \ + const char *ttos_tmpdir = guestfs_tmpdir (); \ + char var[strlen (ttos_tmpdir) + 32]; \ + sprintf (var, "%s/guestfishXXXXXX", ttos_tmpdir) \ + /* in fish.c */ extern guestfs_h *g; extern int read_only; diff --git a/fish/hexedit.c b/fish/hexedit.c index dfa18890..bd3efc8e 100644 --- a/fish/hexedit.c +++ b/fish/hexedit.c @@ -100,7 +100,7 @@ run_hexedit (const char *cmd, int argc, char *argv[]) int r; struct stat oldstat, newstat; char buf[BUFSIZ]; - char tmp[] = "/tmp/guestfishXXXXXX"; + TMP_TEMPLATE_ON_STACK (tmp); int fd = mkstemp (tmp); if (fd == -1) { perror ("mkstemp"); diff --git a/fish/more.c b/fish/more.c index 27fc5481..e8a6d052 100644 --- a/fish/more.c +++ b/fish/more.c @@ -30,7 +30,7 @@ int run_more (const char *cmd, int argc, char *argv[]) { - char filename[] = "/tmp/guestfishXXXXXX"; + TMP_TEMPLATE_ON_STACK (filename); char buf[256]; const char *pager; int r, fd; |