~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/common/misc/sg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: sg.cpp $ */
 
1
/* $Id: sg.cpp 31583 2010-08-11 21:34:40Z vboxsync $ */
2
2
/** @file
3
3
 * IPRT - S/G buffer handling.
4
4
 */
341
341
RTDECL(size_t) RTSgBufSegArrayCreate(PRTSGBUF pSgBuf, PRTSGSEG paSeg, unsigned *pcSeg, size_t cbData)
342
342
{
343
343
    AssertPtrReturn(pSgBuf, 0);
344
 
    AssertPtrReturn(paSeg, 0);
345
344
    AssertPtrReturn(pcSeg, 0);
346
345
 
 
346
    unsigned cSeg = 0;
347
347
    size_t   cb = 0;
348
 
    unsigned cSeg = 0;
349
 
 
350
 
    while (   cbData
351
 
           && cSeg < *pcSeg)
352
 
    {
353
 
        size_t  cbThisSeg = cbData;
354
 
        void   *pvSeg     = NULL;
355
 
 
356
 
        pvSeg = sgBufGet(pSgBuf, &cbThisSeg);
357
 
 
358
 
        if (!cbThisSeg)
359
 
        {
360
 
            Assert(!pvSeg);
361
 
            break;
362
 
        }
363
 
 
364
 
        AssertMsg(cbThisSeg <= cbData, ("Impossible!\n"));
365
 
 
366
 
        paSeg[cSeg].cbSeg = cbThisSeg;
367
 
        paSeg[cSeg].pvSeg = pvSeg;
368
 
        cSeg++;
369
 
        cbData -= cbThisSeg;
370
 
        cb     += cbThisSeg;
 
348
 
 
349
    if (!paSeg)
 
350
    {
 
351
        if (pSgBuf->cbSegLeft > 0)
 
352
        {
 
353
            size_t idx = pSgBuf->idxSeg;
 
354
            cSeg = 1;
 
355
 
 
356
            cb     += RT_MIN(pSgBuf->cbSegLeft, cbData);
 
357
            cbData -= RT_MIN(pSgBuf->cbSegLeft, cbData);
 
358
 
 
359
            while (   cbData
 
360
                   && idx < pSgBuf->cSegs - 1)
 
361
            {
 
362
                idx++;
 
363
                cSeg++;
 
364
                cb     += RT_MIN(pSgBuf->paSegs[idx].cbSeg, cbData);
 
365
                cbData -= RT_MIN(pSgBuf->paSegs[idx].cbSeg, cbData);
 
366
            }
 
367
        }
 
368
    }
 
369
    else
 
370
    {
 
371
        while (   cbData
 
372
               && cSeg < *pcSeg)
 
373
        {
 
374
            size_t  cbThisSeg = cbData;
 
375
            void   *pvSeg     = NULL;
 
376
 
 
377
            pvSeg = sgBufGet(pSgBuf, &cbThisSeg);
 
378
 
 
379
            if (!cbThisSeg)
 
380
            {
 
381
                Assert(!pvSeg);
 
382
                break;
 
383
            }
 
384
 
 
385
            AssertMsg(cbThisSeg <= cbData, ("Impossible!\n"));
 
386
 
 
387
            paSeg[cSeg].cbSeg = cbThisSeg;
 
388
            paSeg[cSeg].pvSeg = pvSeg;
 
389
            cSeg++;
 
390
            cbData -= cbThisSeg;
 
391
            cb     += cbThisSeg;
 
392
        }
371
393
    }
372
394
 
373
395
    *pcSeg = cSeg;