1.1 --- a/src/File.cpp Mon Sep 28 23:39:08 2009 -0700
1.2 +++ b/src/File.cpp Tue Sep 29 15:46:42 2009 -0700
1.3 @@ -21,14 +21,8 @@
1.4
1.5 namespace Mooseyard {
1.6
1.7 - File::File (const char *filename, bool writeable, bool create) throw(Error)
1.8 - :_fd(_check( ::open(filename, writeable ?(create ?O_RDWR|O_CREAT :O_RDWR) :O_RDONLY, 0644) )),
1.9 - _memoryMap(NULL),
1.10 - _locked(0)
1.11 - { }
1.12 -
1.13 File::File (const char *filename, int oflag, bool locked) throw(Error)
1.14 -#if BSD
1.15 +#ifdef _DARWIN_C_SOURCE
1.16 :_fd(_check( ::open(filename, oflag | (locked ? O_EXLOCK : 0), 0644) )),
1.17 #else
1.18 :_fd(_check( ::open(filename, oflag, 0644) )),
1.19 @@ -36,7 +30,7 @@
1.20 _memoryMap(NULL),
1.21 _locked( locked ? 1 : 0)
1.22 {
1.23 -#if !BSDISH
1.24 +#ifndef _DARWIN_C_SOURCE
1.25 _check( ::flock(_fd, LOCK_EX) );
1.26 #endif
1.27 }
1.28 @@ -59,15 +53,21 @@
1.29 }
1.30
1.31 off_t File::position() const throw(Error) {
1.32 - return _check( lseek(_fd,0,SEEK_CUR) );
1.33 + off_t pos = lseek(_fd,0,SEEK_CUR);
1.34 + if (pos < 0)
1.35 + _check(-1);
1.36 + return pos;
1.37 }
1.38
1.39 void File::setPosition (off_t pos) throw(Error) {
1.40 - _check( lseek(_fd,pos,SEEK_SET) );
1.41 + _check( (int) lseek(_fd,pos,SEEK_SET) );
1.42 }
1.43
1.44 off_t File::setPositionToEnd (off_t bytesBefore) throw(Error) {
1.45 - return _check( lseek(_fd,-bytesBefore,SEEK_END) );
1.46 + off_t pos = lseek(_fd,-bytesBefore,SEEK_END);
1.47 + if (pos < 0)
1.48 + _check(-1);
1.49 + return pos;
1.50 }
1.51
1.52 void File::read (void *dst, size_t size) throw(Error) {
1.53 @@ -111,7 +111,13 @@
1.54 }
1.55
1.56 void File::flushDisk() throw(Error) {
1.57 -#if OSX
1.58 +#if _DARWIN_C_SOURCE
1.59 + /* F_FULLFSYNC is Mac/Darwin specific. From the man page:
1.60 + Does the same thing as fsync(2) then asks the drive to flush all buffered data to
1.61 + the permanent storage device (arg is ignored). This is currently implemented on
1.62 + HFS, MS-DOS (FAT), and Universal Disk Format (UDF) file systems. The operation may
1.63 + take quite a while to complete. Certain FireWire drives have also been known to
1.64 + ignore the request to flush their buffered data. */
1.65 _check( ::fcntl(_fd,F_FULLFSYNC) );
1.66 #else
1.67 _check( fsync(_fd) );