]> git.decadent.org.uk Git - videolink.git/blob - auto_fd.hpp
Brought documentation up to date.
[videolink.git] / auto_fd.hpp
1 // Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #ifndef INC_AUTO_FD_HPP
5 #define INC_AUTO_FD_HPP
6
7 #include "auto_handle.hpp"
8
9 #include <cassert>
10
11 #include <unistd.h>
12
13 struct auto_fd_closer
14 {
15     void operator()(int fd) const
16         {
17             if (fd >= 0)
18             {
19                 int result = close(fd);
20                 assert(result == 0);
21             }
22         }
23 };
24 struct auto_fd_factory
25 {
26     int operator()() const { return -1; }
27 };
28 typedef auto_handle<int, auto_fd_closer, auto_fd_factory> auto_fd;
29
30 #endif // !INC_AUTO_FD_HPP