Mail Archives: djgpp/1998/12/08/11:32:23
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.
- Raw text -