From 71de17d38ee8db40e5f50d2ce8986e9676767309 Mon Sep 17 00:00:00 2001
From: Patrick Walton <pcwalton@mimiga.net>
Date: Mon, 21 Mar 2011 16:40:26 -0700
Subject: [PATCH] Add a binding to ftell()

---
 src/lib/io.rs       | 4 ++++
 src/lib/linux_os.rs | 1 +
 src/lib/macos_os.rs | 1 +
 src/lib/win32_os.rs | 1 +
 4 files changed, 7 insertions(+)

diff --git a/src/lib/io.rs b/src/lib/io.rs
index 58cb1f80495..165fe0302d6 100644
--- a/src/lib/io.rs
+++ b/src/lib/io.rs
@@ -24,6 +24,7 @@ type reader =
           impure fn read_le_int(uint size) -> int;
 
           impure fn seek(int offset, seek_style whence);
+          impure fn tell() -> uint; // TODO: eventually u64
     };
 
 state obj FILE_reader(os.libc.FILE f, bool must_close) {
@@ -97,6 +98,9 @@ state obj FILE_reader(os.libc.FILE f, bool must_close) {
         }
         check(os.libc.fseek(f, offset, wh) == 0);
     }
+    impure fn tell() -> uint {
+        ret os.libc.ftell(f) as uint;
+    }
     drop {
         if (must_close) {os.libc.fclose(f);}
     }
diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs
index 030dcdbc0e5..bce859567e3 100644
--- a/src/lib/linux_os.rs
+++ b/src/lib/linux_os.rs
@@ -19,6 +19,7 @@ native mod libc = "libc.so.6" {
     fn ungetc(int c, FILE f);
     fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
     fn fseek(FILE f, int offset, int whence) -> int;
+    fn ftell(FILE f) -> int;
 
     type dir;
     fn opendir(sbuf d) -> dir;
diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs
index c2a1bee3ed9..f9734de3caa 100644
--- a/src/lib/macos_os.rs
+++ b/src/lib/macos_os.rs
@@ -16,6 +16,7 @@ native mod libc = "libc.dylib" {
     fn ungetc(int c, FILE f);
     fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
     fn fseek(FILE f, int offset, int whence) -> int;
+    fn ftell(FILE f) -> int;
 
     type dir;
     fn opendir(sbuf d) -> dir;
diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs
index 6885be243e4..3ca76e77d77 100644
--- a/src/lib/win32_os.rs
+++ b/src/lib/win32_os.rs
@@ -15,6 +15,7 @@ native mod libc = "msvcrt.dll" {
     fn ungetc(int c, FILE f);
     fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
     fn fseek(FILE f, int offset, int whence) -> int;
+    fn ftell(FILE f) -> int;
 
     fn _pipe(vbuf fds, uint size, int mode) -> int;
 }