PIFile::openTemporary on Windows

PIPair from std::tuple
This commit is contained in:
2021-12-24 14:41:18 +03:00
parent 92b20f6f46
commit 3c8ccf357b
3 changed files with 10 additions and 2 deletions

View File

@@ -149,12 +149,15 @@ PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(p
bool PIFile::openTemporary(PIIODevice::DeviceMode mode) {
PIString tp;
#ifdef WINDOWS
tp = PIDir::temporary().path() + PIDir::separator + "file" + PIString::fromNumber(randomi());
#else
char * rc = tmpnam(0);
if (!rc) return false;
tp = rc;
#ifdef WINDOWS
tp = PIDir::temporary().path() + PIDir::separator + "file" + tp.cutLeft(1).cutRight(1);
#endif
while (isExists(tp))
tp += PIString::fromNumber(randomi() % 10);
return open(tp, mode);
}