- Timestamp:
- Oct 12, 2010 12:10:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/manifest.cpp
r32568 r33057 328 328 } 329 329 330 RTR3DECL(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.