From: Yuan Zhou Date: Wed, 23 Jan 2019 15:54:33 +0000 (+0800) Subject: common/buffer: return 0 on short read in pread_file X-Git-Tag: v15.0.0~136^2~34 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e4214eea2c0daaf332be275ae4719a7dfbd1bdd2;p=ceph.git common/buffer: return 0 on short read in pread_file Signed-off-by: Yuan Zhou --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 5f3f948ff984..41ed3c1ea2f3 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 08ad06aff2de..1c1acba8db6e 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);