Browse thread
[Caml-list] Bug with really_input under cygwin
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Eric Dahlman <edahlman@a...> |
| Subject: | [Caml-list] Bug with really_input under cygwin |
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