2 * Copyright 2013 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/types.h>
27 * A File represents an open file.
32 * Creates an empty File object, for late initialization.
37 * Create a File object from an existing file descriptor.
38 * Takes ownership of the file descriptor if ownsFd is true.
40 /* implicit */ File(int fd,
44 * Open and create a file object. Throws on error.
46 /* implicit */ File(const char* name,
53 * Create and return a temporary, owned file (uses tmpfile()).
55 static File temporary();
58 * Return the file descriptor, or -1 if the file was closed.
60 int fd() const { return fd_; }
63 * Returns 'true' iff the file was successfully opened.
65 explicit operator bool() const {
70 * If we own the file descriptor, close the file and throw on error.
71 * Otherwise, do nothing.
76 * Closes the file (if owned). Returns true on success, false (and sets
82 * Releases the file descriptor; no longer owned by this File.
87 * Swap this File with another.
89 void swap(File& other);
93 File& operator=(File&&);
97 File(const File&) = delete;
98 File& operator=(const File&) = delete;
104 void swap(File& a, File& b);
108 #endif /* FOLLY_FILE_H_ */