mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
[FileAccess] Return error codes from store_* methods.
This commit is contained in:
committed by
Pāvels Nadtočajevs
parent
56a7dba10b
commit
a4b17e7852
@@ -372,9 +372,9 @@ void FileAccessWindows::flush() {
|
||||
}
|
||||
}
|
||||
|
||||
void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_NULL(f);
|
||||
ERR_FAIL_COND(!p_src && p_length > 0);
|
||||
bool FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_NULL_V(f, false);
|
||||
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
|
||||
|
||||
if (flags == READ_WRITE || flags == WRITE_READ) {
|
||||
if (prev_op == READ) {
|
||||
@@ -385,7 +385,7 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
prev_op = WRITE;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != (size_t)p_length);
|
||||
return fwrite(p_src, 1, p_length, f) == (size_t)p_length;
|
||||
}
|
||||
|
||||
bool FileAccessWindows::file_exists(const String &p_name) {
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
|
||||
virtual Error resize(int64_t p_length) override;
|
||||
virtual void flush() override;
|
||||
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
|
||||
virtual bool store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
|
||||
|
||||
virtual bool file_exists(const String &p_name) override; ///< return true if a file exists
|
||||
|
||||
|
||||
@@ -119,16 +119,18 @@ Error FileAccessWindowsPipe::get_error() const {
|
||||
return last_error;
|
||||
}
|
||||
|
||||
void FileAccessWindowsPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_COND_MSG(fd[1] == nullptr, "Pipe must be opened before use.");
|
||||
ERR_FAIL_COND(!p_src && p_length > 0);
|
||||
bool FileAccessWindowsPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_COND_V_MSG(fd[1] == nullptr, false, "Pipe must be opened before use.");
|
||||
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
|
||||
|
||||
DWORD read = -1;
|
||||
bool ok = WriteFile(fd[1], p_src, p_length, &read, nullptr);
|
||||
if (!ok || read != p_length) {
|
||||
last_error = ERR_FILE_CANT_WRITE;
|
||||
return false;
|
||||
} else {
|
||||
last_error = OK;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
|
||||
virtual Error resize(int64_t p_length) override { return ERR_UNAVAILABLE; }
|
||||
virtual void flush() override {}
|
||||
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
|
||||
virtual bool store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
|
||||
|
||||
virtual bool file_exists(const String &p_name) override { return false; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user