设为首页 加入收藏 繁体中文
当前位置:速查手册首页 >> 函数命令 >> u >> C语言函数: unlock
C语言函数: unlock
2008-09-03 15:22:51  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
  •   功 能: 解除文件共享锁

函数名: unlock
功  能: 解除文件共享锁
用  法: int unlock(int handle, long offset, long length);
程序例:

#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;
}

0

顶一下

0

踩一下
友情链接 | 诚聘英才 | 关于我们 | 版权声明 | 联系我们 | 广告服务

  • 〖 颖思设计 ☆ WinYes.COM 〗
  • 在线咨询:   
  •     粤ICP备05002304号