OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* ftstream.c */ | 3 /* ftstream.c */ |
4 /* */ | 4 /* */ |
5 /* I/O stream support (body). */ | 5 /* I/O stream support (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 2000-2002, 2004-2006, 2008-2011, 2013 by */ | 7 /* Copyright 2000-2015 by */ |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 /* */ | 9 /* */ |
10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
11 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
15 /* */ | 15 /* */ |
16 /***************************************************************************/ | 16 /***************************************************************************/ |
17 | 17 |
(...skipping 14 matching lines...) Expand all Loading... |
32 | 32 |
33 | 33 |
34 FT_BASE_DEF( void ) | 34 FT_BASE_DEF( void ) |
35 FT_Stream_OpenMemory( FT_Stream stream, | 35 FT_Stream_OpenMemory( FT_Stream stream, |
36 const FT_Byte* base, | 36 const FT_Byte* base, |
37 FT_ULong size ) | 37 FT_ULong size ) |
38 { | 38 { |
39 stream->base = (FT_Byte*) base; | 39 stream->base = (FT_Byte*) base; |
40 stream->size = size; | 40 stream->size = size; |
41 stream->pos = 0; | 41 stream->pos = 0; |
42 stream->cursor = 0; | 42 stream->cursor = NULL; |
43 stream->read = 0; | 43 stream->read = NULL; |
44 stream->close = 0; | 44 stream->close = NULL; |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 FT_BASE_DEF( void ) | 48 FT_BASE_DEF( void ) |
49 FT_Stream_Close( FT_Stream stream ) | 49 FT_Stream_Close( FT_Stream stream ) |
50 { | 50 { |
51 if ( stream && stream->close ) | 51 if ( stream && stream->close ) |
52 stream->close( stream ); | 52 stream->close( stream ); |
53 } | 53 } |
54 | 54 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 FT_BASE_DEF( FT_Error ) | 91 FT_BASE_DEF( FT_Error ) |
92 FT_Stream_Skip( FT_Stream stream, | 92 FT_Stream_Skip( FT_Stream stream, |
93 FT_Long distance ) | 93 FT_Long distance ) |
94 { | 94 { |
95 if ( distance < 0 ) | 95 if ( distance < 0 ) |
96 return FT_THROW( Invalid_Stream_Operation ); | 96 return FT_THROW( Invalid_Stream_Operation ); |
97 | 97 |
98 return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) ); | 98 return FT_Stream_Seek( stream, stream->pos + (FT_ULong)distance ); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 FT_BASE_DEF( FT_Long ) | 102 FT_BASE_DEF( FT_ULong ) |
103 FT_Stream_Pos( FT_Stream stream ) | 103 FT_Stream_Pos( FT_Stream stream ) |
104 { | 104 { |
105 return stream->pos; | 105 return stream->pos; |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 FT_BASE_DEF( FT_Error ) | 109 FT_BASE_DEF( FT_Error ) |
110 FT_Stream_Read( FT_Stream stream, | 110 FT_Stream_Read( FT_Stream stream, |
111 FT_Byte* buffer, | 111 FT_Byte* buffer, |
112 FT_ULong count ) | 112 FT_ULong count ) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 { | 196 { |
197 FT_Error error; | 197 FT_Error error; |
198 | 198 |
199 | 199 |
200 error = FT_Stream_EnterFrame( stream, count ); | 200 error = FT_Stream_EnterFrame( stream, count ); |
201 if ( !error ) | 201 if ( !error ) |
202 { | 202 { |
203 *pbytes = (FT_Byte*)stream->cursor; | 203 *pbytes = (FT_Byte*)stream->cursor; |
204 | 204 |
205 /* equivalent to FT_Stream_ExitFrame(), with no memory block release */ | 205 /* equivalent to FT_Stream_ExitFrame(), with no memory block release */ |
206 stream->cursor = 0; | 206 stream->cursor = NULL; |
207 stream->limit = 0; | 207 stream->limit = NULL; |
208 } | 208 } |
209 | 209 |
210 return error; | 210 return error; |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 FT_BASE_DEF( void ) | 214 FT_BASE_DEF( void ) |
215 FT_Stream_ReleaseFrame( FT_Stream stream, | 215 FT_Stream_ReleaseFrame( FT_Stream stream, |
216 FT_Byte** pbytes ) | 216 FT_Byte** pbytes ) |
217 { | 217 { |
218 if ( stream && stream->read ) | 218 if ( stream && stream->read ) |
219 { | 219 { |
220 FT_Memory memory = stream->memory; | 220 FT_Memory memory = stream->memory; |
221 | 221 |
222 #ifdef FT_DEBUG_MEMORY | 222 #ifdef FT_DEBUG_MEMORY |
223 ft_mem_free( memory, *pbytes ); | 223 ft_mem_free( memory, *pbytes ); |
224 *pbytes = NULL; | 224 *pbytes = NULL; |
225 #else | 225 #else |
226 FT_FREE( *pbytes ); | 226 FT_FREE( *pbytes ); |
227 #endif | 227 #endif |
228 } | 228 } |
229 *pbytes = 0; | 229 *pbytes = NULL; |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 FT_BASE_DEF( FT_Error ) | 233 FT_BASE_DEF( FT_Error ) |
234 FT_Stream_EnterFrame( FT_Stream stream, | 234 FT_Stream_EnterFrame( FT_Stream stream, |
235 FT_ULong count ) | 235 FT_ULong count ) |
236 { | 236 { |
237 FT_Error error = FT_Err_Ok; | 237 FT_Error error = FT_Err_Ok; |
238 FT_ULong read_bytes; | 238 FT_ULong read_bytes; |
239 | 239 |
(...skipping 13 matching lines...) Expand all Loading... |
253 FT_ERROR(( "FT_Stream_EnterFrame:" | 253 FT_ERROR(( "FT_Stream_EnterFrame:" |
254 " frame size (%lu) larger than stream size (%lu)\n", | 254 " frame size (%lu) larger than stream size (%lu)\n", |
255 count, stream->size )); | 255 count, stream->size )); |
256 | 256 |
257 error = FT_THROW( Invalid_Stream_Operation ); | 257 error = FT_THROW( Invalid_Stream_Operation ); |
258 goto Exit; | 258 goto Exit; |
259 } | 259 } |
260 | 260 |
261 #ifdef FT_DEBUG_MEMORY | 261 #ifdef FT_DEBUG_MEMORY |
262 /* assume _ft_debug_file and _ft_debug_lineno are already set */ | 262 /* assume _ft_debug_file and _ft_debug_lineno are already set */ |
263 stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error ); | 263 stream->base = (unsigned char*)ft_mem_qalloc( memory, |
| 264 (FT_Long)count, |
| 265 &error ); |
264 if ( error ) | 266 if ( error ) |
265 goto Exit; | 267 goto Exit; |
266 #else | 268 #else |
267 if ( FT_QALLOC( stream->base, count ) ) | 269 if ( FT_QALLOC( stream->base, count ) ) |
268 goto Exit; | 270 goto Exit; |
269 #endif | 271 #endif |
270 /* read it */ | 272 /* read it */ |
271 read_bytes = stream->read( stream, stream->pos, | 273 read_bytes = stream->read( stream, stream->pos, |
272 stream->base, count ); | 274 stream->base, count ); |
273 if ( read_bytes < count ) | 275 if ( read_bytes < count ) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 { | 328 { |
327 FT_Memory memory = stream->memory; | 329 FT_Memory memory = stream->memory; |
328 | 330 |
329 #ifdef FT_DEBUG_MEMORY | 331 #ifdef FT_DEBUG_MEMORY |
330 ft_mem_free( memory, stream->base ); | 332 ft_mem_free( memory, stream->base ); |
331 stream->base = NULL; | 333 stream->base = NULL; |
332 #else | 334 #else |
333 FT_FREE( stream->base ); | 335 FT_FREE( stream->base ); |
334 #endif | 336 #endif |
335 } | 337 } |
336 stream->cursor = 0; | 338 stream->cursor = NULL; |
337 stream->limit = 0; | 339 stream->limit = NULL; |
338 } | 340 } |
339 | 341 |
340 | 342 |
341 FT_BASE_DEF( FT_Char ) | 343 FT_BASE_DEF( FT_Char ) |
342 FT_Stream_GetChar( FT_Stream stream ) | 344 FT_Stream_GetChar( FT_Stream stream ) |
343 { | 345 { |
344 FT_Char result; | 346 FT_Char result; |
345 | 347 |
346 | 348 |
347 FT_ASSERT( stream && stream->cursor ); | 349 FT_ASSERT( stream && stream->cursor ); |
348 | 350 |
349 result = 0; | 351 result = 0; |
350 if ( stream->cursor < stream->limit ) | 352 if ( stream->cursor < stream->limit ) |
351 result = *stream->cursor++; | 353 result = (FT_Char)*stream->cursor++; |
352 | 354 |
353 return result; | 355 return result; |
354 } | 356 } |
355 | 357 |
356 | 358 |
357 FT_BASE_DEF( FT_UShort ) | 359 FT_BASE_DEF( FT_UShort ) |
358 FT_Stream_GetUShort( FT_Stream stream ) | 360 FT_Stream_GetUShort( FT_Stream stream ) |
359 { | 361 { |
360 FT_Byte* p; | 362 FT_Byte* p; |
361 FT_Short result; | 363 FT_UShort result; |
362 | 364 |
363 | 365 |
364 FT_ASSERT( stream && stream->cursor ); | 366 FT_ASSERT( stream && stream->cursor ); |
365 | 367 |
366 result = 0; | 368 result = 0; |
367 p = stream->cursor; | 369 p = stream->cursor; |
368 if ( p + 1 < stream->limit ) | 370 if ( p + 1 < stream->limit ) |
369 result = FT_NEXT_USHORT( p ); | 371 result = FT_NEXT_USHORT( p ); |
370 stream->cursor = p; | 372 stream->cursor = p; |
371 | 373 |
372 return result; | 374 return result; |
373 } | 375 } |
374 | 376 |
375 | 377 |
376 FT_BASE_DEF( FT_UShort ) | 378 FT_BASE_DEF( FT_UShort ) |
377 FT_Stream_GetUShortLE( FT_Stream stream ) | 379 FT_Stream_GetUShortLE( FT_Stream stream ) |
378 { | 380 { |
379 FT_Byte* p; | 381 FT_Byte* p; |
380 FT_Short result; | 382 FT_UShort result; |
381 | 383 |
382 | 384 |
383 FT_ASSERT( stream && stream->cursor ); | 385 FT_ASSERT( stream && stream->cursor ); |
384 | 386 |
385 result = 0; | 387 result = 0; |
386 p = stream->cursor; | 388 p = stream->cursor; |
387 if ( p + 1 < stream->limit ) | 389 if ( p + 1 < stream->limit ) |
388 result = FT_NEXT_USHORT_LE( p ); | 390 result = FT_NEXT_USHORT_LE( p ); |
389 stream->cursor = p; | 391 stream->cursor = p; |
390 | 392 |
391 return result; | 393 return result; |
392 } | 394 } |
393 | 395 |
394 | 396 |
395 FT_BASE_DEF( FT_ULong ) | 397 FT_BASE_DEF( FT_ULong ) |
396 FT_Stream_GetUOffset( FT_Stream stream ) | 398 FT_Stream_GetUOffset( FT_Stream stream ) |
397 { | 399 { |
398 FT_Byte* p; | 400 FT_Byte* p; |
399 FT_Long result; | 401 FT_ULong result; |
400 | 402 |
401 | 403 |
402 FT_ASSERT( stream && stream->cursor ); | 404 FT_ASSERT( stream && stream->cursor ); |
403 | 405 |
404 result = 0; | 406 result = 0; |
405 p = stream->cursor; | 407 p = stream->cursor; |
406 if ( p + 2 < stream->limit ) | 408 if ( p + 2 < stream->limit ) |
407 result = FT_NEXT_UOFF3( p ); | 409 result = FT_NEXT_UOFF3( p ); |
408 stream->cursor = p; | 410 stream->cursor = p; |
409 return result; | 411 return result; |
410 } | 412 } |
411 | 413 |
412 | 414 |
413 FT_BASE_DEF( FT_ULong ) | 415 FT_BASE_DEF( FT_ULong ) |
414 FT_Stream_GetULong( FT_Stream stream ) | 416 FT_Stream_GetULong( FT_Stream stream ) |
415 { | 417 { |
416 FT_Byte* p; | 418 FT_Byte* p; |
417 FT_Long result; | 419 FT_ULong result; |
418 | 420 |
419 | 421 |
420 FT_ASSERT( stream && stream->cursor ); | 422 FT_ASSERT( stream && stream->cursor ); |
421 | 423 |
422 result = 0; | 424 result = 0; |
423 p = stream->cursor; | 425 p = stream->cursor; |
424 if ( p + 3 < stream->limit ) | 426 if ( p + 3 < stream->limit ) |
425 result = FT_NEXT_ULONG( p ); | 427 result = FT_NEXT_ULONG( p ); |
426 stream->cursor = p; | 428 stream->cursor = p; |
427 return result; | 429 return result; |
428 } | 430 } |
429 | 431 |
430 | 432 |
431 FT_BASE_DEF( FT_ULong ) | 433 FT_BASE_DEF( FT_ULong ) |
432 FT_Stream_GetULongLE( FT_Stream stream ) | 434 FT_Stream_GetULongLE( FT_Stream stream ) |
433 { | 435 { |
434 FT_Byte* p; | 436 FT_Byte* p; |
435 FT_Long result; | 437 FT_ULong result; |
436 | 438 |
437 | 439 |
438 FT_ASSERT( stream && stream->cursor ); | 440 FT_ASSERT( stream && stream->cursor ); |
439 | 441 |
440 result = 0; | 442 result = 0; |
441 p = stream->cursor; | 443 p = stream->cursor; |
442 if ( p + 3 < stream->limit ) | 444 if ( p + 3 < stream->limit ) |
443 result = FT_NEXT_ULONG_LE( p ); | 445 result = FT_NEXT_ULONG_LE( p ); |
444 stream->cursor = p; | 446 stream->cursor = p; |
445 return result; | 447 return result; |
(...skipping 18 matching lines...) Expand all Loading... |
464 } | 466 } |
465 else | 467 else |
466 { | 468 { |
467 if ( stream->pos < stream->size ) | 469 if ( stream->pos < stream->size ) |
468 result = stream->base[stream->pos]; | 470 result = stream->base[stream->pos]; |
469 else | 471 else |
470 goto Fail; | 472 goto Fail; |
471 } | 473 } |
472 stream->pos++; | 474 stream->pos++; |
473 | 475 |
474 return result; | 476 return (FT_Char)result; |
475 | 477 |
476 Fail: | 478 Fail: |
477 *error = FT_THROW( Invalid_Stream_Operation ); | 479 *error = FT_THROW( Invalid_Stream_Operation ); |
478 FT_ERROR(( "FT_Stream_ReadChar:" | 480 FT_ERROR(( "FT_Stream_ReadChar:" |
479 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 481 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
480 stream->pos, stream->size )); | 482 stream->pos, stream->size )); |
481 | 483 |
482 return 0; | 484 return 0; |
483 } | 485 } |
484 | 486 |
485 | 487 |
486 FT_BASE_DEF( FT_UShort ) | 488 FT_BASE_DEF( FT_UShort ) |
487 FT_Stream_ReadUShort( FT_Stream stream, | 489 FT_Stream_ReadUShort( FT_Stream stream, |
488 FT_Error* error ) | 490 FT_Error* error ) |
489 { | 491 { |
490 FT_Byte reads[2]; | 492 FT_Byte reads[2]; |
491 FT_Byte* p = 0; | 493 FT_Byte* p = 0; |
492 FT_Short result = 0; | 494 FT_UShort result = 0; |
493 | 495 |
494 | 496 |
495 FT_ASSERT( stream ); | 497 FT_ASSERT( stream ); |
496 | 498 |
497 *error = FT_Err_Ok; | 499 *error = FT_Err_Ok; |
498 | 500 |
499 if ( stream->pos + 1 < stream->size ) | 501 if ( stream->pos + 1 < stream->size ) |
500 { | 502 { |
501 if ( stream->read ) | 503 if ( stream->read ) |
502 { | 504 { |
503 if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) | 505 if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) |
504 goto Fail; | 506 goto Fail; |
505 | 507 |
506 p = reads; | 508 p = reads; |
507 } | 509 } |
508 else | 510 else |
509 { | |
510 p = stream->base + stream->pos; | 511 p = stream->base + stream->pos; |
511 } | |
512 | 512 |
513 if ( p ) | 513 if ( p ) |
514 result = FT_NEXT_USHORT( p ); | 514 result = FT_NEXT_USHORT( p ); |
515 } | 515 } |
516 else | 516 else |
517 goto Fail; | 517 goto Fail; |
518 | 518 |
519 stream->pos += 2; | 519 stream->pos += 2; |
520 | 520 |
521 return result; | 521 return result; |
522 | 522 |
523 Fail: | 523 Fail: |
524 *error = FT_THROW( Invalid_Stream_Operation ); | 524 *error = FT_THROW( Invalid_Stream_Operation ); |
525 FT_ERROR(( "FT_Stream_ReadUShort:" | 525 FT_ERROR(( "FT_Stream_ReadUShort:" |
526 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 526 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
527 stream->pos, stream->size )); | 527 stream->pos, stream->size )); |
528 | 528 |
529 return 0; | 529 return 0; |
530 } | 530 } |
531 | 531 |
532 | 532 |
533 FT_BASE_DEF( FT_UShort ) | 533 FT_BASE_DEF( FT_UShort ) |
534 FT_Stream_ReadUShortLE( FT_Stream stream, | 534 FT_Stream_ReadUShortLE( FT_Stream stream, |
535 FT_Error* error ) | 535 FT_Error* error ) |
536 { | 536 { |
537 FT_Byte reads[2]; | 537 FT_Byte reads[2]; |
538 FT_Byte* p = 0; | 538 FT_Byte* p = 0; |
539 FT_Short result = 0; | 539 FT_UShort result = 0; |
540 | 540 |
541 | 541 |
542 FT_ASSERT( stream ); | 542 FT_ASSERT( stream ); |
543 | 543 |
544 *error = FT_Err_Ok; | 544 *error = FT_Err_Ok; |
545 | 545 |
546 if ( stream->pos + 1 < stream->size ) | 546 if ( stream->pos + 1 < stream->size ) |
547 { | 547 { |
548 if ( stream->read ) | 548 if ( stream->read ) |
549 { | 549 { |
550 if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) | 550 if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) |
551 goto Fail; | 551 goto Fail; |
552 | 552 |
553 p = reads; | 553 p = reads; |
554 } | 554 } |
555 else | 555 else |
556 { | |
557 p = stream->base + stream->pos; | 556 p = stream->base + stream->pos; |
558 } | |
559 | 557 |
560 if ( p ) | 558 if ( p ) |
561 result = FT_NEXT_USHORT_LE( p ); | 559 result = FT_NEXT_USHORT_LE( p ); |
562 } | 560 } |
563 else | 561 else |
564 goto Fail; | 562 goto Fail; |
565 | 563 |
566 stream->pos += 2; | 564 stream->pos += 2; |
567 | 565 |
568 return result; | 566 return result; |
569 | 567 |
570 Fail: | 568 Fail: |
571 *error = FT_THROW( Invalid_Stream_Operation ); | 569 *error = FT_THROW( Invalid_Stream_Operation ); |
572 FT_ERROR(( "FT_Stream_ReadUShortLE:" | 570 FT_ERROR(( "FT_Stream_ReadUShortLE:" |
573 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 571 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
574 stream->pos, stream->size )); | 572 stream->pos, stream->size )); |
575 | 573 |
576 return 0; | 574 return 0; |
577 } | 575 } |
578 | 576 |
579 | 577 |
580 FT_BASE_DEF( FT_ULong ) | 578 FT_BASE_DEF( FT_ULong ) |
581 FT_Stream_ReadUOffset( FT_Stream stream, | 579 FT_Stream_ReadUOffset( FT_Stream stream, |
582 FT_Error* error ) | 580 FT_Error* error ) |
583 { | 581 { |
584 FT_Byte reads[3]; | 582 FT_Byte reads[3]; |
585 FT_Byte* p = 0; | 583 FT_Byte* p = 0; |
586 FT_Long result = 0; | 584 FT_ULong result = 0; |
587 | 585 |
588 | 586 |
589 FT_ASSERT( stream ); | 587 FT_ASSERT( stream ); |
590 | 588 |
591 *error = FT_Err_Ok; | 589 *error = FT_Err_Ok; |
592 | 590 |
593 if ( stream->pos + 2 < stream->size ) | 591 if ( stream->pos + 2 < stream->size ) |
594 { | 592 { |
595 if ( stream->read ) | 593 if ( stream->read ) |
596 { | 594 { |
597 if (stream->read( stream, stream->pos, reads, 3L ) != 3L ) | 595 if (stream->read( stream, stream->pos, reads, 3L ) != 3L ) |
598 goto Fail; | 596 goto Fail; |
599 | 597 |
600 p = reads; | 598 p = reads; |
601 } | 599 } |
602 else | 600 else |
603 { | |
604 p = stream->base + stream->pos; | 601 p = stream->base + stream->pos; |
605 } | |
606 | 602 |
607 if ( p ) | 603 if ( p ) |
608 result = FT_NEXT_UOFF3( p ); | 604 result = FT_NEXT_UOFF3( p ); |
609 } | 605 } |
610 else | 606 else |
611 goto Fail; | 607 goto Fail; |
612 | 608 |
613 stream->pos += 3; | 609 stream->pos += 3; |
614 | 610 |
615 return result; | 611 return result; |
616 | 612 |
617 Fail: | 613 Fail: |
618 *error = FT_THROW( Invalid_Stream_Operation ); | 614 *error = FT_THROW( Invalid_Stream_Operation ); |
619 FT_ERROR(( "FT_Stream_ReadUOffset:" | 615 FT_ERROR(( "FT_Stream_ReadUOffset:" |
620 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 616 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
621 stream->pos, stream->size )); | 617 stream->pos, stream->size )); |
622 | 618 |
623 return 0; | 619 return 0; |
624 } | 620 } |
625 | 621 |
626 | 622 |
627 FT_BASE_DEF( FT_ULong ) | 623 FT_BASE_DEF( FT_ULong ) |
628 FT_Stream_ReadULong( FT_Stream stream, | 624 FT_Stream_ReadULong( FT_Stream stream, |
629 FT_Error* error ) | 625 FT_Error* error ) |
630 { | 626 { |
631 FT_Byte reads[4]; | 627 FT_Byte reads[4]; |
632 FT_Byte* p = 0; | 628 FT_Byte* p = 0; |
633 FT_Long result = 0; | 629 FT_ULong result = 0; |
634 | 630 |
635 | 631 |
636 FT_ASSERT( stream ); | 632 FT_ASSERT( stream ); |
637 | 633 |
638 *error = FT_Err_Ok; | 634 *error = FT_Err_Ok; |
639 | 635 |
640 if ( stream->pos + 3 < stream->size ) | 636 if ( stream->pos + 3 < stream->size ) |
641 { | 637 { |
642 if ( stream->read ) | 638 if ( stream->read ) |
643 { | 639 { |
644 if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) | 640 if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) |
645 goto Fail; | 641 goto Fail; |
646 | 642 |
647 p = reads; | 643 p = reads; |
648 } | 644 } |
649 else | 645 else |
650 { | |
651 p = stream->base + stream->pos; | 646 p = stream->base + stream->pos; |
652 } | |
653 | 647 |
654 if ( p ) | 648 if ( p ) |
655 result = FT_NEXT_ULONG( p ); | 649 result = FT_NEXT_ULONG( p ); |
656 } | 650 } |
657 else | 651 else |
658 goto Fail; | 652 goto Fail; |
659 | 653 |
660 stream->pos += 4; | 654 stream->pos += 4; |
661 | 655 |
662 return result; | 656 return result; |
663 | 657 |
664 Fail: | 658 Fail: |
665 *error = FT_THROW( Invalid_Stream_Operation ); | 659 *error = FT_THROW( Invalid_Stream_Operation ); |
666 FT_ERROR(( "FT_Stream_ReadULong:" | 660 FT_ERROR(( "FT_Stream_ReadULong:" |
667 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 661 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
668 stream->pos, stream->size )); | 662 stream->pos, stream->size )); |
669 | 663 |
670 return 0; | 664 return 0; |
671 } | 665 } |
672 | 666 |
673 | 667 |
674 FT_BASE_DEF( FT_ULong ) | 668 FT_BASE_DEF( FT_ULong ) |
675 FT_Stream_ReadULongLE( FT_Stream stream, | 669 FT_Stream_ReadULongLE( FT_Stream stream, |
676 FT_Error* error ) | 670 FT_Error* error ) |
677 { | 671 { |
678 FT_Byte reads[4]; | 672 FT_Byte reads[4]; |
679 FT_Byte* p = 0; | 673 FT_Byte* p = 0; |
680 FT_Long result = 0; | 674 FT_ULong result = 0; |
681 | 675 |
682 | 676 |
683 FT_ASSERT( stream ); | 677 FT_ASSERT( stream ); |
684 | 678 |
685 *error = FT_Err_Ok; | 679 *error = FT_Err_Ok; |
686 | 680 |
687 if ( stream->pos + 3 < stream->size ) | 681 if ( stream->pos + 3 < stream->size ) |
688 { | 682 { |
689 if ( stream->read ) | 683 if ( stream->read ) |
690 { | 684 { |
691 if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) | 685 if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) |
692 goto Fail; | 686 goto Fail; |
693 | 687 |
694 p = reads; | 688 p = reads; |
695 } | 689 } |
696 else | 690 else |
697 { | |
698 p = stream->base + stream->pos; | 691 p = stream->base + stream->pos; |
699 } | |
700 | 692 |
701 if ( p ) | 693 if ( p ) |
702 result = FT_NEXT_ULONG_LE( p ); | 694 result = FT_NEXT_ULONG_LE( p ); |
703 } | 695 } |
704 else | 696 else |
705 goto Fail; | 697 goto Fail; |
706 | 698 |
707 stream->pos += 4; | 699 stream->pos += 4; |
708 | 700 |
709 return result; | 701 return result; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 Exit: | 851 Exit: |
860 /* close the frame if it was opened by this read */ | 852 /* close the frame if it was opened by this read */ |
861 if ( frame_accessed ) | 853 if ( frame_accessed ) |
862 FT_Stream_ExitFrame( stream ); | 854 FT_Stream_ExitFrame( stream ); |
863 | 855 |
864 return error; | 856 return error; |
865 } | 857 } |
866 | 858 |
867 | 859 |
868 /* END */ | 860 /* END */ |
OLD | NEW |