Changeset 2984 in kBuild
- Timestamp:
- Nov 1, 2016 6:24:11 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/md5sum.c
r2414 r2984 300 300 int cb; 301 301 int rc = 0; 302 char abBuf[32*1024];303 302 struct MD5Context Ctx; 304 303 unsigned uPercent = 0; 305 double cbFile = 0.0;306 304 double off = 0.0; 307 308 if (fProgress) 309 { 310 cbFile = size_file(pvFile); 311 if (cbFile < 1024*1024) 312 fProgress = 0; 313 } 305 double cbFile = size_file(pvFile); 306 307 /* Get a decent sized buffer assuming we'll be spending more time reading 308 from the storage than doing MD5 sums. (2MB was choosen based on recent 309 SATA storage benchmarks which used that block size for sequential 310 tests.) We align the buffer address on a 16K boundrary to avoid most 311 transfer alignment issues. */ 312 char *pabBufAligned; 313 size_t const cbBufAlign = 16*1024 - 1; 314 size_t const cbBufMax = 2048*1024; 315 size_t cbBuf = cbFile >= cbBufMax ? cbBufMax : ((size_t)cbFile + cbBufAlign) & ~(size_t)cbBufAlign; 316 char *pabBuf = (char *)malloc(cbBuf + cbBufAlign); 317 if (pabBuf) 318 pabBufAligned = (char *)(((uintptr_t)pabBuf + cbBufAlign) & ~(uintptr_t)cbBufAlign ); 319 else 320 { 321 do 322 { 323 cbBuf /= 2; 324 pabBuf = (char *)malloc(cbBuf); 325 } while (!pabBuf && cbBuf > 4096); 326 if (!pabBuf) 327 return ENOMEM; 328 pabBufAligned = pabBuf; 329 } 330 331 if (cbFile < cbBuf * 4) 332 fProgress = 0; 314 333 315 334 MD5Init(&Ctx); … … 317 336 { 318 337 /* process a chunk. */ 319 cb = read_file(pvFile, abBuf, sizeof(abBuf));338 cb = read_file(pvFile, pabBufAligned, cbBuf); 320 339 if (cb > 0) 321 MD5Update(&Ctx, (unsigned char *) &abBuf[0], cb);340 MD5Update(&Ctx, (unsigned char *)pabBufAligned, cb); 322 341 else if (!cb) 323 342 break; … … 349 368 printf("\b\b\b\b \b\b\b\b"); 350 369 370 free(pabBuf); 351 371 return rc; 352 372 } … … 572 592 573 593 /* 574 * Calcu ate and print the MD5 sum for one file.594 * Calculate and print the MD5 sum for one file. 575 595 */ 576 596 pvFile = open_file(pszFilename, fText);
Note:
See TracChangeset
for help on using the changeset viewer.