title: fread sometimes returns wrong values with files larger than 4GiB
body: <p>I'm trying to read a big binary file made of 30e6 positions, each with 195 doubles.
  Since the file is too big to read all into memory, I'm reading it by chunks of 10000 positions. I then do some calculation with it and read the next chunk....</p>
  
  <p>Since I need random access to the file, I've written a function to read a given chunk (unsigned int chunk) from the file and store it in **chunk_data. the function returns the total number of positions read.</p>
  
  <pre><code>unsigned int read_chunk(double **chunk_data, unsigned int chunk) {
      FILE *in_glf_fh;
      unsigned int total_bytes_read = 0;
  
      // Define chunk start and end positions
      unsigned int start_pos = chunk * 10000;
      unsigned int end_pos = start_pos + 10000 - 1;
      unsigned int chunk_size = end_pos - start_pos + 1;
  
      // Open input file
      in_glf_fh = fopen(in_glf, "rb");
      if( in_glf_fh == NULL )
          error("ERROR: cannot open file!");
  
      // Search start position
      if( fseek(in_glf_fh, start_pos * 195 * sizeof(double), SEEK_SET) != 0 )
          error("ERROR: cannot seek file!");
  
      // Read data from file
      for(unsigned int c = 0; c &lt; chunk_size; c++) {
           unsigned int bytes_read = fread ( (void*) chunk_data[c], sizeof(double), 195, in_glf_fh);
           if( bytes_read != 195 &amp;&amp; !feof(in_glf_fh) )
               error("ERROR: cannot read file!");
           total_bytes_read += bytes_read;
      }
  
      fclose(in_glf_fh);
      return( total_bytes_read/195 );
  }
  </code></pre>
  
  <p>The problem is, after reading some chunks, <code>fread()</code> starts giving the wrong values!
  Also, depending on the chunk size, the positions where <code>fread()</code> starts behaving strangely differs:</p>
  
  <pre><code>chunk of 1 pos, wrong at chunk 22025475
  chunk of 10000 pos, wrong at chunk 2203
  chunk of 100000 pos, wrong at chunk 221
  </code></pre>
  
  <p>Anyone has any idea of what might be going on?</p>