Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] no tell on files?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ed L Cashin <ecashin@u...>
Subject: Re: [Caml-list] no tell on files?
Chris Hecker <> writes:

> There appears to be no "tell" function on pervasives streams or Unix
> file descriptors.  Is there a reason for this?  The combination of
> that plus the lack of a pervasives relative seek makes it hard to move
> around in files without keeping parallel information.

Seek is tell!  The program below gives this output:

  ecashin@meili seek-tell$ ./a.out 
  read 10 chars: " Unix.SEEK"

let main = 
  let fd = Unix.openfile "" [Unix.O_RDONLY] 0 in
  let end_pos = Unix.lseek fd 0 Unix.SEEK_END in
  let half_pos = Unix.lseek fd (end_pos/2) Unix.SEEK_SET and
      buf = String.create 1024 in
  Printf.printf "read %d chars: \"%s\"\n"
    ( fd ~buf ~pos:0 ~len:10)


--Ed L Cashin            |   PGP public key:        |
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: