]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: return 0 on short read in pread_file
authorYuan Zhou <yuan.zhou@intel.com>
Wed, 23 Jan 2019 15:54:33 +0000 (23:54 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Thu, 21 Mar 2019 16:16:28 +0000 (00:16 +0800)
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
src/common/buffer.cc
src/include/buffer.h

index 5f3f948ff9848b8fc74a32e3dd3868999c2ecd9a..41ed3c1ea2f3b7f79ad73332b72232ff2f091572 100644 (file)
@@ -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) {
index 08ad06aff2deb82bf4f7de9cc83a4985502ac4b7..1c1acba8db6ebb99f209c4943f8b8b78af4f39cd 100644 (file)
@@ -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);