[fpc-pascal]Signal handling with libc.pp

Jeff Pohlmeyer yetanothergeek at yahoo.com
Sat Jan 24 09:19:40 CET 2004


The libc unit declares the sigaction() function in "sigactionh.inc" as:

function sigaction( __sig:longint; Const act: _sigaction;
                    Var oldact: _sigaction):longint;cdecl;external clib name 'sigaction';


According to the libc man page: "Either act or oldact can be a null pointer."
 - But this is not possible, because call by var parameters have to match exactly.

So I think the function should be overloaded:

function sigaction( __sig:longint; act: P_sigaction;
                    oldact: P_sigaction):longint;cdecl;external clib name 'sigaction';




libc also says that the sa_handler field of a sigaction record can be
a function pointer, or one of the constants SIG_DFL or SIG_IGN.

"signumh.inc" defines these constants as:

    Const
       SIG_DFL  = (0);
       SIG_IGN  = (1);




But this does not work, because of pascal's strong type checking:

  MySigRec.sa_handler:=SIG_IGN;

% Error: Incompatible types:
    got "LongInt"
    expected "<procedure variable type of procedure(Longint);CDecl>"


Maybe this would be better?


    Const
         SIG_DFL = nil;


    function SIG_IGN:__sighandler_t;
    begin
      SIG_IGN:=__sighandler_t(pointer(1));
    end;




__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/




More information about the fpc-pascal mailing list