Browse thread
Re: [Caml-list] Unix.lseek versus Pervasives.pos
-
cashin@c...
- Nicolas George
- Ken Rose
- Basile STARYNKEVITCH
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Nicolas George <nicolas.george@e...> |
| Subject: | Re: [Caml-list] Unix.lseek versus Pervasives.pos |
Le nonidi 29 ventôse, an CCXI, cashin@cs.uga.edu a écrit :
> Printf.printf "after reading %d chars: \"%s\", position is %d\n"
> (UnixLabels.read fd ~buf ~pos:0 ~len:10)
> buf
> (UnixLabels.lseek fd 0 ~mode:Unix.SEEK_CUR)
Use strace, and you'll see something like that :
open("main.ml", O_RDONLY|O_LARGEFILE) = 3
_llseek(3, 0, [0], SEEK_CUR) = 0
read(3, " let main", 10) = 10
write(1, "after reading 10 chars: \" let m"..., 1066) = 1066
So you can see that the lseek is done before the read. And indeed, your
calls to read and lseek can occur in an unspecified order. I guess that
if you write
let len = UnixLabels.read ... in
let pos = UnixLabels.lseek ... in
Printf.printf ...
you will get the right result.