geopm 3.1.1.dev587+g880145a5
GEOPM - Global Extensible Open Power Manager
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UniqueFd.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 - 2025 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef UNIQUEFD_HPP_INCLUDE
7#define UNIQUEFD_HPP_INCLUDE
8
9namespace geopm
10{
13 {
14 public:
15 UniqueFd() = delete;
16
17 // Disable copies since we only want one wrapper to close the fd
18 UniqueFd(UniqueFd const&) = delete;
19 UniqueFd& operator=(UniqueFd const&) = delete;
20 UniqueFd& operator=(UniqueFd &&other) = delete;
21
23 UniqueFd(int fd);
24
26 UniqueFd(UniqueFd &&other);
27
29 ~UniqueFd();
30
32 int get();
33 private:
34 int m_fd;
35 };
36}
37
38#endif
A wrapper to close a file descriptor when the descriptor goes out of scope.
Definition UniqueFd.hpp:13
~UniqueFd()
Close the wrapped fd if it is valid.
Definition UniqueFd.cpp:29
UniqueFd(UniqueFd const &)=delete
UniqueFd()=delete
int get()
Get the wrapped raw fd (e.g., to call IO functions on it)
Definition UniqueFd.cpp:41
UniqueFd & operator=(UniqueFd &&other)=delete
UniqueFd & operator=(UniqueFd const &)=delete
Definition Agg.cpp:20