RAD Studio |  |

unlock

Header File

io.h

Category

Input/output Routines

Prototype

int unlock(int handle, long offset, long length);

Description

Releases file-sharing locks.

unlock provides an interface to the operating system 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

On success, unlock returns 0

O error, it returns -1.

Example

Copy Code

    #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",O_RDONLY,SH_DENYNO,S_IREAD);
       if (handle < 0)
       {
           printf("_sopen failed\n");
           exit(1);
       }
       length = filelength(handle);
       status = lock(handle,0L,length/2);
       if (status == 0)
          printf("lock succeeded\n");
       else
          printf("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;
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
| + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!