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

Function cf_ReadString

cfile/cfile.cpp:721–743  ·  view source on GitHub ↗

Reads a string from a CFILE. If the file is type binary, this function reads until a NULL or EOF is found. If the file is text, the function reads until a newline or EOF is found. The string is always written to the destination buffer null-terminated, without the newline. Parameters: buf - where the string is written n - the maximum string length, including the terminating 0 cfp - the CFILE po

Source from the content-addressed store, hash-verified

719// Returns the number of bytes in the string, before the terminator
720// Does not generate an exception on EOF
721int cf_ReadString(char *buf, size_t n, CFILE *cfp) {
722 int c;
723 int count;
724 char *bp;
725 if (n == 0)
726 return -1;
727 bp = buf;
728 for (count = 0;; count++) {
729 c = cfgetc(cfp);
730 if (c == EOF) {
731 if (!cfeof(cfp)) // not actually at EOF, so must be error
732 ThrowCFileError(CFE_READING, cfp, strerror(errno));
733 break;
734 }
735
736 if ((!(cfp->flags & CFF_TEXT) && (c == 0)) || ((cfp->flags & CFF_TEXT) && (c == '\n')))
737 break; // end-of-string
738 if (count < n - 1) // store char if room in buffer
739 *bp++ = c;
740 }
741 *bp = 0; // write terminator
742 return count;
743}
744// Writes the specified number of bytes from a file into the buffer
745// DO NOT USE THIS TO WRITE STRUCTURES. This function is for byte
746// data, such as a string or a bitmap of 8-bit pixels.

Callers 15

mng_ReadNewShipPageFunction · 0.85
mng_ReadShipPageFunction · 0.85
mng_ReadNewSoundPageFunction · 0.85
mng_ReadNewGamefilePageFunction · 0.85
mng_ReadGamefilePageFunction · 0.85
mng_CheckIfLockerPresentFunction · 0.85
mng_CompileAddonPagesFunction · 0.85
mng_ReadMegacellPageFunction · 0.85
mng_ReadNewMegacellPageFunction · 0.85
mng_ReadNewGenericPageFunction · 0.85
mng_ReadGenericPageFunction · 0.85
mng_ReadNewDoorPageFunction · 0.85

Calls 3

cfgetcFunction · 0.85
cfeofFunction · 0.85
ThrowCFileErrorFunction · 0.85

Tested by 1

TESTFunction · 0.68