summaryrefslogtreecommitdiff
path: root/src/flam3.c
diff options
context:
space:
mode:
authorErik Reckase <e.reckase@gmail.com>2011-01-09 16:48:18 +0000
committerScott Draves <spot@draves.org>2015-02-15 12:20:14 -0500
commit3274d1b51b721e388e9e038d1945412c450ae224 (patch)
tree4226b2794448af7280a70b7d0002f069222ea398 /src/flam3.c
parent6cfbf0cbb191898182f10d409809ca26b2ed21da (diff)
downloadpucket-3274d1b51b721e388e9e038d1945412c450ae224.tar.gz
pucket-3274d1b51b721e388e9e038d1945412c450ae224.tar.bz2
pucket-3274d1b51b721e388e9e038d1945412c450ae224.zip
in some circumstances, temporary files are not created as they are supposed to (windows tries to create it in a place protected by Admin.) We need to be able to try to create them in the location pointed to by the TEMP env var. Note that this is not threadsafe, but it's unlikely to cause a problem at the moment.
git-svn-id: https://flam3.googlecode.com/svn/trunk@154 77852712-ef1d-11de-8684-7d64432d61a3
Diffstat (limited to 'src/flam3.c')
-rw-r--r--src/flam3.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/flam3.c b/src/flam3.c
index c56b233..9df618c 100644
--- a/src/flam3.c
+++ b/src/flam3.c
@@ -28,6 +28,7 @@
#include "parser.h"
#include "filters.h"
#include "palettes.h"
+#include "unistd.h"
#include <limits.h>
#include <locale.h>
#include <math.h>
@@ -1617,7 +1618,31 @@ char *flam3_print_to_string(flam3_genome *cp) {
long stringbytes;
char *genome_string;
+ int using_tmpdir = 0;
+ char *tmp_path;
+ char tmpnam[256];
+
tmpflame = tmpfile();
+ if (NULL==tmpflame) {
+#ifdef _WIN32
+ // This might be a permissions problem, so let's try to open a
+ // tempfile in the env var TEMP's area instead
+ tmp_path = getenv("TEMP");
+
+ if (tmp_path != NULL) {
+ strcpy(tmpnam, tmp_path);
+ strcat(tmpnam, "\\fr0st.tmp");
+ tmpflame = fopen(tmpnam, "w+");
+ if (tmpflame != NULL) {
+ using_tmpdir = 1;
+ }
+ }
+#endif
+ if (using_tmpdir == 0) {
+ perror("FLAM3: opening temporary file");
+ return (NULL);
+ }
+ }
flam3_print(tmpflame,cp,NULL,flam3_dont_print_edits);
stringbytes = ftell(tmpflame);
fseek(tmpflame,0L, SEEK_SET);
@@ -1626,6 +1651,9 @@ char *flam3_print_to_string(flam3_genome *cp) {
perror("FLAM3: reading string from temp file");
}
fclose(tmpflame);
+
+ if (using_tmpdir)
+ unlink(tmpnam);
return(genome_string);
}