blob: 74d48177e4b976ff27689e3e79c5a76f140beceb [file] [log] [blame]
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +02001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/base/file.h"
12
13namespace rtc {
14
15File::File(PlatformFile file) : file_(file) {}
16
Viktor Palmkvist1d477ea2016-10-03 13:16:02 +020017File::File() : file_(kInvalidPlatformFileValue) {}
18
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020019File::~File() {
20 Close();
21}
22
Viktor Palmkvist971eb272016-09-16 10:19:23 +020023File File::Open(const std::string& path) {
24 return File(OpenPlatformFile(path));
25}
26
27File File::Create(const std::string& path) {
28 return File(CreatePlatformFile(path));
29}
30
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020031File::File(File&& other) : file_(other.file_) {
32 other.file_ = kInvalidPlatformFileValue;
33}
34
35File& File::operator=(File&& other) {
36 Close();
37 file_ = other.file_;
38 other.file_ = kInvalidPlatformFileValue;
39 return *this;
40}
41
42bool File::IsOpen() {
43 return file_ != kInvalidPlatformFileValue;
44}
45
46} // namespace rtc