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 | |
| 10 | #include "file_interface.h" |
| 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; |
| 27 | |
| 28 | private: |
| 29 | // Creates the File instance for the |fd|. Takes ownership of the file |
| 30 | // descriptor. |
| 31 | File(int fd); |
| 32 | |
| 33 | int fd_; |
| 34 | }; |
| 35 | |
| 36 | } // namespace bsdiff |
| 37 | |
| 38 | #endif // _BSDIFF_FILE_H_ |