LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
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
15namespace LC::Util
16{
17 FDGuard::FDGuard (const char *file, int mode)
18 : FD_ { open (file, mode) }
19 {
20 }
21
23 : FD_ { other.FD_ }
24 {
25 other.FD_ = -1;
26 }
27
29 {
30 swap (*this, other);
31
32 return *this;
33 }
34
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}
FDGuard & operator=(const FDGuard &)=delete
friend void swap(FDGuard &g1, FDGuard &g2)
Definition fdguard.cpp:51
FDGuard(const char *file, int mode)
Definition fdguard.cpp:17
void swap(FDGuard &g1, FDGuard &g2)
Definition fdguard.cpp:51