From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA30617; Wed, 19 Mar 2003 20:01:40 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA30830 for ; Wed, 19 Mar 2003 20:01:38 +0100 (MET) Received: from ajax.cs.uga.edu (ajax.cs.uga.edu [128.192.251.3]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h2JJ1aX05539 for ; Wed, 19 Mar 2003 20:01:37 +0100 (MET) Received: from cs.uga.edu (ajax.cs.uga.edu [128.192.251.3]) by ajax.cs.uga.edu (8.9.3/8.9.3) with ESMTP id OAA04311 for ; Wed, 19 Mar 2003 14:01:32 -0500 (EST) To: caml-list@inria.fr From: cashin@cs.uga.edu Subject: Re: [Caml-list] Unix.lseek versus Pervasives.pos Date: Wed, 19 Mar 2003 14:01:31 -0500 In-Reply-To: <20030319184840.GA12900@clipper.ens.fr> (Nicolas George's message of "Wed, 19 Mar 2003 19:48:40 +0100") Message-ID: <871y13rxis.fsf@cs.uga.edu> User-Agent: Gnus/5.090014 (Oort Gnus v0.14) Emacs/21.2 (i386-debian-linux-gnu) References: <877kavryp3.fsf@cs.uga.edu> <20030319184840.GA12900@clipper.ens.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; caml-list:01 lseek:01 pervasives:01 unspecified:01 unixlabels:01 printf:01 openfile:01 rdonly:01 nicolas:01 buf:01 writes:01 pgp:02 unix:02 string:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Nicolas George 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