[fpc-pascal] getlastoserror giving wrong value?
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);
> n := getlastoserror;
> The output:
> file: /home/marc/program/Test_C/unreadable/
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.
More information about the fpc-pascal