blob: 959c53ebdcd4a62662be263479aa7a830979ccc2 [file] [log] [blame]
Alex Deymo03f1deb2015-10-13 02:15:31 -07001// 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 Deymoddf9db52017-03-02 16:10:41 -080010#include "bsdiff/file_interface.h"
Alex Deymo03f1deb2015-10-13 02:15:31 -070011
12namespace bsdiff {
13
14class 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 Deymodaf35162015-10-14 20:43:15 -070027 bool GetSize(uint64_t* size) override;
Alex Deymo03f1deb2015-10-13 02:15:31 -070028
29 private:
30 // Creates the File instance for the |fd|. Takes ownership of the file
31 // descriptor.
Chih-Hung Hsieh32315992016-06-29 15:05:28 -070032 explicit File(int fd);
Alex Deymo03f1deb2015-10-13 02:15:31 -070033
34 int fd_;
35};
36
37} // namespace bsdiff
38
39#endif // _BSDIFF_FILE_H_