Changeset ea459d4 in mainline for uspace/lib/riff/src/chunk.c


Ignore:
Timestamp:
2020-09-24T14:25:21Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
120031a5
Parents:
aaf962e6
git-author:
Jiri Svoboda <jiri@…> (2020-09-22 17:25:10)
git-committer:
Jiri Svoboda <jiri@…> (2020-09-24 14:25:21)
Message:

Reading typeface from TPF file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/riff/src/chunk.c

    raaf962e6 rea459d4  
    393393}
    394394
     395/** Seek to position in chunk.
     396 *
     397 * @param rchunk RIFF chunk
     398 * @param offset Offset
     399 * @param whence SEEK_SET, SEEK_CUR or SEEK_END
     400 * @return EOK on success or an error code
     401 */
     402errno_t riff_rchunk_seek(riff_rchunk_t *rchunk, long offset, int whence)
     403{
     404        long pos;
     405        long dest;
     406        int rv;
     407
     408        switch (whence) {
     409        case SEEK_SET:
     410                dest = rchunk->ckstart + offset;
     411                break;
     412        case SEEK_END:
     413                dest = rchunk->ckstart + rchunk->cksize + offset;
     414                break;
     415        case SEEK_CUR:
     416                pos = ftell(rchunk->riffr->f);
     417                if (pos < 0)
     418                        return EIO;
     419                dest = pos + offset;
     420                break;
     421        default:
     422                return EINVAL;
     423        }
     424
     425        if (dest < rchunk->ckstart || dest > rchunk->ckstart + rchunk->cksize)
     426                return ELIMIT;
     427
     428        rv = fseek(rchunk->riffr->f, dest, SEEK_SET);
     429        if (rv < 0)
     430                return EIO;
     431
     432        return EOK;
     433}
     434
    395435/** Return chunk data size.
    396436 *
     
    431471/** Finish reading RIFF chunk.
    432472 *
    433  * Seek to the first byte after end of chunk.
     473 * Seek to the first byte after end of chunk. It is allowed, though,
     474 * to return to the chunk later, e.g. using riff_rchunk_seek(@a rchunk, ..).
    434475 *
    435476 * @param rchunk Chunk structure
     
    444485                return EIO;
    445486
    446         rchunk->riffr = NULL;
    447487        return EOK;
    448488}
Note: See TracChangeset for help on using the changeset viewer.