filesystem::CreateFile

This commit is contained in:
Dr. Chat 2015-11-28 16:30:20 -06:00 committed by Ben Vanik
parent e206d13af7
commit 62351a62de
2 changed files with 15 additions and 0 deletions

View File

@ -42,6 +42,9 @@ bool DeleteFolder(const std::wstring& path);
// Returns true if the given path exists and is a folder.
bool IsFolder(const std::wstring& path);
// Creates an empty file at the given path.
bool CreateFile(const std::wstring& path);
// Opens the file at the given path with the specified mode.
// This behaves like fopen and the returned handle can be used with stdio.
FILE* OpenFile(const std::wstring& path, const char* mode);

View File

@ -47,6 +47,18 @@ bool IsFolder(const std::wstring& path) {
(attrib & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
}
#undef CreateFile
bool CreateFile(const std::wstring& path) {
auto handle = CreateFileW(path.c_str(), 0, 0, nullptr, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, nullptr);
if (handle == INVALID_HANDLE_VALUE) {
return false;
}
CloseHandle(handle);
return true;
}
FILE* OpenFile(const std::wstring& path, const char* mode) {
auto fixed_path = xe::fix_path_separators(path);
return _wfopen(fixed_path.c_str(), xe::to_wstring(mode).c_str());