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 TAA31116; Wed, 19 Mar 2003 19:56:06 +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 TAA31123 for ; Wed, 19 Mar 2003 19:56:04 +0100 (MET) Received: from cluster2.tfb.com ([204.212.132.102]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h2JIu3X05361 for ; Wed, 19 Mar 2003 19:56:03 +0100 (MET) Received: from tfb.com (host-66-81-198-200.rev.o1.com [66.81.198.200]) by cluster2.tfb.com (8.11.0/8.11.0) with ESMTP id h2JItte02509; Wed, 19 Mar 2003 10:55:55 -0800 Message-ID: <3E78BD39.B6499AC0@tfb.com> Date: Wed, 19 Mar 2003 10:55:53 -0800 From: Ken Rose Reply-To: rose@acm.org X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en MIME-Version: 1.0 To: cashin@cs.uga.edu CC: caml-list@inria.fr Subject: Re: [Caml-list] Unix.lseek versus Pervasives.pos References: <877kavryp3.fsf@cs.uga.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; caml-list:01 lseek:01 pervasives:01 flushes:01 openfile:01 rdonly:01 printf:01 unixlabels:01 ocaml:01 buf:01 writes:01 unix:02 bytes:02 string:03 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk cashin@cs.uga.edu wrote: > > Flushes are for writes, but even when using a test program that just > reads, zero is returned when it appears that it shouldn't return zero. > Compare the short ocaml program below to the comparable C version. > > The ocaml version has lseek returning position zero after reading 10 > bytes from the file. > > ecashin@meili seek-tell$ ./test > after reading 10 chars: "let main =", position is 0 > 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 > 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) > ;; > > main > It looks like you're getting bitten by the order of evaluation of function arguments. $ cat main.ml let main = let fd = Unix.openfile "main.ml" [Unix.O_RDONLY] 0 and buf = String.create 1024 in let r = (UnixLabels.read fd ~buf ~pos:0 ~len:10) in Printf.printf "after reading %d chars: \"%s\", position is %d\n" r buf (UnixLabels.lseek fd 0 ~mode:Unix.SEEK_CUR) ;; main $ ./a.out after reading 10 chars: "let main =", position is 10 $ - ken ------------------- 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