[FileAccess] Implement resize method.

This commit is contained in:
bruvzg 2024-04-08 22:09:34 +03:00
parent 029aadef56
commit 88b3e68f93
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
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);