From 3c8ccf357be3020c9cc1b8cd55fbed70cab4caf7 Mon Sep 17 00:00:00 2001 From: peri4 Date: Fri, 24 Dec 2021 14:41:18 +0300 Subject: [PATCH] PIFile::openTemporary on Windows PIPair from std::tuple --- cmake/FindPIP.cmake | 4 ++++ libs/main/containers/pipair.h | 1 + libs/main/io_devices/pifile.cpp | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake/FindPIP.cmake b/cmake/FindPIP.cmake index aec725ed..b3bfdb38 100644 --- a/cmake/FindPIP.cmake +++ b/cmake/FindPIP.cmake @@ -71,6 +71,10 @@ if (NOT BUILDING_pip) find_library(PTHREAD_LIBRARY pthread) find_library(UTIL_LIBRARY util) set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY}) + if((NOT DEFINED ENV{QNX_HOST}) AND (NOT APPLE) AND (NOT PIP_FREERTOS)) + find_library(RT_LIBRARY rt) + list(APPEND _PIP_ADD_LIBS_ ${RT_LIBRARY}) + endif() list(APPEND PIP_LIBRARY ${_PIP_ADD_LIBS_}) endif() endif() diff --git a/libs/main/containers/pipair.h b/libs/main/containers/pipair.h index d0b49fc7..e032960c 100644 --- a/libs/main/containers/pipair.h +++ b/libs/main/containers/pipair.h @@ -33,6 +33,7 @@ template class PIPair { public: PIPair() {first = Type0(); second = Type1();} + PIPair(std::tuple tuple) {first = std::get<0>(tuple); second = std::get<1>(tuple);} PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;} Type0 first; Type1 second; diff --git a/libs/main/io_devices/pifile.cpp b/libs/main/io_devices/pifile.cpp index 29f3af79..4abd37b6 100644 --- a/libs/main/io_devices/pifile.cpp +++ b/libs/main/io_devices/pifile.cpp @@ -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); }