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 "bsdiff/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 bool GetSize(uint64_t* size) override; 28 29 private: 30 // Creates the File instance for the |fd|. Takes ownership of the file 31 // descriptor. 32 explicit File(int fd); 33 34 int fd_; 35 }; 36 37 } // namespace bsdiff 38 39 #endif // _BSDIFF_FILE_H_ 40