On Nov 25, 2006, at 7:26 PM, Sisyphus wrote:
Hi,
Where do I find the definitions (assuming such exist) that I can
use to
determine from within an XSub:
1) The operating system in use (specifically, whether it's Cygwin);
2) The version of perl (specifically, whether it's >= 5.6.1);
In the past I've used the values of $] and $^O to DEFINE my own
symbols in
the Makefile.PL - which works fine, but is a little silly if the
info the
XSub needs is already available.
You can use those variables in XS the same as in perl code. This
works for me:
void
do_it ()
CODE:
/* Note that ^O is literally ^O, as in ^v^O in vim, or hex 0x0f.
* The control char doesn't want to show in my mailer so here
* it is in C hex. */
SV * os = get_sv ("\x0f", FALSE);
SV * version = get_sv ("]", FALSE);
if (os)
warn ("$^O = '%s'\n", SvPV_nolen (os));
if (version)
warn ("$] = '%s'\n", SvPV_nolen (version));
That prints
$^O = 'linux'
$] = '5.008003'
on my system.
But the perlvar manpage warns against using $^O on windows...
$^O The name of the operating system under which this
copy of Perl was
built, as determined during the configuration
process. The value
is identical to $Config{'osname'}. See also Config
and the -V
command-line switch documented in perlrun.
In Windows platforms, $^O is not very helpful: since
it is always
"MSWin32", it doesn't tell the difference between
95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or
Win32::GetOSVersion() (see Win32 and perlport) to
distinguish
between the variants.
Dunno if that's relevant for using Cygwin.