libzypp
17.7.0
Fd.cc
Go to the documentation of this file.
1
/*---------------------------------------------------------------------\
2
| ____ _ __ __ ___ |
3
| |__ / \ / / . \ . \ |
4
| / / \ V /| _/ _/ |
5
| / /__ | | | | | | |
6
| /_____||_| |_| |_| |
7
| |
8
\---------------------------------------------------------------------*/
12
extern
"C"
13
{
14
#include <sys/types.h>
15
#include <sys/stat.h>
16
#include <fcntl.h>
17
}
18
19
#include <iostream>
20
21
#include "
zypp/base/Exception.h
"
22
#include "
zypp/base/Fd.h
"
23
25
namespace
zypp
26
{
27
namespace
base
29
{
30
32
//
33
// METHOD NAME : Fd::Fd
34
// METHOD TYPE : Ctor
35
//
36
Fd::Fd
(
const
Pathname
& file_r,
int
open_flags, mode_t mode )
37
: m_fd( -1 )
38
{
39
m_fd
= open( file_r.
asString
().c_str(), open_flags, mode );
40
if
(
m_fd
== -1 )
41
ZYPP_THROW_ERRNO_MSG
(
Exception
, std::string(
"open "
)+file_r.
asString
() );
42
}
43
45
//
46
// METHOD NAME : Fd::close
47
// METHOD TYPE : void
48
//
49
void
Fd::close
()
50
{
51
if
(
m_fd
!= -1 )
52
{
53
::close
(
m_fd
);
54
m_fd
= -1;
55
}
56
}
57
59
}
// namespace base
62
}
// namespace zypp
zypp::Exception
Base class for Exception.
Definition:
Exception.h:145
zypp::base::Fd::m_fd
int m_fd
The filedescriptor.
Definition:
Fd.h:83
ZYPP_THROW_ERRNO_MSG
#define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)
Throw Exception built from errno and a message string.
Definition:
Exception.h:417
Fd.h
Exception.h
zypp::base::Fd::close
void close()
Explicitly close the file.
Definition:
Fd.cc:49
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition:
CodePitfalls.doc:1
zypp::filesystem::Pathname
Pathname.
Definition:
Pathname.h:43
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition:
Pathname.h:90
zypp::base::Fd::Fd
Fd(const Pathname &file_r, int open_flags, mode_t mode=0)
Ctor opens file.
Definition:
Fd.cc:36
zypp
base
Fd.cc
Generated by
1.8.17