AcornSearch - Acorn and RISC OS information searching
RISC OS Search
containing
"Nutty quip goes here!"
Home  |  About  |  Filebase Archive  |  StrongHelp Manuals  |  Newsgroups  |  Module Database
flock FILEHANDLE,OPERATION

Calls flock(2) on FILEHANDLE.  See flock(2) for
definition of OPERATION.  Returns TRUE for success, FALSE on failure.
Will produce a fatal error if used on a machine that doesn't implement
flock(2).  Here's a mailbox appender for BSD systems.

$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;

sub lock {
flock(MBOX,$LOCK_EX);
seek(MBOX, 0, 2);
}

sub unlock {
flock(MBOX,$LOCK_UN);
}

open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
or die "Can't open mailbox: $!";

lock();
print MBOX $msg,"\n\n";
unlock();

Note that flock() can't lock things over the network.  You need to do
locking with fcntl() for that.


[sh-index] Back to list of manuals