MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / init

Method init

src/common/classes/TempFile.cpp:176–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174//
175
176void TempFile::init(const PathName& directory, const PathName& prefix)
177{
178 // set up temporary directory, if not specified
179 filename = directory;
180 if (filename.empty())
181 {
182 filename = getTempPath();
183 }
184 PathUtils::ensureSeparator(filename);
185
186#if defined(WIN_NT)
187 _timeb t;
188 _ftime(&t);
189 __int64 randomness = t.time;
190 randomness *= 1000;
191 randomness += t.millitm;
192 PathName suffix = NAME_PATTERN;
193 for (int tries = 0; tries < MAX_TRIES; tries++)
194 {
195 PathName name = filename + prefix;
196 __int64 temp = randomness;
197 for (FB_SIZE_T i = 0; i < suffix.length(); i++)
198 {
199 suffix[i] = NAME_LETTERS[temp % (strlen(NAME_LETTERS))];
200 temp /= strlen(NAME_LETTERS);
201 }
202 name += suffix;
203 DWORD attributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY;
204 if (doUnlink)
205 {
206 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
207 }
208 handle = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE,
209 0, NULL, CREATE_NEW, attributes, NULL);
210 if (handle != INVALID_HANDLE_VALUE)
211 {
212 filename = name;
213 break;
214 }
215 const DWORD err = GetLastError();
216 if (err != ERROR_FILE_EXISTS)
217 {
218 (Arg::Gds(isc_io_error) << Arg::Str("CreateFile (create)") << Arg::Str(name) <<
219 Arg::Gds(isc_io_create_err) << Arg::OsError(err)).raise();
220 }
221 randomness++;
222 }
223 if (handle == INVALID_HANDLE_VALUE)
224 {
225 (Arg::Gds(isc_io_error) << Arg::Str("CreateFile (create)") << Arg::Str(filename) <<
226 Arg::Gds(isc_io_create_err) << Arg::OsError()).raise();
227 }
228#else
229 filename += prefix;
230 filename += NAME_PATTERN;
231
232#ifdef HAVE_MKSTEMP
233 handle = (IPTR) os_utils::mkstemp(filename.begin());

Callers

nothing calls this directly

Calls 11

GdsClass · 0.85
StrClass · 0.85
OsErrorClass · 0.85
mkstempFunction · 0.85
openFunction · 0.50
unlinkFunction · 0.50
emptyMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45
raiseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected