/* Retrieves source as a wide string * Returns 1 if successful or -1 on error */ int smdev_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 = "smdev_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 ); }
/* Copies the system string size from the UTF-8 string * Returns 1 if successful or -1 on error */ int libcsystem_string_copy_from_utf8_string( libcstring_system_character_t *string, size_t string_size, const uint8_t *utf8_string, size_t utf8_string_size, libcerror_error_t **error ) { static char *function = "libcsystem_string_copy_from_utf8_string"; 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( utf8_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-8 string.", function ); return( -1 ); } if( utf8_string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid UTF-8 string size value exceeds maximum.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) #if SIZEOF_WCHAR_T == 4 if( libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) string, string_size, (libuna_utf8_character_t *) utf8_string, utf8_string_size, error ) != 1 ) #elif SIZEOF_WCHAR_T == 2 if( libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) string, string_size, (libuna_utf8_character_t *) utf8_string, utf8_string_size, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set string.", function ); return( -1 ); } #else if( libclocale_codepage == 0 ) { if( string_size < utf8_string_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: string too small.", function ); return( -1 ); } if( memory_copy( string, utf8_string, utf8_string_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set string.", function ); return( -1 ); } } else if( libuna_byte_stream_copy_from_utf8( (uint8_t *) string, string_size, libclocale_codepage, (libuna_utf8_character_t *) utf8_string, utf8_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set string.", function ); return( -1 ); } #endif return( 1 ); }
/* Retrieves the basename * Returns 1 if successful, 0 if value not present or -1 on error */ int libewf_segment_table_get_basename_wide( libewf_segment_table_t *segment_table, wchar_t *basename, size_t basename_size, libcerror_error_t **error ) { static char *function = "libewf_segment_table_get_basename_wide"; size_t wide_basename_size = 0; #if !defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) int result = 0; #endif if( segment_table == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid segment table.", function ); return( -1 ); } if( basename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid basename.", function ); return( -1 ); } if( segment_table->basename == NULL ) { return( 0 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) wide_basename_size = segment_table->basename_size; #else if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_size_from_utf8( (libuna_utf8_character_t *) segment_table->basename, segment_table->basename_size, &wide_basename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_size_from_utf8( (libuna_utf8_character_t *) segment_table->basename, segment_table->basename_size, &wide_basename_size, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_size_from_byte_stream( (uint8_t *) segment_table->basename, segment_table->basename_size, libclocale_codepage, &wide_basename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_size_from_byte_stream( (uint8_t *) segment_table->basename, segment_table->basename_size, libclocale_codepage, &wide_basename_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 basename size.", function ); return( -1 ); } #endif /* defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) */ if( basename_size < wide_basename_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: basename too small.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libcstring_system_string_copy( basename, segment_table->basename, segment_table->basename_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set basename.", function ); return( -1 ); } basename[ segment_table->basename_size - 1 ] = 0; #else if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) basename, basename_size, (libuna_utf8_character_t *) segment_table->basename, segment_table->basename_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) basename, basename_size, (libuna_utf8_character_t *) segment_table->basename, segment_table->basename_size, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_byte_stream( (libuna_utf32_character_t *) basename, basename_size, (uint8_t *) segment_table->basename, segment_table->basename_size, libclocale_codepage, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) basename, basename_size, (uint8_t *) segment_table->basename, segment_table->basename_size, libclocale_codepage, 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 basename.", function ); return( -1 ); } #endif /* defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) */ return( 1 ); }
/* Sets the basename * Returns 1 if successful or -1 on error */ int libewf_segment_table_set_basename( libewf_segment_table_t *segment_table, const char *basename, size_t basename_length, libcerror_error_t **error ) { static char *function = "libewf_segment_table_set_basename"; #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) int result = 0; #endif if( segment_table == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid segment table.", function ); return( -1 ); } if( basename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid basename.", function ); return( -1 ); } if( segment_table->basename != NULL ) { memory_free( segment_table->basename ); segment_table->basename = NULL; segment_table->basename_size = 0; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_size_from_utf8( (libuna_utf8_character_t *) basename, basename_length + 1, &( segment_table->basename_size ), error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_size_from_utf8( (libuna_utf8_character_t *) basename, basename_length + 1, &( segment_table->basename_size ), error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_size_from_byte_stream( (uint8_t *) basename, basename_length + 1, libclocale_codepage, &( segment_table->basename_size ), error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_size_from_byte_stream( (uint8_t *) basename, basename_length + 1, libclocale_codepage, &( segment_table->basename_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 basename size.", function ); return( -1 ); } #else segment_table->basename_size = basename_length + 1; #endif segment_table->basename = libcstring_system_string_allocate( segment_table->basename_size ); if( segment_table->basename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create basename.", function ); segment_table->basename_size = 0; return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_utf8( (libuna_utf32_character_t *) segment_table->basename, segment_table->basename_size, (libuna_utf8_character_t *) basename, basename_length + 1, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_utf8( (libuna_utf16_character_t *) segment_table->basename, segment_table->basename_size, (libuna_utf8_character_t *) basename, basename_length + 1, error ); #else #error Unsupported size of wchar_t #endif /* SIZEOF_WCHAR_T */ } else { #if SIZEOF_WCHAR_T == 4 result = libuna_utf32_string_copy_from_byte_stream( (libuna_utf32_character_t *) segment_table->basename, segment_table->basename_size, (uint8_t *) basename, basename_length + 1, libclocale_codepage, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) segment_table->basename, segment_table->basename_size, (uint8_t *) basename, basename_length + 1, libclocale_codepage, 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 basename.", function ); memory_free( segment_table->basename ); segment_table->basename = NULL; segment_table->basename_size = 0; return( -1 ); } #else if( libcstring_system_string_copy( segment_table->basename, basename, basename_length ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set basename.", function ); memory_free( segment_table->basename ); segment_table->basename = NULL; segment_table->basename_size = 0; return( -1 ); } segment_table->basename[ basename_length ] = 0; #endif /* defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) */ return( 1 ); }
/* Retrieves the UTF-16 encoded name value * The size should include the end of string character * Returns 1 if successful or -1 on error */ int libewf_single_file_entry_get_utf16_name( libewf_single_file_entry_t *single_file_entry, uint16_t *utf16_string, size_t utf16_string_size, libcerror_error_t **error ) { static char *function = "libewf_single_file_entry_get_utf16_name"; if( single_file_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid single file entry.", function ); return( -1 ); } if( utf16_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-16 string.", function ); return( -1 ); } if( utf16_string_size == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: invalid UTF-16 string size value too small.", function ); return( -1 ); } if( ( single_file_entry->name == NULL ) || ( single_file_entry->name_size == 0 ) ) { utf16_string[ 0 ] = 0; } else { if( libuna_utf16_string_copy_from_utf8( utf16_string, utf16_string_size, single_file_entry->name, single_file_entry->name_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy name to UTF-16 string.", function ); return( -1 ); } } return( 1 ); }
/* Retrieves the UTF-16 encoded SHA1 hash value * Returns 1 if successful, 0 if value not present or -1 on error */ int libewf_single_file_entry_get_utf16_hash_value_sha1( libewf_single_file_entry_t *single_file_entry, uint16_t *utf16_string, size_t utf16_string_size, libcerror_error_t **error ) { static char *function = "libewf_single_file_entry_get_utf16_hash_value_sha1"; if( single_file_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid single file entry.", function ); return( -1 ); } if( utf16_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-16 string.", function ); return( -1 ); } if( utf16_string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid UTF-16 string size value exceeds maximum.", function ); return( -1 ); } if( utf16_string_size < single_file_entry->sha1_hash_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: UTF-16 string too small.", function ); return( -1 ); } if( single_file_entry->sha1_hash_size == 0 ) { return( 0 ); } if( libuna_utf16_string_copy_from_utf8( utf16_string, utf16_string_size, single_file_entry->sha1_hash, single_file_entry->sha1_hash_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy SHA1 hash to UTF-16 string.", function ); return( -1 ); } return( 1 ); }
/* 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 cfile_test_get_temporary_filename_wide( wchar_t *temporary_filename, size_t temporary_filename_size, libcerror_error_t **error ) { static char *function = "cfile_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 ) */ }