src/File.cpp
changeset 8 21a6c17f4e3e
parent 2 851de24ecb61
child 9 629f61203db1
     1.1 --- a/src/File.cpp	Sun Sep 20 21:25:47 2009 -0700
     1.2 +++ b/src/File.cpp	Mon Sep 28 23:39:08 2009 -0700
     1.3 @@ -10,6 +10,7 @@
     1.4  #include "File.h"
     1.5  #include "MemoryMap.h"
     1.6  
     1.7 +#include <sys/file.h>
     1.8  #include <assert.h>
     1.9  #include <errno.h>
    1.10  #include <fcntl.h>
    1.11 @@ -26,11 +27,19 @@
    1.12           _locked(0)
    1.13      { }
    1.14  
    1.15 -    File::File (const char *filename, int oflag)  throw(Error)
    1.16 +    File::File (const char *filename, int oflag, bool locked)  throw(Error)
    1.17 +#if BSD
    1.18 +        :_fd(_check( ::open(filename, oflag | (locked ? O_EXLOCK : 0), 0644) )),
    1.19 +#else
    1.20          :_fd(_check( ::open(filename, oflag, 0644) )),
    1.21 +#endif
    1.22           _memoryMap(NULL),
    1.23 -         _locked( (oflag | O_EXLOCK) ?1 :0)
    1.24 -    { }
    1.25 +         _locked( locked ? 1 : 0)
    1.26 +    {
    1.27 +#if !BSDISH
    1.28 +      _check( ::flock(_fd, LOCK_EX) );
    1.29 +#endif
    1.30 +    }
    1.31  
    1.32      File::~File() {
    1.33          delete _memoryMap;
    1.34 @@ -102,7 +111,11 @@
    1.35      }
    1.36      
    1.37      void File::flushDisk()  throw(Error) {
    1.38 +#if OSX
    1.39          _check( ::fcntl(_fd,F_FULLFSYNC) );
    1.40 +#else
    1.41 +        _check( fsync(_fd) );
    1.42 +#endif
    1.43      }
    1.44      
    1.45      bool File::hasPath (const char *path) const  throw(Error) {