----------------------------------------------------------------------------- Read from a file. The number of bytes to read is passed in size, the data is returned in src. The number of bytes read is available in bytesRead if a non-Null pointer is provided. -----------------------------------------------------------------------------
| 703 | // provided. |
| 704 | //----------------------------------------------------------------------------- |
| 705 | File::Status File::read(U32 size, char *dst, U32 *bytesRead) |
| 706 | { |
| 707 | #ifdef DEBUG |
| 708 | // fprintf(stdout,"reading %d bytes\n",size);fflush(stdout); |
| 709 | #endif |
| 710 | AssertFatal(Closed != currentStatus, "File::read: file closed"); |
| 711 | AssertFatal(NULL != handle, "File::read: invalid file handle"); |
| 712 | AssertFatal(NULL != dst, "File::read: NULL destination pointer"); |
| 713 | AssertFatal(true == hasCapability(FileRead), "File::read: file lacks capability"); |
| 714 | AssertWarn(0 != size, "File::read: size of zero"); |
| 715 | |
| 716 | /* show stats for this file */ |
| 717 | #ifdef DEBUG |
| 718 | //struct stat st; |
| 719 | //fstat(*((int *)handle), &st); |
| 720 | //fprintf(stdout,"file size = %d\n", st.st_size); |
| 721 | #endif |
| 722 | /****************************/ |
| 723 | |
| 724 | if (Ok != currentStatus || 0 == size) |
| 725 | return currentStatus; |
| 726 | else |
| 727 | { |
| 728 | long lastBytes; |
| 729 | long *bytes = (NULL == bytesRead) ? &lastBytes : (long *)bytesRead; |
| 730 | if ( (*((U32 *)bytes) = x86UNIXRead(*((int *)handle), dst, size)) == -1) |
| 731 | { |
| 732 | #ifdef DEBUG |
| 733 | // fprintf(stdout,"unsuccessful: %d\n", *((U32 *)bytes));fflush(stdout); |
| 734 | #endif |
| 735 | return setStatus(); // unsuccessful |
| 736 | } else { |
| 737 | // dst[*((U32 *)bytes)] = '\0'; |
| 738 | if (*((U32 *)bytes) != size || *((U32 *)bytes) == 0) { |
| 739 | #ifdef DEBUG |
| 740 | // fprintf(stdout,"end of stream: %d\n", *((U32 *)bytes));fflush(stdout); |
| 741 | #endif |
| 742 | return currentStatus = EOS; // end of stream |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | // dst[*bytesRead] = '\0'; |
| 747 | #ifdef DEBUG |
| 748 | //fprintf(stdout, "We read:\n"); |
| 749 | //fprintf(stdout, "====================================================\n"); |
| 750 | //fprintf(stdout, "%s\n",dst); |
| 751 | //fprintf(stdout, "====================================================\n"); |
| 752 | //fprintf(stdout,"read ok: %d\n", *bytesRead);fflush(stdout); |
| 753 | #endif |
| 754 | return currentStatus = Ok; // successfully read size bytes |
| 755 | } |
| 756 | |
| 757 | //----------------------------------------------------------------------------- |
| 758 | // Write to a file. |
no test coverage detected