www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/09/11:46:03

Message-ID: <366EA8DF.CA28AC5D@CGSTE.MQ>
Date: Wed, 09 Dec 1998 12:44:15 -0400
From: HANRIGOU <HANRIGOU AT cgste DOT mq>
X-Mailer: Mozilla 4.06 [en] (Win95; I)
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>,
"djgpp AT delorie DOT com" <djgpp AT delorie DOT com>
Subject: Re: read/write in binary mode: fopen/open behaviour
References: <Pine DOT SUN DOT 3 DOT 91 DOT 981209123127 DOT 7705K-100000 AT is>
Reply-To: djgpp AT delorie DOT com

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 -


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