Changeset 2867 for trunk/kLdr/kLdrHlp.c
- Timestamp:
- Nov 11, 2006, 10:33:17 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrHlp.c
r2861 r2867 385 385 * Get an environment variable. 386 386 * 387 * @returns 0 on success, on failure an OS specific status code is returned. 387 * @returns 0 on success. 388 * @returns KLDR_ERR_BUFFER_OVERFLOW on if the buffer is too small (it'll be partially filled). 389 * @returns KLDR_ERR_SYMBOL_NOT_FOUND if not found. (Yeah, abusing the status code, but it's only internally...) 390 * @returns OS specfic status code on other error. 388 391 * @param pszVar The variable name. 389 * @param pszVal Where to store the value. NULL is allowed if *pcchVal is 0. 390 * @param pcchVal On input the size of the buffer pointed to by pszVal. 391 * On output this contains the string length on success, while on 392 * failure (including buffer overflow) the require buffer size. 393 * If the variable wasn't found, it's set to 0. 394 */ 395 int kldrHlpGetEnv(const char *pszVar, char *pszVal, size_t *pcchVal) 392 * @param pszVal Where to store the value. 393 * @param cchVal The size of the buffer pointed to by pszVal. 394 */ 395 int kldrHlpGetEnv(const char *pszVar, char *pszVal, size_t cchVal) 396 396 { 397 397 #ifdef __OS2__ 398 398 PSZ pszValue = NULL; 399 int rc = DosScanEnv((PCSZ)pszVar, &pszValue); 399 int rc; 400 401 *pszVal = '\0'; 402 rc = DosScanEnv((PCSZ)pszVar, &pszValue); 400 403 if (!rc) 401 404 { 402 405 size_t cch = kLdrHlpStrLen(pszValue); 403 if (pszVal) 404 { 405 if (*pcchVal > cch) 406 { 407 kLdrHlpMemCopy(pszVal, pszValue, cch + 1); 408 *pcchVal = cch; 409 } 410 else if (*pcchVal) 406 if (cchVal > cch) 407 kLdrHlpMemCopy(pszVal, pszValue, cch + 1); 408 else 409 { 410 rc = KLDR_ERR_BUFFER_OVERFLOW; 411 if (cchVal > 1) 411 412 { 412 413 kLdrHlpMemCopy(pszVal, pszValue, *pcchVal); 413 414 pszVal[*pcchVal - 1] = '\0'; 414 rc = ERROR_BUFFER_OVERFLOW;415 *pcchVal = cch + 1;416 415 } 417 416 } 418 else419 {420 rc = ERROR_BUFFER_OVERFLOW;421 *pcchVal = cch + 1;422 }423 417 } 424 418 else 425 { 426 if (pszVal) 427 *pszVal = '\0'; 428 *pcchVal = 0; 429 } 430 419 rc = KLDR_ERR_SYMBOL_NOT_FOUND; 431 420 return rc; 432 421 433 422 #elif defined(__WIN__) 434 423 DWORD cch; 424 435 425 SetLastError(0); 436 cch = GetEnvironmentVariable(pszVar, pszVal, *pcchVal); 437 if (cch) 438 { 439 *pcchVal = cch; 426 cch = GetEnvironmentVariable(pszVar, pszVal, cchVal); 427 if (cch < cchVal) 440 428 return 0; 441 } 442 if (!GetLastError() == ERROR_ENVVAR_NOT_FOUND) 443 { 444 *pcchVal = 0; 445 return ERROR_ENVVAR_NOT_FOUND; 446 } 447 *pcchVal = cch; 448 return ERROR_BUFFER_OVERFLOW; 429 430 *pszVal = '\0'; 431 if (cch >= cchVal) 432 return KLDR_ERR_BUFFER_OVERFLOW; 433 if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) 434 return KLDR_ERR_SYMBOL_NOT_FOUND; 435 return GetLastError(); 449 436 450 437 #else … … 458 445 * 459 446 * @returns 0 and *pcb on success. 460 * Some non-zero OS or kLdr status code on failure.447 * @returns On failure see kldrHlpGetEnv. 461 448 * @param pszVar The name of the variable. 462 449 * @param pcb Where to put the value. … … 472 459 473 460 *pcb = 0; 474 rc = kldrHlpGetEnv(pszVar, szVal, &cchVal);461 rc = kldrHlpGetEnv(pszVar, szVal, cchVal); 475 462 if (rc) 476 463 return rc; … … 602 589 603 590 591 /** 592 * Checks if this is only a filename or if it contains any kind 593 * of drive, directory, or server specs. 594 * 595 * @returns 1 if this is a filename only. 596 * @returns 0 of it's isn't only a filename. 597 * @param pszFilename The filename to parse. 598 */ 599 int kldrHlpIsFilenameOnly(const char *pszFilename) 600 { 601 const char *pszLast = NULL; 602 for (;;) 603 { 604 const char ch = *pszFilename++; 605 #if defined(__OS2__) || defined(__WIN__) 606 if (ch == '/' || ch == '\\' || ch == ':') 607 #else 608 if (ch == '/') 609 #endif 610 return 0; 611 if (!ch) 612 return 1; 613 } 614 } 615 604 616 605 617 /**
Note:
See TracChangeset
for help on using the changeset viewer.