[comp.os.minix] fopen: "r" |/& "rb"?

greyham@hades.OZ (Greyham Stoney) (02/14/89)

in article <659@mks.UUCP>, wheels@mks.UUCP (Gerry Wheeler) says:
> 
> I've also compiled this on U**x and MS-DOS.  The only change required
> for DOS was that the fopen() had to have binary mode added, so it looked
> like this:
> 
> 		fopen(argv[arg], "rb")
> 
> This prevents DOS from returning EOF when it reads a ^Z character.

Can someone correct me if I'm wrong, but the same code (namely "rb") should
work for both shouldn't it?. In the MesSDOS case, it will see the "b" and
hence open the file in binary mode; in the Unix/Minix case it only looks at
the first character of the string anyway, so it sees the "r" and opens the
file as you would expect. So, can't everyone use "rb" when they know it's
a "binary" file {to make it easier for those who have to cope with MSDOS, but
mightn't spot the problem}. Right? Wrong? Comments?
							Greyham

-- 
# Greyham Stoney:    (disclaimer not necessary: I'm obviously irresponsible)
# greyham@hades.nucleus.oz - Ausonics.        +61 2 428-6476 (my_phone@work)
# replys WILL bounce; try:    greyham@utscsd.oz - Uni of Technology, Sydney.
# WARNING: Reply mail is VERY broken at present. Any replys to utscsd.oz pls

Leisner.Henr@xerox.com (marty) (02/20/89)

in article <659@mks.UUCP>, wheels@mks.UUCP (Gerry Wheeler) says:
>> 		fopen(argv[arg], "rb")
> 
> This prevents DOS from returning EOF when it reads a ^Z character.

When doing handle I/O, I don't think the cntl-Z character is used (read
works with file sizes).

I'm now running the Minix stdio routines on Ms/Dos.   I added to FILE a
flag for binary mode  (to go along with the "*b" option in fopen) -- at the
end of getc.c I have:

        /* filter out returns */
        if(result == '\r' && !testflag(iop, BINMODE))
                return getc(iop);
        else    return result;

In putc.c, I have:

        if(ch == '\n' && !testflag(iop, BINMODE))
                putc('\r', iop);        /* ms/dos patch ? */
		

The fact that the C library needs to do the filtering is a real pain.

If the application is processing binary data through the stdio library, the
ANSI way of doing it requires the "b" mode.


marty
ARPA:	leisner.henr@xerox.com
GV:  leisner.henr
NS:  martin leisner:wbst139:xerox
UUCP:  hplabs!arisia!leisner