aboutsummaryrefslogtreecommitdiff
path: root/src/file.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/file.h')
-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