Changeset 2846 for trunk/kLdr/kLdrHlp.c
- Timestamp:
- Nov 1, 2006, 7:26:35 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrHlp.c
r2842 r2846 456 456 457 457 /** 458 * Gets an environment variable and converts it to a size_t. 459 * 460 * @returns 0 and *pcb on success. 461 * Some non-zero OS or kLdr status code on failure. 462 * @param pszVar The name of the variable. 463 * @param pcb Where to put the value. 464 */ 465 int kldrHlpGetEnvUZ(const char *pszVar, size_t *pcb) 466 { 467 size_t cb; 468 unsigned uBase; 469 char szVal[64]; 470 size_t cchVal = sizeof(szVal); 471 const char *psz; 472 int rc; 473 474 *pcb = 0; 475 rc = kldrHlpGetEnv(pszVar, szVal, &cchVal); 476 if (rc) 477 return rc; 478 479 /* figure out the base. */ 480 uBase = 10; 481 psz = szVal; 482 if ( *psz == '0' 483 && (psz[1] == 'x' || psz[1] == 'X')) 484 { 485 uBase = 16; 486 psz += 2; 487 } 488 489 /* convert it up to the first unknown char. */ 490 cb = 0; 491 for(;;) 492 { 493 const char ch = *psz; 494 unsigned uDigit; 495 if (!ch) 496 break; 497 else if (ch >= '0' && ch <= '9') 498 uDigit = ch - '0'; 499 else if (ch >= 'a' && ch <= 'z') 500 uDigit = ch - 'a' + 10; 501 else if (ch >= 'A' && ch <= 'Z') 502 uDigit = ch - 'A' + 10; 503 else 504 break; 505 if (uDigit >= uBase) 506 break; 507 508 /* add the digit */ 509 cb *= uBase; 510 cb += uDigit; 511 512 psz++; 513 } 514 515 /* check for unit */ 516 if (*psz == 'm' || *psz == 'M') 517 cb *= 1024*1024; 518 else if (*psz == 'k' ||*psz == 'K') 519 cb *= 1024; 520 else if (*psz == 'g' || *psz == 'G') 521 cb *= 1024*1024*1024; 522 523 *pcb = cb; 524 return 0; 525 } 526 527 528 /** 458 529 * Terminate the process. 459 530 *
Note:
See TracChangeset
for help on using the changeset viewer.