[comp.sys.mac] LSC fread limitation?

mike@artsvax.UUCP (12/02/87)

This is a continuation of my problem with reading entire files into
memory.  The following command:

unsigned char buffer[300*512];
FILE *fp;

fread(buffer,sizeof(char),300*512,fp);


... always reads in only 44 blocks, even though the file in question
contains no resources, and is over 300k in size.  The fread should
read until the end of file, set the EOF flag, and then return the
number of bytes read.  It always returns the number 44*512...
Does anyone have any idea why?

Any help would be appreciated..

--mike


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Michael S. Czeiszperger    | Disclaimer: "Sorry, I'm all out of pith" 
  Systems Programmer I	    | Smail: Room 406 Baker      (614)
   College of the Arts      |        1971 Neil Avenue      292-
     Computer Lab           |        Columbus, OH 43210     0895
The Ohio State University   | UUCP: {decvax,ucbvax}!cbosgd!osupyr!artsvax!mike
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

thomas%spline.utah.edu.uucp@utah-gr.UUCP (Spencer W. Thomas) (01/21/88)

In article <214@artsvax.UUCP> mike@artsvax.UUCP (Michael Czeiszperger) writes:
>fread(buffer,sizeof(char),300*512,fp);
>
>... always reads in only 44 blocks ... It always returns the number 44*512...
>Does anyone have any idea why?

Well, let's look at it.

300*512 = 153600

153600 mod 65536 = 22528

22528 / 512 = 44

Therefore we can conclude that LSC's 16 bit integer arithmetic is
truncating your result.  In fact, the documentation for fread claims
that the count argument is an int, so you really can't do better than
32767 bytes at once (unless you set size_of_ptr to something bigger
than one).

What happens if you use
	fread( buffer, 300, 512, fp );
?

=Spencer   ({ihnp4,decvax}!utah-cs!thomas, thomas@cs.utah.edu)