Subject: Re: Bug in od, cat, etc reading binary files
From: [email-masked] (Larry Hall)

22 Sep 1997 08:31:37 -0700
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
To: Eric De Mund <[email-masked]>, GNU-Win32 List <[email-masked]>
Cc: Joe Peterson <[email-masked]>

At 01:30 AM 9/22/97 -0700, Eric De Mund wrote:
>GNU-Win32 People,
>
>    Joe Peterson <[email-masked]> to <[email-masked]>:
>    ] Sorry if this is documented somewhere, but I could not find
>    ] mention of it. I find that when, for example, using "od" to look
>    ] at a binary file, if a ctrl-Z is encountered, the reading stops.
>    ] This is because the fopen presumably does a "r" rather than a "rb"
>    ] (a pc-ism).
>    ]
>    ] Other programs like "cat" and possibly others have this problem as
>    ] well...
>
>GNU-Win32 cat(1) does have this problem, as does md5sum(1), rendering
>them significantly less useful. It's the understanding of this Unix
>developer new to the Windows world that the equivalent of Microsoft's
>Visual C++ 5.0 Run-Time Library function _setmode(3) is required (global
>variable _fmode in that development world setting the default file-
>translation mode of all files *except* stdin, stdout, and stderr).
>
>Questions: How do I do these in the GNU-Win32 world? How do I:
>    * set the analog of MSVC++5.0's _fmode
>    * call the analog of MSVC++5.0's int _setmode(int handle, int mode)
>
>Thank you,
>Eric De Mund
>
>"Magazines all too frequently lead to books and should be regarded by the
>prudent as the heavy petting of literature." --Fran Lebowitz

Eric,

You're half right in your understanding.  The problem is due to "text"
files in Windows and the need to open files in binary mode in order to
"get things right".  You have 2 choices:

  - Recompile offending code, either setting the mode or changing all
    file open commands to use the "b" (for binary) flag.

  - mount (via the mount command) your filesystems as binary (-b) so that
    all files are automatically treated as binary just like in UNIX.  This
    step is usually the easiest and best in the long run but also tends
    to cause short term headaches since all the "text" files that you 
    currently have will be filled with <cr>s which bash and other things 
    will barf on.  Reinstalling the system using cygwin tar/gzip or 
    translating all your system files (at least) usually handles the 
    problems.

Larry Hall                              [email-masked]
RFK Partners, Inc.                      (781) 239-1053
8 Grove Street                          (781) 239-1655 - FAX
Wellesley, MA  02181                             

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".