/* filesystem/file.c This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include "filesystem/filesystem.h" #include "filesystem/diskfile.h" namespace filesystem { DiskFile::DiskFile() { diskfile_handle = 0; } DiskFile::~DiskFile() { if (diskfile_handle) fclose(diskfile_handle); } FILE *DiskFile::handle() { return diskfile_handle; } bool DiskFile::open(const char *filename) { if (diskfile_handle) { con_warn << file_name << " already open!" << std::endl; return false; } file_name.assign(filename); file_path.clear(); #ifdef _WIN32 for (size_t i = 0; i < file_name.size(); i++) if (file_name[i] == '/') file_name[i] = '\\'; #endif for (SearchPath::iterator path = searchpath().begin(); path != searchpath().end(); path++) { std::string fn((*path)); fn.append(filename); diskfile_handle = fopen(fn.c_str(), "rb"); if (diskfile_handle) { file_path.assign((*path)); return true; } } //con_error << "Could not open " << filename << std::endl; return false; } void DiskFile::close() { if (diskfile_handle) fclose(diskfile_handle); diskfile_handle = 0; } size_t DiskFile::read(void *buffer, const size_t count) { if (!diskfile_handle) return 0; return (fread(buffer, count, 1, diskfile_handle)); } void DiskFile::skip(size_t count) { fseek(diskfile_handle, (long) count, SEEK_CUR); } } // namespace filesystem