Changeset 20667af in mainline
- Timestamp:
- 2020-11-21T19:56:45Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68698ba
- Parents:
- 06d0c81
- git-author:
- Jiri Svoboda <jiri@…> (2020-11-21 19:25:27)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-11-21 19:56:45)
- Location:
- uspace/lib/riff
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/riff/include/types/riff/chunk.h
r06d0c81 r20667af 54 54 typedef struct { 55 55 FILE *f; 56 /** Current file position */ 57 long pos; 56 58 } riffr_t; 57 59 -
uspace/lib/riff/src/chunk.c
r06d0c81 r20667af 213 213 } 214 214 215 rr->pos = 0; 216 215 217 rr->f = fopen(fname, "rb"); 216 218 if (rr->f == NULL) { … … 302 304 { 303 305 errno_t rc; 304 long pos;305 306 pos = ftell(parent->riffr->f);307 if (pos < 0) {308 rc = EIO;309 goto error;310 }311 306 312 307 rchunk->riffr = parent->riffr; 313 rchunk->ckstart = p os + 8;308 rchunk->ckstart = parent->riffr->pos + 8; 314 309 rc = riff_read_uint32(parent, &rchunk->ckid); 315 310 if (rc != EOK) … … 402 397 errno_t riff_rchunk_seek(riff_rchunk_t *rchunk, long offset, int whence) 403 398 { 404 long pos;405 399 long dest; 406 400 int rv; … … 414 408 break; 415 409 case SEEK_CUR: 416 pos = ftell(rchunk->riffr->f); 417 if (pos < 0) 418 return EIO; 419 dest = pos + offset; 410 dest = rchunk->riffr->pos + offset; 420 411 break; 421 412 default: … … 432 423 return EIO; 433 424 425 rchunk->riffr->pos = dest; 434 426 return EOK; 435 427 } … … 482 474 { 483 475 long ckend; 476 uint8_t byte; 477 size_t nread; 478 errno_t rc; 484 479 485 480 ckend = riff_rchunk_get_ndpos(rchunk); 486 if (fseek(rchunk->riffr->f, ckend, SEEK_SET) < 0) 487 return EIO; 481 if (rchunk->riffr->pos < ckend && 482 ckend <= rchunk->riffr->pos + 512) { 483 /* (Buffered) reading is faster than seeking */ 484 while (rchunk->riffr->pos < ckend) { 485 rc = riff_read(rchunk, &byte, sizeof(byte), &nread); 486 if (rc != EOK) 487 return rc; 488 489 if (nread != sizeof(byte)) 490 return EIO; 491 } 492 493 } else if (rchunk->riffr->pos != ckend) { 494 /* Need to seek (backwards or too far) */ 495 if (fseek(rchunk->riffr->f, ckend, SEEK_SET) < 0) 496 return EIO; 497 rchunk->riffr->pos = ckend; 498 } 488 499 489 500 return EOK; … … 511 522 long toread; 512 523 513 pos = ftell(rchunk->riffr->f); 514 if (pos < 0) 515 return EIO; 524 pos = rchunk->riffr->pos; 516 525 517 526 ckend = riff_rchunk_get_end(rchunk); … … 529 538 return EIO; 530 539 540 rchunk->riffr->pos += *nread; 531 541 return EOK; 532 542 }
Note:
See TracChangeset
for help on using the changeset viewer.