Example #1
0
//============================================================================================
// Сообщает о СИСТЕМНЫХ ошибках времени исполнения
//============================================================================================
void BKBReportError(TCHAR *SourceFile, TCHAR *FuncName, int LineNumber)
{
	DWORD res;				// Результат функции FormatMessage
	void *BKBStringError;	// Указатель на строку для получения системной ошибки
	TCHAR BKBMessage[2048];	// Это строка, в которой формируется сообщение об ошибке
	DWORD BKBLastError=GetLastError(); // Получили код системной ошибки
	
	
	if (BKBLastError!=(DWORD)0) // Получить строку, если код не равен нулю
	{
		res=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
						NULL, BKBLastError,
						MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
						(LPTSTR) &BKBStringError, 0, NULL );

		if(res==(DWORD)0) BKBStringError=(void *)Internat::Message(1,L"Сообщение об ошибке не найдено");
	}
	else
	{
		BKBStringError=(void *)Internat::Message(2,L"Нет системной ошибки");
	}
	
	// Сформировать строку с полным описанием ошибки
	swprintf_s(BKBMessage, _countof(BKBMessage),
			L"Module: %s\r\nFunction: %s\r\nLine number: %d\r\nSysErr: %d (%s)",
			SourceFile, FuncName, LineNumber,
			BKBLastError, (TCHAR *)BKBStringError);


	//Освобождаем память, которую выделила функция FormatMessage
	if (BKBLastError!=(DWORD)0)
	{
			LocalFree( BKBStringError );
	}

	//Печатаем сообщение об ошибке (если возможно, на экран)
	BKBMessageBox(NULL,BKBMessage,Internat::Message(0,L"BKB: сообщение об ошибке"),MB_OK|MB_ICONINFORMATION );

	//А также в файл 
	FILE *fout;
	fopen_s(&fout,"reperr.log","ab");

	time_t mytime = time(0); /* not 'long' */
	TCHAR ctbuf[1024];
	_wctime_s(ctbuf,1023,&mytime);
	fwprintf(fout,L"****\r\n%s\r\n%s\r\n", ctbuf, BKBMessage);
	fflush(fout);
	fclose(fout);
}
Example #2
0
//============================================================================================
// Для ошибок Tobii Gaze SDK (перегружена)
//============================================================================================
void BKBReportError(tobiigaze_error_code tbg_error_code, TCHAR *SourceFile, TCHAR *FuncName, int LineNumber)
{
	TCHAR BKBMessage[1024];	// Это строка, в которой формируется сообщение об ошибке
	TCHAR ConvertASCII2W[1024];

	if (tbg_error_code)
    {
		const TCHAR *tmp_char;
		if(fp_tobiigaze_get_error_message)
		{
			MultiByteToWideChar(CP_ACP, 0, (*fp_tobiigaze_get_error_message)(tbg_error_code), -1, ConvertASCII2W, 1023);
			tmp_char=ConvertASCII2W;
		}
		else tmp_char=Internat::Message(24,L"неизвестно");

		// Сформировать строку с полным описанием ошибки
		swprintf_s(BKBMessage, _countof(BKBMessage),
			Internat::Message(25,L"Module: %s\nFunction: %s\nLine number: %d\nОшибка Tobii Gaze SDK: %d (%s)"),
			SourceFile, FuncName, LineNumber,
			tbg_error_code, 
			tmp_char);


		//Печатаем сообщение об ошибке (если возможно, на экран)
		BKBMessageBox(NULL,BKBMessage,Internat::Message(26,L"BKB:Gaze SDK: сообщение об ошибке"),MB_OK|MB_ICONINFORMATION );

		//А также в файл 
		FILE *fout;
		fopen_s(&fout,"reperr.log","ab");

		time_t mytime = time(0); /* not 'long' */
		TCHAR ctbuf[1024];
		_wctime_s(ctbuf,1023,&mytime);
		
		fwprintf(fout,L"****\n%s%s\n", ctbuf, BKBMessage);
		fflush(fout);
		fclose(fout);
	}
}
Example #3
0
void testtime_s( void )
{
    int                 violations = NumViolations;
    time_t              tt1;
    time_t              tt2;
    struct tm           tm1;
    struct tm           tm2;
    wchar_t const * const  datestr = L"Wed Aug 14 17:23:31 2002\n";
    wchar_t             buf[64];

    /*** Test various functions ***/

    tm1.tm_sec   = 31;
    tm1.tm_min   = 23;
    tm1.tm_hour  = 17;
    tm1.tm_mday  = 14;
    tm1.tm_mon   = 7;
    tm1.tm_year  = 102;
    tm1.tm_isdst = -1;
    tt1 = mktime( &tm1 );

    tm1.tm_sec++;
    tt2 = mktime( &tm1 );

    /* Test localtime_s() and _wasctime_s() */
    VERIFY( localtime_s( &tt1, &tm2 ) == &tm2 );

    VERIFY( _wasctime_s( buf, sizeof(buf), &tm2 ) == 0 );
    VERIFY( NumViolations == violations );
    VERIFY( wcscmp( buf, datestr ) == 0 );

    VERIFY( _wasctime_s( NULL, sizeof(buf), &tm2 ) != 0 );
    VERIFY( NumViolations == ++violations );

    buf[0] = L'X';
    VERIFY( _wasctime_s( buf, 25, &tm2 ) != 0 );
    VERIFY( NumViolations == ++violations );
    VERIFY( L'\0' == buf[0] );

#if RSIZE_MAX != SIZE_MAX
    buf[0] = L'X';
    VERIFY( _wasctime_s( buf, ~0, &tm2 ) != 0 );
    VERIFY( NumViolations == ++violations );
    VERIFY( L'X' == buf[0] );
#endif

    tm2.tm_year = -1;
    buf[0] = L'X';
    VERIFY( _wasctime_s( buf, sizeof(buf), &tm2 ) != 0 );
    VERIFY( NumViolations == ++violations );
    VERIFY( L'\0' == buf[0] );

    tm2.tm_year = 9999+1;
    buf[0] = L'X';
    VERIFY( _wasctime_s( buf, sizeof(buf), &tm2 ) != 0 );
    VERIFY( NumViolations == ++violations );
    VERIFY( L'\0' == buf[0] );

    /*  _wctime_s()                                       */
    VERIFY( _wctime_s( buf, sizeof(buf), &tt1 ) == 0 );
    VERIFY( NumViolations == violations );
    VERIFY( wcscmp( buf, datestr ) == 0 );

    VERIFY( _wctime_s( NULL, sizeof(buf), &tt1 ) != 0 );
    VERIFY( NumViolations == ++violations );

    buf[0] = L'X';
    VERIFY( _wctime_s( buf, 25, &tt1 ) != 0 );
    VERIFY( NumViolations == ++violations );
    VERIFY( L'\0' == buf[0] );

#if RSIZE_MAX != SIZE_MAX
    buf[0] = L'X';
    VERIFY( _wctime_s( buf, ~0, &tt1 ) != 0 );
    VERIFY( NumViolations == ++violations );
    VERIFY( L'X' == buf[0] );
#endif


}
Example #4
0
/* Retrieves a ctime formatted string
 * The string must be at least 32 characters of size including the end of string character
 * Returns 1 if successful or -1 on error
 */
