1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

[FileAccess] Implement resize method.

This commit is contained in:
bruvzg
2024-04-08 22:09:34 +03:00
parent 029aadef56
commit 88b3e68f93
19 changed files with 111 additions and 0 deletions

View File

@@ -286,6 +286,23 @@ Error FileAccessUnix::get_error() const {
return last_error;
}
Error FileAccessUnix::resize(int64_t p_length) {
ERR_FAIL_NULL_V_MSG(f, FAILED, "File must be opened before use.");
int res = ::ftruncate(fileno(f), p_length);
switch (res) {
case 0:
return OK;
case EBADF:
return ERR_FILE_CANT_OPEN;
case EFBIG:
return ERR_OUT_OF_MEMORY;
case EINVAL:
return ERR_INVALID_PARAMETER;
default:
return FAILED;
}
}
void FileAccessUnix::flush() {
ERR_FAIL_NULL_MSG(f, "File must be opened before use.");
fflush(f);