delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/12/20/17:15:39

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Radical NetSurfer <RadSurfer AT yahoo DOT com>
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: <boo8s01asckvrn9mb24hdl9fkjjq3bqq1g AT 4ax DOT com> <200412190006 DOT iBJ06ike016912 AT envy DOT delorie DOT com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
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 <dj AT delorie DOT com> 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 <stdio.h>
>
>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>

- Raw text -


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