MCPcopy Create free account
hub / github.com/catboost/catboost / MakeTempName

Function MakeTempName

util/system/mktemp.cpp:17–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15extern "C" int mkstemps(char* path, int slen);
16
17TString MakeTempName(const char* wrkDir, const char* prefix, const char* extension) {
18 TString filePath;
19
20 if (wrkDir && *wrkDir) {
21 filePath += wrkDir;
22 } else {
23 filePath += GetSystemTempDir();
24 }
25
26#ifdef _win32_
27 // https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea?redirectedfrom=MSDN
28 const unsigned int DirPathMaxLen = 247;
29 if (filePath.length() <= DirPathMaxLen) {
30 // it always takes up to 3 characters, no more
31 char winFilePath[MAX_PATH];
32 if (GetTempFileName(filePath.c_str(), (prefix) ? (prefix) : "yan", 0,
33 winFilePath)) {
34 return winFilePath;
35 }
36 }
37#endif // _win32_
38
39 if (filePath.back() != '/') {
40 filePath += '/';
41 }
42
43 if (prefix) {
44 filePath += prefix;
45 }
46
47 filePath += "XXXXXX"; // mkstemps requirement
48
49 size_t extensionPartLength = 0;
50 if (extension && *extension) {
51 if (extension[0] != '.') {
52 filePath += '.';
53 extensionPartLength += 1;
54 }
55 filePath += extension;
56 extensionPartLength += strlen(extension);
57 }
58
59 int fd = mkstemps(const_cast<char*>(filePath.data()), extensionPartLength);
60 if (fd >= 0) {
61 close(fd);
62 return filePath;
63 }
64
65 ythrow TSystemError() << "can not create temp name(" << wrkDir << ", " << prefix << ", " << extension << ")";
66}

Callers 15

TestNamedChunkedDataMethod · 0.85
TOutputCapturerMethod · 0.85
TFinalCtrsCalcerMethod · 0.85
GetModelWithCtrDataMethod · 0.85
Y_UNIT_TESTFunction · 0.85
SaveQuantizedPoolFunction · 0.85
Y_UNIT_TESTFunction · 0.85
SaveDataToTempFileFunction · 0.85
Y_UNIT_TESTFunction · 0.85

Calls 7

GetSystemTempDirFunction · 0.85
mkstempsFunction · 0.85
closeFunction · 0.50
lengthMethod · 0.45
c_strMethod · 0.45
backMethod · 0.45
dataMethod · 0.45

Tested by 3

TestNamedChunkedDataMethod · 0.68
TestCacheMethod · 0.68
TestSimpleMethod · 0.68