#ifndef H_CORAL_FILEDESCRIPTOR
#define H_CORAL_FILEDESCRIPTOR
// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

/*
 * Exception-safe file descriptor.
 *
 */
#include <coral/coral.h>
#include <unistd.h>

NAMESPACE_BEGIN(coral);

class filedescriptor {
	int fd;
public:
	filedescriptor(int _fd = -1) { fd = _fd; }
	~filedescriptor() throw () { close(); }
	int getFD() const throw () { return fd; }
	void setFD(int _fd) throw () {
		if (fd != _fd) {
			close();
			fd = _fd;
		}
	}
	void close() throw () {
		if (fd != -1) ::close(fd);
		fd = -1;
	}
};

NAMESPACE_END();

#endif



