Message-ID: <366D541F.7E73636E@CGSTE.MQ> Date: Tue, 08 Dec 1998 12:30:23 -0400 From: HANRIGOU X-Mailer: Mozilla 4.06 [en] (Win95; I) MIME-Version: 1.0 To: "djgpp AT delorie DOT com" Subject: read/write in binary mode: fopen/open behaviour Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Hi, I'm trying to port some UNIX code to DJGPP. A piece of the original code try to copy a binary file. it looks like that: 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; Obviously this code do not work under DJGPP (for binary files) since the default file type for read() and write() is TEXT. Nevertheless I thought just changing first two lines into: fin = fopen(input_file, "rb"); dout = fopen(output_file, "wb"); whould be enough. Nevertheless this do not work. Changing file mode on FILE *f do not seem affect the file pointed by fileno(f). This is not a real problem, because adding setmode(fileno(fin), O_BINARY); setmode(fileno(dout), O_BINARY); before doing any read() or write() is OK. Nevertheless is this behaviour correct? Couldn't we expect file mode changes on FILE *f to be automatically applied to fileno(f)? Please give me a clue. -- Sorry for my bad english. Spelling corrections are appreciated.