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
This commit is contained in:
Erik Reckase 2011-01-09 16:48:18 +00:00 committed by Scott Draves
parent 6cfbf0cbb1
commit 3274d1b51b
2 changed files with 29 additions and 1 deletions

View File

@ -28,6 +28,7 @@
#include "parser.h" #include "parser.h"
#include "filters.h" #include "filters.h"
#include "palettes.h" #include "palettes.h"
#include "unistd.h"
#include <limits.h> #include <limits.h>
#include <locale.h> #include <locale.h>
#include <math.h> #include <math.h>
@ -1617,7 +1618,31 @@ char *flam3_print_to_string(flam3_genome *cp) {
long stringbytes; long stringbytes;
char *genome_string; char *genome_string;
int using_tmpdir = 0;
char *tmp_path;
char tmpnam[256];
tmpflame = tmpfile(); 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); flam3_print(tmpflame,cp,NULL,flam3_dont_print_edits);
stringbytes = ftell(tmpflame); stringbytes = ftell(tmpflame);
fseek(tmpflame,0L, SEEK_SET); fseek(tmpflame,0L, SEEK_SET);
@ -1626,6 +1651,9 @@ char *flam3_print_to_string(flam3_genome *cp) {
perror("FLAM3: reading string from temp file"); perror("FLAM3: reading string from temp file");
} }
fclose(tmpflame); fclose(tmpflame);
if (using_tmpdir)
unlink(tmpnam);
return(genome_string); return(genome_string);
} }

View File

@ -559,7 +559,7 @@ void apply_motion_parameters(flam3_xform *xf, flam3_xform *addto, double blend);
EXPORT void flam3_interpolate(flam3_genome *genomes, int ngenomes, double time, double stagger, flam3_genome *result); EXPORT void flam3_interpolate(flam3_genome *genomes, int ngenomes, double time, double stagger, flam3_genome *result);
/* print genome to given file with extra_attributes if not NULL */ /* print genome to given file with extra_attributes if not NULL */
void flam3_print(FILE *f, flam3_genome *g, char *extra_attributes, int print_edits); EXPORT void flam3_print(FILE *f, flam3_genome *g, char *extra_attributes, int print_edits);
void flam3_print_xform(FILE *f, flam3_xform *x, int final_flag, int numstd, double *chaos_row, int motion_flag); void flam3_print_xform(FILE *f, flam3_xform *x, int final_flag, int numstd, double *chaos_row, int motion_flag);
EXPORT char *flam3_print_to_string(flam3_genome *cp); EXPORT char *flam3_print_to_string(flam3_genome *cp);