Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-01

Signal handling with libc.pp

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jeff Pohlmeyer

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/