From e4214eea2c0daaf332be275ae4719a7dfbd1bdd2 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Wed, 23 Jan 2019 23:54:33 +0800 Subject: [PATCH] common/buffer: return 0 on short read in pread_file Signed-off-by: Yuan Zhou --- src/common/buffer.cc | 7 ++++--- src/include/buffer.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 5f3f948ff9848..41ed3c1ea2f3b 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1781,7 +1781,7 @@ void buffer::list::decode_base64(buffer::list& e) push_back(std::move(bp)); } -int buffer::list::pread_file(const char *fn, uint64_t off, uint64_t len, std::string *error) +ssize_t buffer::list::pread_file(const char *fn, uint64_t off, uint64_t len, std::string *error) { int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC)); if (fd < 0) { @@ -1806,9 +1806,10 @@ int buffer::list::pread_file(const char *fn, uint64_t off, uint64_t len, std::st if (off > st.st_size) { std::ostringstream oss; - oss << "bufferlist::read_file(" << fn << "): read error: size < offset"; + oss << "bufferlist::read_file(" << fn << "): read error: size < offset " + << cpp_strerror(-1); VOID_TEMP_FAILURE_RETRY(::close(fd)); - return -1; + return 0; } if (len > st.st_size - off) { diff --git a/src/include/buffer.h b/src/include/buffer.h index 08ad06aff2deb..1c1acba8db6eb 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -1216,7 +1216,7 @@ inline namespace v14_2_0 { void write_stream(std::ostream &out) const; void hexdump(std::ostream &out, bool trailing_newline = true) const; - int pread_file(const char *fn, uint64_t off, uint64_t len, std::string *error); + ssize_t pread_file(const char *fn, uint64_t off, uint64_t len, std::string *error); int read_file(const char *fn, std::string *error); ssize_t read_fd(int fd, size_t len); int write_file(const char *fn, int mode=0644); -- 2.39.5