29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
+
+
|
** For the fossil_timer_xxx() family of functions...
*/
#ifdef _WIN32
# include <windows.h>
#else
# include <sys/time.h>
# include <sys/resource.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
#endif
/*
** Exit. Take care to close the database first.
|
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
|
** Construct a temporary filename.
**
** The returned string is obtained from sqlite3_malloc() and must be
** freed by the caller.
*/
char *fossil_temp_filename(void){
char *zTFile = 0;
sqlite3 *db;
const char *zDir;
u64 r[2];
int i;
#ifdef _WIN32
char zTempDir[1000];
#else
static const char *azTmp[] = {"/var/tmp","/usr/tmp","/tmp"};
#endif
if( g.db ){
sqlite3_file_control(g.db, 0, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTFile);
if( zTFile ) return zTFile;
}
sqlite3_randomness(sizeof(r), &r);
#if _WIN32
db = g.db;
zTempDir[0] = 0;
GetTempPathA(sizeof(zTempDir), zTempDir);
if( zTempDir[0] ){
zDir = zTempDir;
}else{
sqlite3_open("",&db);
zDir = fossil_getenv("LOCALAPPDATA");
if( zDir==0 ) zDir = ".";
}
sqlite3_file_control(db, 0, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTFile);
if( g.db==0 ) sqlite3_close(db);
return zTFile;
#else
for(i=0; i<sizeof(azTmp)/sizeof(azTmp[0]); i++){
struct stat buf;
zDir = azTmp[i];
if( stat(zDir,&buf)==0 && S_ISDIR(buf.st_mode) && access(zDir,03)==0 ){
break;
}
}
if( i>=sizeof(azTmp)/sizeof(azTmp[0]) ) zDir = ".";
#endif
return sqlite3_mprintf("%s/fossil%016llx%016llx", zDir, r[0], r[1]);
}
/*
** Turn memory limits for stack and heap on and off. The argument
** is true to turn memory limits on and false to turn them off.
**
** Memory limits should be enabled at startup, but then turned off
|