[Melbourne-pm] Q re perlxs

Brendon Oliver brendon.oliver at gmail.com
Mon Aug 22 15:12:34 PDT 2005


On Monday 22 August 2005 17:19, Sisyphus wrote:
> > I'm writing a perl wrapper for some functions in a C library we
> > have here at work. I have a situation where I want to return 0 if a
> > function call fails and set $! accordingly.
> >
> > Anybody have an example of how you do this?
>
> Seems you can just assign the appropriate value to errno. (Check
> 'errno.h' to see what the allowable values are and what they mean.)
> Here's an Inline::C demo, which prints a different message for $!,
> depending upon the random value that gets assigned to errno.
>
> use warnings;
>
> use Inline C => Config =>
>     BUILD_NOISY => 1;
>
> use Inline C => <<'EOC';
>
> #include <errno.h>
>
> void foo(SV * a) {
>      errno = (int)SvIV(a);
>      }
>
>
> EOC
>
> # Assign a random number in the range 1..42
> $x = 1 + int(rand(42));
>
> foo($x);
>
> print $x, "\n", $!, "\n";
>
> __END__
>

Ahh, ok - that should probably be all I need then.  For some reason I 
was thinking it was more complex.

Cheers,

- Brendon.

-- 
 ______________________________________ 
/ Living in New York City gives people \
| real incentives to want things that  |
\ nobody else wants. -- Andy Warhol    /
 -------------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


More information about the Melbourne-pm mailing list