[Lldb-commits] [PATCH] D25783: [Host] handle short reads and writes

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 19 13:55:49 PDT 2016


zturner added inline comments.


================
Comment at: source/Host/common/File.cpp:405
 
-    if (bytes_read == 0) {
-      if (::feof(m_stream))
-        error.SetErrorString("feof");
-      else if (::ferror(m_stream))
-        error.SetErrorString("ferror");
-      num_bytes = 0;
-    } else
-      num_bytes = bytes_read;
-  } else {
-    num_bytes = 0;
-    error.SetErrorString("invalid file handle");
-  }
-  return error;
+  off_t offset = lseek(fd, 0, SEEK_CUR);
+  return Read(buf, num_bytes, offset);
----------------
clayborg wrote:
> Why are we calling lseek when we are passing the offset into the read below?
> 
> Shouldn't this just be:
> ```
> off_t offset = 0;
> ```
This `lseek` is to get the current file pointer.  If someone calls `Write()` with no offset, they expect this to mean "write at the current file position".  In order to do that with `pwrite()`, you need to know what the current file position actually is.  If we just set `offset=0`, it will write at the beginning of the file, which is probably not the intention.

LMK if I've misunderstood.


https://reviews.llvm.org/D25783





More information about the lldb-commits mailing list