|
@@ -46,10 +46,18 @@
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-void FileAccessUnix::check_errors() const {
|
|
|
|
|
|
+void FileAccessUnix::check_errors(bool p_write) const {
|
|
ERR_FAIL_NULL_MSG(f, "File must be opened before use.");
|
|
ERR_FAIL_NULL_MSG(f, "File must be opened before use.");
|
|
|
|
|
|
- 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;
|
|
last_error = ERR_FILE_EOF;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -217,7 +225,6 @@ String FileAccessUnix::get_real_path() const {
|
|
void FileAccessUnix::seek(uint64_t p_position) {
|
|
void FileAccessUnix::seek(uint64_t p_position) {
|
|
ERR_FAIL_NULL_MSG(f, "File must be opened before use.");
|
|
ERR_FAIL_NULL_MSG(f, "File must be opened before use.");
|
|
|
|
|
|
- last_error = OK;
|
|
|
|
if (fseeko(f, p_position, SEEK_SET)) {
|
|
if (fseeko(f, p_position, SEEK_SET)) {
|
|
check_errors();
|
|
check_errors();
|
|
}
|
|
}
|
|
@@ -256,7 +263,7 @@ uint64_t FileAccessUnix::get_length() const {
|
|
}
|
|
}
|
|
|
|
|
|
bool FileAccessUnix::eof_reached() const {
|
|
bool FileAccessUnix::eof_reached() const {
|
|
- return last_error == ERR_FILE_EOF;
|
|
|
|
|
|
+ return feof(f);
|
|
}
|
|
}
|
|
|
|
|
|
uint64_t FileAccessUnix::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
|
uint64_t FileAccessUnix::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
|
@@ -298,7 +305,9 @@ void FileAccessUnix::flush() {
|
|
bool FileAccessUnix::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
|
bool FileAccessUnix::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
|
ERR_FAIL_NULL_V_MSG(f, false, "File must be opened before use.");
|
|
ERR_FAIL_NULL_V_MSG(f, false, "File must be opened before use.");
|
|
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
|
|
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
|
|
- return fwrite(p_src, 1, p_length, f) == p_length;
|
|
|
|
|
|
+ bool res = fwrite(p_src, 1, p_length, f) == p_length;
|
|
|
|
+ check_errors(true);
|
|
|
|
+ return res;
|
|
}
|
|
}
|
|
|
|
|
|
bool FileAccessUnix::file_exists(const String &p_path) {
|
|
bool FileAccessUnix::file_exists(const String &p_path) {
|