MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / read

Method read

engine/source/platformAndroid/AndroidFileio.cpp:543–611  ·  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

541// provided.
542//-----------------------------------------------------------------------------
543File::Status File::read(U32 _size, char *dst, U32 *bytesRead)
544{
545 if (handle != NULL)
546 {
547 AssertFatal(Closed != currentStatus, "File::read: file closed");
548 AssertFatal(handle != NULL, "File::read: invalid file handle");
549 AssertFatal(NULL != dst, "File::read: NULL destination pointer");
550 AssertFatal(true == hasCapability(FileRead), "File::read: file lacks capability");
551 AssertWarn(0 != size, "File::read: size of zero");
552
553 if (Ok != currentStatus || 0 == size)
554 return currentStatus;
555
556 // read from stream
557 U32 nBytes = fread(dst, 1, size, (FILE*)handle);
558
559 // did we hit the end of the stream?
560 if( nBytes != size)
561 currentStatus = EOS;
562
563 // if bytesRead is a valid pointer, send number of bytes read there.
564 if(bytesRead)
565 *bytesRead = nBytes;
566
567 // successfully read size bytes
568 return currentStatus;
569 }
570
571 AssertFatal(Closed != currentStatus, "File::read: file closed");
572 AssertFatal(buffer != NULL, "File::read: invalid file buffer");
573 AssertFatal(NULL != dst, "File::read: NULL destination pointer");
574 AssertFatal(true == hasCapability(FileRead), "File::read: file lacks capability");
575 AssertWarn(0 != size, "File::read: size of zero");
576
577 if (Ok != currentStatus || 0 == size)
578 return currentStatus;
579
580 // read from stream
581 U32 nBytes = 0;
582
583 if ((size-filePointer) > (_size))
584 {
585 memcpy(dst, buffer+filePointer, _size);
586 nBytes = _size;
587 }
588 else if (size-filePointer <= 0)
589 {
590 nBytes = 0;
591 }
592 else
593 {
594 memcpy(dst, buffer+filePointer, size-filePointer);
595 nBytes = size-filePointer;
596 }
597
598 //Advanced the pointer
599 filePointer += nBytes;
600

Callers 1

_AndroidGetTxtFileArgsFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected