1 /* COPYING ******************************************************************
2 For copyright and licensing terms, see the file named COPYING.
3 // **************************************************************************
4 */
5 
6 #include <algorithm>
7 #include <unistd.h>
8 #include "FileDescriptorOwner.h"
9 
~FileDescriptorOwner()10 FileDescriptorOwner::~FileDescriptorOwner()
11 {
12 	if (-1 != fd) close(fd);
13 }
14 
FileDescriptorOwner(FileDescriptorOwner && o)15 FileDescriptorOwner::FileDescriptorOwner(
16 	FileDescriptorOwner && o
17 ) :
18 	fd(-1)
19 {
20 	std::swap(fd, o.fd);
21 }
22 
23 void
reset(int f)24 FileDescriptorOwner::reset(int f)
25 {
26 	if (-1 != fd) close(fd);
27 	std::swap(fd, f);
28 }
29 
30 int
release()31 FileDescriptorOwner::release()
32 {
33 	int f(-1);
34 	std::swap(fd, f);
35 	return f;
36 }
37