Add a binding to ftell()

This commit is contained in:
Patrick Walton 2011-03-21 16:40:26 -07:00
parent ea1321fcdd
commit 71de17d38e
4 changed files with 7 additions and 0 deletions

View file

@ -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);}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;
}