Re: Locking Files?
Re: Locking Files?
- Subject: Re: Locking Files?
- From: Vince DeMarco <email@hidden>
- Date: Fri, 7 Sep 2001 11:36:27 -0700
On Friday, September 7, 2001, at 02:16 am, Josh M. Hurd wrote:
Hello list,
Is it possible to lock and unlock files in Cocoa? I checked the
NSFileManger docs but it doesn't seem to mention anything about locking
files. I also checked the Functions section for Foundation and AppKit.
Do I have to resort to using Carbon functions? I'd rather not if
possible.
man flock
FLOCK(2) System Programmer's Manual
FLOCK(2)
NAME
flock - apply or remove an advisory lock on an open file
SYNOPSIS
#include <sys/file.h>
#define LOCK_SH 1 /* shared lock */
#define LOCK_EX 2 /* exclusive lock */
#define LOCK_NB 4 /* don't block when locking */
#define LOCK_UN 8 /* unlock */
int
flock(int fd, int operation)
DESCRIPTION
Flock() applies or removes an advisory lock on the file associated
with
the file descriptor fd. A lock is applied by specifying an operation
pa-
rameter that is one of LOCK_SH or LOCK_EX with the optional addition
of
LOCK_NB. To unlock an existing lock operation should be LOCK_UN.
Advisory locks allow cooperating processes to perform consistent
opera-
tions on files, but do not guarantee consistency (i.e., processes may
still access files without using advisory locks possibly resulting in
in-
consistencies).