Date: Wed, 9 Dec 1998 12:31:58 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: HANRIGOU , DJ Delorie cc: "djgpp AT delorie DOT com" Subject: Re: read/write in binary mode: fopen/open behaviour In-Reply-To: <366D541F.7E73636E@CGSTE.MQ> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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?