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 TAA29855; Wed, 19 Mar 2003 19:36:15 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA30367 for ; Wed, 19 Mar 2003 19:36:14 +0100 (MET) Received: from ajax.cs.uga.edu (ajax.cs.uga.edu [128.192.251.3]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2JIaCf00952 for ; Wed, 19 Mar 2003 19:36:12 +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 NAA02549 for ; Wed, 19 Mar 2003 13:36:08 -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 13:36:08 -0500 Message-ID: <877kavryp3.fsf@cs.uga.edu> User-Agent: Gnus/5.090014 (Oort Gnus v0.14) Emacs/21.2 (i386-debian-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; caml-list:01 lseek:01 pervasives:01 basile:01 flushes:01 openfile:01 rdonly:01 printf:01 unixlabels:01 stdio:01 stdlib:01 unistd:01 char:01 sizeof:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Sorry if this shows up as a duplicate. Basile STARYNKEVITCH writes: ... > You apparently forgot to flush the channel. 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 ... but in the C version you get the expected position reported. ecashin@meili seek-tell$ ./test after reading "#include <" lseek returns 10 ecashin@meili seek-tell$ cat main.c #include #include #include #include #include #include int main(void) { int fd = open("main.c", O_RDONLY); char buf[1024]; if (fd == -1) { perror("open"); exit(EXIT_FAILURE); } memset(buf, '\0', sizeof(buf)); read(fd, buf, 10); printf("after reading \"%s\" lseek returns %d\n", buf, (int) lseek(fd, 0, SEEK_CUR)); return 0; } -- --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