MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / cfopen

Function cfopen

cfile/cfile.cpp:483–531  ·  view source on GitHub ↗

Opens a file for reading or writing If a path is specified, will try to open the file only in that path. If no path is specified, will look through search directories and library files. Parameters: filename - the name if the file, with or without a path mode - the standard C mode string Returns: the CFile handle, or NULL if file not opened

Source from the content-addressed store, hash-verified

481// mode - the standard C mode string
482// Returns: the CFile handle, or NULL if file not opened
483CFILE *cfopen(const std::filesystem::path &filename, const char *mode) {
484 CFILE *cfile;
485
486 // Check for valid mode
487 ASSERT((mode[0] == 'r') || (mode[0] == 'w'));
488 ASSERT((mode[1] == 'b') || (mode[1] == 't'));
489 // get the parts of the pathname
490 std::filesystem::path path = filename.parent_path();
491 std::filesystem::path fname = filename.stem();
492 std::filesystem::path ext = filename.extension();
493
494 // if there is a path specified, use it instead of the libraries, search dirs, etc.
495 // if the file is writable, just open it, instead of looking in libs, etc.
496 if (!path.empty() || (mode[0] == 'w')) {
497 // use path specified with file
498 cfile = open_file_in_directory(filename, mode, std::filesystem::path());
499 goto got_file; // don't look in libs, etc.
500 }
501
502 // First look in the directories for this file's extension
503 for (auto const &entry : extensions) {
504 if (!strnicmp(entry.first.u8string().c_str(), ext.u8string().c_str(), _MAX_EXT)) {
505 // found ext
506 cfile = open_file_in_directory(filename, mode, entry.second);
507 if (cfile) {
508 goto got_file;
509 }
510 }
511 }
512
513 // Next look in the general directories
514 for (auto const &entry : paths) {
515 if (!entry.second) {
516 cfile = open_file_in_directory(filename, mode, entry.first);
517 if (cfile)
518 goto got_file;
519 }
520 }
521 // Lastly, try the hog files
522 cfile = open_file_in_lib(filename.u8string().c_str());
523got_file:;
524 if (cfile) {
525 if (mode[0] == 'w')
526 cfile->flags |= CFF_WRITING;
527 if (mode[1] == 't')
528 cfile->flags |= CFF_TEXT;
529 }
530 return cfile;
531}
532
533// Returns the length of the specified file
534// Parameters: cfp - the file pointer returned by cfopen()

Callers 15

mng_FindSpecificShipPageFunction · 0.85
mng_InitPagelocksFunction · 0.85
mng_CheckIfLockerPresentFunction · 0.85
TableVersionCurrentFunction · 0.85
mng_MakeLockerFunction · 0.85
mng_EraseLockerFunction · 0.85
mng_CheckIfPageLockedFunction · 0.85
mng_CheckIfPageOwnedFunction · 0.85
mng_ReplacePagelockFunction · 0.85
mng_DeletePagelockFunction · 0.85

Calls 2

open_file_in_directoryFunction · 0.85
open_file_in_libFunction · 0.85

Tested by 1

TESTFunction · 0.68