MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / open

Method open

Engine/source/platformWin32/winFileio.cpp:262–349  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Open a file in the mode specified by openMode (Read, Write, or ReadWrite). Truncate the file if the mode is either Write or ReadWrite and truncate is true. Sets capability appropriate to the openMode. Returns the currentStatus of the file. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

260// Returns the currentStatus of the file.
261//-----------------------------------------------------------------------------
262File::FileStatus File::open(const char *filename, const AccessMode openMode)
263{
264 AssertFatal(NULL != filename, "File::open: NULL fname");
265 AssertWarn(INVALID_HANDLE_VALUE == (HANDLE)handle, "File::open: handle already valid");
266
267 TempAlloc< TCHAR > fname( dStrlen( filename ) + 1 );
268
269#ifdef UNICODE
270 convertUTF8toUTF16N( filename, fname, fname.size );
271#else
272 dStrcpy(fname, filename, fname.size);
273#endif
274 backslash( fname );
275
276 // Close the file if it was already open...
277 if (Closed != currentStatus)
278 close();
279
280 // create the appropriate type of file...
281 switch (openMode)
282 {
283 case Read:
284 handle = (void *)CreateFile(fname,
285 GENERIC_READ,
286 FILE_SHARE_READ,
287 NULL,
288 OPEN_EXISTING,
289 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
290 NULL);
291 break;
292 case Write:
293 handle = (void *)CreateFile(fname,
294 GENERIC_WRITE,
295 0,
296 NULL,
297 CREATE_ALWAYS,
298 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
299 NULL);
300 break;
301 case ReadWrite:
302 handle = (void *)CreateFile(fname,
303 GENERIC_WRITE | GENERIC_READ,
304 0,
305 NULL,
306 OPEN_ALWAYS,
307 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
308 NULL);
309 break;
310 case WriteAppend:
311 handle = (void *)CreateFile(fname,
312 GENERIC_WRITE,
313 0,
314 NULL,
315 OPEN_ALWAYS,
316 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
317 NULL);
318 break;
319

Callers

nothing calls this directly

Calls 6

convertUTF8toUTF16NFunction · 0.85
dStrcpyFunction · 0.85
backslashFunction · 0.85
CreateFileFunction · 0.85
dStrlenFunction · 0.50
U32Enum · 0.50

Tested by

no test coverage detected