aboutsummaryrefslogtreecommitdiff
path: root/src/file.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-10-01 21:48:33 +0000
committerMike Buland <eichlan@xagasoft.com>2008-10-01 21:48:33 +0000
commitb6f57560fb7fae00f0854ca19158bd5512e5405b (patch)
treeaa3c7012ee2b1ee9b97b1ba136217cbf6a84d587 /src/file.h
parentd872f7e07c5367f251cf5ebb70a03916251f5306 (diff)
downloadlibbu++-b6f57560fb7fae00f0854ca19158bd5512e5405b.tar.gz
libbu++-b6f57560fb7fae00f0854ca19158bd5512e5405b.tar.bz2
libbu++-b6f57560fb7fae00f0854ca19158bd5512e5405b.tar.xz
libbu++-b6f57560fb7fae00f0854ca19158bd5512e5405b.zip
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.
Diffstat (limited to '')
-rw-r--r--src/file.h27
1 files changed, 20 insertions, 7 deletions
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 @@
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <sys/types.h> 12#include <sys/types.h>
13#include <stdlib.h>
14 13
15#include "bu/stream.h" 14#include "bu/stream.h"
16#include "bu/fstring.h" 15#include "bu/fstring.h"
@@ -27,9 +26,8 @@ namespace Bu
27 class File : public Bu::Stream 26 class File : public Bu::Stream
28 { 27 {
29 public: 28 public:
30 File( const char *sName, const char *sFlags ); 29 File( const Bu::FString &sName, int iFlags );
31 File( const Bu::FString &sName, const char *sFlags ); 30 File( int fd );
32 File( int fd, const char *sFlags );
33 virtual ~File(); 31 virtual ~File();
34 32
35 virtual void close(); 33 virtual void close();
@@ -56,6 +54,19 @@ namespace Bu
56 virtual bool isBlocking(); 54 virtual bool isBlocking();
57 virtual void setBlocking( bool bBlocking=true ); 55 virtual void setBlocking( bool bBlocking=true );
58 56
57 enum {
58 // Flags
59 Read = 0x01, //< Open file for reading
60 Write = 0x02, //< Open file for writing
61 Create = 0x04, //< Create file if it doesn't exist
62 Truncate = 0x08, //< Truncate file if it does exist
63 Append = 0x10, //< Always append on every write
64 NonBlock = 0x20, //< Open file in non-blocking mode
65 Exclusive = 0x44, //< Create file, if it exists then fail
66
67 // Helpful mixes
68 ReadWrite = 0x03 //< Open for reading and writing
69 };
59 /** 70 /**
60 * Create a temp file and return its handle 71 * Create a temp file and return its handle
61 *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" 72 *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX"
@@ -65,11 +76,11 @@ namespace Bu
65 *@returns (Bu::File) A file object representing your temp file. 76 *@returns (Bu::File) A file object representing your temp file.
66 */ 77 */
67#ifndef WIN32 78#ifndef WIN32
68 inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) 79 inline static Bu::File tempFile( Bu::FString &sName, int /*iFlags*/ )
69 { 80 {
70 int afh_d = mkstemp( sName.getStr() ); 81 int afh_d = mkstemp( sName.getStr() );
71 82
72 return Bu::File( afh_d, sFlags ); 83 return Bu::File( afh_d );
73 } 84 }
74 85
75 /** 86 /**
@@ -87,8 +98,10 @@ namespace Bu
87#endif 98#endif
88 99
89 private: 100 private:
90 FILE *fh; 101 int getPosixFlags( int iFlags );
91 102
103 private:
104 int fd;
92 }; 105 };
93} 106}
94 107