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();
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 
98  bool truncate();
99 
113  int64_t read(void *buf, int64_t count);
114 
125  int64_t write(void const* buf, int64_t count);
126 
127 private:
128 #ifdef FZ_WINDOWS
129  HANDLE hFile_{INVALID_HANDLE_VALUE};
130 #else
131  int fd_{-1};
132 #endif
133 };
134 
135 }
136 #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
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:30
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.