int process_status_get_ctime_string(
     const time_t *timestamp,
     libcstring_system_character_t *string,
     size_t string_size,
     libcerror_error_t **error )
{
	static char *function                                    = "process_status_get_ctime_string";

#if ( defined( HAVE_CTIME ) && !defined( HAVE_CTIME_R ) ) || ( defined( WINAPI ) && !defined( _MSC_VER ) )
	const libcstring_system_character_t *static_ctime_string = NULL;
	size_t static_ctime_string_length                        = 0;
#endif

	if( timestamp == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid timestamp.",
		 function );

		return( -1 );
	}
	if( string == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid string.",
		 function );

		return( -1 );
	}
	if( string_size > (size_t) SSIZE_MAX )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid string size value exceeds maximum.",
		 function );

		return( -1 );
	}
	if( string_size < 32 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
		 "%s: string too small.",
		 function );

		return( -1 );
	}
#if defined( _MSC_VER )
#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER )
	if( _wctime_s(
	     string,
	     string_size,
	     timestamp ) != 0 )
#else
	if( ctime_s(
	     string,
	     string_size,
	     timestamp ) != 0 )
#endif
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to set string.",
		 function );

		return( -1 );
	}

#elif defined( HAVE_CTIME_R )
/* Sanity check
 */
#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER )
#error Missing wide character ctime_r function
#endif

#if defined( HAVE_CTIME_R_SIZE )
	if( ctime_r(
	     timestamp,
	     string,
	     string_size ) == NULL )
#else
	if( ctime_r(
	     timestamp,
	     string ) == NULL )
#endif
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to set string.",
		 function );

		return( -1 );
	}

#else
/* Sanity check
 */
#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) && !defined( WINAPI )
#error Missing wide character ctime function
#endif

#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER )
	static_ctime_string = _wctime(
	                       timestamp );
#else
	static_ctime_string = ctime(
	                       timestamp );
#endif
	if( static_ctime_string == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to create static ctime string.",
		 function );

		return( -1 );
	}
	static_ctime_string_length = libcstring_system_string_length(
	                              static_ctime_string );

	if( libcstring_system_string_copy(
	     string,
	     static_ctime_string,
	     static_ctime_string_length ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to set string.",
		 function );

		return( -1 );
	}
	string[ static_ctime_string_length ] = 0;
#endif

	return( 1 );
}