MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / read

Method read

Engine/source/platformPOSIX/POSIXFileio.cpp:729–779  ·  view source on GitHub ↗

----------------------------------------------------------------------------- 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. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

727// provided.
728//-----------------------------------------------------------------------------
729File::FileStatus File::read(U32 size, char *dst, U32 *bytesRead)
730{
731#ifdef DEBUG
732 // fprintf(stdout,"reading %d bytes\n",size);fflush(stdout);
733#endif
734 AssertFatal(Closed != currentStatus, "File::read: file closed");
735 AssertFatal(NULL != handle, "File::read: invalid file handle");
736 AssertFatal(NULL != dst, "File::read: NULL destination pointer");
737 AssertFatal(true == hasCapability(FileRead), "File::read: file lacks capability");
738 AssertWarn(0 != size, "File::read: size of zero");
739
740 /* show stats for this file */
741#ifdef DEBUG
742 //struct stat st;
743 //fstat(*((int *)handle), &st);
744 //fprintf(stdout,"file size = %d\n", st.st_size);
745#endif
746 /****************************/
747
748 if (Ok != currentStatus || 0 == size)
749 return currentStatus;
750 else
751 {
752 long lastBytes;
753 long *bytes = (NULL == bytesRead) ? &lastBytes : (long *)bytesRead;
754 if ( (*((U32 *)bytes) = x86UNIXRead(*((int *)handle), dst, size)) == -1)
755 {
756#ifdef DEBUG
757 // fprintf(stdout,"unsuccessful: %d\n", *((U32 *)bytes));fflush(stdout);
758#endif
759 return setStatus(); // unsuccessful
760 } else {
761 // dst[*((U32 *)bytes)] = '\0';
762 if (*((U32 *)bytes) != size || *((U32 *)bytes) == 0) {
763#ifdef DEBUG
764 // fprintf(stdout,"end of stream: %d\n", *((U32 *)bytes));fflush(stdout);
765#endif
766 return currentStatus = EOS; // end of stream
767 }
768 }
769 }
770 // dst[*bytesRead] = '\0';
771#ifdef DEBUG
772 //fprintf(stdout, "We read:\n");
773 //fprintf(stdout, "====================================================\n");
774 //fprintf(stdout, "%s\n",dst);
775 //fprintf(stdout, "====================================================\n");
776 //fprintf(stdout,"read ok: %d\n", *bytesRead);fflush(stdout);
777#endif
778 return currentStatus = Ok; // successfully read size bytes
779}
780
781//-----------------------------------------------------------------------------
782// Write to a file.

Callers

nothing calls this directly

Calls 1

x86UNIXReadFunction · 0.85

Tested by

no test coverage detected