/* * Functions for testing * * Copyright (C) 2009-2019, Joachim Metz * * Refer to AUTHORS for acknowledgements. * * This software is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software. If not, see . */ #include #include #include #include #include #include #if defined( HAVE_STDLIB_H ) || defined( WINAPI ) #include #endif #if defined( HAVE_UNISTD_H ) #include #endif #include #include "bfio_test_libcerror.h" #include "bfio_test_libclocale.h" #include "bfio_test_libuna.h" /* Retrieves source as a narrow string * Returns 1 if successful or -1 on error */ int bfio_test_get_narrow_source( const system_character_t *source, char *narrow_string, size_t narrow_string_size, libcerror_error_t **error ) { static char *function = "bfio_test_get_narrow_source"; size_t narrow_source_size = 0; size_t source_length = 0; #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) int result = 0; #endif if( source == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid source.", function ); return( -1 ); } if( narrow_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid narrow string.", function ); return( -1 ); } if( narrow_string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid narrow string size value exceeds maximum.", function ); return( -1 ); } source_length = system_string_length( source ); if( source_length > (size_t) ( SSIZE_MAX - 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid source length value out of bounds.", function ); return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) source, source_length + 1, &narrow_source_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) source, source_length + 1, &narrow_source_size, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_size_from_utf32( (libuna_utf32_character_t *) source, source_length + 1, libclocale_codepage, &narrow_source_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_size_from_utf16( (libuna_utf16_character_t *) source, source_length + 1, libclocale_codepage, &narrow_source_size, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to determine narrow string size.", function ); return( -1 ); } #else narrow_source_size = source_length + 1; #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ if( narrow_string_size < narrow_source_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: narrow string too small.", function ); return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_copy_from_utf32( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf32_character_t *) source, source_length + 1, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_copy_from_utf16( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf16_character_t *) source, source_length + 1, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_copy_from_utf32( (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, (libuna_utf32_character_t *) source, source_length + 1, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_copy_from_utf16( (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, (libuna_utf16_character_t *) source, source_length + 1, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set narrow string.", function ); return( -1 ); } #else if( system_string_copy( narrow_string, source, source_length ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set narrow string.", function ); return( -1 ); } narrow_string[ source_length ] = 0; #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ return( 1 ); } #if defined( HAVE_WIDE_CHARACTER_TYPE ) /* Retrieves source as a wide string * Returns 1 if successful or -1 on error */ int bfio_test_get_wide_source( const system_character_t *source, wchar_t *wide_string, size_t wide_string_size, libcerror_error_t **error ) { static char *function = "bfio_test_get_wide_source"; size_t wide_source_size = 0; size_t source_length = 0; #if !defined( HAVE_WIDE_SYSTEM_CHARACTER ) int result = 0; #endif if( source == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid source.", function ); return( -1 ); } if( wide_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid wide string.", function ); return( -1 ); } if( wide_string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid wide string size value exceeds maximum.", function ); return( -1 ); } source_length = system_string_length( source ); if( source_length > (size_t) ( SSIZE_MAX - 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid source length value out of bounds.", function ); return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) wide_source_size = source_length + 1; #else if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_size_from_utf8( (libuna_utf8_character_t *) source, source_length + 1, &wide_source_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_size_from_utf8( (libuna_utf8_character_t *) source, source_length + 1, &wide_source_size, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_size_from_byte_stream( (uint8_t *) source, source_length + 1, libclocale_codepage, &wide_source_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_size_from_byte_stream( (uint8_t *) source, source_length + 1, libclocale_codepage, &wide_source_size, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to determine wide string size.", function ); return( -1 ); } #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ if( wide_string_size < wide_source_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: wide string too small.", function ); return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( system_string_copy( wide_string, source, source_length ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set wide string.", function ); return( -1 ); } wide_string[ source_length ] = 0; #else if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) wide_string, wide_string_size, (uint8_t *) source, source_length + 1, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) wide_string, wide_string_size, (uint8_t *) source, source_length + 1, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_byte_stream( (libuna_utf32_character_t *) wide_string, wide_string_size, (uint8_t *) source, source_length + 1, libclocale_codepage, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) wide_string, wide_string_size, (uint8_t *) source, source_length + 1, libclocale_codepage, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set wide string.", function ); return( -1 ); } #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ return( 1 ); } #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ /* Retrieves a temporary filename * * On entry temporary_filename should contain a template filename. * * Returns 1 if successful, 0 if not available or -1 on error */ int bfio_test_get_temporary_filename( char *temporary_filename, size_t temporary_filename_size, libcerror_error_t **error ) { static char *function = "bfio_test_get_temporary_filename"; #if defined( HAVE_MKSTEMP ) && defined( HAVE_CLOSE ) int file_descriptor = -1; #endif if( temporary_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid temporary filename.", function ); return( -1 ); } if( temporary_filename_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid temporary filename size value exceeds maximum.", function ); return( -1 ); } #if defined( HAVE_MKSTEMP ) && defined( HAVE_CLOSE ) file_descriptor = mkstemp( temporary_filename ); if( file_descriptor == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open temporary file.", function ); return( -1 ); } if( close( file_descriptor ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close temporary file.", function ); return( -1 ); } return( 1 ); #else return( 0 ); #endif /* defined( HAVE_MKSTEMP ) && defined( HAVE_CLOSE ) */ } #if defined( HAVE_WIDE_CHARACTER_TYPE ) /* Retrieves a temporary filename * * On entry temporary_filename should contain a template filename. * * Returns 1 if successful, 0 if not available or -1 on error */ int bfio_test_get_temporary_filename_wide( wchar_t *temporary_filename, size_t temporary_filename_size, libcerror_error_t **error ) { static char *function = "bfio_test_get_temporary_filename_wide"; #if defined( HAVE_MKSTEMP ) && defined( HAVE_CLOSE ) char *narrow_string = NULL; size_t narrow_string_size = 0; int file_descriptor = -1; int result = 0; #endif if( temporary_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid temporary filename.", function ); return( -1 ); } if( temporary_filename_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid temporary filename size value exceeds maximum.", function ); return( -1 ); } #if defined( HAVE_MKSTEMP ) && defined( HAVE_CLOSE ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) temporary_filename, temporary_filename_size, &narrow_string_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) temporary_filename, temporary_filename_size, &narrow_string_size, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_size_from_utf32( (libuna_utf32_character_t *) temporary_filename, temporary_filename_size, libclocale_codepage, &narrow_string_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_size_from_utf16( (libuna_utf16_character_t *) temporary_filename, temporary_filename_size, libclocale_codepage, &narrow_string_size, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to determine narrow string size.", function ); return( -1 ); } narrow_string = narrow_string_allocate( narrow_string_size ); if( narrow_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create narrow string.", function ); goto on_error; } if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_copy_from_utf32( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf32_character_t *) temporary_filename, temporary_filename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_copy_from_utf16( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf16_character_t *) temporary_filename, temporary_filename_size, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_copy_from_utf32( (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, (libuna_utf32_character_t *) temporary_filename, temporary_filename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_copy_from_utf16( (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, (libuna_utf16_character_t *) temporary_filename, temporary_filename_size, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set narrow string.", function ); return( -1 ); } file_descriptor = mkstemp( narrow_string ); if( file_descriptor == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open temporary file.", function ); goto on_error; } if( close( file_descriptor ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close temporary file.", function ); goto on_error; } if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) temporary_filename, temporary_filename_size, (uint8_t *) narrow_string, narrow_string_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) temporary_filename, temporary_filename_size, (uint8_t *) narrow_string, narrow_string_size, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_byte_stream( (libuna_utf32_character_t *) temporary_filename, temporary_filename_size, (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) temporary_filename, temporary_filename_size, (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set temporary filename.", function ); return( -1 ); } memory_free( narrow_string ); narrow_string = NULL; return( 1 ); on_error: if( narrow_string != NULL ) { memory_free( narrow_string ); } return( -1 ); #else return( 0 ); #endif /* defined( HAVE_MKSTEMP ) && defined( HAVE_CLOSE ) */ } #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ #if defined( WINAPI ) /* Removes a temporary file * This function uses the WINAPI function for Windows XP (0x0501) or later * Returns 1 if successful or -1 on error */ int bfio_test_remove_temporary_file( char *temporary_filename, libcerror_error_t **error ) { static char *function = "bfio_test_remove_temporary_file"; DWORD error_code = 0; BOOL result = FALSE; if( temporary_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid temporary filename.", function ); return( -1 ); } result = DeleteFileA( temporary_filename ); if( result == 0 ) { error_code = GetLastError(); libcerror_system_set_error( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_UNLINK_FAILED, error_code, "%s: unable to remove temporary file.", function ); return( -1 ); } return( 1 ); } #elif defined( HAVE_UNLINK ) /* Removes a temporary file * This function uses the POSIX unlink function or equivalent * Returns 1 if successful or -1 on error */ int bfio_test_remove_temporary_file( char *temporary_filename, libcerror_error_t **error ) { static char *function = "bfio_test_remove_temporary_file"; if( temporary_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid temporary filename.", function ); return( -1 ); } if( unlink( temporary_filename ) != 0 ) { libcerror_system_set_error( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_UNLINK_FAILED, errno, "%s: unable to unlink file.", function ); return( -1 ); } return( 1 ); } #else #error Missing file remove function #endif #if defined( HAVE_WIDE_CHARACTER_TYPE ) #if defined( WINAPI ) /* Removes a temporary file * This function uses the WINAPI function for Windows XP (0x0501) or later * Returns 1 if successful or -1 on error */ int bfio_test_remove_temporary_file_wide( wchar_t *temporary_filename, libcerror_error_t **error ) { static char *function = "bfio_test_remove_temporary_file_wide"; DWORD error_code = 0; BOOL result = FALSE; if( temporary_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid temporary filename.", function ); return( -1 ); } result = DeleteFileW( temporary_filename ); if( result == 0 ) { error_code = GetLastError(); libcerror_system_set_error( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_UNLINK_FAILED, error_code, "%s: unable to remove file.", function ); return( -1 ); } return( 1 ); } #elif defined( HAVE_UNLINK ) /* Removes a temporary file * This function uses the POSIX unlink function or equivalent * Returns 1 if successful or -1 on error */ int bfio_test_remove_temporary_file_wide( wchar_t *temporary_filename, libcerror_error_t **error ) { static char *function = "bfio_test_remove_temporary_file_wide"; char *narrow_filename = NULL; size_t filename_size = 0; size_t narrow_filename_size = 0; int result = 0; if( temporary_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid temporary filename.", function ); return( -1 ); } filename_size = 1 + wide_string_length( temporary_filename ); /* Convert the filename to a narrow string * if the platform has no wide character open function */ if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) temporary_filename, filename_size, &narrow_filename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) temporary_filename, filename_size, &narrow_filename_size, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_size_from_utf32( (libuna_utf32_character_t *) temporary_filename, filename_size, libclocale_codepage, &narrow_filename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_size_from_utf16( (libuna_utf16_character_t *) temporary_filename, filename_size, libclocale_codepage, &narrow_filename_size, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to determine narrow character filename size.", function ); goto on_error; } narrow_filename = narrow_string_allocate( narrow_filename_size ); if( narrow_filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create narrow character filename.", function ); goto on_error; } if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_copy_from_utf32( (libuna_utf8_character_t *) narrow_filename, narrow_filename_size, (libuna_utf32_character_t *) temporary_filename, filename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_copy_from_utf16( (libuna_utf8_character_t *) narrow_filename, narrow_filename_size, (libuna_utf16_character_t *) temporary_filename, filename_size, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_copy_from_utf32( (uint8_t *) narrow_filename, narrow_filename_size, libclocale_codepage, (libuna_utf32_character_t *) temporary_filename, filename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_copy_from_utf16( (uint8_t *) narrow_filename, narrow_filename_size, libclocale_codepage, (libuna_utf16_character_t *) temporary_filename, filename_size, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set narrow character filename.", function ); goto on_error; } if( unlink( narrow_filename ) != 0 ) { libcerror_system_set_error( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_UNLINK_FAILED, errno, "%s: unable to unlink file.", function ); goto on_error; } memory_free( narrow_filename ); return( 1 ); on_error: if( narrow_filename != NULL ) { memory_free( narrow_filename ); } return( -1 ); } #else #error Missing file remove wide function #endif #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */