You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-01 16:38:31 +00:00
[FileAccess] Set last_error on file read/write errors.
This commit is contained in:
committed by
Pāvels Nadtočajevs
parent
893bbdfde8
commit
d97313cd7d
@@ -52,10 +52,18 @@
|
||||
#define S_ISREG(m) ((m) & _S_IFREG)
|
||||
#endif
|
||||
|
||||
void FileAccessWindows::check_errors() const {
|
||||
void FileAccessWindows::check_errors(bool p_write) const {
|
||||
ERR_FAIL_NULL(f);
|
||||
|
||||
if (feof(f)) {
|
||||
last_error = OK;
|
||||
if (ferror(f)) {
|
||||
if (p_write) {
|
||||
last_error = ERR_FILE_CANT_WRITE;
|
||||
} else {
|
||||
last_error = ERR_FILE_CANT_READ;
|
||||
}
|
||||
}
|
||||
if (!p_write && feof(f)) {
|
||||
last_error = ERR_FILE_EOF;
|
||||
}
|
||||
}
|
||||
@@ -284,7 +292,6 @@ bool FileAccessWindows::is_open() const {
|
||||
void FileAccessWindows::seek(uint64_t p_position) {
|
||||
ERR_FAIL_NULL(f);
|
||||
|
||||
last_error = OK;
|
||||
if (_fseeki64(f, p_position, SEEK_SET)) {
|
||||
check_errors();
|
||||
}
|
||||
@@ -320,8 +327,7 @@ uint64_t FileAccessWindows::get_length() const {
|
||||
}
|
||||
|
||||
bool FileAccessWindows::eof_reached() const {
|
||||
check_errors();
|
||||
return last_error == ERR_FILE_EOF;
|
||||
return feof(f);
|
||||
}
|
||||
|
||||
uint64_t FileAccessWindows::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
||||
@@ -385,7 +391,9 @@ bool FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
prev_op = WRITE;
|
||||
}
|
||||
|
||||
return fwrite(p_src, 1, p_length, f) == (size_t)p_length;
|
||||
bool res = fwrite(p_src, 1, p_length, f) == (size_t)p_length;
|
||||
check_errors(true);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool FileAccessWindows::file_exists(const String &p_name) {
|
||||
|
||||
Reference in New Issue
Block a user