| 31 | namespace Firebird { |
| 32 | |
| 33 | class TempFile : public File |
| 34 | { |
| 35 | public: |
| 36 | TempFile(MemoryPool& pool, const PathName& prefix, const PathName& directory, |
| 37 | bool do_unlink = true) |
| 38 | : filename(pool), position(0), size(0), doUnlink(do_unlink) |
| 39 | { |
| 40 | init(directory, prefix); |
| 41 | } |
| 42 | |
| 43 | TempFile(const PathName& prefix, bool do_unlink = true) |
| 44 | : position(0), size(0), doUnlink(do_unlink) |
| 45 | { |
| 46 | init("", prefix); |
| 47 | } |
| 48 | |
| 49 | virtual ~TempFile(); |
| 50 | |
| 51 | FB_SIZE_T read(offset_t, void*, FB_SIZE_T); |
| 52 | FB_SIZE_T write(offset_t, const void*, FB_SIZE_T); |
| 53 | |
| 54 | void unlink(); |
| 55 | |
| 56 | offset_t getSize() const |
| 57 | { |
| 58 | return size; |
| 59 | } |
| 60 | |
| 61 | void extend(offset_t); |
| 62 | |
| 63 | const PathName& getName() const |
| 64 | { |
| 65 | return filename; |
| 66 | } |
| 67 | |
| 68 | static PathName getTempPath(); |
| 69 | static PathName create(const PathName& prefix, const PathName& directory = ""); |
| 70 | static PathName create(CheckStatusWrapper* status, const PathName& prefix, |
| 71 | const PathName& directory = ""); |
| 72 | |
| 73 | private: |
| 74 | void init(const PathName&, const PathName&); |
| 75 | void seek(const offset_t); |
| 76 | |
| 77 | #if defined(WIN_NT) |
| 78 | HANDLE handle; |
| 79 | #else |
| 80 | int handle; |
| 81 | #endif |
| 82 | |
| 83 | PathName filename; |
| 84 | offset_t position; |
| 85 | offset_t size; |
| 86 | bool doUnlink; |
| 87 | }; |
| 88 | |
| 89 | } // namespace Firebird |
| 90 | |