[fpc-pascal] getlastoserror giving wrong value?

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Dec 21 13:37:31 CET 2007


On 21 Dec 2007, at 06:37, Marc Santhoff wrote:

> when I try to use getlastoserror something "funny" happens.
>
> We're dealing with:
>
> $ ll /home/marc/program/Test_C/unreadable/
> ls: : Permission denied
>
> The source:
>
>   tmp := aFile^ + '/' + dirrec.Name;
>   writeln('file: '+ tmp );
>   n := fpaccess(tmp , R_OK);
>   writeln(n);
>   n := getlastoserror;
>   writeln(n);
>
> The output:
>
> file: /home/marc/program/Test_C/unreadable/
> -1
> -65523

Regardless of what the real problem is, the above code is wrong:  
writeln (obviously) also makes use of OS functions to write things  
out to the screen, and if one of those (temporarily) fails for some  
reason (e.g., ESysEINTR) then your call to getlastoserror will return  
the result of that failure. Just like with ioresult, you always have  
to store the result of getlastoserror immediately in a local variable  
after the operation you want to check.


Jonas



More information about the fpc-pascal mailing list