Changeset 1a8fe67a in rtems for cpukit/libmisc/untar/untar.c
- Timestamp:
- Jul 13, 2016, 7:22:35 AM (5 years ago)
- Branches:
- 5, master
- Children:
- 6a174c02
- Parents:
- c1b815ab
- git-author:
- Alexander Krutwig <alexander.krutwig@…> (07/13/16 07:22:35)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (07/26/16 08:00:04)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libmisc/untar/untar.c
rc1b815ab r1a8fe67a 37 37 #include <rtems/untar.h> 38 38 #include <rtems/bspIo.h> 39 40 39 41 40 /* … … 542 541 } 543 542 543 544 void Untar_ChunkContext_Init(Untar_ChunkContext *context) 545 { 546 context->state = UNTAR_CHUNK_HEADER; 547 context->done_bytes = 0; 548 context->out_fd = -1; 549 } 550 551 int Untar_FromChunk_Print( 552 Untar_ChunkContext *context, 553 void *chunk, 554 size_t chunk_size, 555 const rtems_printer* printer 556 ) 557 { 558 char *buf; 559 size_t done; 560 size_t todo; 561 size_t remaining; 562 size_t consume; 563 int retval; 564 unsigned char linkflag; 565 566 buf = chunk; 567 done = 0; 568 todo = chunk_size; 569 570 while (todo > 0) { 571 switch (context->state) { 572 case UNTAR_CHUNK_HEADER: 573 remaining = 512 - context->done_bytes; 574 consume = MIN(remaining, todo); 575 memcpy(&context->header[context->done_bytes], &buf[done], consume); 576 context->done_bytes += consume; 577 578 if (context->done_bytes == 512) { 579 retval = Untar_ProcessHeader( 580 &context->header[0], 581 &context->fname[0], 582 &context->todo_bytes, 583 &context->todo_blocks, 584 &linkflag, 585 printer 586 ); 587 588 if (retval != UNTAR_SUCCESSFUL) { 589 context->state = UNTAR_CHUNK_ERROR; 590 return retval; 591 } 592 593 if (linkflag == REGTYPE) { 594 context->out_fd = creat(&context->fname[0], 0644); 595 596 if (context->out_fd >= 0) { 597 context->state = UNTAR_CHUNK_WRITE; 598 context->done_bytes = 0; 599 } else { 600 context->state = UNTAR_CHUNK_SKIP; 601 context->todo_bytes = 512 * context->todo_blocks; 602 context->done_bytes = 0; 603 } 604 } else { 605 context->done_bytes = 0; 606 } 607 } 608 609 break; 610 case UNTAR_CHUNK_SKIP: 611 remaining = context->todo_bytes - context->done_bytes; 612 consume = MIN(remaining, todo); 613 context->done_bytes += consume; 614 615 if (context->done_bytes == context->todo_bytes) { 616 context->state = UNTAR_CHUNK_HEADER; 617 context->done_bytes = 0; 618 } 619 620 break; 621 case UNTAR_CHUNK_WRITE: 622 remaining = context->todo_bytes - context->done_bytes; 623 consume = MIN(remaining, todo); 624 write(context->out_fd, &buf[done], consume); 625 context->done_bytes += consume; 626 627 if (context->done_bytes == context->todo_bytes) { 628 close(context->out_fd); 629 context->out_fd = -1; 630 context->state = UNTAR_CHUNK_SKIP; 631 context->todo_bytes = 512 * context->todo_blocks - context->todo_bytes; 632 context->done_bytes = 0; 633 } 634 635 break; 636 default: 637 return UNTAR_FAIL; 638 } 639 640 done += consume; 641 todo -= consume; 642 } 643 644 return UNTAR_SUCCESSFUL; 645 } 646 544 647 /* 545 648 * Function: Untar_FromFile
Note: See TracChangeset
for help on using the changeset viewer.