LeechCraft
0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
fdguard.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
* Copyright (C) 2012 Maxim Ignatenko
5
*
6
* Distributed under the Boost Software License, Version 1.0.
7
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
8
**********************************************************************/
9
10
#include "
fdguard.h
"
11
12
#include <fcntl.h>
13
#include <unistd.h>
14
15
namespace
LC::Util
16
{
17
FDGuard::FDGuard
(
const
char
*file,
int
mode)
18
: FD_ { open (file, mode) }
19
{
20
}
21
22
FDGuard::FDGuard
(FDGuard&& other)
23
: FD_ { other.FD_ }
24
{
25
other.FD_ = -1;
26
}
27
28
FDGuard
&
FDGuard::operator=
(
FDGuard
&& other)
29
{
30
swap
(*
this
, other);
31
32
return
*
this
;
33
}
34
35
FDGuard::~FDGuard
()
36
{
37
if
(FD_ >= 0)
38
close (FD_);
39
}
40
41
FDGuard::operator bool ()
const
42
{
43
return
FD_ >= 0;
44
}
45
46
FDGuard::operator int ()
const
47
{
48
return
FD_;
49
}
50
51
void
swap
(
FDGuard
& g1,
FDGuard
& g2)
52
{
53
std::swap
(g1.FD_, g2.FD_);
54
}
55
}
LC::Util
Definition:
icoreproxy.h:33
LC::Util::swap
void swap(FDGuard &g1, FDGuard &g2)
Definition:
fdguard.cpp:58
LC::Util::FDGuard::~FDGuard
~FDGuard()
Definition:
fdguard.cpp:42
LC::Util::FDGuard::swap
friend void swap(FDGuard &g1, FDGuard &g2)
Definition:
fdguard.cpp:58
LC::Util::FDGuard::FDGuard
FDGuard(const char *file, int mode)
Definition:
fdguard.cpp:24
LC::Util::FDGuard
Definition:
fdguard.h:23
fdguard.h
LC::Util::FDGuard::operator=
FDGuard & operator=(const FDGuard &)=delete
src
util
sys
fdguard.cpp
Generated by
1.8.17