blob: 62024119fcc17a49c5a7d331da42ef7ed22f6505 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/file.h"
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020012
zijiehedd87d582016-12-06 15:04:02 -080013#include <utility>
14
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020015namespace rtc {
16
17File::File(PlatformFile file) : file_(file) {}
18
Viktor Palmkvist1d477ea2016-10-03 13:16:02 +020019File::File() : file_(kInvalidPlatformFileValue) {}
20
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020021File::~File() {
22 Close();
23}
24
zijiehedd87d582016-12-06 15:04:02 -080025// static
Viktor Palmkvist971eb272016-09-16 10:19:23 +020026File File::Open(const std::string& path) {
27 return File(OpenPlatformFile(path));
28}
29
zijiehedd87d582016-12-06 15:04:02 -080030// static
Viktor Palmkvist971eb272016-09-16 10:19:23 +020031File File::Create(const std::string& path) {
32 return File(CreatePlatformFile(path));
33}
34
zijiehedd87d582016-12-06 15:04:02 -080035// static
zijiehe2769ec62016-12-14 15:03:03 -080036bool File::Remove(const std::string& path) {
37 return RemoveFile(path);
38}
39
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020040File::File(File&& other) : file_(other.file_) {
41 other.file_ = kInvalidPlatformFileValue;
42}
43
44File& File::operator=(File&& other) {
45 Close();
46 file_ = other.file_;
47 other.file_ = kInvalidPlatformFileValue;
48 return *this;
49}
50
51bool File::IsOpen() {
52 return file_ != kInvalidPlatformFileValue;
53}
54
55} // namespace rtc