MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / CreateTempFilename

Function CreateTempFilename

src/OpenColorIO/Platform.cpp:222–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222std::string CreateTempFilename(const std::string & filenameExt)
223{
224 std::string filename;
225
226#ifdef _WIN32
227
228 // Note: Because of security issue, tmpnam could not be used.
229
230 // Note 2: MinGW doesn't define L_tmpnam_s, we need to patch it in.
231 // https://www.mail-archive.com/mingw-w64-public@lists.sourceforge.net/msg17360.html
232#if !defined(L_tmpnam_s)
233#define L_tmpnam_s L_tmpnam
234#endif
235
236 char tmpFilename[L_tmpnam_s];
237 if(tmpnam_s(tmpFilename))
238 {
239 throw Exception("Could not create a temporary file.");
240 }
241
242 // Note that when a file name is pre-pended with a backslash and no path information, such as \fname21, this
243 // indicates that the name is valid for the current working directory.
244 filename = tmpFilename[0] == '\\' ? tmpFilename + 1 : tmpFilename;
245
246#else
247
248 // Linux flavors must have a /tmp directory.
249 std::stringstream ss;
250 ss << "/tmp/ocio_" << GenerateRandomNumber();
251
252 filename = ss.str();
253
254#endif
255
256 filename += filenameExt;
257
258 return filename;
259}
260
261std::ifstream CreateInputFileStream(const char * filename, std::ios_base::openmode mode)
262{

Callers 3

OCIO_ADD_TESTFunction · 0.85
FileCreationGuardMethod · 0.85
FileGuardMethod · 0.85

Calls 1

GenerateRandomNumberFunction · 0.85

Tested by 3

OCIO_ADD_TESTFunction · 0.68
FileCreationGuardMethod · 0.68
FileGuardMethod · 0.68