[fpc-pascal]blockread in a procedure (last try!)

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Sun Feb 29 12:54:23 CET 2004

On Sun, 29 Feb 2004, David Emerson wrote:

> Hi there,
> I'm having trouble using blockread. It was working for... oh, a year... and all of a sudden it's not working. I'm getting a runtime error 87 in win32/i386 (fpc 1.0.10) and an error 217 in linux/i386 (fpc 1.0.6). Since I always compile with -gl it tells me it's failing right at blockread. Here's the code...

OK, last try. Not being entirely satisfied with my previous posts, I dug a
little deeper. The strace on linux pointed me to the error.

> const
>   test_file_name = 'test.txt';
>   the_source : ansistring = '';
> procedure read_source_file;
>   const
>     bufsize = 2048;
>   var
>     source_file : file;
>     buf : array [1..bufsize] of char;
>     count_read : longint;   // longint required by blockread
>   begin
>     write ('Reading source file.....');
>     assign (source_file, test_file_name);
>     reset (source_file);

This is the culprit. It should read
      reset (source_file,1);
By default, the blocksize is 128.

>     the_source := '';
>     repeat
>       blockread (source_file, buf, bufsize, count_read);

With a blocksize of 128, this will try to read 128*2028 (256K) 
bytes.  My guess is that the OS decides this is outside the 
valid stack range, and bails out. Chaning the blocksize to 1 in your
original procedure makes things work just fine.

Remains the question how this ever could have worked.


More information about the fpc-pascal mailing list