libfilezilla
file.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_FILE_HEADER
2 #define LIBFILEZILLA_FILE_HEADER
3 
4 #include "libfilezilla.hpp"
5 
6 #ifdef FZ_WINDOWS
7 #include "private/windows.hpp"
8 #endif
9 
14 #include <stdint.h>
15 
16 namespace fz {
17 
25 class FZ_PUBLIC_SYMBOL file final
26 {
27 public:
29  enum mode {
30  reading,
31  writing
32  };
33 
43 
45  empty
46  };
47 
48  file() = default;
49  file(native_string const& f, mode m, creation_flags d = existing);
50 
51  ~file();
52 
53  file(file const&) = delete;
54  file& operator=(file const&) = delete;
55 
56  bool opened() const;
57 
58  bool open(native_string const& f, mode m, creation_flags d = existing);
59 
60  void close();
61 
63  enum seek_mode {
66 
69 
71  end
72  };
73 
77  int64_t size() const;
78 
91  int64_t seek(int64_t offset, seek_mode m);
92 
94  int64_t position() { return seek(0, current); }
95 
101  bool truncate();
102 
116  int64_t read(void *buf, int64_t count);
117 
128  int64_t write(void const* buf, int64_t count);
129 
135  bool fsync();
136 
137 private:
138 #ifdef FZ_WINDOWS
139  HANDLE hFile_{INVALID_HANDLE_VALUE};
140 #else
141  int fd_{-1};
142 #endif
143 };
144 
145 bool FZ_PUBLIC_SYMBOL remove_file(native_string const& name);
146 
147 }
148 #endif
mode
Files can be opened for reading or writing, but not both.
Definition: file.hpp:29
Keep existing data if file exists, otherwise create new.
Definition: file.hpp:42
Seek from current position in the file.
Definition: file.hpp:68
int64_t position()
Get Current position in file.
Definition: file.hpp:94
std::wstring native_string
A string in the system&#39;s native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:32
Seek from beginning of file.
Definition: file.hpp:65
The namespace used by libfilezilla.
Definition: apply.hpp:16
seek_mode
Used by seek.
Definition: file.hpp:63
creation_flags
Creation flags when opening file for writing.
Definition: file.hpp:40
Lean class for file access.
Definition: file.hpp:25
Sets some global macros and further includes string.hpp.