[fpc-devel] Weird output from fpGetErrNo

Ewald ewald at yellowcouch.org
Wed Jan 30 20:06:48 CET 2013


Hello,

I was just writing a little mmapped (that's two `m`'s -- no typo ;-) )
file stream and thought to do it properly just in case I might fork().
So I thought to give some advise about memory:

    madvise(daBuffer, FileSize, MADV_DONTFORK);


Now if I check the result value and, if <> 0, print the detailed error
code using:

    ErrorCode:= fpGetErrNo();
    WriteMsg(strError(ErrorCode));


I get the most ambiguous results (ENOTTY, ENOENT, which are not even
documented as being possible error comditions after this call).

After some research I decided to try implement fpGetErrNo myself using
(straight from <errno.h> -- using linux 3.7.4 running x86_64 hardware):

    Function __errno_location: pcint; cdecl; external 'c' name
    '__errno_location';

    Function fpGetErrNo: cint;
    Begin
        Result:= __errno_location()^;
    End;


And this gave me the expected results (Out of memory, Success, ...).

So, did I discover a bug or do I miss something?


Just for the record: `daBuffer` is just mmapped in the line preceding
this one, there is no error there, it contains the right data,
`Filesize` is obtained through stat(), so no issue there either.

-- 
Ewald

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130130/bfb792b3/attachment.html>


More information about the fpc-devel mailing list