MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / tryOpenFile

Method tryOpenFile

src/simulate/fs_file_info.cpp:22–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace das {
21#if !defined(DAS_NO_FILEIO)
22 FileInfo * FsFileSystem::tryOpenFile ( const string & fileName ) {
23 if ( FILE * ff = fopen ( fileName.c_str(), "rb" ) ) {
24 struct stat st;
25 int fd = fileno((FILE *)ff);
26 fstat(fd, &st);
27 if ( !st.st_size ) {
28 fclose(ff);
29 return new TextFileInfo("", st.st_size, false);
30 }
31 char *source = (char *) das_aligned_alloc16(st.st_size);
32 auto info = new TextFileInfo(source, st.st_size, true);
33 auto bytesRead = fread(source, 1, st.st_size, ff);
34 fclose(ff);
35 if ( size_t(bytesRead) == size_t(st.st_size) ) {
36 return info;
37 } else {
38 return nullptr;
39 }
40 } else {
41 return nullptr;
42 }
43 }
44
45 FsReadOnlyCachedFileSystem::~FsReadOnlyCachedFileSystem() {
46 lock_guard<mutex> guard(fsm);

Callers 1

getNewFileInfoMethod · 0.80

Calls 7

das_aligned_alloc16Function · 0.85
hash64zFunction · 0.85
getSourceAndLengthMethod · 0.80
c_strMethod · 0.45
insertMethod · 0.45
resetMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected