diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-02 12:12:42 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-02 12:12:42 +0200 |
commit | 527c716784fbca1f82dcfcaedaceb67ef85789a4 (patch) | |
tree | ac46fb161b36d3bb33c6f6fbcb4a2a33dbbcb058 /drivers/unix/file_access_unix_pipe.cpp | |
parent | 9ff888bcd4ba74f94d5854ba9243d0f93a367f7a (diff) | |
parent | 205a10e0ae7bfff1bc6ebba481838e3ac856b6b8 (diff) | |
download | redot-engine-527c716784fbca1f82dcfcaedaceb67ef85789a4.tar.gz |
Merge pull request #92167 from BlueCube3310/file-access-the-final-season-part3-ep2
Reduce code duplication in FileAccess
Diffstat (limited to 'drivers/unix/file_access_unix_pipe.cpp')
-rw-r--r-- | drivers/unix/file_access_unix_pipe.cpp | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/drivers/unix/file_access_unix_pipe.cpp b/drivers/unix/file_access_unix_pipe.cpp index 5d9a27ad05..34758e8c7d 100644 --- a/drivers/unix/file_access_unix_pipe.cpp +++ b/drivers/unix/file_access_unix_pipe.cpp @@ -125,22 +125,9 @@ String FileAccessUnixPipe::get_path_absolute() const { return path_src; } -uint8_t FileAccessUnixPipe::get_8() const { - ERR_FAIL_COND_V_MSG(fd[0] < 0, 0, "Pipe must be opened before use."); - - uint8_t b; - if (::read(fd[0], &b, 1) == 0) { - last_error = ERR_FILE_CANT_READ; - b = '\0'; - } else { - last_error = OK; - } - return b; -} - uint64_t FileAccessUnixPipe::get_buffer(uint8_t *p_dst, uint64_t p_length) const { - ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); ERR_FAIL_COND_V_MSG(fd[0] < 0, -1, "Pipe must be opened before use."); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); uint64_t read = ::read(fd[0], p_dst, p_length); if (read == p_length) { @@ -155,18 +142,10 @@ Error FileAccessUnixPipe::get_error() const { return last_error; } -void FileAccessUnixPipe::store_8(uint8_t p_src) { - ERR_FAIL_COND_MSG(fd[1] < 0, "Pipe must be opened before use."); - if (::write(fd[1], &p_src, 1) != 1) { - last_error = ERR_FILE_CANT_WRITE; - } else { - last_error = OK; - } -} - void FileAccessUnixPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) { ERR_FAIL_COND_MSG(fd[1] < 0, "Pipe must be opened before use."); ERR_FAIL_COND(!p_src && p_length > 0); + if (::write(fd[1], p_src, p_length) != (ssize_t)p_length) { last_error = ERR_FILE_CANT_WRITE; } else { |