/*
 *  lib/debug.c
 *
 *  Debug routine
 *
 *  Copyright (C) 2004  Phoenix Grid Computing Project
 *                      ( http://www.logos.ic.i.u-tokyo.ac.jp/phoenix/ )
 *
 *  2004-11-26  Implemented basic functions 
 *              by Kaneda Kenji
 */


#include "common.h"
#include <openssl/err.h>
#include <stdarg.h>


void
dprint ( const char *format, ... ) 
{
	va_list ap;

	assert ( format != NULL );

	va_start ( ap, format );
	vfprintf ( stderr, format, ap );
	fflush ( stderr );
	va_end ( ap );
}

void
fatal_failure ( const char *format, ... )
{
	va_list ap;

	assert ( format != NULL);

	va_start ( ap, format );
	vfprintf ( stderr, format, ap );
	fflush ( stderr );
	va_end ( ap );

	exit ( 1 );
}

void
sys_failure ( const char *string )
{
	assert ( string != NULL );

	perror ( string );
	fflush ( stderr );

	exit ( 1 );
}

int
ssl_failure ( const char *string )
{
	assert ( string != NULL );

	fprintf ( stderr, "Error on %s()\n", string );
	ERR_print_errors_fp ( stderr );
	fflush ( stderr );

	exit ( 1 );
}
