X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Radical NetSurfer Newsgroups: comp.os.msdos.djgpp Subject: Re: v2.953 Additional Observations Date: Mon, 20 Dec 2004 17:09:59 -0500 Message-ID: <89jes0tf1auvn3p360ue9c2hs55itdvicn@4ax.com> References: <200412190006 DOT iBJ06ike016912 AT envy DOT delorie DOT com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Organization: Velocity.Net Cache-Post-Path: web.velocity.net!unknown AT 66-211-207-208 DOT velocity DOT net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Lines: 54 X-Complaints-To: abuse AT newshosting DOT com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Apparently the error about retrieving data compatible with a char* was in error; the *other* point I was attempting to expose, is "WHAT does happen when in order to obtain a *specific* type of object, and there are insufficient bytes, WHAT should be expected from fread THEN ? As I tried to illustrate: a long is 4-bytes, double 8-bytes, if these number of bytes can not be retrieved, due to truncation, etc of the file, THEN what should be expected? I hope this clarifies things. Thanks. It is meant to trigger discussion; not criticize DJGPP. On Sat, 18 Dec 2004 19:06:44 -0500, DJ Delorie wrote: > >> Apparently we are seeing that using fread() and reading a size that >> exceeds the end_of_file, causes ZERO elements to be returned; this >> does not seem to be what most people are expecting: > >Please post your test program. Mine works fine: > >#include > >char buf[1024]; > >main() >{ > int rv; > FILE *f = fopen("afile.bin", "rb"); > > rv = fread (buf, sizeof(char), 128, f); > printf("ask 128 got %d\n", rv); > > rv = fread (buf, sizeof(char), 64, f); > printf("ask 64 got %d\n", rv); > > rv = fread (buf, sizeof(char), 128, f); > printf("ask 128 got %d\n", rv); > > fclose(f); > exit(0); >} > >C:\TMP> dj >ask 128 got 128 >ask 64 got 64 >ask 128 got 64 > >C:\TMP>