#include "error.h"

char *program_invocation;

void set_invocation(char *prog_name){
	program_invocation = prog_name;
}

void BenchErr(char *message, char *function, int action){
	printf("%s: %s\n", message, program_invocation); 
#ifdef _WIN32
	printf("%s: %s - %s\n", message, function, strerror(GetLastError(void)) );
#else
	printf("%s: %s - %s\n", message, function, strerror(errno) );
#endif
	if(action){
		printf("Exiting!\n");
		exit(1);
	}
}

/*

#ifndef _WIN32
void Error_Exit(char *prog_name){
	

}
#else
void Error_Exit(LPTSTR lpszFunction){
	LPVOID MsgBuf;
	LPVOID DisplayBuf;
	DWORD dw = GetLastError(); 

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    // Display the error message and exit the process

    lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
        (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); 
    StringCchPrintf((LPTSTR)lpDisplayBuf, 
        LocalSize(lpDisplayBuf) / sizeof(TCHAR),
        TEXT("%s failed with error %d: %s"), 
        lpszFunction, dw, lpMsgBuf); 
    MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 

    LocalFree(lpMsgBuf);
    LocalFree(lpDisplayBuf);
    ExitProcess(dw); 

}
#endif
*/
