filelock.cpp

来自「一套linux下的C++开发库」· C++ 代码 · 共 56 行

CPP
56
字号
/***************************************************************************                          filelock.cpp  -  description                             -------------------    begin                : Fri Jul 20 2001    copyright            : (C) 2001 by Mark    email                : alben@yeah.net ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include "filelock.h"CFileLock::CFileLock(const char* sPath){	if ((m_iFd = open(sPath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0)		throw CFileLockException(strerror(errno), __FILE__, __LINE__);}CFileLock::~CFileLock(){	close(m_iFd);}bool CFileLock::Fcntl(int iCmd, int iType, int iOffset, int iLen, int iWhence){	struct flock stLock;	stLock.l_type = iType;	stLock.l_start = iOffset;	stLock.l_whence = iWhence;	stLock.l_len = iLen;	if (fcntl(m_iFd, iCmd, &stLock) < 0)	{		if (errno == EINTR)			return false;					throw CFileLockException(strerror(errno), __FILE__, __LINE__);	}		return true;}

⌨️ 快捷键说明

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