Borland C++ reference

unlock

raw OCR

Releases file-sharing locks.

Defined in header <io.h>

Syntax

#include <io.h>
int unlock(int handle, long offset,long length);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

unlock provides an interface to the DOS 3.x file-sharing mechanism.

unlock removes a lock previously placed with a call to lock. To avoid error, all locks must be removed before a file is closed. A program must release all locks before completing.

Return value

unlock returns 0 on success, -1 on error.

See also

Example

#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <process.h>
#include <share.h>
#include <stdio.h>

int main (void)
{
   int handle, status;
   long length;
   handle = sopen("c:\\autoexec.bat",0_RDONLY,SH_DENYNO,S_IREAD)  ;
   if (handle < 0)  {
       printf("sopen  failed\n");
       exit(l);
   }
   length = filelength (handle);
   status = lock(handle, 0L,length/2);
if (status == 0)
   printfC'lock succeeded\n" );
else
   printfC'lock failed\n");
status = unlock(handle, 0L,length/2);
if (status == 0)
   printf("unlock succeeded\n" );
else
   printf("unlock failed\n");
close(handle);
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.