~vanhoof/+junk/znc

« back to all changes in this revision

Viewing changes to FileUtils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2011-02-06 17:41:38 UTC
  • mfrom: (21.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110206174138-ush4l5mkr4wg738n
Tags: 0.096-2
* Merge 0.092-3~bpo50+1 changelog.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include <sys/stat.h>
13
13
#include <sys/types.h>
14
14
#include <sys/wait.h>
 
15
#include <fcntl.h>
15
16
 
16
17
#ifndef HAVE_LSTAT
17
18
#  define lstat(a, b)   stat(a, b)
388
389
}
389
390
 
390
391
bool CFile::TryExLock() {
391
 
        return Lock(LOCK_EX|LOCK_NB);
 
392
        return Lock(F_WRLCK, false);
 
393
}
 
394
 
 
395
bool CFile::ExLock() {
 
396
        return Lock(F_WRLCK, true);
392
397
}
393
398
 
394
399
bool CFile::UnLock() {
395
 
        return Lock(LOCK_UN);
 
400
        return Lock(F_UNLCK, true);
396
401
}
397
402
 
398
 
bool CFile::Lock(int iOperation) {
 
403
bool CFile::Lock(int iType, bool bBlocking) {
 
404
        struct flock fl;
 
405
 
399
406
        if (m_iFD == -1) {
400
407
                return false;
401
408
        }
402
409
 
403
 
        if (flock(m_iFD, iOperation) != 0) {
 
410
        fl.l_type   = iType;
 
411
        fl.l_whence = SEEK_SET;
 
412
        fl.l_start  = 0;
 
413
        fl.l_len    = 0;
 
414
        if (fcntl(m_iFD, (bBlocking ? F_SETLKW : F_SETLK), &fl) == -1) {
404
415
                return false;
 
416
        } else {
 
417
                return true;
405
418
        }
406
 
 
407
 
        return true;
408
419
}
409
420
 
410
421
bool CFile::IsOpen() const { return (m_iFD != -1); }