OSDN Git Service

Remember if lseek works in this FD.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 10 Apr 2015 18:15:51 +0000 (18:15 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 10 Apr 2015 18:15:51 +0000 (18:15 +0000)
It will be used in clang in a sec.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234619 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp

index 6b0bde7..c378fa9 100644 (file)
@@ -333,6 +333,8 @@ class raw_fd_ostream : public raw_ostream {
 
   uint64_t pos;
 
+  bool SupportsSeeking;
+
   /// See raw_ostream::write_impl.
   void write_impl(const char *Ptr, size_t Size) override;
 
@@ -370,6 +372,8 @@ public:
   /// fsync.
   void close();
 
+  bool supportsSeeking() { return SupportsSeeking; }
+
   /// Flushes the stream and repositions the underlying file descriptor position
   /// to the offset specified from the beginning of the file.
   uint64_t seek(uint64_t off);
index b7e9ba6..199f0a6 100644 (file)
@@ -525,7 +525,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered)
 
   // Get the starting position.
   off_t loc = ::lseek(FD, 0, SEEK_CUR);
-  if (loc == (off_t)-1)
+  SupportsSeeking = loc != (off_t)-1;
+  if (!SupportsSeeking)
     pos = 0;
   else
     pos = static_cast<uint64_t>(loc);