MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / BFD_read

Function BFD_read

src/SB/Core/x/xbinio.cpp:495–575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495static S32 BFD_read(void* data, S32 elesize, S32 elecnt, tag_xFile* bffp, void* xtradata)
496{
497 st_BINIO_XTRADATA* xtra = (st_BINIO_XTRADATA*)xtradata;
498 char* dest = (char*)data;
499 S32 readbeg;
500 S32 refill = 0;
501 S32 remain;
502 S32 actual;
503 U32 holdpos;
504 U32 numBytes = 0;
505 U32 safety = 0;
506 S32 r26 = elesize * elecnt;
507
508 if (r26 == 0)
509 {
510 return 0;
511 }
512
513 if (!xtra->dbl_buf || xtra->dblbuf_size < 1 || r26 > xtra->dblbuf_size)
514 {
515 iFileSeek(bffp, xtra->fpos, IFILE_SEEK_SET);
516 numBytes = iFileRead(bffp, dest, r26);
517
518 xtra->fpos += numBytes;
519 }
520 else
521 {
522 remain = r26;
523
524 while (true)
525 {
526 if (xtra->fpos < xtra->dbl_beg)
527 {
528 refill = 1;
529
530 xtra->dbl_beg = xtra->fpos - (xtra->fpos % xtra->dblbuf_size);
531 xtra->dbl_end = xtra->dbl_beg + xtra->dblbuf_size;
532 xtra->dbl_amt = 0;
533 }
534 else if (xtra->fpos >= xtra->dbl_end)
535 {
536 refill = 1;
537
538 xtra->dbl_beg = xtra->fpos - (xtra->fpos % xtra->dblbuf_size);
539 xtra->dbl_end = xtra->dbl_beg + xtra->dblbuf_size;
540 xtra->dbl_amt = 0;
541 }
542
543 if (refill)
544 {
545 holdpos = xtra->fpos;
546
547 iFileSeek(bffp, xtra->dbl_beg, IFILE_SEEK_SET);
548
549 xtra->fpos = holdpos;
550 xtra->dbl_amt = iFileRead(bffp, xtra->dbl_buf, xtra->dblbuf_size);
551 }
552

Callers 1

ReadRawFunction · 0.70

Calls 3

memcpyFunction · 0.85
iFileSeekFunction · 0.50
iFileReadFunction · 0.50

Tested by

no test coverage detected