2
Vote

jxrlib uses size_t to represent file offset

description

As per interface design we have:
struct WMPStream
{
[...]
    ERR (*SetPos)(struct WMPStream* me, size_t offPos);
    ERR (*GetPos)(struct WMPStream* me, size_t* poffPos);
};
Which means that on some system size_t could be 32bits, but the underlying file I/O implementation is 64bits. Since the Set/GetPos API expect absolute position as per:
ERR ReadContainer(
    PKImageDecode* pID)
[...]
    Call(pWS->GetPos(pWS, &offPos));
    FailIf(0 != offPos, WMP_errUnsupportedFormat);
It is potentially difficult to implement proper decoding for those systems.

BTW the default implementation uses the 32bits API:

ERR SetPosWS_File(struct WMPStream* pWS, size_t offPos)
{
    ERR err = WMP_errSuccess;

    FailIf(0 != fseek(pWS->state.file.pFile, (long)offPos, SEEK_SET),
WMP_errFileIO);

Cleanup:
    return err;
}

ERR GetPosWS_File(struct WMPStream* pWS, size_t* poffPos)
{
    ERR err = WMP_errSuccess;
    long lOff = 0;

    FailIf(-1 == (lOff = ftell(pWS->state.file.pFile)), WMP_errFileIO);
    *poffPos = (size_t)lOff;

Cleanup:
    return err;
}

comments