2 * Copyright 2012 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 * Create a File object from an existing file descriptor.
33 * Takes ownership of the file descriptor if ownsFd is true.
35 /* implicit */ File(int fd, bool ownsFd=false);
38 * Open and create a file object. Throws on error.
40 /* implicit */ File(const char* name, int flags=O_RDONLY, mode_t mode=0644);
45 * Return the file descriptor, or -1 if the file was closed.
47 int fd() const { return fd_; }
50 * If we own the file descriptor, close the file and throw on error.
51 * Otherwise, do nothing.
56 * Closes the file (if owned). Returns true on success, false (and sets
62 * Releases the file descriptor; no longer owned by this File.
67 * Swap this File with another.
69 void swap(File& other);
73 File& operator=(File&&);
76 File(const File&) = delete;
77 File& operator=(const File&) = delete;
83 void swap(File& a, File& b);
87 #include "folly/experimental/File-inl.h"
89 #endif /* FOLLY_FILE_H_ */