Added library target, changed some build settings, and fixed 64-to-32-bit conversion warnings.
5 * Created by Jens Alfke on 8/20/09.
6 * Copyright 2009 Jens Alfke. All rights reserved.
7 * BSD-Licensed: See the file "LICENSE.txt" for details.
10 #ifndef _MOOSEYARD_FILE_
11 #define _MOOSEYARD_FILE_
19 /** An open file on disk; a thin wrapper around a Unix file descriptor. */
25 const char* const message;
27 Error(int c, const char *m) :code(c), message(m) { }
30 static const int kEOF = 10001;
33 File (const char *filename, bool writeable =false, bool create =false) throw(Error);
34 File (const char *filename, int oflag) throw(Error);
37 off_t length() const throw(Error);
38 void setLength (off_t) throw(Error);
40 off_t position() const throw(Error);
41 void setPosition (off_t) throw(Error);
42 off_t setPositionToEnd (off_t bytesBefore =0) throw(Error);
44 void read (void *dst, size_t) throw(Error);
45 size_t write (const void *src, size_t) throw(Error);
47 void readFrom (off_t where, void *dst, size_t) throw(Error);
48 void writeTo (off_t where, const void *src, size_t) throw(Error);
50 size_t writeMultiple (Blob blobs[], int count) throw(Error);
51 size_t writePadding (int alignment); // alignment should be a power of 2
54 const MemoryMap* map() const {return const_cast<File*>(this)->map();}
55 void mapRegion (off_t position, size_t length);
56 const void* mappedPosition (off_t position) const;
58 void flush() throw(Error); // Regular fsync call
59 void flushDisk() throw(Error); // Expensive F_FULLFSYNC call
62 void read (T& t) throw(Error) {read(&t,sizeof(t));}
64 size_t write (const T& t) throw(Error) {return write(&t,sizeof(t));}
66 void readFrom (off_t where, T &t) throw(Error) {readFrom(where,&t,sizeof(t));}
68 void writeTo (off_t where, const T &t) throw(Error) {writeTo(where,&t,sizeof(t));}
70 bool hasPath (const char *path) const throw(Error);
72 static void unlink (const char *filename) throw(Error);
73 static void rename (const char *srcFilename, const char *dstFilename) throw(Error);
78 Lock (File*, bool block =true) throw(Error);
80 bool isLocked() const {return _locked;}
81 operator bool() const {return _locked;}
91 static int _open (const char *filename, int posixMode) throw(Error);
92 static ssize_t _check (ssize_t result) throw(Error) {_check((int)result); return result;}
93 static off_t _check (off_t result) throw(Error) {_check((int)result); return result;}
94 static int _check (int result) throw(Error);
95 static void _checkRead (ssize_t result, size_t expectedSize) throw(Error);
96 bool _lock (bool block);
101 mutable MemoryMap *_memoryMap;
104 friend class MemoryMap;
109 #endif _MOOSEYARD_FILE_