From: daz Date: 2005-10-26T06:17:04+09:00 Subject: Re: ruby gives different answer for checksum of files on windows and FreeBSD? Pit Capitain wrote: > Yukihiro Matsumoto schrieb: > > > > Unless your program communicates with other programs on Windows, that > > use text-mode. > > Could someone provide an example for such a program? My Ruby programs > communicate with Vim and SQL*Plus, but I haven't used text-mode yet. > Notepad. Many text editors these days are smart enough to pick out text files in unix format and display them in lines rather than one long line as Notepad ("correctly") does. (If there are no "\r\n" sequences, there are no newlines.) The smart editors give the illusion that your file has been written correctly but the file on disk still has only one line. IBM's DOS Technical Reference[1] says that file I/O always uses binary mode and cannot be changed. (in contrast with device I/O - e.g. the console) Windows CreateFile follows that lead - no binary/text option AFAICS. C's "fopen" seems to have missed this fact (??) "If a t or b is not given in the mode string the mode is governed by the global variable _fmode. If _fmode is set to O_BINARY files are opened in binary mode. If _fmode is set to O_TEXT they are opened in text mode. These O_... constants are defined in fcntl.h." _fmode defaults to O_TEXT (under Windows) That looks to be inconsistent with the DOS/Windows specification. My interpretation is that STDIO should be in text mode and all other files in binmode. That covers the cases when STDIO is redirected - it'll be in text mode which is usually what's required. BTW, I don't think Ruby is at fault, here. Changing now is likely to cause some problems. daz [1] Maybe not official(?) but it says the same as an old copy I have. Two thirds down the page - headed [ASCII and BINARY MODE] http://www.textfiles.com/programming/dostech.pro