📄 my_lock.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -