unlock
io.h:インデックス への移動
ヘッダーファイル
io.h
カテゴリ
入出力ルーチン
プロトタイプ
int unlock(int handle, long offset, long length);
説明
ファイル共有ロックを解放します。
unlock は,オペレーティングシステムのファイル共有メカニズムへのインターフェースを提供します。unlock は,前に lock を呼び出して設定されたロックを解除します。エラーを回避するには,ファイルを閉じる前にすべてのロックを解除する必要があります。プログラムは,終了する前にすべてのロックを解放する必要があります。
戻り値
成功した場合,unlock は 0 を返します。
O エラーの場合は -1 を返します。
例
#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;
}
移植性
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |