VirtualBox

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

Last change on this file since 24 was 2, checked in by bird, 17 years ago

Imported http://svn.netlabs.org/repos/libc/trunk/kStuff, revision 3612.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.8 KB
Line 
1/* $Id: kHlpBareAssert.c 2 2007-11-16 16:07:14Z bird $ */
2/** @file
3 * kHlpBare - Assert Backend.
4 */
5
6/*
7 * Copyright (c) 2006-2007 knut st. osmundsen <[email protected]>
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 * In addition to the permissions in the GNU Lesser General Public
17 * License, you are granted unlimited permission to link the compiled
18 * version of this file into combinations with other programs, and to
19 * distribute those combinations without any restriction coming from
20 * the use of this file.
21 *
22 * kStuff is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with kStuff; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 * 02110-1301, USA
31 */
32
33/*******************************************************************************
34* Header Files *
35*******************************************************************************/
36#include <k/kHlpAssert.h>
37#include <k/kHlpString.h>
38
39#if K_OS == K_OS_DARWIN \
40 || K_OS == K_OS_FREEBSD \
41 || K_OS == K_OS_LINUX \
42 || K_OS == K_OS_NETBSD \
43 || K_OS == K_OS_OPENBSD \
44 || K_OS == K_OS_SOLARIS
45# include <k/kHlpSys.h>
46
47#elif K_OS == K_OS_OS2
48# define INCL_BASE
49# define INCL_ERRORS
50# include <os2.h>
51
52#elif K_OS == K_OS_WINDOWS
53# include <Windows.h>
54
55#else
56# error "port me"
57#endif
58
59
60/**
61 * Writes a assert string with unix lineendings.
62 *
63 * @param pszMsg The string.
64 */
65static void kHlpAssertWrite(const char *pszMsg)
66{
67#if K_OS == K_OS_DARWIN \
68 || K_OS == K_OS_FREEBSD \
69 || K_OS == K_OS_LINUX \
70 || K_OS == K_OS_NETBSD \
71 || K_OS == K_OS_OPENBSD \
72 || K_OS == K_OS_SOLARIS
73 KSIZE cchMsg = kHlpStrLen(pszMsg);
74 kHlpSys_write(2 /* stderr */, pszMsg, cchMsg);
75
76#elif K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
77 /*
78 * Line by line.
79 */
80 ULONG cbWritten;
81 const char *pszNl = kHlpStrChr(pszMsg, '\n');
82 while (pszNl)
83 {
84 cbWritten = pszNl - pszMsg;
85
86#if K_OS == K_OS_OS2
87 if (cbWritten)
88 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
89 DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
90#else /* K_OS == K_OS_WINDOWS */
91 if (cbWritten)
92 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
93 WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
94#endif
95
96 /* next */
97 pszMsg = pszNl + 1;
98 pszNl = kHlpStrChr(pszMsg, '\n');
99 }
100
101 /*
102 * Remaining incomplete line.
103 */
104 if (*pszMsg)
105 {
106 cbWritten = kHlpStrLen(pszMsg);
107#if K_OS == K_OS_OS2
108 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
109#else /* K_OS == K_OS_WINDOWS */
110 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
111#endif
112 }
113
114#else
115# error "port me"
116#endif
117}
118
119
120KHLP_DECL(void) kHlpAssertMsg1(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction)
121{
122 char szLine[16];
123
124 kHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: ");
125 kHlpAssertWrite(pszExpr);
126 kHlpAssertWrite("\nAt: ");
127 kHlpAssertWrite(pszFile);
128 kHlpAssertWrite("(");
129 kHlpAssertWrite(kHlpInt2Ascii(szLine, sizeof(szLine), iLine, 10));
130 kHlpAssertWrite(") ");
131 kHlpAssertWrite(pszFunction);
132 kHlpAssertWrite("\n");
133}
134
135
136KHLP_DECL(void) kHlpAssertMsg2(const char *pszFormat, ...)
137{
138 kHlpAssertWrite(pszFormat);
139}
140
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette