blob: a793500646af623d603896b234a10d3162a6b611 [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
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
zijiehedd87d582016-12-06 15:04:02 -080023// static
Viktor Palmkvist971eb272016-09-16 10:19:23 +020024File File::Open(const std::string& path) {
25 return File(OpenPlatformFile(path));
26}
27
zijiehedd87d582016-12-06 15:04:02 -080028// static
Viktor Palmkvist971eb272016-09-16 10:19:23 +020029File File::Create(const std::string& path) {
30 return File(CreatePlatformFile(path));
31}
32
zijiehedd87d582016-12-06 15:04:02 -080033// static
zijiehe2769ec62016-12-14 15:03:03 -080034bool File::Remove(const std::string& path) {
35 return RemoveFile(path);
36}
37
Viktor Palmkvist4ec6a0c2016-09-02 13:38:32 +020038File::File(File&& other) : file_(other.file_) {
39 other.file_ = kInvalidPlatformFileValue;
40}
41
42File& File::operator=(File&& other) {
43 Close();
44 file_ = other.file_;
45 other.file_ = kInvalidPlatformFileValue;
46 return *this;
47}
48
49bool File::IsOpen() {
50 return file_ != kInvalidPlatformFileValue;
51}
52
53} // namespace rtc