diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-22 12:51:55 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-22 12:51:55 +0200 |
commit | 504d01b61eaa3e0d1af0a4cea866c18ecfc1395c (patch) | |
tree | 20086da672e04f63a91c945581b062ff20e97939 /drivers/windows/file_access_windows.cpp | |
parent | 0b89b8b64c60b7fb7e9f1c26bf20b2c7d7c0adac (diff) | |
parent | 88b3e68f93fad5681b27b11ddacc562b03d5ef45 (diff) | |
download | redot-engine-504d01b61eaa3e0d1af0a4cea866c18ecfc1395c.tar.gz |
Merge pull request #90403 from bruvzg/file_resize
[FileAccess] Implement `resize` method.
Diffstat (limited to 'drivers/windows/file_access_windows.cpp')
-rw-r--r-- | drivers/windows/file_access_windows.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index dd8bceb573..726e0fdc5a 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -41,6 +41,7 @@ #include <windows.h> #include <errno.h> +#include <io.h> #include <sys/stat.h> #include <sys/types.h> #include <tchar.h> @@ -369,6 +370,24 @@ Error FileAccessWindows::get_error() const { return last_error; } +Error FileAccessWindows::resize(int64_t p_length) { + ERR_FAIL_NULL_V_MSG(f, FAILED, "File must be opened before use."); + errno_t res = _chsize_s(_fileno(f), p_length); + switch (res) { + case 0: + return OK; + case EACCES: + case EBADF: + return ERR_FILE_CANT_OPEN; + case ENOSPC: + return ERR_OUT_OF_MEMORY; + case EINVAL: + return ERR_INVALID_PARAMETER; + default: + return FAILED; + } +} + void FileAccessWindows::flush() { ERR_FAIL_NULL(f); |