46 #include "qtlockedfile.h" 48 bool QtLockedFile::lock(LockMode mode,
bool block)
51 qWarning(
"QtLockedFile::lock(): file is not opened");
58 if (mode == m_lock_mode)
61 if (m_lock_mode != NoLock)
65 fl.l_whence = SEEK_SET;
68 fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
69 int cmd = block ? F_SETLKW : F_SETLK;
70 int ret = fcntl(handle(), cmd, &fl);
73 if (errno != EINTR && errno != EAGAIN)
74 qWarning(
"QtLockedFile::lock(): fcntl: %s", strerror(errno));
84 bool QtLockedFile::unlock()
87 qWarning(
"QtLockedFile::unlock(): file is not opened");
95 fl.l_whence = SEEK_SET;
99 int ret = fcntl(handle(), F_SETLKW, &fl);
102 qWarning(
"QtLockedFile::lock(): fcntl: %s", strerror(errno));
106 m_lock_mode = NoLock;
110 QtLockedFile::~QtLockedFile()