VirtualBox

Changeset 32629 in vbox


Ignore:
Timestamp:
Sep 20, 2010 9:24:01 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
66035
Message:

Runtime: remove the useless secondary temporary memory pointer

File:
1 edited

Legend:

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

    r32602 r32629  
    169169
    170170    *ppvBuf = 0;
    171     void *pvTmp = 0;
    172171    do
    173172    {
     
    181180        }
    182181
    183         /* Allocate a temporary buffer for reading the tar content in blocks. */
    184         size_t cbTmp = 0;
    185         pvTmp = rtTarMemTmpAlloc(&cbTmp);
    186         if (!pvTmp)
    187         {
    188             rc = VERR_NO_MEMORY;
    189             break;
    190         }
    191 
    192182        uint64_t cbAllWritten = 0; /* Already copied */
     183        uint64_t cbToRead = 0; /* What to read in the next step */
    193184        uint64_t cbRead = 0; /* Actually read in the last step */
    194         /* Copy the content from hFile over to the memory. This is done block
    195          * wise in 512 byte aligned steps. After this copying is finished hFile
    196          * will be on a 512 byte boundary, regardless if the file copied is 512
    197          * byte size aligned. */
     185        /* Copy the content from hFile over to the memory. */
    198186        for (;;)
    199187        {
     
    203191            if (cbAllWritten == cbToCopy)
    204192                break;
    205             /* Read one block. This will be 512 aligned in any case. */
    206             cbRead = RT_ALIGN(RT_MIN(cbToCopy - cbAllWritten, cbTmp), sizeof(RTTARRECORD));
    207             rc = RTFileRead(hFile, pvTmp, cbRead, NULL);
     193            /* Try to read all at once */
     194            cbToRead = cbToCopy - cbAllWritten;
     195            rc = RTFileRead(hFile, pcsTmp, cbToRead, &cbRead);
    208196            if (RT_FAILURE(rc))
    209197                break;
    210             /* Check for the last block which has not to be 512 bytes in size. */
    211             if (cbAllWritten + cbRead > cbToCopy)
    212                 cbRead = cbToCopy - cbAllWritten;
    213             /* Write the block */
    214             memcpy(pcsTmp, pvTmp, cbRead);
    215198            /* Count how many bytes are written already */
    216199            cbAllWritten += cbRead;
     
    218201            pcsTmp += cbRead;
    219202        }
     203        int64_t offSeek = RT_ALIGN(cbAllWritten, sizeof(RTTARRECORD)) - cbAllWritten;
     204        /* We have to make sure the file pointer is 512 byte aligned. */
     205        if (   RT_SUCCESS(rc)
     206            && offSeek > 0)
     207        {
     208            rc = RTFileSeek(hFile, offSeek, RTFILE_SEEK_CURRENT, NULL);
     209            if (RT_FAILURE(rc))
     210                break;
     211        }
    220212    }
    221213    while(0);
    222 
    223     if (pvTmp)
    224         RTMemTmpFree(pvTmp);
    225214
    226215    if (   RT_FAILURE(rc)
Note: See TracChangeset for help on using the changeset viewer.

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