Browse thread
Re: [Caml-list] Unix.lseek versus Pervasives.pos
-
cashin@c...
-
Nicolas George
- cashin@c...
- Ken Rose
- Basile STARYNKEVITCH
-
Nicolas George
[
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: | cashin@c... |
| Subject: | Re: [Caml-list] Unix.lseek versus Pervasives.pos |
Nicolas George <nicolas.george@ens.fr> writes:
...
> 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.
You're right!
ecashin@meili seek-tell$ ./test
after reading 10 chars: "let main =", position is 10
ecashin@meili seek-tell$ cat main.ml
let main =
let fd = Unix.openfile "main.ml" [Unix.O_RDONLY] 0
and buf = String.create 1024 in
let n = UnixLabels.read fd ~buf ~pos:0 ~len:10 in
Printf.printf "after reading %d chars: \"%s\", position is %d\n"
n
buf
(UnixLabels.lseek fd 0 ~mode:Unix.SEEK_CUR)
;;
main
--
--Ed L Cashin | PGP public key:
ecashin@uga.edu | http://noserose.net/e/pgp/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners