in reply to Why no LockFile() in Win32API::File ?
However, if you need the emulation, then it already exists in and is exported by perl58.dll under the name win32_flock. It can be access through Win32::API::Prototype as follows:
Update: Changed use to require + import.
#! perl -slw use strict; use Fcntl qw[ :flock ]; $|=1; if( $^O eq 'MSWin32' ) { { local $^W; require Win32::API::Prototype; Win32::API::Prototype->import( 'ApiLink' ); } ApiLink( 'perl58', 'int win32_flock(int fd, int oper)' ) or die $^ +E; our $flock; *flock = *win32_flock = *win32_flock; } die 'Already running' unless flock( DATA, LOCK_EX ); sleep 10; flock( DATA, LOCK_UN ) or die $!; __DATA__ stuff
However, in my tests just now, when running a second copy of the above script, the call to flock( LOCK_EX ), causes the script to silently terminate, so that may not be so useful after all.
I'm not sure whether
but maybe this and the pointer to the source will let someone who knows what they are doing work out which and, either point out my stupidity or raise a bug against the responsible component?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Why no LockFile() in Win32API::File ?
by demerphq (Chancellor) on Apr 11, 2006 at 08:30 UTC | |
by BrowserUk (Patriarch) on Apr 11, 2006 at 08:37 UTC | |
by demerphq (Chancellor) on Apr 11, 2006 at 09:40 UTC |