Alex Deymo | 03f1deb | 2015-10-13 02:15:31 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef _BSDIFF_FILE_H_ |
| 6 | #define _BSDIFF_FILE_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
Alex Deymo | ddf9db5 | 2017-03-02 16:10:41 -0800 | [diff] [blame] | 10 | #include "bsdiff/file_interface.h" |
Alex Deymo | 03f1deb | 2015-10-13 02:15:31 -0700 | [diff] [blame] | 11 | |
| 12 | namespace bsdiff { |
| 13 | |
| 14 | class File : public FileInterface { |
| 15 | public: |
| 16 | // Opens a file |pathname| with flags |flags| as defined by open(2). In case |
| 17 | // of error, an empty unique_ptr is returned and errno is set accordingly. |
| 18 | static std::unique_ptr<File> FOpen(const char* pathname, int flags); |
| 19 | |
| 20 | ~File() override; |
| 21 | |
| 22 | // FileInterface overrides. |
| 23 | bool Read(void* buf, size_t count, size_t* bytes_read) override; |
| 24 | bool Write(const void* buf, size_t count, size_t* bytes_written) override; |
| 25 | bool Seek(off_t pos) override; |
| 26 | bool Close() override; |
Alex Deymo | daf3516 | 2015-10-14 20:43:15 -0700 | [diff] [blame] | 27 | bool GetSize(uint64_t* size) override; |
Alex Deymo | 03f1deb | 2015-10-13 02:15:31 -0700 | [diff] [blame] | 28 | |
| 29 | private: |
| 30 | // Creates the File instance for the |fd|. Takes ownership of the file |
| 31 | // descriptor. |
Chih-Hung Hsieh | 3231599 | 2016-06-29 15:05:28 -0700 | [diff] [blame] | 32 | explicit File(int fd); |
Alex Deymo | 03f1deb | 2015-10-13 02:15:31 -0700 | [diff] [blame] | 33 | |
| 34 | int fd_; |
| 35 | }; |
| 36 | |
| 37 | } // namespace bsdiff |
| 38 | |
| 39 | #endif // _BSDIFF_FILE_H_ |