| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <common.h> |
| 23 |
#include <types.h> |
| 24 |
|
| 25 |
#include "libuna_definitions.h" |
| 26 |
#include "libuna_libcerror.h" |
| 27 |
#include "libuna_types.h" |
| 28 |
#include "libuna_unicode_character.h" |
| 29 |
#include "libuna_utf32_stream.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
int libuna_utf32_stream_copy_byte_order_mark( |
| 35 |
uint8_t *utf32_stream, |
| 36 |
size_t utf32_stream_size, |
| 37 |
size_t *utf32_stream_index, |
| 38 |
int byte_order, |
| 39 |
libcerror_error_t **error ) |
| 40 |
{ |
| 41 |
static char *function = "libuna_utf32_stream_copy_byte_order_mark"; |
| 42 |
|
| 43 |
if( utf32_stream == NULL ) |
| 44 |
{ |
| 45 |
libcerror_error_set( |
| 46 |
error, |
| 47 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 48 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 49 |
"%s: invalid UTF-32 stream.", |
| 50 |
function ); |
| 51 |
|
| 52 |
return( -1 ); |
| 53 |
} |
| 54 |
if( utf32_stream_size > (size_t) SSIZE_MAX ) |
| 55 |
{ |
| 56 |
libcerror_error_set( |
| 57 |
error, |
| 58 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 59 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 60 |
"%s: invalid UTF-32 stream size value exceeds maximum.", |
| 61 |
function ); |
| 62 |
|
| 63 |
return( -1 ); |
| 64 |
} |
| 65 |
if( utf32_stream_index == NULL ) |
| 66 |
{ |
| 67 |
libcerror_error_set( |
| 68 |
error, |
| 69 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 70 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 71 |
"%s: invalid UTF-32 stream index.", |
| 72 |
function ); |
| 73 |
|
| 74 |
return( -1 ); |
| 75 |
} |
| 76 |
if( ( *utf32_stream_index + 4 ) > utf32_stream_size ) |
| 77 |
{ |
| 78 |
libcerror_error_set( |
| 79 |
error, |
| 80 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 81 |
LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
| 82 |
"%s: UTF-32 stream too small.", |
| 83 |
function ); |
| 84 |
|
| 85 |
return( -1 ); |
| 86 |
} |
| 87 |
if( ( byte_order != LIBUNA_ENDIAN_BIG ) |
| 88 |
&& ( byte_order != LIBUNA_ENDIAN_LITTLE ) ) |
| 89 |
{ |
| 90 |
libcerror_error_set( |
| 91 |
error, |
| 92 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 93 |
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
| 94 |
"%s: unsupported byte order.", |
| 95 |
function ); |
| 96 |
|
| 97 |
return( -1 ); |
| 98 |
} |
| 99 |
if( byte_order == LIBUNA_ENDIAN_BIG ) |
| 100 |
{ |
| 101 |
utf32_stream[ *utf32_stream_index ] = 0x00; |
| 102 |
utf32_stream[ *utf32_stream_index + 1 ] = 0x00; |
| 103 |
utf32_stream[ *utf32_stream_index + 2 ] = 0xfe; |
| 104 |
utf32_stream[ *utf32_stream_index + 3 ] = 0xff; |
| 105 |
} |
| 106 |
else if( byte_order == LIBUNA_ENDIAN_LITTLE ) |
| 107 |
{ |
| 108 |
utf32_stream[ *utf32_stream_index ] = 0xff; |
| 109 |
utf32_stream[ *utf32_stream_index + 1 ] = 0xfe; |
| 110 |
utf32_stream[ *utf32_stream_index + 2 ] = 0x00; |
| 111 |
utf32_stream[ *utf32_stream_index + 3 ] = 0x00; |
| 112 |
} |
| 113 |
*utf32_stream_index += 4; |
| 114 |
|
| 115 |
return( 1 ); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
int libuna_utf32_stream_size_from_utf8( |
| 122 |
const libuna_utf8_character_t *utf8_string, |
| 123 |
size_t utf8_string_size, |
| 124 |
size_t *utf32_stream_size, |
| 125 |
libcerror_error_t **error ) |
| 126 |
{ |
| 127 |
static char *function = "libuna_utf32_stream_size_from_utf8"; |
| 128 |
libuna_unicode_character_t unicode_character = 0; |
| 129 |
size_t safe_utf32_stream_size = 0; |
| 130 |
size_t utf8_string_index = 0; |
| 131 |
|
| 132 |
if( utf8_string == NULL ) |
| 133 |
{ |
| 134 |
libcerror_error_set( |
| 135 |
error, |
| 136 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 137 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 138 |
"%s: invalid UTF-8 string.", |
| 139 |
function ); |
| 140 |
|
| 141 |
return( -1 ); |
| 142 |
} |
| 143 |
if( utf8_string_size > (size_t) SSIZE_MAX ) |
| 144 |
{ |
| 145 |
libcerror_error_set( |
| 146 |
error, |
| 147 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 148 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 149 |
"%s: invalid UTF-8 string size value exceeds maximum.", |
| 150 |
function ); |
| 151 |
|
| 152 |
return( -1 ); |
| 153 |
} |
| 154 |
if( utf32_stream_size == NULL ) |
| 155 |
{ |
| 156 |
libcerror_error_set( |
| 157 |
error, |
| 158 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 159 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 160 |
"%s: invalid UTF-32 stream size.", |
| 161 |
function ); |
| 162 |
|
| 163 |
return( -1 ); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
safe_utf32_stream_size = 1; |
| 168 |
|
| 169 |
while( utf8_string_index < utf8_string_size ) |
| 170 |
{ |
| 171 |
|
| 172 |
|
| 173 |
if( libuna_unicode_character_copy_from_utf8( |
| 174 |
&unicode_character, |
| 175 |
utf8_string, |
| 176 |
utf8_string_size, |
| 177 |
&utf8_string_index, |
| 178 |
error ) != 1 ) |
| 179 |
{ |
| 180 |
libcerror_error_set( |
| 181 |
error, |
| 182 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 183 |
LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, |
| 184 |
"%s: unable to copy Unicode character from UTF-8.", |
| 185 |
function ); |
| 186 |
|
| 187 |
return( -1 ); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
if( libuna_unicode_character_size_to_utf32( |
| 192 |
unicode_character, |
| 193 |
&safe_utf32_stream_size, |
| 194 |
error ) != 1 ) |
| 195 |
{ |
| 196 |
libcerror_error_set( |
| 197 |
error, |
| 198 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 199 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 200 |
"%s: unable to determine size of Unicode character in UTF-32.", |
| 201 |
function ); |
| 202 |
|
| 203 |
return( -1 ); |
| 204 |
} |
| 205 |
if( unicode_character == 0 ) |
| 206 |
{ |
| 207 |
break; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
*utf32_stream_size = safe_utf32_stream_size * 4; |
| 213 |
|
| 214 |
return( 1 ); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
int libuna_utf32_stream_copy_from_utf8( |
| 221 |
uint8_t *utf32_stream, |
| 222 |
size_t utf32_stream_size, |
| 223 |
int byte_order, |
| 224 |
const libuna_utf8_character_t *utf8_string, |
| 225 |
size_t utf8_string_size, |
| 226 |
libcerror_error_t **error ) |
| 227 |
{ |
| 228 |
static char *function = "libuna_utf32_stream_copy_from_utf8"; |
| 229 |
libuna_unicode_character_t unicode_character = 0; |
| 230 |
size_t utf32_stream_index = 0; |
| 231 |
size_t utf8_string_index = 0; |
| 232 |
|
| 233 |
if( utf32_stream == NULL ) |
| 234 |
{ |
| 235 |
libcerror_error_set( |
| 236 |
error, |
| 237 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 238 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 239 |
"%s: invalid UTF-32 stream.", |
| 240 |
function ); |
| 241 |
|
| 242 |
return( -1 ); |
| 243 |
} |
| 244 |
if( utf32_stream_size > (size_t) SSIZE_MAX ) |
| 245 |
{ |
| 246 |
libcerror_error_set( |
| 247 |
error, |
| 248 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 249 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 250 |
"%s: invalid UTF-32 stream size value exceeds maximum.", |
| 251 |
function ); |
| 252 |
|
| 253 |
return( -1 ); |
| 254 |
} |
| 255 |
if( ( byte_order != LIBUNA_ENDIAN_BIG ) |
| 256 |
&& ( byte_order != LIBUNA_ENDIAN_LITTLE ) ) |
| 257 |
{ |
| 258 |
libcerror_error_set( |
| 259 |
error, |
| 260 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 261 |
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
| 262 |
"%s: unsupported byte order.", |
| 263 |
function ); |
| 264 |
|
| 265 |
return( -1 ); |
| 266 |
} |
| 267 |
if( utf8_string == NULL ) |
| 268 |
{ |
| 269 |
libcerror_error_set( |
| 270 |
error, |
| 271 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 272 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 273 |
"%s: invalid UTF-8 string.", |
| 274 |
function ); |
| 275 |
|
| 276 |
return( -1 ); |
| 277 |
} |
| 278 |
if( utf8_string_size > (size_t) SSIZE_MAX ) |
| 279 |
{ |
| 280 |
libcerror_error_set( |
| 281 |
error, |
| 282 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 283 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 284 |
"%s: invalid UTF-8 string size value exceeds maximum.", |
| 285 |
function ); |
| 286 |
|
| 287 |
return( -1 ); |
| 288 |
} |
| 289 |
if( libuna_utf32_stream_copy_byte_order_mark( |
| 290 |
utf32_stream, |
| 291 |
utf32_stream_size, |
| 292 |
&utf32_stream_index, |
| 293 |
byte_order, |
| 294 |
error ) != 1 ) |
| 295 |
{ |
| 296 |
libcerror_error_set( |
| 297 |
error, |
| 298 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 299 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 300 |
"%s: unable to copy UTF-32 byte order mark.", |
| 301 |
function ); |
| 302 |
|
| 303 |
return( -1 ); |
| 304 |
} |
| 305 |
while( utf8_string_index < utf8_string_size ) |
| 306 |
{ |
| 307 |
|
| 308 |
|
| 309 |
if( libuna_unicode_character_copy_from_utf8( |
| 310 |
&unicode_character, |
| 311 |
utf8_string, |
| 312 |
utf8_string_size, |
| 313 |
&utf8_string_index, |
| 314 |
error ) != 1 ) |
| 315 |
{ |
| 316 |
libcerror_error_set( |
| 317 |
error, |
| 318 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 319 |
LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, |
| 320 |
"%s: unable to copy Unicode character from UTF-8 string.", |
| 321 |
function ); |
| 322 |
|
| 323 |
return( -1 ); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
if( libuna_unicode_character_copy_to_utf32_stream( |
| 328 |
unicode_character, |
| 329 |
utf32_stream, |
| 330 |
utf32_stream_size, |
| 331 |
&utf32_stream_index, |
| 332 |
byte_order, |
| 333 |
error ) != 1 ) |
| 334 |
{ |
| 335 |
libcerror_error_set( |
| 336 |
error, |
| 337 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 338 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 339 |
"%s: unable to copy Unicode character to UTF-32 stream.", |
| 340 |
function ); |
| 341 |
|
| 342 |
return( -1 ); |
| 343 |
} |
| 344 |
if( unicode_character == 0 ) |
| 345 |
{ |
| 346 |
break; |
| 347 |
} |
| 348 |
} |
| 349 |
return( 1 ); |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
int libuna_utf32_stream_size_from_utf16( |
| 356 |
const libuna_utf16_character_t *utf16_string, |
| 357 |
size_t utf16_string_size, |
| 358 |
size_t *utf32_stream_size, |
| 359 |
libcerror_error_t **error ) |
| 360 |
{ |
| 361 |
static char *function = "libuna_utf32_stream_size_from_utf16"; |
| 362 |
libuna_unicode_character_t unicode_character = 0; |
| 363 |
size_t safe_utf32_stream_size = 0; |
| 364 |
size_t utf16_string_index = 0; |
| 365 |
|
| 366 |
if( utf16_string == NULL ) |
| 367 |
{ |
| 368 |
libcerror_error_set( |
| 369 |
error, |
| 370 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 371 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 372 |
"%s: invalid UTF-16 string.", |
| 373 |
function ); |
| 374 |
|
| 375 |
return( -1 ); |
| 376 |
} |
| 377 |
if( utf16_string_size > (size_t) SSIZE_MAX ) |
| 378 |
{ |
| 379 |
libcerror_error_set( |
| 380 |
error, |
| 381 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 382 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 383 |
"%s: invalid UTF-16 string size value exceeds maximum.", |
| 384 |
function ); |
| 385 |
|
| 386 |
return( -1 ); |
| 387 |
} |
| 388 |
if( utf32_stream_size == NULL ) |
| 389 |
{ |
| 390 |
libcerror_error_set( |
| 391 |
error, |
| 392 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 393 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 394 |
"%s: invalid UTF-32 stream size.", |
| 395 |
function ); |
| 396 |
|
| 397 |
return( -1 ); |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
safe_utf32_stream_size = 1; |
| 402 |
|
| 403 |
while( utf16_string_index < utf16_string_size ) |
| 404 |
{ |
| 405 |
|
| 406 |
|
| 407 |
if( libuna_unicode_character_copy_from_utf16( |
| 408 |
&unicode_character, |
| 409 |
utf16_string, |
| 410 |
utf16_string_size, |
| 411 |
&utf16_string_index, |
| 412 |
error ) != 1 ) |
| 413 |
{ |
| 414 |
libcerror_error_set( |
| 415 |
error, |
| 416 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 417 |
LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, |
| 418 |
"%s: unable to copy Unicode character from UTF-16.", |
| 419 |
function ); |
| 420 |
|
| 421 |
return( -1 ); |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
if( libuna_unicode_character_size_to_utf32( |
| 426 |
unicode_character, |
| 427 |
&safe_utf32_stream_size, |
| 428 |
error ) != 1 ) |
| 429 |
{ |
| 430 |
libcerror_error_set( |
| 431 |
error, |
| 432 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 433 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 434 |
"%s: unable to determine size of Unicode character in UTF-32.", |
| 435 |
function ); |
| 436 |
|
| 437 |
return( -1 ); |
| 438 |
} |
| 439 |
if( unicode_character == 0 ) |
| 440 |
{ |
| 441 |
break; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
*utf32_stream_size = safe_utf32_stream_size * 4; |
| 447 |
|
| 448 |
return( 1 ); |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
int libuna_utf32_stream_copy_from_utf16( |
| 455 |
uint8_t *utf32_stream, |
| 456 |
size_t utf32_stream_size, |
| 457 |
int byte_order, |
| 458 |
const libuna_utf16_character_t *utf16_string, |
| 459 |
size_t utf16_string_size, |
| 460 |
libcerror_error_t **error ) |
| 461 |
{ |
| 462 |
static char *function = "libuna_utf32_stream_copy_from_utf16"; |
| 463 |
libuna_unicode_character_t unicode_character = 0; |
| 464 |
size_t utf16_string_index = 0; |
| 465 |
size_t utf32_stream_index = 0; |
| 466 |
|
| 467 |
if( utf32_stream == NULL ) |
| 468 |
{ |
| 469 |
libcerror_error_set( |
| 470 |
error, |
| 471 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 472 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 473 |
"%s: invalid UTF-32 stream.", |
| 474 |
function ); |
| 475 |
|
| 476 |
return( -1 ); |
| 477 |
} |
| 478 |
if( utf32_stream_size > (size_t) SSIZE_MAX ) |
| 479 |
{ |
| 480 |
libcerror_error_set( |
| 481 |
error, |
| 482 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 483 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 484 |
"%s: invalid UTF-32 stream size value exceeds maximum.", |
| 485 |
function ); |
| 486 |
|
| 487 |
return( -1 ); |
| 488 |
} |
| 489 |
if( ( byte_order != LIBUNA_ENDIAN_BIG ) |
| 490 |
&& ( byte_order != LIBUNA_ENDIAN_LITTLE ) ) |
| 491 |
{ |
| 492 |
libcerror_error_set( |
| 493 |
error, |
| 494 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 495 |
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
| 496 |
"%s: unsupported byte order.", |
| 497 |
function ); |
| 498 |
|
| 499 |
return( -1 ); |
| 500 |
} |
| 501 |
if( utf16_string == NULL ) |
| 502 |
{ |
| 503 |
libcerror_error_set( |
| 504 |
error, |
| 505 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 506 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 507 |
"%s: invalid UTF-16 string.", |
| 508 |
function ); |
| 509 |
|
| 510 |
return( -1 ); |
| 511 |
} |
| 512 |
if( utf16_string_size > (size_t) SSIZE_MAX ) |
| 513 |
{ |
| 514 |
libcerror_error_set( |
| 515 |
error, |
| 516 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 517 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 518 |
"%s: invalid UTF-16 string size value exceeds maximum.", |
| 519 |
function ); |
| 520 |
|
| 521 |
return( -1 ); |
| 522 |
} |
| 523 |
if( libuna_utf32_stream_copy_byte_order_mark( |
| 524 |
utf32_stream, |
| 525 |
utf32_stream_size, |
| 526 |
&utf32_stream_index, |
| 527 |
byte_order, |
| 528 |
error ) != 1 ) |
| 529 |
{ |
| 530 |
libcerror_error_set( |
| 531 |
error, |
| 532 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 533 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 534 |
"%s: unable to copy UTF-32 byte order mark.", |
| 535 |
function ); |
| 536 |
|
| 537 |
return( -1 ); |
| 538 |
} |
| 539 |
while( utf16_string_index < utf16_string_size ) |
| 540 |
{ |
| 541 |
|
| 542 |
|
| 543 |
if( libuna_unicode_character_copy_from_utf16( |
| 544 |
&unicode_character, |
| 545 |
utf16_string, |
| 546 |
utf16_string_size, |
| 547 |
&utf16_string_index, |
| 548 |
error ) != 1 ) |
| 549 |
{ |
| 550 |
libcerror_error_set( |
| 551 |
error, |
| 552 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 553 |
LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, |
| 554 |
"%s: unable to copy Unicode character from UTF-16 string.", |
| 555 |
function ); |
| 556 |
|
| 557 |
return( -1 ); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
if( libuna_unicode_character_copy_to_utf32_stream( |
| 562 |
unicode_character, |
| 563 |
utf32_stream, |
| 564 |
utf32_stream_size, |
| 565 |
&utf32_stream_index, |
| 566 |
byte_order, |
| 567 |
error ) != 1 ) |
| 568 |
{ |
| 569 |
libcerror_error_set( |
| 570 |
error, |
| 571 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 572 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 573 |
"%s: unable to copy Unicode character to UTF-32 stream.", |
| 574 |
function ); |
| 575 |
|
| 576 |
return( -1 ); |
| 577 |
} |
| 578 |
if( unicode_character == 0 ) |
| 579 |
{ |
| 580 |
break; |
| 581 |
} |
| 582 |
} |
| 583 |
return( 1 ); |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
int libuna_utf32_stream_size_from_utf32( |
| 590 |
const libuna_utf32_character_t *utf32_string, |
| 591 |
size_t utf32_string_size, |
| 592 |
size_t *utf32_stream_size, |
| 593 |
libcerror_error_t **error ) |
| 594 |
{ |
| 595 |
static char *function = "libuna_utf32_stream_size_from_utf32"; |
| 596 |
libuna_unicode_character_t unicode_character = 0; |
| 597 |
size_t safe_utf32_stream_size = 0; |
| 598 |
size_t utf32_string_index = 0; |
| 599 |
|
| 600 |
if( utf32_string == NULL ) |
| 601 |
{ |
| 602 |
libcerror_error_set( |
| 603 |
error, |
| 604 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 605 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 606 |
"%s: invalid UTF-32 string.", |
| 607 |
function ); |
| 608 |
|
| 609 |
return( -1 ); |
| 610 |
} |
| 611 |
if( utf32_string_size > (size_t) SSIZE_MAX ) |
| 612 |
{ |
| 613 |
libcerror_error_set( |
| 614 |
error, |
| 615 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 616 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 617 |
"%s: invalid UTF-32 string size value exceeds maximum.", |
| 618 |
function ); |
| 619 |
|
| 620 |
return( -1 ); |
| 621 |
} |
| 622 |
if( utf32_stream_size == NULL ) |
| 623 |
{ |
| 624 |
libcerror_error_set( |
| 625 |
error, |
| 626 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 627 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 628 |
"%s: invalid UTF-32 stream size.", |
| 629 |
function ); |
| 630 |
|
| 631 |
return( -1 ); |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
safe_utf32_stream_size = 1; |
| 636 |
|
| 637 |
while( utf32_string_index < utf32_string_size ) |
| 638 |
{ |
| 639 |
|
| 640 |
|
| 641 |
if( libuna_unicode_character_copy_from_utf32( |
| 642 |
&unicode_character, |
| 643 |
utf32_string, |
| 644 |
utf32_string_size, |
| 645 |
&utf32_string_index, |
| 646 |
error ) != 1 ) |
| 647 |
{ |
| 648 |
libcerror_error_set( |
| 649 |
error, |
| 650 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 651 |
LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, |
| 652 |
"%s: unable to copy Unicode character from UTF-32.", |
| 653 |
function ); |
| 654 |
|
| 655 |
return( -1 ); |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
if( libuna_unicode_character_size_to_utf32( |
| 660 |
unicode_character, |
| 661 |
&safe_utf32_stream_size, |
| 662 |
error ) != 1 ) |
| 663 |
{ |
| 664 |
libcerror_error_set( |
| 665 |
error, |
| 666 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 667 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 668 |
"%s: unable to determine size of Unicode character in UTF-32.", |
| 669 |
function ); |
| 670 |
|
| 671 |
return( -1 ); |
| 672 |
} |
| 673 |
if( unicode_character == 0 ) |
| 674 |
{ |
| 675 |
break; |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
*utf32_stream_size = safe_utf32_stream_size * 4; |
| 681 |
|
| 682 |
return( 1 ); |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
int libuna_utf32_stream_copy_from_utf32( |
| 689 |
uint8_t *utf32_stream, |
| 690 |
size_t utf32_stream_size, |
| 691 |
int byte_order, |
| 692 |
const libuna_utf32_character_t *utf32_string, |
| 693 |
size_t utf32_string_size, |
| 694 |
libcerror_error_t **error ) |
| 695 |
{ |
| 696 |
static char *function = "libuna_utf32_stream_copy_from_utf32"; |
| 697 |
libuna_unicode_character_t unicode_character = 0; |
| 698 |
size_t utf32_stream_index = 0; |
| 699 |
size_t utf32_string_index = 0; |
| 700 |
|
| 701 |
if( utf32_stream == NULL ) |
| 702 |
{ |
| 703 |
libcerror_error_set( |
| 704 |
error, |
| 705 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 706 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 707 |
"%s: invalid UTF-32 stream.", |
| 708 |
function ); |
| 709 |
|
| 710 |
return( -1 ); |
| 711 |
} |
| 712 |
if( utf32_stream_size > (size_t) SSIZE_MAX ) |
| 713 |
{ |
| 714 |
libcerror_error_set( |
| 715 |
error, |
| 716 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 717 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 718 |
"%s: invalid UTF-32 stream size value exceeds maximum.", |
| 719 |
function ); |
| 720 |
|
| 721 |
return( -1 ); |
| 722 |
} |
| 723 |
if( ( byte_order != LIBUNA_ENDIAN_BIG ) |
| 724 |
&& ( byte_order != LIBUNA_ENDIAN_LITTLE ) ) |
| 725 |
{ |
| 726 |
libcerror_error_set( |
| 727 |
error, |
| 728 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 729 |
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
| 730 |
"%s: unsupported byte order.", |
| 731 |
function ); |
| 732 |
|
| 733 |
return( -1 ); |
| 734 |
} |
| 735 |
if( utf32_string == NULL ) |
| 736 |
{ |
| 737 |
libcerror_error_set( |
| 738 |
error, |
| 739 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 740 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 741 |
"%s: invalid UTF-32 string.", |
| 742 |
function ); |
| 743 |
|
| 744 |
return( -1 ); |
| 745 |
} |
| 746 |
if( utf32_string_size > (size_t) SSIZE_MAX ) |
| 747 |
{ |
| 748 |
libcerror_error_set( |
| 749 |
error, |
| 750 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 751 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 752 |
"%s: invalid UTF-32 string size value exceeds maximum.", |
| 753 |
function ); |
| 754 |
|
| 755 |
return( -1 ); |
| 756 |
} |
| 757 |
if( libuna_utf32_stream_copy_byte_order_mark( |
| 758 |
utf32_stream, |
| 759 |
utf32_stream_size, |
| 760 |
&utf32_stream_index, |
| 761 |
byte_order, |
| 762 |
error ) != 1 ) |
| 763 |
{ |
| 764 |
libcerror_error_set( |
| 765 |
error, |
| 766 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 767 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 768 |
"%s: unable to copy UTF-32 byte order mark.", |
| 769 |
function ); |
| 770 |
|
| 771 |
return( -1 ); |
| 772 |
} |
| 773 |
while( utf32_string_index < utf32_string_size ) |
| 774 |
{ |
| 775 |
|
| 776 |
|
| 777 |
if( libuna_unicode_character_copy_from_utf32( |
| 778 |
&unicode_character, |
| 779 |
utf32_string, |
| 780 |
utf32_string_size, |
| 781 |
&utf32_string_index, |
| 782 |
error ) != 1 ) |
| 783 |
{ |
| 784 |
libcerror_error_set( |
| 785 |
error, |
| 786 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 787 |
LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, |
| 788 |
"%s: unable to copy Unicode character from UTF-32 string.", |
| 789 |
function ); |
| 790 |
|
| 791 |
return( -1 ); |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
if( libuna_unicode_character_copy_to_utf32_stream( |
| 796 |
unicode_character, |
| 797 |
utf32_stream, |
| 798 |
utf32_stream_size, |
| 799 |
&utf32_stream_index, |
| 800 |
byte_order, |
| 801 |
error ) != 1 ) |
| 802 |
{ |
| 803 |
libcerror_error_set( |
| 804 |
error, |
| 805 |
LIBCERROR_ERROR_DOMAIN_CONVERSION, |
| 806 |
LIBCERROR_CONVERSION_ERROR_OUTPUT_FAILED, |
| 807 |
"%s: unable to copy Unicode character to UTF-32 stream.", |
| 808 |
function ); |
| 809 |
|
| 810 |
return( -1 ); |
| 811 |
} |
| 812 |
if( unicode_character == 0 ) |
| 813 |
{ |
| 814 |
break; |
| 815 |
} |
| 816 |
} |
| 817 |
return( 1 ); |
| 818 |
} |
| 819 |
|