source: trunk/kStuff/kHlp/Bare/kHlpBareAssert.c@ 3573

Last change on this file since 3573 was 3573, checked in by bird, 18 years ago

kHlp work...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: kHlpBareAssert.c 3573 2007-08-31 04:09:23Z bird $ */
2/** @file
3 * kHlpBare - Assert Backend.
4 */
5
6/*
7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * This file is part of kStuff.
10 *
11 * kStuff is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * kStuff is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with kStuff; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <k/kHlpAssert.h>
31#include <k/kHlpString.h>
32
33#if K_OS == K_OS_OS2
34# define INCL_BASE
35# define INCL_ERRORS
36# include <os2.h>
37#elif K_OS == K_OS_WINDOWS
38# include <Windows.h>
39#else
40# error "port me"
41#endif
42
43
44/**
45 * Writes a assert string with unix lineendings.
46 *
47 * @param pszMsg The string.
48 */
49static void kHlpAssertWrite(const char *pszMsg)
50{
51#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
52 /*
53 * Line by line.
54 */
55 ULONG cbWritten;
56 const char *pszNl = kHlpStrChr(pszMsg, '\n');
57 while (pszNl)
58 {
59 cbWritten = pszNl - pszMsg;
60
61#if K_OS == K_OS_OS2
62 if (cbWritten)
63 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
64 DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
65#else /* __WIN32__ */
66 if (cbWritten)
67 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
68 WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
69#endif
70
71 /* next */
72 pszMsg = pszNl + 1;
73 pszNl = kHlpStrChr(pszMsg, '\n');
74 }
75
76 /*
77 * Remaining incomplete line.
78 */
79 if (*pszMsg)
80 {
81 cbWritten = kHlpStrLen(pszMsg);
82#if K_OS == K_OS_OS2
83 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
84#else /* __WIN32__ */
85 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
86#endif
87 }
88
89#else
90# error "port me"
91#endif
92}
93
94
95KHLP_DECL(void) kHlpAssertMsg1(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction)
96{
97 char szLine[16];
98
99 kHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: ");
100 kHlpAssertWrite(pszExpr);
101 kHlpAssertWrite("\nAt: ");
102 kHlpAssertWrite(pszFile);
103 kHlpAssertWrite("(");
104 kHlpAssertWrite(kHlpInt2Ascii(szLine, sizeof(szLine), iLine, 10));
105 kHlpAssertWrite(") ");
106 kHlpAssertWrite(pszFunction);
107 kHlpAssertWrite("\n");
108}
109
110
111KHLP_DECL(void) kHlpAssertMsg2(const char *pszFormat, ...)
112{
113 kHlpAssertWrite(pszFormat);
114}
115
Note: See TracBrowser for help on using the repository browser.