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
| 652 | // Returns the number of bytes read. |
| 653 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 654 | int 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. |
no outgoing calls
no test coverage detected