my_lock.cpp

来自「液晶电视完整代码可实现人机界面」· C++ 代码 · 共 64 行

CPP
64
字号
#include "my_lock.h"static int lock_fd = -1;int errno;#define LOCK_FILE "LOCKFILE.LOC"//static char *tmp_file;int operFilelock(int fd, int cmd, int type, off_t offset, int whence, off_t len){	struct flock	lock;	lock.l_type	= type;	lock.l_start	= offset;	lock.l_whence	= whence;	lock.l_len	= len;	return ( fcntl(fd, cmd, &lock) );}//int my_lock_init(char* lock_file)//{//	tmp_file = new char[20];//	sprintf( tmp_file, lock_file);//		//	return 0;//}int my_lock_wait(char *runlock){	long	rc	= 0;	char    lockfile[50];	memset( lockfile, 0x0, sizeof(lockfile));	if( strlen(runlock)==0 )		exit(-1);	sprintf( lockfile,"%s/bin/%s", getenv("HOME"),runlock);		lock_fd = open( lockfile, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);	rc = filelockW(lock_fd, 0, SEEK_SET, 0);	if (rc < 0) 	{		if (lock_fd > 0)		{ 			close(lock_fd);		}		if ((EACCES == errno) || (EAGAIN == errno)) 		{			return ( 0 );		} 		else 		{			return ( -1 );		}	}	return lock_fd;}int my_lock_release(){		filelockU(lock_fd, 0, SEEK_SET, 0);	close(lock_fd);		return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?