"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/qtsingleapplication/src/qtlockedfile_unix.cpp" between
cb2bib-1.9.9.tar.gz and cb2bib-2.0.0.tar.gz

About: cb2Bib is a multiplatform application for rapidly extracting unformatted, or unstandardized bibliographic references from email alerts, journal Web pages, and PDF files.

qtlockedfile_unix.cpp  (cb2bib-1.9.9):qtlockedfile_unix.cpp  (cb2bib-2.0.0)
skipping to change at line 50 skipping to change at line 50
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include "qtlockedfile.h" #include "qtlockedfile.h"
bool QtLockedFile::lock(LockMode mode, bool block) bool QtLockedFile::lock(LockMode mode, bool block)
{ {
if (!isOpen()) { if (!isOpen())
{
qWarning("QtLockedFile::lock(): file is not opened"); qWarning("QtLockedFile::lock(): file is not opened");
return false; return false;
} }
if (mode == NoLock) if (mode == NoLock)
return unlock(); return unlock();
if (mode == m_lock_mode) if (mode == m_lock_mode)
return true; return true;
skipping to change at line 72 skipping to change at line 73
unlock(); unlock();
struct flock fl; struct flock fl;
fl.l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
fl.l_start = 0; fl.l_start = 0;
fl.l_len = 0; fl.l_len = 0;
fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
int cmd = block ? F_SETLKW : F_SETLK; int cmd = block ? F_SETLKW : F_SETLK;
int ret = fcntl(handle(), cmd, &fl); int ret = fcntl(handle(), cmd, &fl);
if (ret == -1) { if (ret == -1)
{
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
return false; return false;
} }
m_lock_mode = mode; m_lock_mode = mode;
return true; return true;
} }
bool QtLockedFile::unlock() bool QtLockedFile::unlock()
{ {
if (!isOpen()) { if (!isOpen())
{
qWarning("QtLockedFile::unlock(): file is not opened"); qWarning("QtLockedFile::unlock(): file is not opened");
return false; return false;
} }
if (!isLocked()) if (!isLocked())
return true; return true;
struct flock fl; struct flock fl;
fl.l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
fl.l_start = 0; fl.l_start = 0;
fl.l_len = 0; fl.l_len = 0;
fl.l_type = F_UNLCK; fl.l_type = F_UNLCK;
int ret = fcntl(handle(), F_SETLKW, &fl); int ret = fcntl(handle(), F_SETLKW, &fl);
if (ret == -1) { if (ret == -1)
{
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
return false; return false;
} }
m_lock_mode = NoLock; m_lock_mode = NoLock;
return true; return true;
} }
QtLockedFile::~QtLockedFile() QtLockedFile::~QtLockedFile()
{ {
 End of changes. 4 change blocks. 
4 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)