-
Notifications
You must be signed in to change notification settings - Fork 6
/
file_descriptor.hpp
49 lines (38 loc) · 1.14 KB
/
file_descriptor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @file
* SPDX-FileCopyrightText: 2021-2022 Mattéo Delabre <[email protected]>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef WAVED_FILE_DESCRIPTOR_HPP
#define WAVED_FILE_DESCRIPTOR_HPP
namespace Waved
{
/** Wrapper around C file descriptors. */
class FileDescriptor
{
public:
/**
* Open a file.
*
* @param path Path to the file to open.
* @param flags Opening flags.
* @throws std::system_error If opening fails.
*/
FileDescriptor(const char* path, int flags);
/** Take ownership of an existing file descriptor. */
FileDescriptor(int fd);
// Disallow copying input device handles
FileDescriptor(const FileDescriptor& other) = delete;
FileDescriptor& operator=(const FileDescriptor& other) = delete;
// Transfer handle ownership
FileDescriptor(FileDescriptor&& other) noexcept;
FileDescriptor& operator=(FileDescriptor&& other) noexcept;
/** Get the underlying file descriptor. */
operator int() const;
/** Close the file. */
~FileDescriptor();
private:
int fd;
}; // class FileDescriptor
} // namespace Waved
#endif // WAVED_FILE_DESCRIPTOR_HPP