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

Function GetTemp

util/system/mktemp_system.cpp:51–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
50
51static int
52GetTemp(char* path, int* doopen, int domkdir, int slen)
53{
54 char *start, *trv, *suffp;
55 char* pad;
56#ifndef _win32_
57 struct stat sbuf;
58 int rval;
59#endif
60 ui32 rand;
61
62 if (doopen != nullptr && domkdir) {
63 errno = EINVAL;
64 return (0);
65 }
66
67 trv = path;
68 while (*trv != 0) {
69 ++trv;
70 }
71 trv -= slen;
72 suffp = trv;
73 --trv;
74 if (trv < path) {
75 errno = EINVAL;
76 return (0);
77 }
78
79 /* Fill space with random characters */
80 while (trv >= path && *trv == 'X') {
81 rand = (RandomNumber<ui32>()) % (sizeof(padchar) - 1);
82 *trv-- = padchar[rand];
83 }
84 start = trv + 1;
85
86 /*
87 * check the target directory.
88 */
89 if (doopen != nullptr || domkdir) {
90 for (; trv > path; --trv) {
91 if (*trv == '/') {
92 *trv = '\0';
93#ifdef _win32_
94 ui32 attr = ::GetFileAttributesA(path);
95 *trv = '/';
96 if (attr == 0xFFFFFFFF)
97 return (0);
98 if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) {
99 errno = ENOTDIR;
100 return (0);
101 }
102#else
103 rval = stat(path, &sbuf);
104 *trv = '/';
105 if (rval != 0) {
106 return (0);
107 }
108 if (!S_ISDIR(sbuf.st_mode)) {

Callers 2

mkstempsFunction · 0.85
mkdtempFunction · 0.85

Calls 5

statClass · 0.70
MkdirFunction · 0.70
openFunction · 0.50
lstatFunction · 0.50
strchrFunction · 0.50

Tested by

no test coverage detected