diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:22:18 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:22:18 +0200 |
commit | bcc5cc28c6dc5178e8f4fd0cc521034ae5def388 (patch) | |
tree | bacc60d27b435d32172f97643576c5e4e953177d /zen/file_io.h | |
parent | 5.9 (diff) | |
download | FreeFileSync-bcc5cc28c6dc5178e8f4fd0cc521034ae5def388.tar.gz FreeFileSync-bcc5cc28c6dc5178e8f4fd0cc521034ae5def388.tar.bz2 FreeFileSync-bcc5cc28c6dc5178e8f4fd0cc521034ae5def388.zip |
5.10
Diffstat (limited to 'zen/file_io.h')
-rw-r--r-- | zen/file_io.h | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/zen/file_io.h b/zen/file_io.h index b4d58ea4..31373857 100644 --- a/zen/file_io.h +++ b/zen/file_io.h @@ -7,15 +7,16 @@ #ifndef FILEIO_H_INCLUDED #define FILEIO_H_INCLUDED +#include "file_io_base.h" +#include "file_error.h" + #ifdef FFS_WIN #include "win.h" //includes "windows.h" - #elif defined FFS_LINUX #include <cstdio> +#include <sys/stat.h> #endif -#include "zstring.h" -#include "file_error.h" namespace zen { @@ -25,7 +26,7 @@ static const char LINE_BREAK[] = "\r\n"; static const char LINE_BREAK[] = "\n"; #endif -//file IO optimized for sequential read/write accesses + better error reporting + long path support (following symlinks) +//buffered file IO optimized for sequential read/write accesses + better error reporting + long path support (following symlinks) #ifdef FFS_WIN typedef HANDLE FileHandle; @@ -33,52 +34,66 @@ typedef HANDLE FileHandle; typedef FILE* FileHandle; #endif -class FileInput +class FileInput : public FileInputBase { public: FileInput(const Zstring& filename); //throw FileError, ErrorNotExisting FileInput(FileHandle handle, const Zstring& filename); //takes ownership! ~FileInput(); - size_t read(void* buffer, size_t bytesToRead); //throw FileError; returns actual number of bytes read - bool eof() { return eofReached; } //end of file reached - - const Zstring& getFilename() const { return filename_; } + virtual size_t read(void* buffer, size_t bytesToRead); //throw FileError; returns actual number of bytes read + //expected to fill buffer completely unless "end of file" private: - FileInput(const FileInput&); - FileInput& operator=(const FileInput&); - - bool eofReached; FileHandle fileHandle; - const Zstring filename_; }; -class FileOutput +class FileOutput : public FileOutputBase { public: - enum AccessFlag - { - ACC_OVERWRITE, - ACC_CREATE_NEW - }; FileOutput(const Zstring& filename, AccessFlag access); //throw FileError, ErrorTargetPathMissing, ErrorTargetExisting FileOutput(FileHandle handle, const Zstring& filename); //takes ownership! ~FileOutput(); - void write(const void* buffer, size_t bytesToWrite); //throw FileError - - const Zstring& getFilename() const { return filename_; } + virtual void write(const void* buffer, size_t bytesToWrite); //throw FileError private: - FileOutput(const FileOutput&); - FileOutput& operator=(const FileOutput&); - FileHandle fileHandle; - const Zstring filename_; }; + +#ifdef FFS_LINUX +class FileInputUnbuffered : public FileInputBase +{ +public: + FileInputUnbuffered(const Zstring& filename); //throw FileError, ErrorNotExisting + ~FileInputUnbuffered(); + + //considering safe-read.c it seems buffer size should be a multiple of 8192 + virtual size_t read(void* buffer, size_t bytesToRead); //throw FileError; returns actual number of bytes read + //we should not rely on buffer being filled completely! + + int getDescriptor() { return fdFile;} + +private: + int fdFile; +}; + +class FileOutputUnbuffered : public FileOutputBase +{ +public: + //creates a new file (no overwrite allowed!) + FileOutputUnbuffered(const Zstring& filename, mode_t mode); //throw FileError, ErrorTargetPathMissing, ErrorTargetExisting + ~FileOutputUnbuffered(); + + virtual void write(const void* buffer, size_t bytesToWrite); //throw FileError + int getDescriptor() { return fdFile;} + +private: + int fdFile; +}; +#endif } #endif // FILEIO_H_INCLUDED |