| 41 | } |
| 42 | |
| 43 | bool FileStream::open(const char *filename, AccessMode mode) |
| 44 | { |
| 45 | const char* modeStrings[] = { "rb", "wb", "rb+", "ab" }; |
| 46 | char fn[TFE_MAX_PATH]; |
| 47 | char *fn2; |
| 48 | |
| 49 | if (!filename || 1 > strlen(filename)) |
| 50 | return false; |
| 51 | |
| 52 | memset(fn, 0, TFE_MAX_PATH); |
| 53 | strcpy(fn, filename); |
| 54 | // relative path: try to find in one of the system paths. |
| 55 | if (filename[0] != '/') |
| 56 | TFE_Paths::mapSystemPath(fn); |
| 57 | |
| 58 | // try to open the given filename first; if that fails, |
| 59 | // because the filename cannot be found, try to find |
| 60 | // a matching filename with different case in the |
| 61 | // given directory. |
| 62 | m_file = fopen(fn, modeStrings[mode]); |
| 63 | if ((m_file == NULL) && (errno == ENOENT)) { |
| 64 | // ok, try harder to find a filename with different case |
| 65 | fn2 = FileUtil::findFileNoCase(filename); |
| 66 | if (fn2 == NULL) { |
| 67 | m_mode = MODE_INVALID; |
| 68 | return false; |
| 69 | } |
| 70 | m_file = fopen(fn2, modeStrings[mode]); |
| 71 | free(fn2); |
| 72 | } |
| 73 | m_mode = mode; |
| 74 | |
| 75 | return m_file != nullptr; |
| 76 | } |
| 77 | |
| 78 | bool FileStream::open(const FilePath *filePath, AccessMode mode) |
| 79 | { |
no test coverage detected