fix callPreviousSignalHandler()
[folly.git] / folly / experimental / File-inl.h
1 /*
2  * Copyright 2012 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef FOLLY_FILE_H_
18 #error This file may only be included from folly/experimental/File.h
19 #endif
20
21 #include <algorithm>
22
23 namespace folly {
24
25 inline File::File(int fd, bool ownsFd) : fd_(fd), ownsFd_(ownsFd) { }
26
27 inline File::~File() {
28   closeNoThrow();  // ignore error
29 }
30
31 inline void File::release() {
32   fd_ = -1;
33   ownsFd_ = false;
34 }
35
36 inline void File::swap(File& other) {
37   using std::swap;
38   swap(fd_, other.fd_);
39   swap(ownsFd_, other.ownsFd_);
40 }
41
42 inline File::File(File&& other) : fd_(other.fd_), ownsFd_(other.ownsFd_) {
43   other.release();
44 }
45
46 inline File& File::operator=(File&& other) {
47   File(std::move(other)).swap(*this);
48   return *this;
49 }
50
51 inline void swap(File& a, File& b) {
52   a.swap(b);
53 }
54
55 }  // namespace folly
56