I have developed this simple test to set $! - would appreciate comments -
thank you.
#! /usr/local/bin/perl -w
use Inline C => Config => CCFLAGS => '-Wall';
use Inline C;
$value = perl_std_rtn("good") || die "Cannot do function: $!";
print ($value,"\n");
if ($value = perl_std_rtn("good")) {
print ("Test[2] $value\n");
} else {
print ("Test[2] $!\n");
}
if (perl_std_rtn("good")) {
print ("Test[3] true\n");
} else {
print ("Test[3] $!\n");
}
if ($value = perl_std_rtn("error")) {
print ("Test[4] true\n");
} else {
print ("Test[4] $!\n");
}
$value = perl_std_rtn("error") || die "Cannot do function: $!";
print ($value,"\n");
__END__
__C__
void perl_std_rtn(char *test) {
SV* perlbang = get_sv("!", FALSE);
int i;
Inline_Stack_Vars;
Inline_Stack_Reset;
// Setup the success code.
sv_setiv(perlbang,(IV) 0);
sv_setpv(perlbang,"");
SvIOK_on(perlbang);
// Simulated error.
if (strcmp(test,"error") == 0) {
// Set the error return.
sv_setiv(perlbang, (IV) 1);
sv_setpv(perlbang, "error msg");
SvIOK_on(perlbang);
Inline_Stack_Done;
return;
} else {
// Simulated success.
Inline_Stack_Push(newSVpv(test,0));
Inline_Stack_Done;
return;
}
}