sg.cpp revision 4bd3e7685494afe7c303fc131c66e685023b6b4a
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * IPRT - S/G buffer handling.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2010 Oracle Corporation
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * available from http://www.virtualbox.org. This file is free software;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * you can redistribute it and/or modify it under the terms of the GNU
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * General Public License (GPL) as published by the Free Software
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * The contents of this file may alternatively be used under the terms
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * of the Common Development and Distribution License Version 1.0
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * VirtualBox OSE distribution, in which case the provisions of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * CDDL are applicable instead of those of the GPL.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * You may elect to license modified versions of this file under the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * terms and conditions of either the GPL or the CDDL or both.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/*******************************************************************************
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync* Header Files *
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync*******************************************************************************/
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncstatic void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync size_t cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft);
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync /* Advance to the next segment if required. */
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync pSgBuf->pvSegCur = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync pSgBuf->cbSegLeft = pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync pSgBuf->pvSegCur = (uint8_t *)pSgBuf->pvSegCur + cbData;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsyncRTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, unsigned cSegs)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(void) RTSgBufClone(PRTSGBUF pSgBufTo, PCRTSGBUF pSgBufFrom)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufCopy(PRTSGBUF pSgBufDst, PRTSGBUF pSgBufSrc, size_t cbCopy)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync size_t cbThisCopy = RT_MIN(RT_MIN(pSgBufDst->cbSegLeft, cbLeft), pSgBufSrc->cbSegLeft);
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(int) RTSgBufCmp(PCRTSGBUF pSgBuf1, PCRTSGBUF pSgBuf2, size_t cbCmp)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync /* Set up the temporary buffers */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync size_t cbThisCmp = RT_MIN(RT_MIN(SgBuf1.cbSegLeft, cbLeft), SgBuf2.cbSegLeft);
018872730d2bb228577f818371b9b3d513168a74vboxsyncRTDECL(int) RTSgBufCmpEx(PRTSGBUF pSgBuf1, PRTSGBUF pSgBuf2, size_t cbCmp,
018872730d2bb228577f818371b9b3d513168a74vboxsync /* Set up the temporary buffers */
018872730d2bb228577f818371b9b3d513168a74vboxsync size_t cbThisCmp = RT_MIN(RT_MIN(pSgBuf1Tmp->cbSegLeft, cbLeft), pSgBuf2Tmp->cbSegLeft);
018872730d2bb228577f818371b9b3d513168a74vboxsync /* Search for the correct offset */
018872730d2bb228577f818371b9b3d513168a74vboxsync while ( cbThisCmp-- > 0
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufSet(PRTSGBUF pSgBuf, uint8_t ubFill, size_t cbSet)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufCopyToBuf(PRTSGBUF pSgBuf, void *pvBuf, size_t cbCopy)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufCopyFromBuf(PRTSGBUF pSgBuf, void *pvBuf, size_t cbCopy)
c1e15b3c98815ead93f67b8eb8b116189497cfb4vboxsyncRTDECL(size_t) RTSgBufAdvance(PRTSGBUF pSgBuf, size_t cbAdvance)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufSegArrayCreate(PRTSGBUF pSgBuf, PRTSGSEG paSeg, unsigned *pcSeg, size_t cbData)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync unsigned cSeg = 0;