libzypp  16.22.5
Fd.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_FD_H
13 #define ZYPP_BASE_FD_H
14 
15 #include "zypp/Pathname.h"
16 
18 namespace zypp
19 {
20  namespace base
22  {
23 
25  //
26  // CLASS NAME : Fd
27  //
44  class Fd
45  {
46  NON_COPYABLE( Fd );
47  public:
51  Fd( const Pathname & file_r, int open_flags, mode_t mode = 0 );
52 
54  Fd( Fd && rhs )
55  : m_fd( -1 )
56  { std::swap( m_fd, rhs.m_fd ); }
57 
59  Fd & operator=( Fd && rhs )
60  { if ( this != &rhs ) std::swap( m_fd, rhs.m_fd ); return *this; }
61 
63  ~Fd()
64  { close(); }
65 
67  void close();
68 
70  bool isOpen() const
71  { return m_fd != -1; }
72 
74  int fd() const
75  { return m_fd; }
76 
78  int operator*() const
79  { return m_fd; }
80 
81  private:
83  int m_fd;
84  };
86 
88  } // namespace base
91 } // namespace zypp
93 #endif // ZYPP_BASE_FD_H
Fd & operator=(Fd &&rhs)
Move assign.
Definition: Fd.h:59
Fd(Fd &&rhs)
Move ctor.
Definition: Fd.h:54
int operator*() const
Return the filedescriptor.
Definition: Fd.h:78
void close()
Explicitly close the file.
Definition: Fd.cc:49
int m_fd
The filedescriptor.
Definition: Fd.h:83
bool isOpen() const
Test for valid filedescriptor.
Definition: Fd.h:70
Fd(const Pathname &file_r, int open_flags, mode_t mode=0)
Ctor opens file.
Definition: Fd.cc:36
Assert close called on open filedescriptor.
Definition: Fd.h:44
int fd() const
Return the filedescriptor.
Definition: Fd.h:74
~Fd()
Dtor closes file.
Definition: Fd.h:63