#ifndef H_CORAL_CPP_POSIX
#define H_CORAL_CPP_POSIX

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

/*
 * Some C++ wrappers around POSIX calls
 *
 */

#include "fdstreambuf.h"
#include <memory>
#include <string>

namespace coral {
	/*
	 * Fork. Throws on error.
	 */
	int cpp_fork();
	/*
	 * mkstemp(). Throws on error.
	 * @template is supposed to end with XXXXXX.
	 * @output is allowed to be the same as template, and
	 * will contain the actual filename used for creating the
	 * safe temporary file. On failure, @output is not changed.
	 * The return value ought to be fed to the std::ostream constructor.
	 */
	std::auto_ptr<std::streambuf>
	cpp_mkstemp(const std::string& filename_template);
	std::auto_ptr<std::streambuf>
	cpp_mkstemp(const std::string& filename_template, std::string& output);
	/*
	 * Same as mkstmp(), but honor TMP environment variable and such.
	 *
	 */
	std::auto_ptr<std::streambuf>
	cpp_mkstemp_with_TMP(const std::string& filename_template,
			     std::string& output);
	std::auto_ptr<std::streambuf>
	cpp_mkstemp_with_TMP(const std::string& filename_template);

	void cpp_file_rename(const std::string& old_name,
			     const std::string& new_name);
}

#endif
