VirtualBox

Changeset 68183 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jul 31, 2017 8:25:25 AM (7 years ago)
Author:
vboxsync
Message:

IPRT: Added new RTFileReadAll* flag RTFILE_RDALL_F_TRAILING_ZERO_BYTE for simplify reading in text files and treating the result as a zero terminated string.

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/fs/isomaker.cpp

    r68147 r68183  
    3838#include <iprt/err.h>
    3939#include <iprt/ctype.h>
     40#include <iprt/md5.h>
    4041#include <iprt/file.h>
    4142#include <iprt/list.h>
     
    4647#include <iprt/vfs.h>
    4748#include <iprt/vfslowlevel.h>
     49#include <iprt/zero.h>
    4850#include <iprt/formats/iso9660.h>
    4951
     
    51075109    }
    51085110
     5111#if 0 /* this doesn't quite fool it. */
     5112    /*
     5113     * isomd5sum fake.
     5114     */
     5115    if (1)
     5116    {
     5117        uint8_t      abDigest[RTMD5_HASH_SIZE];
     5118        if (pThis->cbSysArea == 0)
     5119            RTMd5(g_abRTZero4K, ISO9660_SECTOR_SIZE, abDigest);
     5120        else
     5121        {
     5122            RTMD5CONTEXT Ctx;
     5123            RTMd5Init(&Ctx);
     5124            RTMd5Update(&Ctx, pThis->pbSysArea, RT_MIN(pThis->cbSysArea, ISO9660_SECTOR_SIZE));
     5125            if (pThis->cbSysArea < ISO9660_SECTOR_SIZE)
     5126                RTMd5Update(&Ctx, g_abRTZero4K, ISO9660_SECTOR_SIZE - pThis->cbSysArea);
     5127            RTMd5Final(abDigest, &Ctx);
     5128        }
     5129        char szFakeHash[RTMD5_DIGEST_LEN + 1];
     5130        RTMd5ToString(abDigest, szFakeHash, sizeof(szFakeHash));
     5131
     5132        size_t cch = RTStrPrintf((char *)&pPrimary->abAppUse[0], sizeof(pPrimary->abAppUse),
     5133                                 "ISO MD5SUM = %s;SKIPSECTORS = %u;RHLISOSTATUS=1;THIS IS JUST A FAKE!",
     5134                                 szFakeHash, pThis->cbFinalizedImage / RTFSISOMAKER_SECTOR_SIZE - 1);
     5135        memset(&pPrimary->abAppUse[cch], ' ', sizeof(pPrimary->abAppUse) - cch);
     5136    }
     5137#endif
     5138
    51095139    return VINF_SUCCESS;
    51105140}
  • trunk/src/VBox/Runtime/generic/RTFileReadAllByHandleEx-generic.cpp

    r62477 r68183  
    6565                 * Try allocate the required memory and initialize the header (hardcoded fun).
    6666                 */
    67                 void *pvHdr = RTMemAlloc(cbAllocMem + 32);
     67                void *pvHdr = RTMemAlloc(cbAllocMem + 32 + (fFlags & RTFILE_RDALL_F_TRAILING_ZERO_BYTE ? 1 : 0));
    6868                if (pvHdr)
    6969                {
     
    8181                        if (RT_SUCCESS(rc))
    8282                        {
     83                            if (fFlags & RTFILE_RDALL_F_TRAILING_ZERO_BYTE)
     84                                ((uint8_t *)pvFile)[cbAllocFile] = '\0';
     85
    8386                            /*
    8487                             * Success - fill in the return values.
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