delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/09/05:34:58

Date: Wed, 9 Dec 1998 12:31:58 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: HANRIGOU <HANRIGOU AT cgste DOT mq>, DJ Delorie <dj AT delorie DOT com>
cc: "djgpp AT delorie DOT com" <djgpp AT delorie DOT com>
Subject: Re: read/write in binary mode: fopen/open behaviour
In-Reply-To: <366D541F.7E73636E@CGSTE.MQ>
Message-ID: <Pine.SUN.3.91.981209123127.7705K-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Tue, 8 Dec 1998, HANRIGOU wrote:

> fin = fopen(input_file, "r");
> dout = fopen(output_file, "w");
> ...
> while ((c = read(fileno(fin), buf, sizeof (buf))) > 0)
>     for (bufp = buf; c > 0; c -= d, bufp += d)
>         if ((d = write(fileno(dout), bufp, c)) <= 0)
>             break;

I'd say this program has a bug.  Why would anybody use `fopen' to open
a file, and then read it with `read' rather than `fread'?

> Nevertheless is this behaviour correct? Couldn't we expect file mode
> changes on FILE *f to be automatically applied to fileno(f)?

I don't know if there's something to expect here, as `fopen' and
`read' are largely unrelated.  Obviously, ANSI doesn't even know about
`read'.

DJ, does Posix say anything about O_BINARY in `open', or whether "rb"
should imply the underlying handle is open in binary mode?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019