caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Eric Dahlman <edahlman@atcorp.com>
To: caml-list@pauillac.inria.fr
Subject: [Caml-list] Bug with really_input under cygwin
Date: Tue, 9 Mar 2004 16:30:08 -0600	[thread overview]
Message-ID: <51FE3429-7219-11D8-8BF5-000393914EAA@atcorp.com> (raw)

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


             reply	other threads:[~2004-03-09 22:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-09 22:30 Eric Dahlman [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51FE3429-7219-11D8-8BF5-000393914EAA@atcorp.com \
    --to=edahlman@atcorp.com \
    --cc=caml-list@pauillac.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).