source: filezilla/trunk/fuentes/src/include/file.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 1.4 KB
RevLine 
[130]1#ifndef FILEZILLA_FILE_HEADER
2#define FILEZILLA_FILE_HEADER
3
4// Lean replacement of wxFile that is implemented in terms of CreateFile instead of _open on Windows.
5class CFile final
6{
7public:
8        enum mode {
9                read,
10                write
11        };
12
13        // Only evaluated when opening existing files for writing
14        // Non-existing files will always be created when writing.
15        // Opening for reading never creates files
16        enum disposition
17        {
18                existing, // Keep existing data
19                truncate  // Truncate file
20        };
21
22        CFile();
23        CFile(wxString const& f, mode m, disposition d = existing);
24
25        ~CFile();
26
27        CFile(CFile const&) = delete;
28        CFile& operator=(CFile const&) = delete;
29
30        bool Opened() const;
31
32        bool Open(wxString const& f, mode m, disposition d = existing);
33        void Close();
34
35        enum seekMode
36        {
37                begin,
38                current,
39                end
40        };
41
42        // Gets size of file
43        // Returns -1 on error
44        wxFileOffset Length() const;
45
46        // Relative seek based on seek mode
47        // Returns -1 on error, otherwise new absolute offset in file
48        // On failure, the new position in the file is undefined.
49        wxFileOffset Seek(wxFileOffset offset, seekMode m);
50
51        // Truncate the file to the current position of the file pointer.
52        bool Truncate();
53
54        // Returns number of bytes read or -1 on error
55        ssize_t Read(void *buf, size_t count);
56
57        // Returns number of bytes written or -1 on error
58        ssize_t Write(void const* buf, size_t count);
59
60protected:
61#ifdef __WXMSW__
62        HANDLE hFile_{INVALID_HANDLE_VALUE};
63#else
64        int fd_{-1};
65#endif
66};
67
68#endif
Note: See TracBrowser for help on using the repository browser.