From b6f57560fb7fae00f0854ca19158bd5512e5405b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 1 Oct 2008 21:48:33 +0000 Subject: This commit is sure to break things. This should be a very, very minor change. What changed API-Wise: - I deleted a constructor in Bu::File that shouldn't have been used anyway. - I changed it from using fopen style mode strings to using libbu++ style mode flags. Check the docs for the complete list, but basically instead of "wb" you do Bu::File::Write, and so on, you can or any of the libbu++ flags together. There is no binary/text mode, it just writes whatever you tell it to verbatim (binary mode). Lots of extras are supported. Nothing else should have changed (except now the file stream is unbuffered, like all the other streams). Sorry if this breaks anything, if it's too annoying, use the last revision for a while longer. --- src/file.h | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/file.h') diff --git a/src/file.h b/src/file.h index e48e6f1..40419b0 100644 --- a/src/file.h +++ b/src/file.h @@ -10,7 +10,6 @@ #include #include -#include #include "bu/stream.h" #include "bu/fstring.h" @@ -27,9 +26,8 @@ namespace Bu class File : public Bu::Stream { public: - File( const char *sName, const char *sFlags ); - File( const Bu::FString &sName, const char *sFlags ); - File( int fd, const char *sFlags ); + File( const Bu::FString &sName, int iFlags ); + File( int fd ); virtual ~File(); virtual void close(); @@ -56,6 +54,19 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + enum { + // Flags + Read = 0x01, //< Open file for reading + Write = 0x02, //< Open file for writing + Create = 0x04, //< Create file if it doesn't exist + Truncate = 0x08, //< Truncate file if it does exist + Append = 0x10, //< Always append on every write + NonBlock = 0x20, //< Open file in non-blocking mode + Exclusive = 0x44, //< Create file, if it exists then fail + + // Helpful mixes + ReadWrite = 0x03 //< Open for reading and writing + }; /** * Create a temp file and return its handle *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" @@ -65,11 +76,11 @@ namespace Bu *@returns (Bu::File) A file object representing your temp file. */ #ifndef WIN32 - inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) + inline static Bu::File tempFile( Bu::FString &sName, int /*iFlags*/ ) { int afh_d = mkstemp( sName.getStr() ); - return Bu::File( afh_d, sFlags ); + return Bu::File( afh_d ); } /** @@ -87,8 +98,10 @@ namespace Bu #endif private: - FILE *fh; + int getPosixFlags( int iFlags ); + private: + int fd; }; } -- cgit v1.2.3