caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] slight difference of behavior of OCaml on MinGw and Linux
@ 2011-03-28  7:32 Yoriyuki Yamagata
  2011-03-28  8:13 ` David Allsopp
  0 siblings, 1 reply; 2+ messages in thread
From: Yoriyuki Yamagata @ 2011-03-28  7:32 UTC (permalink / raw)
  To: Caml List


[-- Attachment #1.1: Type: text/plain, Size: 827 bytes --]

Hi, list.

I think I found a slight difference of behavior of OCaml on MinGW and Linux
regarding the EOF character.  On Linux, the EOF char in the middle of a file
is ignored, but on MinGW, the attempt to read EOF causes End_of_file
Exception.  Is this a supposed behavior?

(ok, I have found some discussion on EOF on beginners list, but cannot find
something exactly answering this problem.)

I attached an ocaml program (which is simply a cat) and a file which
reproduce the problem.  On Linux, doing
ocaml testEoF.ml < UTF-32#LE
outputs the whole file before the exception End_of_file, but on MinGW, the
script fails in the middle of Etruscan text, which happens to contain 0x1a
character.

Best,

-- 
Yoriyuki Yamagata
yoriyuki.y@gmail.com
http://sites.google.com/site/yoriyukiy/<https://sites.google.com/site/yoriyukiy/>

[-- Attachment #1.2: Type: text/html, Size: 998 bytes --]

[-- Attachment #2: testEoF.ml --]
[-- Type: application/octet-stream, Size: 62 bytes --]

while true do
  output_char stdout (input_char stdin)
done

[-- Attachment #3: UTF-32#LE --]
[-- Type: application/octet-stream, Size: 1068 bytes --]

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

* RE: [Caml-list] slight difference of behavior of OCaml on MinGw and Linux
  2011-03-28  7:32 [Caml-list] slight difference of behavior of OCaml on MinGw and Linux Yoriyuki Yamagata
@ 2011-03-28  8:13 ` David Allsopp
  0 siblings, 0 replies; 2+ messages in thread
From: David Allsopp @ 2011-03-28  8:13 UTC (permalink / raw)
  To: Yoriyuki Yamagata, Caml List

Yoriyuki Yamagata wrote:
> Hi, list.
>
> I think I found a slight difference of behavior of
> OCaml on MinGW and Linux regarding the EOF character.
> On Linux, the EOF char in the middle of a file is 
> ignored, but on MinGW, the attempt to read EOF causes
> End_of_file Exception.  Is this a supposed behavior?  

I think you're simply seeing the underlying difference in handling of EOF between Unix and Windows - files in text mode on Windows are terminated by an EOF character but this is not the case on Unix.

> (ok, I have found some discussion on EOF on beginners
> list, but cannot find something exactly answering this problem.)
>
> I attached an ocaml program (which is simply a cat) and a file
> which reproduce the problem.  On Linux, doing
> ocaml testEoF.ml < UTF-32#LE
> outputs the whole file before the exception End_of_file, but 
> on MinGW, the script fails in the middle of Etruscan text, 
> which happens to contain 0x1a character.

You can make this work by calling set_binary_mode_in stdin before you start but you'll have to handle end-of-line marker differences manually in your code (in my experience of writing cross-platform text processing programs in OCaml, this is necessary anyway as if you read a file on Unix which happens to use Windows end-of-line markers then you probably aren't actually after each line ending with \r which is what you'll get)


David



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

end of thread, other threads:[~2011-03-28  8:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-28  7:32 [Caml-list] slight difference of behavior of OCaml on MinGw and Linux Yoriyuki Yamagata
2011-03-28  8:13 ` David Allsopp

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).