[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl & Databases



At 14.24 -0500 1999.01.03, Bart Lateur wrote:
>As it is now, you need to check $^O to see if your platform
>supports/needs flock. Very messy.
>
>I would prefer it if at least there would be some flag available to the
>Perl programmer to see which case you're in.

Your wish is my command.

  #!perl -w
  use Config;
  printf "I %s flock!\n", $Config{d_flock} ? "can" : "cannot";

Also:

% perl -MConfig -e 'printf "I %s flock!\n", $Config{d_flock} ? "can" :
"cannot"'

Although, this depends on d_flock being properly defined/undefined in
Config.pm, which may not be the case: perlfunc notes you can have perl use
its own fcntl-based emulation by undeffing flock in Config.pm.

Although, when i have seen flock() undefined, I have always seen lockf()
defined (where flock() is supported), so maybe this would be good:

  $can_flock = $Config{d_flock} || $Config{d_lockf};

In my experience, that should work.

If that's not good, you can try this serious kludge:

  $can_flock = defined(eval "flock(undef, 9)");

In my experience, flock actually returns 0 on failure.  It is documented to
return FALSE on failure, but it seems that FALSE is in the form of 0.  So
an eval() of a bad flock() will return 0, but an eval of an unsupported
flock() will return undef.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch