VirtualBox

Changeset 99960 in vbox for trunk/include/iprt


Ignore:
Timestamp:
May 24, 2023 9:55:50 PM (23 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157620
Message:

IPRT/sg: Corrected RTSgBufIsAtEnd and made the code deal with (skip) empty segments. Added a testcase (incomplete).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/sg.h

    r99739 r99960  
    176176DECLINLINE(bool) RTSgBufIsAtEnd(PCRTSGBUF pSgBuf)
    177177{
    178     return pSgBuf->idxSeg > pSgBuf->cSegs
    179         || (   pSgBuf->idxSeg == pSgBuf->cSegs
    180             && pSgBuf->cbSegLeft == 0);
     178    return pSgBuf->idxSeg >= pSgBuf->cSegs
     179        || (   pSgBuf->cbSegLeft == 0  /* sg.cpp doesn't create this situation, but just in case someone does. */
     180            && pSgBuf->idxSeg + 1 == pSgBuf->cSegs);
    181181}
    182182
     
    200200 * @param   cSegs     Number of segments in the array.
    201201 *
    202  * @note paSegs and cSegs can be NULL and 0 respectively to indicate an empty
    203  *       S/G buffer.  Operations on the S/G buffer will not do anything in this
    204  *       case.
     202 * @note    paSegs and cSegs can be NULL and 0 respectively to indicate an empty
     203 *          S/G buffer.  Operations on the S/G buffer will not do anything in
     204 *          this case.
    205205 */
    206206RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, size_t cSegs);
     
    215215/**
    216216 * Clones a given S/G buffer.
    217  *
     217 * 
     218 * This is only a shallow copy.  Both S/G buffers will point to the same segment
     219 * array.
     220 * 
     221 * The buffer position will be preserved.
     222 * 
    218223 * @param   pSgBufNew    The new S/G buffer to clone to.
    219224 * @param   pSgBufOld    The source S/G buffer to clone from.
    220  *
    221  * @note This is only a shallow copy. Both S/G buffers will point to the
    222  *       same segment array.
    223225 */
    224226RTDECL(void) RTSgBufClone(PRTSGBUF pSgBufNew, PCRTSGBUF pSgBufOld);
     
    257259 *                       is smaller than the amount of bytes requested.
    258260 *
    259  * @note This operation advances the internal buffer pointer of both S/G buffers.
     261 * @note    This operation advances the internal buffer pointer of both S/G buffers.
    260262 */
    261263RTDECL(void *) RTSgBufGetNextSegment(PRTSGBUF pSgBuf, size_t *pcbSeg);
     
    269271 * @param   cbCopy       Number of bytes to copy.
    270272 *
    271  * @note This operation advances the internal buffer pointer of both S/G buffers.
     273 * @note    This operation advances the internal buffer pointer of both S/G buffers.
    272274 */
    273275RTDECL(size_t) RTSgBufCopy(PRTSGBUF pSgBufDst, PRTSGBUF pSgBufSrc, size_t cbCopy);
     
    281283 * @param   cbCmp        How many bytes to compare.
    282284 *
    283  * @note This operation doesn't change the internal position of the S/G buffers.
     285 * @note    This operation doesn't change the internal position of the S/G buffers.
    284286 */
    285287RTDECL(int) RTSgBufCmp(PCRTSGBUF pSgBuf1, PCRTSGBUF pSgBuf2, size_t cbCmp);
     
    306308 *          Can be less than than cbSet if the end of the S/G buffer was reached.
    307309 * @param   pSgBuf       The S/G buffer.
    308  * @param   ubFill       The byte to fill the buffer with.
    309  * @param   cbSet        How many bytes to set.
    310  *
    311  * @note This operation advances the internal buffer pointer of the S/G buffer.
    312  */
    313 RTDECL(size_t) RTSgBufSet(PRTSGBUF pSgBuf, uint8_t ubFill, size_t cbSet);
     310 * @param   bFill        The byte to fill the buffer with.
     311 * @param   cbToSet      How many bytes to set.
     312 *
     313 * @note    This operation advances the internal buffer pointer of the S/G buffer.
     314 */
     315RTDECL(size_t) RTSgBufSet(PRTSGBUF pSgBuf, uint8_t bFill, size_t cbToSet);
    314316
    315317/**
     
    321323 * @param   cbCopy       How many bytes to copy.
    322324 *
    323  * @note This operation advances the internal buffer pointer of the S/G buffer.
     325 * @note    This operation advances the internal buffer pointer of the S/G buffer.
    324326 */
    325327RTDECL(size_t) RTSgBufCopyToBuf(PRTSGBUF pSgBuf, void *pvBuf, size_t cbCopy);
     
    333335 * @param   cbCopy       How many bytes to copy.
    334336 *
    335  * @note This operation advances the internal buffer pointer of the S/G buffer.
     337 * @note    This operation advances the internal buffer pointer of the S/G buffer.
    336338 */
    337339RTDECL(size_t) RTSgBufCopyFromBuf(PRTSGBUF pSgBuf, const void *pvBuf, size_t cbCopy);
     
    346348 * @param   pvUser       Opaque user data to pass in the given callback.
    347349 *
    348  * @note This operation advances the internal buffer pointer of the S/G buffer.
     350 * @note    This operation advances the internal buffer pointer of the S/G buffer.
    349351 */
    350352RTDECL(size_t) RTSgBufCopyToFn(PRTSGBUF pSgBuf, size_t cbCopy, PFNRTSGBUFCOPYTO pfnCopyTo, void *pvUser);
     
    359361 * @param   pvUser       Opaque user data to pass in the given callback.
    360362 *
    361  * @note This operation advances the internal buffer pointer of the S/G buffer.
     363 * @note    This operation advances the internal buffer pointer of the S/G buffer.
    362364 */
    363365RTDECL(size_t) RTSgBufCopyFromFn(PRTSGBUF pSgBuf, size_t cbCopy, PFNRTSGBUFCOPYFROM pfnCopyFrom, void *pvUser);
     
    392394 * Returns whether the given S/G buffer is zeroed out from the current position
    393395 * upto the number of bytes to check.
    394  *
    395  * @returns true if the buffer has only zeros
    396  *          false otherwise.
     396 * 
     397 * @retval true if the buffer has only zeros
     398 * @retval  false otherwise.
    397399 * @param   pSgBuf      The S/G buffer.
    398  * @param   cbCheck     Number of bytes to check.
     400 * @param   cbCheck     Number of bytes to check.
     401 * 
     402 * @note    This operation advances the internal buffer pointer of the S/G buffer.
    399403 */
    400404RTDECL(bool) RTSgBufIsZero(PRTSGBUF pSgBuf, size_t cbCheck);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette