Open the file using given string.
- Parameters
-
| [in] | path | The file path. |
| [in] | mode | The file mode. |
| [in] | binary | The file is a binary file ro not. |
| [out] | out_handle | Out The file handle pointer. |
- Returns
- true if open the file succeed.
Definition at line 22 of file FileLibrary.cpp.
23 {
25
26 out_handle->is_valid = false;
27 out_handle->handle = nullptr;
28 const char* mode_str;
29
31 {
32 mode_str = binary ? "w+b" : "w+";
33 }
35 {
36 mode_str = binary ? "rb" : "r";
37 }
39 {
40 mode_str = binary ? "wb" : "w";
41 }
42 else
43 {
44 SPICES_CORE_INFO("Invalid mode passed while trying to open file")
45 return false;
46 }
47
48 FILE* file;
49 auto state = fopen_s(&file, path, mode_str);
50
51 if (!file)
52 {
53 std::stringstream ss;
54 ss << "Error opening file: " << path;
55
56 SPICES_CORE_WARN(ss.str().c_str())
57 return false;
58 }
59
60 out_handle->handle = file;
61 out_handle->is_valid = true;
62
63 return true;
64 }
#define SPICES_PROFILE_ZONE
@ FILE_MODE_READ
model : read
@ FILE_MODE_WRITE
model : write
References Spices::FILE_MODE_READ, Spices::FILE_MODE_WRITE, Spices::FileHandle::handle, and Spices::FileHandle::is_valid.
Referenced by Spices::MeshLoader::LoadFromSASSET(), Spices::MaterialLoader::LoadFromSASSET(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), Spices::VulkanShaderModule::VulkanShaderModule(), and Spices::MeshLoader::WriteSASSET().