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