diff options
Diffstat (limited to '')
| -rw-r--r-- | src/file.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/file.h b/src/file.h new file mode 100644 index 0000000..d4e43eb --- /dev/null +++ b/src/file.h | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #ifndef BU_FILE_H | ||
| 2 | #define BU_FILE_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "bu/stream.h" | ||
| 7 | #include "bu/fstring.h" | ||
| 8 | |||
| 9 | namespace Bu | ||
| 10 | { | ||
| 11 | class File : public Bu::Stream | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | File( const char *sName, const char *sFlags ); | ||
| 15 | File( const Bu::FString &sName, const char *sFlags ); | ||
| 16 | File( int fd, const char *sFlags ); | ||
| 17 | virtual ~File(); | ||
| 18 | |||
| 19 | virtual void close(); | ||
| 20 | virtual size_t read( void *pBuf, size_t nBytes ); | ||
| 21 | virtual size_t write( const void *pBuf, size_t nBytes ); | ||
| 22 | |||
| 23 | virtual long tell(); | ||
| 24 | virtual void seek( long offset ); | ||
| 25 | virtual void setPos( long pos ); | ||
| 26 | virtual void setPosEnd( long pos ); | ||
| 27 | virtual bool isEOS(); | ||
| 28 | virtual bool isOpen(); | ||
| 29 | |||
| 30 | virtual void flush(); | ||
| 31 | |||
| 32 | virtual bool canRead(); | ||
| 33 | virtual bool canWrite(); | ||
| 34 | |||
| 35 | virtual bool isReadable(); | ||
| 36 | virtual bool isWritable(); | ||
| 37 | virtual bool isSeekable(); | ||
| 38 | |||
| 39 | virtual bool isBlocking(); | ||
| 40 | virtual void setBlocking( bool bBlocking=true ); | ||
| 41 | |||
| 42 | /** | ||
| 43 | * Create a temp file and return its handle | ||
| 44 | *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" | ||
| 45 | * It will alter your (sName) setting the 'X's to random | ||
| 46 | * characters. | ||
| 47 | *@param sFlags (const char *) Standard file flags 'rb'... etc.. | ||
| 48 | *@returns (Bu::File) A file object representing your temp file. | ||
| 49 | */ | ||
| 50 | #ifndef WIN32 | ||
| 51 | inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) | ||
| 52 | { | ||
| 53 | int afh_d = mkstemp( sName.getStr() ); | ||
| 54 | |||
| 55 | return Bu::File( afh_d, sFlags ); | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Set the size of the file to (nSize). You can either grow or shrink | ||
| 60 | * the file. | ||
| 61 | *@param nSize (long) The new size of the file. | ||
| 62 | */ | ||
| 63 | void truncate( long nSize ); | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Change the file access permissions. | ||
| 67 | *@param t (mode_t) The new file access permissions. | ||
| 68 | */ | ||
| 69 | void chmod( mode_t t ); | ||
| 70 | #endif | ||
| 71 | |||
| 72 | private: | ||
| 73 | FILE *fh; | ||
| 74 | |||
| 75 | }; | ||
| 76 | } | ||
| 77 | |||
| 78 | #endif | ||
