1. wrapping the linux "C" signal function

i am having troubles *wrapping* the "C" language signal function in linux.
when i read the man page for signal the syntax is very confusing and even
when they tries to make it easier to read, it still confuses me.

here are both the function header syntaxes for "signal":

## C code ##

void (*signal(int signum, void(*handler)(int)))(int);

or

typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);

## end C code ##

can anyone clarify what this exactly means? C syntax can get so stupidly
cryptic sometimes. euphoria is simple, and thats good.

here is the euphoria code i have so far:

## eu code clip ##

include mixedlib.e -- Bernie's mixlib library
include lsock.e -- has the c_func definition for signal ( this works fine )

global function c_signal( int signum, pointer sig_handler )
  pointer sighandler_t, signum_ptr

  signum_ptr = get_pointer( signum ) -- get_pointer() just allocs mem for object
                                     -- and returns the pointer to mem
  sighandler_t = c_func( signal_, { signum_ptr, sig_handler } )

  return sighandler_t
end function

## end eu code clip ##

am i on the right track? any help would be appreciated.
thanks in advance everyone.

--
cense,
a member of the
ak-software development team

http://www.ak-software.com/

new topic     » topic index » view message » categorize

2. Re: wrapping the linux "C" signal function

On Wed, 19 Jul 2000, Jeffrey Fielding wrote:

> If you look at the man page on linux, and scroll down a bit, it gives a better
> expnanation:
> ------------------------from man signal--------------
> If you're confused by the prototype at  the  top  of  this
>        manpage, it may help to see it separated out thus:
>
>        typedef void (*sighandler_t)(int);
>        sighandler_t signal(int signum, sighandler_t handler)
> -------------------------------------------------
> The return value is a pointer, either the handler, or SIG_ERR if there's an
> error.
> The signum argument is a standard C_INT. It's passed by value, not by a
> reference
> (pointer).
> The handler argument is a pointer to a void function (procedure) which takes
> one
> argument (an int), which is the signal number.
> Here's an (untested) example:
>
> include dll.e
> include machine.e
> constant STDLIB = open_dll("")
> constant SIGNAL = define_c_func(STDLIB,"signal",{C_INT,C_POINTER},C_POINTER)
> -- routine is the routine_id of a procedure with 1 integer argument (the
> handler)
> -- return 0 if everything is ok, 1 if there's an error
> function c_signal(integer signum, integer routine)
>     atom ptr, r
>     ptr = call_back(routine)
>     r = c_func(SIGNAL,{signum,ptr})
>     if r = ptr then
>         return 0
>     else
>         return 1
>     end if
> end function
>
> Jeff Fielding
> JJProg at cyberbury.net

thanks for the quick response, looks like i was just a *little* off track
there. just one more thing, since i have not done alot of lower level
programming or routine_ids except for this wrapper lib im writing, what does the
call_back() routine actually do?

--
cense,
a member of the
ak-software development team

http://www.ak-software.com/

new topic     » goto parent     » topic index » view message » categorize

3. Re: wrapping the linux "C" signal function

>i am having troubles *wrapping* the "C" language signal function in linux.
>when i read the man page for signal the syntax is very confusing and even
>when they tries to make it easier to read, it still confuses me.

>here are both the function header syntaxes for "signal":

>## C code ##

>void (*signal(int signum, void(*handler)(int)))(int);

>or

>typedef void (*sighandler_t)(int);
>sighandler_t signal(int signum, sighandler_t handler);

>## end C code ##

>can anyone clarify what this exactly means? C syntax can get so stupidly
>cryptic sometimes. euphoria is simple, and thats good.


  cense:

    Although I'am not running linux, I think the first parameter should be

    using is a INTEGER type NOT a pointer.

    I think that you are confusing SIGNAL TYPES and SIGNAL ACTION CODES.

    SIGNAL TYPES look like this:

        SIGXXXX ( example SIGABRT ) this is a integer used in the FIRST
                                    parameter of the signal function.

    SIGNAL ACTION CODES look like this:

        SIG_XXXX ( example SIG_DFL ) NOTE the underscore in the name. This
                                          has to be a POINTER and is used
                                          in the SECOND parameter of the
                                          signal function.
                                          This is made into a POINTER with a
                                          MACRO in the signal.h.

  Hope this helps

  Bernie

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu