⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libewf_common.c

📁 sleuthit-2.09 一个磁盘的工具集
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	return( reallocated_buffer );}/* Function to reallocated wiped newly allocated memory */void *libewf_common_realloc_new_cleared( void *buffer, size_t previous_size, size_t new_size, int clear_value ){	void *reallocated_buffer = NULL;	if( ( previous_size > (size_t) SSIZE_MAX ) || ( new_size > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_common_realloc_new_cleared: invalid size value exceeds maximum.\n" );		return( NULL );	}	if( new_size <= previous_size )	{		LIBEWF_WARNING_PRINT( "libewf_common_realloc_new_cleared: new size must be greater than previous size.\n" );		return( NULL );	}	reallocated_buffer = libewf_common_realloc( buffer, new_size );	if( reallocated_buffer == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_realloc_new_cleared: unable to reallocate buffer.\n" );		return( NULL );	}	if( libewf_common_memset( (void *) &( (uint8_t *) reallocated_buffer )[ previous_size ], clear_value, ( new_size - previous_size ) ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_realloc_new_cleared: unable to clear buffer.\n" );		libewf_common_free( reallocated_buffer );		return( NULL );	}	return( reallocated_buffer );}/* Check for empty block, a block that contains the same value for every byte * Returns 1 if block is empty, or 0 otherwise */uint8_t libewf_common_test_empty_block( uint8_t *block_buffer, size_t size ){	size_t iterator = 0;	if( block_buffer == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_test_empty_block: invalid block buffer.\n" );		return( 0 );	}	if( size > (size_t) SSIZE_MAX )	{		LIBEWF_WARNING_PRINT( "libewf_common_test_empty_block: invalid size value exceeds maximum.\n" );		return( 0 );	}	for( iterator = 1; iterator < size; iterator++ )	{		if( block_buffer[ 0 ] != block_buffer[ iterator ] )		{			return( 0 );		}	}	return( 1 );}#if defined( HAVE_WINDOWS_API )#define libewf_common_localtime_r( timestamp, time_elements ) \	localtime_s( time_elements, timestamp )#elif defined( HAVE_LOCALTIME_R )#define libewf_common_localtime_r( timestamp, time_elements ) \	localtime_r( timestamp, time_elements )#endif/* Returns a structured representation of a time using the local time zone, or NULL on error */struct tm *libewf_common_localtime( const time_t *timestamp ){#if !defined( libewf_common_localtime_r ) && defined( HAVE_LOCALTIME )	struct tm *static_time_elements = NULL;#endif	struct tm *time_elements        = NULL;	if( timestamp == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_localtime: invalid time stamp.\n" );		return( NULL );	}	time_elements = (struct tm *) libewf_common_alloc( sizeof( struct tm ) );	if( time_elements == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_localtime: unable to create time elements.\n" );		return( NULL );	}#if defined( libewf_common_localtime_r )#if defined( HAVE_WINDOWS_API )	if( libewf_common_localtime_r( timestamp, time_elements ) != 0 )#else	if( libewf_common_localtime_r( timestamp, time_elements ) == NULL )#endif	{		LIBEWF_WARNING_PRINT( "libewf_common_localtime: unable to set time elements.\n" );		libewf_common_free( time_elements );		return( NULL );	}	return( time_elements );#elif defined( HAVE_LOCALTIME )	static_time_elements = localtime( timestamp );	if( static_time_elements == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_localtime: unable to create static time elements.\n" );		libewf_common_free( time_elements );		return( NULL );	}	if( libewf_common_string_copy( time_elements, static_time_elements, sizeof( struct tm ) ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_localtime: unable to set time elements.\n" );		libewf_common_free( time_elements );		return( NULL );	}#else#error Missing equivalent of function localtime#endif}#if defined( HAVE_WINDOWS_API )#define libewf_common_ctime_r( timestamp, string, size ) \	ctime_s( string, size, timestamp )#elif defined( HAVE_CTIME_R )#if defined( HAVE_CTIME_R_SIZE )#define libewf_common_ctime_r( timestamp, string, size ) \	ctime_r( timestamp, string, size )#else#define libewf_common_ctime_r( timestamp, string, size ) \	ctime_r( timestamp, string )#endif#endif/* Returns a structured representation of a time using the local time zone, or NULL on error */char *libewf_common_ctime( const time_t *timestamp ){#if !defined( libewf_common_ctime_r ) && defined( HAVE_CTIME )	char *static_time_string = NULL;#endif	char *time_string        = NULL;	size_t time_string_size  = 32;	if( timestamp == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_ctime: invalid time stamp.\n" );		return( NULL );	}	time_string = (char *) libewf_common_alloc( time_string_size * sizeof( char ) );	if( time_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_ctime: unable to create time string.\n" );		return( NULL );	}#if defined( libewf_common_ctime_r )#if defined( HAVE_WINDOWS_API )	if( libewf_common_ctime_r( timestamp, time_string, time_string_size ) != 0 )#else	if( libewf_common_ctime_r( timestamp, time_string, time_string_size ) == NULL )#endif	{		LIBEWF_WARNING_PRINT( "libewf_common_ctime: unable to set time string.\n" );		libewf_common_free( time_string );		return( NULL );	}	return( time_string );#elif defined( HAVE_CTIME )	static_time_string = ctime( timestamp );	if( static_time_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_ctime: unable to create static time string.\n" );		libewf_common_free( time_string );		return( NULL );	}	if( libewf_common_string_copy( time_string, static_time_string, time_string_size ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_ctime: unable to set time string.\n" );		libewf_common_free( time_string );		return( NULL );	}	return( time_string );#else#error Missing equivalent of function ctime#endif}#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS )#if defined( HAVE_WINDOWS_API )#define libewf_common_wide_ctime_r( timestamp, string, size ) \	_wctime_s( string, size, timestamp )#else#error Missing wide character equivalent of function ctime()#endif/* Returns a structured representation of a time using the local time zone, or NULL on error */wchar_t *libewf_common_wide_ctime( const time_t *timestamp ){	wchar_t *time_string    = NULL;	size_t time_string_size = 32;	if( timestamp == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_wide_ctime: invalid time stamp.\n" );		return( NULL );	}	time_string = (wchar_t *) libewf_common_alloc( time_string_size * sizeof( wchar_t ) );	if( time_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_wide_ctime: unable to create time string.\n" );		return( NULL );	}#if defined( libewf_common_ctime_r )	if( libewf_common_ctime_r( timestamp, time_string, time_string_size ) != 0 )	{		LIBEWF_WARNING_PRINT( "libewf_common_wide_ctime: unable to set time string.\n" );		libewf_common_free( time_string );		return( NULL );	}	return( time_string );#endif}#endif#if defined( HAVE_WIDE_CHARACTER_TYPE )/* Copies the source string (of wchar_t) into the destination string (of char) for a certain size * Terminates the destination string with \0 at ( size - 1 ) * Returns 1 if successful, -1 on error */int8_t libewf_common_copy_wchar_to_char( char *destination, const wchar_t *source, size_t size ){	size_t iterator = 0;	if( source == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_copy_wchar_to_char: invalid source.\n" );		return( -1 );	}	if( destination == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_copy_wchar_to_char: invalid destination.\n" );		return( -1 );	}	if( size > (size_t) SSIZE_MAX )	{		LIBEWF_WARNING_PRINT( "libewf_common_copy_wchar_to_char: invalid size value exceeds maximum.\n" );		return( -1 );	}	for( iterator = 0; iterator < size; iterator++ )	{		destination[ iterator ] = (char) wctob( (wint_t) source[ iterator ] );		/* If character is out of the basic ASCII range use '_' as a place holder		 */		if( destination[ iterator ] == EOF )		{			destination[ iterator ] = '_';		}	}	destination[ size - 1 ] = (char) '\0';	return( 1 );}/* Copies the source string (of char) into the destination string (of wchar_t) for a certain size * Terminates the destination string with \0 at ( size - 1 ) * Returns 1 if successful, -1 on error */int8_t libewf_common_copy_char_to_wchar( wchar_t *destination, const char *source, size_t size ){	size_t iterator = 0;	if( source == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_copy_char_to_wchar: invalid source.\n" );		return( -1 );	}	if( destination == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_common_copy_char_to_wchar: invalid destination.\n" );		return( -1 );	}	if( size > (size_t) SSIZE_MAX )	{		LIBEWF_WARNING_PRINT( "libewf_common_copy_char_to_wchar: invalid size value exceeds maximum.\n" );		return( -1 );	}	for( iterator = 0; iterator < size; iterator++ )	{		destination[ iterator ] = (wchar_t) btowc( (int) source[ iterator ] );	}	destination[ size - 1 ] = (wchar_t) '\0';	return( 1 );}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -