From e076257b8cfe4c34e62d13d2b3c342509fb830b5 Mon Sep 17 00:00:00 2001
From: Ted Kremenek <kremenek@apple.com>
Date: Wed, 26 Nov 2008 03:33:13 +0000
Subject: [PATCH] Add 'tell' method to raw_fd_ostream that clients can use to
 query the current location in the file the stream is writing to.

llvm-svn: 60085
---
 llvm/include/llvm/Support/raw_ostream.h | 5 ++++-
 llvm/lib/Support/raw_ostream.cpp        | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 709a063e2aea..2b4b17d7b297 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -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.
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index a8e6c782bc97..b10677e3f271 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -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
 //===----------------------------------------------------------------------===//