blob: 00cd6382447978d3d4a90cdbabc1569c011c1860 [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
10#include "file_interface.h"
11
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;
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_