VirtualBox

Ignore:
Timestamp:
May 25, 2021 11:09:36 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144607
Message:

Runtime/sg.h: Add copy variants which take a callback instead of a buffer to do the actual copying for single segments, bugref:4841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/sg.cpp

    r82968 r89264  
    347347
    348348
     349RTDECL(size_t) RTSgBufCopyToFn(PRTSGBUF pSgBuf, size_t cbCopy, PFNRTSGBUFCOPYTO pfnCopyTo, void *pvUser)
     350{
     351    AssertPtrReturn(pSgBuf, 0);
     352    AssertPtrReturn(pfnCopyTo, 0);
     353
     354    size_t cbLeft = cbCopy;
     355
     356    while (cbLeft)
     357    {
     358        size_t cbThisCopy = cbLeft;
     359        void *pvSrc = rtSgBufGet(pSgBuf, &cbThisCopy);
     360
     361        if (!cbThisCopy)
     362            break;
     363
     364        size_t cbThisCopied = pfnCopyTo(pSgBuf, pvSrc, cbThisCopy, pvUser);
     365        cbLeft -= cbThisCopied;
     366        if (cbThisCopied < cbThisCopy)
     367            break;
     368    }
     369
     370    return cbCopy - cbLeft;
     371}
     372
     373
     374RTDECL(size_t) RTSgBufCopyFromFn(PRTSGBUF pSgBuf, size_t cbCopy, PFNRTSGBUFCOPYFROM pfnCopyFrom, void *pvUser)
     375{
     376    AssertPtrReturn(pSgBuf, 0);
     377    AssertPtrReturn(pfnCopyFrom, 0);
     378
     379    size_t cbLeft = cbCopy;
     380
     381    while (cbLeft)
     382    {
     383        size_t cbThisCopy = cbLeft;
     384        void *pvDst = rtSgBufGet(pSgBuf, &cbThisCopy);
     385
     386        if (!cbThisCopy)
     387            break;
     388
     389        size_t cbThisCopied = pfnCopyFrom(pSgBuf, pvDst, cbThisCopy, pvUser);
     390        cbLeft -= cbThisCopied;
     391        if (cbThisCopied < cbThisCopy)
     392            break;
     393    }
     394
     395    return cbCopy - cbLeft;
     396}
     397
     398
    349399RTDECL(size_t) RTSgBufAdvance(PRTSGBUF pSgBuf, size_t cbAdvance)
    350400{
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