caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Bug with really_input under cygwin
@ 2004-03-09 22:30 Eric Dahlman
  2004-03-09 22:52 ` Karl Zilles
  2004-03-10  3:06 ` skaller
  0 siblings, 2 replies; 12+ messages in thread
From: Eric Dahlman @ 2004-03-09 22:30 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-03-11 15:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-09 22:30 [Caml-list] Bug with really_input under cygwin Eric Dahlman
2004-03-09 22:52 ` Karl Zilles
2004-03-10  3:06 ` skaller
2004-03-10  4:10   ` David Brown
2004-03-10 13:14     ` Richard Zidlicky
2004-03-11  4:11       ` skaller
2004-03-11  3:24     ` skaller
2004-03-10 15:25   ` Nuutti Kotivuori
2004-03-11  3:42     ` skaller
2004-03-11  5:02       ` Nuutti Kotivuori
2004-03-11 15:21         ` skaller
2004-03-11  6:32       ` james woodyatt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).