Viktor Palmkvist | 4ec6a0c | 2016-09-02 13:38:32 +0200 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_base/file.h" |
Viktor Palmkvist | 4ec6a0c | 2016-09-02 13:38:32 +0200 | [diff] [blame] | 12 | |
| 13 | namespace rtc { |
| 14 | |
| 15 | File::File(PlatformFile file) : file_(file) {} |
| 16 | |
Viktor Palmkvist | 1d477ea | 2016-10-03 13:16:02 +0200 | [diff] [blame] | 17 | File::File() : file_(kInvalidPlatformFileValue) {} |
| 18 | |
Viktor Palmkvist | 4ec6a0c | 2016-09-02 13:38:32 +0200 | [diff] [blame] | 19 | File::~File() { |
| 20 | Close(); |
| 21 | } |
| 22 | |
zijiehe | dd87d58 | 2016-12-06 15:04:02 -0800 | [diff] [blame] | 23 | // static |
Viktor Palmkvist | 971eb27 | 2016-09-16 10:19:23 +0200 | [diff] [blame] | 24 | File File::Open(const std::string& path) { |
| 25 | return File(OpenPlatformFile(path)); |
| 26 | } |
| 27 | |
zijiehe | dd87d58 | 2016-12-06 15:04:02 -0800 | [diff] [blame] | 28 | // static |
Viktor Palmkvist | 971eb27 | 2016-09-16 10:19:23 +0200 | [diff] [blame] | 29 | File File::Create(const std::string& path) { |
| 30 | return File(CreatePlatformFile(path)); |
| 31 | } |
| 32 | |
zijiehe | dd87d58 | 2016-12-06 15:04:02 -0800 | [diff] [blame] | 33 | // static |
zijiehe | 2769ec6 | 2016-12-14 15:03:03 -0800 | [diff] [blame] | 34 | bool File::Remove(const std::string& path) { |
| 35 | return RemoveFile(path); |
| 36 | } |
| 37 | |
Viktor Palmkvist | 4ec6a0c | 2016-09-02 13:38:32 +0200 | [diff] [blame] | 38 | File::File(File&& other) : file_(other.file_) { |
| 39 | other.file_ = kInvalidPlatformFileValue; |
| 40 | } |
| 41 | |
| 42 | File& File::operator=(File&& other) { |
| 43 | Close(); |
| 44 | file_ = other.file_; |
| 45 | other.file_ = kInvalidPlatformFileValue; |
| 46 | return *this; |
| 47 | } |
| 48 | |
| 49 | bool File::IsOpen() { |
| 50 | return file_ != kInvalidPlatformFileValue; |
| 51 | } |
| 52 | |
| 53 | } // namespace rtc |