MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / cf_ReadBytes

Function cf_ReadBytes

cfile/cfile.cpp:654–670  ·  view source on GitHub ↗

Reads the specified number of bytes from a file into the buffer DO NOT USE THIS TO READ STRUCTURES. This function is for byte data, such as a string or a bitmap of 8-bit pixels. Returns the number of bytes read. Throws an exception of type (cfile_error *) if the OS returns an error on read

Source from the content-addressed store, hash-verified

652// Returns the number of bytes read.
653// Throws an exception of type (cfile_error *) if the OS returns an error on read
654int cf_ReadBytes(uint8_t *buf, int count, CFILE *cfp) {
655 int i;
656 const char *error_msg = eof_error; // default error
657 ASSERT(!(cfp->flags & CFF_TEXT));
658 if (cfp->position + count <= cfp->size) {
659 i = fread(buf, 1, count, cfp->file);
660 if (i == count) {
661 cfp->position += i;
662 return i;
663 }
664 // if not EOF, then get the error message
665 if (!feof(cfp->file))
666 error_msg = strerror(errno);
667 }
668 mprintf(1, "Error reading %d bytes from position %d of file <%s>; errno=%d.", count, cfp->position, cfp->name, errno);
669 return 0;
670}
671// The following functions read numeric vales from a CFILE. All values are
672// stored in the file in Intel (little-endian) format. These functions
673// will convert to big-endian if required.

Callers 15

mng_ReplacePageFunction · 0.85
mng_DeletePageFunction · 0.85
OpenMethod · 0.85
ReadMethod · 0.85
SoundLoadWaveFileFunction · 0.85
ReadNewModelFileFunction · 0.85
LoadGroupFunction · 0.85
cf_ReadIntFunction · 0.85
cf_ReadShortFunction · 0.85
cf_ReadByteFunction · 0.85
cf_ReadFloatFunction · 0.85
cf_ReadDoubleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected