LockFile()

  LockFile

Description

LockFile() is used to set an exclusive (access) lock on the given file.

Call Signature

int LockFile ( int/string filespec, int wait_flag )

Return Value

int

Returns a flag indicating the success of the lock. 1 (TRUE) indicates the lock succeeded, while 0 (FALSE) indicates it failed. If wait_flag is TRUE, LockFile() will never succeed if the lock can not be grabbed.

Arguments

int/string filespec:

This can either be the handle returned by of of the file opening functions, or the name of such a file.

int wait_flag:

Set to 1 if LockFile() should wait till it can get the lock, or 0 if it should fail immediately if unable to obtain lock on first try.

Remarks

A file handle must first be obtained by opening the file, for Example using DBOpen(). On some platforms, it is necessary for the file to have been opened with write permission in order to successfully obtain an exclusive lock.

On unix systems, this lock is advisatory; that is it only prevents other processes from doing a LockFile() until the lock has been released with UnlockFile(). The file must be obtained with write permission to obtain the lock.

On Windows 95/NT, the lock will prevent the file from being opened with write permission by other processes.

Note: In Win95, LockFile() always return FALSE as the native LockFile() function in Win95 does not operate as expected.

See also

UnlockFile()

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.