[1181] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # gflock.pm - an attempt to use flock only on those platforms
|
---|
| 4 | # on which it's supported (i.e. everything but Windows 95/98)
|
---|
| 5 | #
|
---|
| 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
| 10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
| 26 | ###########################################################################
|
---|
| 27 |
|
---|
| 28 | package gflock;
|
---|
| 29 |
|
---|
| 30 | use Fcntl ':flock';
|
---|
| 31 |
|
---|
| 32 | # returns true if successful (or if OS is a form of windows other than NT)
|
---|
| 33 | sub lock {
|
---|
| 34 | my ($handle) = @_;
|
---|
| 35 |
|
---|
| 36 | if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) {
|
---|
| 37 | return 1;
|
---|
| 38 | } else {
|
---|
| 39 | return flock($handle, LOCK_EX);
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | # returns true if successful (or if OS is a form of windows other than NT)
|
---|
| 44 | sub unlock {
|
---|
| 45 | my ($handle) = @_;
|
---|
| 46 |
|
---|
| 47 | if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) {
|
---|
| 48 | return 1;
|
---|
| 49 | } else {
|
---|
| 50 | return flock($handle, LOCK_UN);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | 1;
|
---|