VirtualBox

Changeset 33057 in vbox


Ignore:
Timestamp:
Oct 12, 2010 12:10:14 PM (14 years ago)
Author:
vboxsync
Message:

Runtime: add a manifest memory writer

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/manifest.h

    r30079 r33057  
    105105                                   PFNRTPROGRESS pfnProgressCallback, void *pvUser);
    106106
     107/**
     108 * Creates a manifest file in memory for a set of files. The manifest file
     109 * contains SHA1 sums of every provided file and could be used to verify the
     110 * data integrity of them.
     111 *
     112 * @returns iprt status code.
     113 *
     114 * @param   ppvBuf               Pointer to resulting memory buffer.
     115 * @param   pcbSize              Pointer for the size of the memory buffer.
     116 * @param   papszFileNames       Array of file names.
     117 * @param   papszFileDigests     Array of file digests.
     118 * @param   cFiles               Number of entries in papszFileNames and papszFileDigests.
     119 */
     120RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, const char * const *papszFileNames, const char * const *papszFileDigests, size_t cFiles);
     121
    107122/** @} */
    108123
  • trunk/src/VBox/Runtime/common/checksum/manifest.cpp

    r32568 r33057  
    328328}
    329329
     330RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, const char * const *papszFileNames, const char * const *papszFileDigests, size_t cFiles)
     331{
     332    /* Validate input */
     333    AssertPtrReturn(ppvBuf, VERR_INVALID_POINTER);
     334    AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
     335    AssertPtrReturn(papszFileNames, VERR_INVALID_POINTER);
     336    AssertPtrReturn(papszFileDigests, VERR_INVALID_POINTER);
     337    AssertReturn(cFiles > 0, VERR_INVALID_PARAMETER);
     338
     339    /* Calculate the size necessary for the memory buffer. */
     340    size_t cbSize = 0;
     341    size_t cbMaxSize = 0;
     342    for (size_t i = 0; i < cFiles; ++i)
     343    {
     344        size_t cbTmp = strlen(RTPathFilename(papszFileNames[i])) + strlen(papszFileDigests[i]) + 10;
     345        cbMaxSize = RT_MAX(cbMaxSize, cbTmp);
     346        cbSize += cbTmp;
     347    }
     348
     349    /* Create the memory buffer */
     350    void *pvBuf = RTMemAlloc(cbSize);
     351    if (!pvBuf)
     352        return VERR_NO_MEMORY;
     353
     354    /* Allocate a temporary string buffer. */
     355    char * pszTmp = RTStrAlloc(cbMaxSize + 1);
     356    size_t cbPos = 0;
     357    for (size_t i = 0; i < cFiles; ++i)
     358    {
     359        size_t cch = RTStrPrintf(pszTmp, cbMaxSize + 1, "SHA1 (%s)= %s\n", RTPathFilename(papszFileNames[i]), papszFileDigests[i]);
     360        memcpy(&((char*)pvBuf)[cbPos], pszTmp, cch);
     361        cbPos += cch;
     362    }
     363    RTStrFree(pszTmp);
     364
     365    /* Results */
     366    *ppvBuf = pvBuf;
     367    *pcbSize = cbSize;
     368
     369    return VINF_SUCCESS;
     370}
     371
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