| 20 | namespace 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); |
no test coverage detected