Mail Archives: djgpp/1998/12/09/11:46:03
Hello Eli,
First, thanks for your help and advice.
Eli Zaretskii wrote:
>
> 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'?
Yes it's quite strange! But I've (over?)simplified this piece of code.
Actually it comes from GNU ftp client. This is the part involved in
transferring a local file to a remote server, in binary transfer mode.
I've stripped a lot of lines (the above "..." sequence). More
precisely:
- fstat is used to get file type and size
- in append mode fseek is called to go to restart point
- a few other stuff is done but do not explain use of fopen versus open
That's why I think that's not a bug of the program. If it is, please
let me know. IMHO I am the only one to blame, because the code I've
extracted looks a bit "artificial". But I wanted to get to the point,
just showing relevant lines...
Thanks again,
Best regards,
Philippe.
--
Sorry for my bad english - Spelling corrections are appreciated.
- Raw text -