fix warning tmpnam

This commit is contained in:
2025-08-13 11:17:31 +03:00
parent be2d3c197c
commit 64e142b8c6
4 changed files with 24 additions and 5 deletions

View File

@@ -176,14 +176,16 @@ 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;
#endif
while (isExists(tp)) {
tp += PIString::fromNumber(randomi() % 10);
}
#else
char template_rc[] = "/tmp/pifile_tmp_XXXXXX";
int fd = mkstemp(template_rc);
if (fd == -1) return false;
::close(fd);
tp = template_rc;
#endif
return open(tp, mode);
}