#pragma interface "file.h"
#endif
-// ----------------------------------------------------------------------------
-// simple types
-// ----------------------------------------------------------------------------
-
-#include <wx/filefn.h>
-
-// define off_t
-#include <sys/types.h>
-
-#ifdef _MSC_VER
- #define off_t _off_t
-#endif
+#include "wx/string.h"
+#include "wx/filefn.h"
// ----------------------------------------------------------------------------
// constants
// -------------------
// opening mode
- enum OpenMode { read, write, read_write };
+ enum OpenMode { read, write, read_write, write_append };
// standard values for file descriptor
enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr };
- // seek type
- enum SeekMode { FromStart, FromEnd, FromCurrent };
// static functions
// ----------------
// open/close
bool Create(const char *szFileName, bool bOverwrite = FALSE);
bool Open(const char *szFileName, OpenMode mode = read);
+ bool Close(); // Close is a NOP if not opened
+
+ // assign an existing file descriptor and get it back from wxFile object
void Attach(int fd) { Close(); m_fd = fd; }
- inline void Close(); // Close is a NOP if not opened
+ void Detach() { m_fd = fd_invalid; }
+ int fd() const { return m_fd; }
// read/write (unbuffered)
// returns number of bytes read or ofsInvalid on error
off_t Read(void *pBuf, off_t nCount);
// returns true on success
- bool Write(const void *pBuf, uint nCount);
+ uint Write(const void *pBuf, uint nCount);
// returns true on success
- bool Write(const wxString& str) { return Write(str.c_str(), str.Len()); }
+ bool Write(const wxString& s) { return Write(s.c_str(), s.Len()) != 0; }
// flush data not yet written
bool Flush();
// file pointer operations (return ofsInvalid on failure)
// move ptr ofs bytes related to start/current off_t/end of file
- off_t Seek(off_t ofs, SeekMode mode = FromStart);
+ off_t Seek(off_t ofs, wxSeekMode mode = wxFromStart);
// move ptr to ofs bytes before the end
- off_t SeekEnd(off_t ofs = 0) { return Seek(ofs, FromEnd); }
+ off_t SeekEnd(off_t ofs = 0) { return Seek(ofs, wxFromEnd); }
// get current off_t
off_t Tell() const;
// get current file length
bool IsOpened() const { return m_fd != fd_invalid; }
// is end of file reached?
bool Eof() const;
+ // is an error occured?
+ bool Error() const { return m_error; }
// dtor closes the file if opened
~wxFile();
wxFile& operator=(const wxFile&);
int m_fd; // file descriptor or INVALID_FD if not opened
+ bool m_error; // error memory
};
// ----------------------------------------------------------------------------
bool IsOpened() const { return m_file.IsOpened(); }
// I/O (both functions return true on success, false on failure)
- bool Write(const void *p, uint n) { return m_file.Write(p, n); }
- bool Write(const wxString& str) { return m_file.Write(str); }
+ bool Write(const void *p, uint n) { return m_file.Write(p, n) != 0; }
+ bool Write(const wxString& str) { return m_file.Write(str); }
// different ways to close the file
// validate changes and delete the old file of name m_strName
};
#endif
- // __FILEH__
+ // __FILEH__