blob: a71458cd0b194bb4eeef181e775380bcc557d534 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#pragma once
2
3namespace phosphor
4{
5namespace dump
6{
7
8/** @struct CustomFd
9 *
10 * RAII wrapper for file descriptor.
11 */
12struct CustomFd
13{
14 private:
15 /** @brief File descriptor */
16 int fd = -1;
17
18 public:
19 CustomFd() = delete;
20 CustomFd(const CustomFd&) = delete;
21 CustomFd& operator=(const CustomFd&) = delete;
22 CustomFd(CustomFd&&) = delete;
23 CustomFd& operator=(CustomFd&&) = delete;
24
25 /** @brief Saves File descriptor and uses it to do file operation
26 *
27 * @param[in] fd - File descriptor
28 */
29 CustomFd(int fd) : fd(fd) {}
30
31 ~CustomFd()
32 {
33 if (fd >= 0)
34 {
35 close(fd);
36 }
37 }
38
39 int operator()() const
40 {
41 return fd;
42 }
43};
44
45} // namespace dump
46} // namespace phosphor