Goto main content

lock

Lock a file or Open and lock a file

LOCK

NAME

lock - Lock or open and lock a file.

SYNOPSIS

lock([locktype:1,2,0x0010,0x000F] [permissions:integer, owner:"rwx", group:"rwx", other:"rwx",][read:bool,write:bool,append:true|false,create:true|false,error:variable]"src filename");

lock([locktype:1,2,0x0010,0x000F] [permissions:integer, owner:"rwx", group:"rwx", other:"rwx",][read:bool,write:bool,append:true|false,create:true|false,error:variable]filename:"src filename");

lock([locktype:1,2,0x0010,0x000F] [permissions:integer, owner:"rwx", group:"rwx", other:"rwx",][read:bool,write:bool,append:true|false,create:true|false,error:variable]filedes: pointer);

DESCRIPTION

This function is used to lock a file. The file is automatically unlock at the end of the request or by using the unction unlock

The type of lock are (defined as constant in extenso.sn):


APR_FLOCK_EXCLUSIVE   2
Exclusive lock. Only one process may hold an exclusive lock at any given time. This is analogous to a "write lock".


APR_FLOCK_NONBLOCK   0x0010
do not block while acquiring the file lock


APR_FLOCK_SHARED   1
Shared lock. More than one process or thread can hold a shared lock at any given time. Essentially, this is a "read lock", preventing writers from establishing an exclusive lock.

APR_FLOCK_TYPEMASK   0x000F
mask to extract lock type

If the file is correctly lock, a pointer to the file open (lock open the file for locking) is returned.

If the file is not correctly lock, an integer is return.

If the file is already open, you can use the pointer return by open to lock the file.

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

l = lock(create:true,write:true,locktype:LOCK_EXCLUSIVE|LOCK_NONBLOCK,"/tmp/lock");
if type(l) eq "int" then
        "An error has occured.\n";
endif

SEE ALSO

{{ include("includes/files.sn") }}

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2016-07-22 21:24:14 laplante@sednove.com

VERSION

Implemented in version 5.66 of Sncode

Edit

© 2024 extenso Inc. All rights reserved.