contents   index   previous   next



Clib.flock()

syntax:

Clib.flock(filePointer, lockFlag)

where:

filePointer - pointer to file to use.

 

lockFlag - determines which locking operation to perform on a file. The flags are:

 

LOCK_EX
File lock exclusive (equivalent to LOCK_SH in Windows)

LOCK_SH
File lock share (equivalent to LOCK_EX in Windows)

LOCK_NB
File lock non-blocking (bitwise or with LOCK_EX or LOCK_SH)

LOCK_UN
File unlock

return:

number - 0 on success, else -1 on failure.

 

description:

This method allows a file to be locked or unlocked, which is a capability that is often important in a multi-tasking operating system.

 

The ability to lock and unlock access to a file varies among operating systems. For normal usage on most systems, the operating system handles all necessary locking and administration of sharing privileges for files. However, if a scripter needs extra control over files, ScriptEase provides the ability. For example, a script might use files to hold data while it is running but does not need to keep the files open during all phases of script execution. By locking and unlocking such files, a scripter ensures that these files are not altered while a script is running.

 

see:

Clib.fopen(), Clib.fclose()

 

example:

// The following fragment opens a file and

// then locks it for exclusive use without blocking

// further execution of the script.

 

var fp = Clib.fopen("myfile", "r");

Clib.flock(fp, LOCK_EX | LOCK_NB);

   // Use the file

Clib.flock(fp, LOCK_UN);

Clib.fclose(fp);

 


Clib.mkdir()