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 XAA30733; Tue, 9 Mar 2004 23:30:04 +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 XAA30700 for ; Tue, 9 Mar 2004 23:30:04 +0100 (MET) Received: from moby.atcorp.com (moby.atcorp.com [204.72.172.2]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i29MUIKW013309 for ; Tue, 9 Mar 2004 23:30:21 +0100 Received: from [192.168.0.36] (conger.atcorp.com [204.72.172.102]) by moby.atcorp.com (8.11.6/8.11.2) with ESMTP id i29MVWZ17437 for ; Tue, 9 Mar 2004 16:31:32 -0600 Mime-Version: 1.0 (Apple Message framework v612) Content-Transfer-Encoding: 7bit Message-Id: <51FE3429-7219-11D8-8BF5-000393914EAA@atcorp.com> Content-Type: text/plain; charset=US-ASCII; format=flowed To: caml-list@pauillac.inria.fr From: Eric Dahlman Subject: [Caml-list] Bug with really_input under cygwin Date: Tue, 9 Mar 2004 16:30:08 -0600 X-Mailer: Apple Mail (2.612) X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; bug:01 cygwin:01 howdy:01 cygwin:01 newlines:01 foo:01 portably:01 bug:01 ocaml:01 lisp:01 binary:02 unix:02 unix:02 string:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 98 Howdy all, I have some code which is reads in a whole file in and returns it as a string. To do this I am using a combination of in_channel_length and really_input which has worked just fine in a Unix environment but which breaks under Cygwin. This looks like a problem with line ending translation where the length reported by in_channel_length counts the DOS line endings as two characters but really_input reads them in as one. The end result is the length is too long by the number of newlines in the file and the call to really_input fails. Here is a function which demonstrates the problem let measureUp () = let (name, channel) = Filename.open_temp_file "temp" ".foo" in List.iter (fun x -> output_string channel x) [ "This\n" ; "is\n" ; "a\n" ; "spiffy\n" ; "test\n" ]; close_out channel; (* now read it back in *) let ins = open_in name in let length = in_channel_length ins in let result = String.create length in really_input ins result 0 length; close_in ins; Unix.unlink name; result This function works fine under Unix but will fail under Cygwin. I have tried to use set_binary_mode_* to see if that would help but it did not alter the the results. So that leaves me with a couple of questions: How should I slurp a whole file into a string portably in ocaml? Is this a bug or just and unfortunate result of running under windows? (At the very least it is a documentation bug.) Going back to the original problem that started me down this road is there an analogue to string-streams in common lisp which are special output channels which write to a string in memory rather than a file on disk? Thanks a bunch! -Eric ------------------- 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