Example #1
0
//	////////////////////////////////////////////////////////////////////////////
void LogHandlerXFile::OpenFileImpl(const char *file_name)
{
	boost::shared_ptr<std::ofstream> tmp_file_ptr(
		new std::ofstream(file_name,
			(!(my_flags_ & DoNotAppend)) ?
			(std::ios_base::app | std::ios_base::ate) :
			(std::ios_base::app | std::ios_base::trunc)));

	if (tmp_file_ptr->fail())
		ThrowErrno("Open attempt failed.");

//	CODE NOTE: LogFileHandler buffering test code. To be removed.
std::streambuf *new_buffer_ptr =
	tmp_file_ptr->rdbuf()->pubsetbuf(TestFileBuffer, sizeof(TestFileBuffer));
if (new_buffer_ptr == NULL)
	ThrowErrno("Attempt to set the log file buffer size to " +
		AnyToString(sizeof(TestFileBuffer)) + " bytes failed.");

	{
		std::string               tmp_file_name(file_name);
		boost::mutex::scoped_lock my_lock(the_lock_);
		if ((out_file_ptr_ != NULL) && out_file_ptr_->is_open()) {
			out_file_ptr_->flush();
			out_file_ptr_->close();
			out_file_ptr_.reset();
		}
		out_file_ptr_.swap(tmp_file_ptr);
		out_file_name_.swap(tmp_file_name);
	}
}
Example #2
0
// ////////////////////////////////////////////////////////////////////////////
unsigned int GetPageSize()
{
#ifdef __MSDOS__
	return(4096);								// Whatever...
#elif _Windows
	SYSTEM_INFO system_data;

	::GetSystemInfo(&system_data);

	return(static_cast<unsigned int>(system_data.dwPageSize));
#elif __SVR4
	int return_code = ::sysconf(_SC_PAGESIZE);

	if (return_code == -1)
		ThrowErrno("Invocation of 'sysconf(_SC_PAGESIZE)' failed");

	return(static_cast<unsigned int>(return_code));
#else
	return(static_cast<unsigned int>(::getpagesize()));
#endif // #ifdef __MSDOS__
}