-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
temporaryfile.patch
34 lines (32 loc) · 1.17 KB
/
temporaryfile.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--- a/src/tools/Tools.cc 2019-10-24 03:48:36.000000000 +0200
+++ b/src/tools/Tools.cc 2021-02-05 09:08:21.000000000 +0100
@@ -1079,10 +1079,28 @@ Tools::TemporaryFile::TemporaryFile()
m_sFile = std::string(tmpName);
#else
- char tmpName[7] = "XXXXXX";
- if (mkstemp(tmpName) == -1)
+ // see https://github.com/boostorg/filesystem/blob/b4d606cdd08640c9bca68f7e97b52245aeef398d/src/operations.cpp#L2783
+ const char* val = nullptr;
+
+ (val = std::getenv("TMPDIR" )) ||
+ (val = std::getenv("TMP" )) ||
+ (val = std::getenv("TEMP" )) ||
+ (val = std::getenv("TEMPDIR"));
+
+# ifdef __ANDROID__
+ const char* default_tmp = "/data/local/tmp";
+# else
+ const char* default_tmp = "/tmp";
+# endif
+ std::string tempDir ((val != nullptr) ? val : default_tmp);
+
+ // now contruct the temporary filename
+ std::string tempName = tempDir + "/spatialindex-XXXXXX";
+ char* tmpName = strdup(tempName.c_str());
+ if (!tmpName || mkstemp(tmpName) == -1)
throw std::ios_base::failure("Tools::TemporaryFile: Cannot create temporary file name.");
- m_sFile = tmpName;
+ m_sFile = tmpName;
+ free(tmpName);
#endif
m_pFile = new Tools::BufferedFileWriter(m_sFile, Tools::CREATE);