Add 'tell' method to raw_fd_ostream that clients can use to query the current locatio...
authorTed Kremenek <kremenek@apple.com>
Wed, 26 Nov 2008 03:33:13 +0000 (03:33 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 26 Nov 2008 03:33:13 +0000 (03:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60085 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 709a063e2aeaa96603e17e122fa2fd69c061ec30..2b4b17d7b29792000d47e7be7f2dba4b15770109 100644 (file)
@@ -175,7 +175,10 @@ public:
   virtual void flush_impl();
   
   /// close - Manually flush the stream and close the file.
-  void close();  
+  void close();
+  
+  /// tell - Return the current offset with the file.
+  uint64_t tell();
 };
   
 /// raw_stdout_ostream - This is a stream that always prints to stdout.
index a8e6c782bc97e276a137b53b641a0a2feb2a77be..b10677e3f271d66342df47118f7f61deb1094995 100644 (file)
@@ -253,6 +253,14 @@ void raw_fd_ostream::close() {
   FD = -1;
 }
 
+uint64_t raw_fd_ostream::tell() {
+  // We have to take into account the bytes waiting in the buffer.  For now
+  // we do the easy thing and just flush the buffer before getting the
+  // current file offset.
+  flush();  
+  return (uint64_t) lseek(FD, 0, SEEK_CUR);
+}
+
 //===----------------------------------------------------------------------===//
 //  raw_stdout/err_ostream
 //===----------------------------------------------------------------------===//