Changeset 2832 for trunk/kLdr/kLdrHlp.c
- Timestamp:
- Oct 25, 2006, 12:26:01 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrHlp.c
r2831 r2832 507 507 508 508 /** 509 * Writes a assert string with unix lineendings. 510 * 511 * @param pszMsg The string. 512 */ 513 static void kldrHlpAssertWrite(const char *pszMsg) 514 { 515 #if defined(__OS2__) || defined(__WIN__) 516 /* 517 * Line by line. 518 */ 519 ULONG cbWritten; 520 const char *pszNl = kLdrHlpStrChr(pszMsg, '\n'); 521 while (pszNl || *pszMsg) 522 { 523 cbWritten = pszNl - pszMsg; 524 525 #ifdef __OS2__ 526 if (cbWritten) 527 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten); 528 DosWrite((HFILE)2, "\r\n", 2, &cbWritten); 529 #else /* __WIN32__ */ 530 if (cbWritten) 531 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL); 532 WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL); 533 #endif 534 535 /* next */ 536 pszMsg = pszNl + 1; 537 pszNl = kLdrHlpStrChr(pszMsg, '\n'); 538 } 539 540 /* 541 * Remaining incomplete line. 542 */ 543 if (*pszMsg) 544 { 545 cbWritten = kLdrHlpStrLen(pszMsg); 546 #ifdef __OS2__ 547 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten); 548 #else /* __WIN32__ */ 549 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL); 550 #endif 551 } 552 553 #else 554 # error "port me" 555 #endif 556 } 557 558 559 /** 509 560 * Internal worker for the kLdrHlpAssert() macro. 510 561 * … … 516 567 void kldrHlpAssertMsg(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction) 517 568 { 518 #ifdef __OS2__ 519 static const char s_szMsg1[] = "\r\n!!!kLdr Assertion Failed!!!\n\rExpression: "; 520 static const char s_szMsg2[] = "\r\nAt: "; 521 static const char s_szMsg3[] = "\r\n"; 522 ULONG cbWritten; 523 char szLine[16]; 524 525 DosWrite((HFILE)2, s_szMsg1, sizeof(s_szMsg1) - 1, &cbWritten); 526 DosWrite((HFILE)2, pszExpr, kLdrHlpStrLen(pszExpr), &cbWritten); 527 DosWrite((HFILE)2, s_szMsg2, sizeof(s_szMsg2) - 1, &cbWritten); 528 DosWrite((HFILE)2, pszFile, kLdrHlpStrLen(pszFile), &cbWritten); 529 DosWrite((HFILE)2, "(", sizeof("(") - 1, &cbWritten); 569 char szLine[16]; 570 571 kldrHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: "); 572 kldrHlpAssertWrite(pszExpr); 573 kldrHlpAssertWrite("\nAt: "); 574 kldrHlpAssertWrite(pszFile); 575 kldrHlpAssertWrite("("); 530 576 int2dec(szLine, iLine); 531 DosWrite((HFILE)2, szLine, kLdrHlpStrLen(szLine), &cbWritten); 532 DosWrite((HFILE)2, ") ", sizeof(") ") - 1, &cbWritten); 533 DosWrite((HFILE)2, pszFunction, kLdrHlpStrLen(pszFunction), &cbWritten); 534 DosWrite((HFILE)2, s_szMsg3, sizeof(s_szMsg3) - 1, &cbWritten); 535 536 #elif defined(__WIN__) 537 static const char s_szMsg1[] = "\r\n!!!kLdr Assertion Failed!!!\n\rExpression: "; 538 static const char s_szMsg2[] = "\r\nAt: "; 539 static const char s_szMsg3[] = "\r\n"; 540 DWORD cbWritten; 541 char szLine[16]; 542 const HANDLE hStdErr = (HANDLE)STD_ERROR_HANDLE; 543 544 WriteFile(hStdErr, s_szMsg1, sizeof(s_szMsg1) - 1, &cbWritten, NULL); 545 WriteFile(hStdErr, pszExpr, kLdrHlpStrLen(pszExpr), &cbWritten, NULL); 546 WriteFile(hStdErr, s_szMsg2, sizeof(s_szMsg2) - 1, &cbWritten, NULL); 547 WriteFile(hStdErr, pszFile, kLdrHlpStrLen(pszFile), &cbWritten, NULL); 548 WriteFile(hStdErr, "(", sizeof("(") - 1, &cbWritten, NULL); 549 int2dec(szLine, iLine); 550 WriteFile(hStdErr, szLine, kLdrHlpStrLen(szLine), &cbWritten, NULL); 551 WriteFile(hStdErr, ") ", sizeof(") ") - 1, &cbWritten, NULL); 552 WriteFile(hStdErr, pszFunction, kLdrHlpStrLen(pszFunction), &cbWritten, NULL); 553 WriteFile(hStdErr, s_szMsg3, sizeof(s_szMsg3) - 1, &cbWritten, NULL); 554 555 #else 556 # error "Port me" 557 #endif 558 } 559 577 kldrHlpAssertWrite(szLine); 578 kldrHlpAssertWrite(") "); 579 kldrHlpAssertWrite(pszFunction); 580 kldrHlpAssertWrite("\n"); 581 } 582 583 584 #ifdef kLdrHlpStrChr_needed 585 char *kLdrHlpStrChr(const char *psz, int ch) 586 { 587 while (*psz) 588 { 589 if (*psz == ch) 590 return (char *)psz; 591 psz++; 592 } 593 return NULL; 594 } 595 #endif 596 597 598 #ifdef kLdrHlpStrChr_needed 599 void *kLdrHlpMemChr(const void *pv, int ch, size_t cb) 600 { 601 const uint8_t *pb = (const uint8_t *)pv; 602 const uint8_t b = (uint8_t)ch; 603 while (cb) 604 { 605 if (*pb == b) 606 return (void *)pb; 607 pb++; 608 } 609 return NULL; 610 } 611 #endif 612
Note:
See TracChangeset
for help on using the changeset viewer.