当前位置: 技术问答>linux和unix
fcntl设定文件锁的问题,求助
来源: 互联网 发布时间:2016-04-27
本文导语: 我想对一个文件实行排他锁,于是在dll里写了这样一个函数: int LockWholeFile(void* fp)//fp是fopen的返回值 { int fd; struct flock stLock; int nRet; memset(&stLock, 0x00, sizeof(stLock)); fd = fileno((FILE*)fp); TRACE("Begin to lock file,f...
我想对一个文件实行排他锁,于是在dll里写了这样一个函数:
int LockWholeFile(void* fp)//fp是fopen的返回值
{
int fd;
struct flock stLock;
int nRet;
memset(&stLock, 0x00, sizeof(stLock));
fd = fileno((FILE*)fp);
TRACE("Begin to lock file,fp[%d], fd[%d]", fp, fd);
stLock.l_type = F_WRLCK;
stLock.l_whence = SEEK_SET;
stLock.l_start = 0;
stLock.l_len = 1;
nRet = fcntl(fd, F_SETLKW, &stLock);
if( nRet
int LockWholeFile(void* fp)//fp是fopen的返回值
{
int fd;
struct flock stLock;
int nRet;
memset(&stLock, 0x00, sizeof(stLock));
fd = fileno((FILE*)fp);
TRACE("Begin to lock file,fp[%d], fd[%d]", fp, fd);
stLock.l_type = F_WRLCK;
stLock.l_whence = SEEK_SET;
stLock.l_start = 0;
stLock.l_len = 1;
nRet = fcntl(fd, F_SETLKW, &stLock);
if( nRet