| 666 | } |
| 667 | |
| 668 | int ply_close(p_ply ply) { |
| 669 | long i; |
| 670 | assert(ply && ply->fp); |
| 671 | assert(ply->element || ply->nelements == 0); |
| 672 | assert(!ply->element || ply->nelements > 0); |
| 673 | /* write last chunk to file */ |
| 674 | if (ply->io_mode == PLY_WRITE && |
| 675 | fwrite(ply->buffer, 1, ply->buffer_last, ply->fp) < ply->buffer_last) { |
| 676 | ply_ferror(ply, "Error closing up"); |
| 677 | return 0; |
| 678 | } |
| 679 | fclose(ply->fp); |
| 680 | /* free all memory used by handle */ |
| 681 | if (ply->element) { |
| 682 | for (i = 0; i < ply->nelements; i++) { |
| 683 | p_ply_element element = &ply->element[i]; |
| 684 | if (element->property) free(element->property); |
| 685 | } |
| 686 | free(ply->element); |
| 687 | } |
| 688 | if (ply->obj_info) free(ply->obj_info); |
| 689 | if (ply->comment) free(ply->comment); |
| 690 | free(ply); |
| 691 | return 1; |
| 692 | } |
| 693 | |
| 694 | /* ---------------------------------------------------------------------- |
| 695 | * Query support functions |
no test coverage detected