File: auto_fd.hpp

package info (click to toggle)
videolink 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 368 kB
  • ctags: 502
  • sloc: cpp: 3,210; ansic: 880; makefile: 121
file content (30 lines) | stat: -rw-r--r-- 534 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
// See the file "COPYING" for licence details.

#ifndef INC_AUTO_FD_HPP
#define INC_AUTO_FD_HPP

#include "auto_handle.hpp"

#include <cassert>

#include <unistd.h>

struct auto_fd_closer
{
    void operator()(int fd) const
	{
	    if (fd >= 0)
	    {
		int result = close(fd);
		assert(result == 0);
	    }
	}
};
struct auto_fd_factory
{
    int operator()() const { return -1; }
};
typedef auto_handle<int, auto_fd_closer, auto_fd_factory> auto_fd;

#endif // !INC_AUTO_FD_HPP