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

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

WIN* DARWIN and OS2 removal.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/* $Id: kHlpBareAssert.c 3582 2007-09-02 22:26:42Z 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
38#elif K_OS == K_OS_WINDOWS
39# include <Windows.h>
40
41#else
42# error "port me"
43#endif
44
45
46/**
47 * Writes a assert string with unix lineendings.
48 *
49 * @param pszMsg The string.
50 */
51static void kHlpAssertWrite(const char *pszMsg)
52{
53#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
54 /*
55 * Line by line.
56 */
57 ULONG cbWritten;
58 const char *pszNl = kHlpStrChr(pszMsg, '\n');
59 while (pszNl)
60 {
61 cbWritten = pszNl - pszMsg;
62
63#if K_OS == K_OS_OS2
64 if (cbWritten)
65 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
66 DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
67#else /* K_OS == K_OS_WINDOWS */
68 if (cbWritten)
69 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
70 WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
71#endif
72
73 /* next */
74 pszMsg = pszNl + 1;
75 pszNl = kHlpStrChr(pszMsg, '\n');
76 }
77
78 /*
79 * Remaining incomplete line.
80 */
81 if (*pszMsg)
82 {
83 cbWritten = kHlpStrLen(pszMsg);
84#if K_OS == K_OS_OS2
85 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
86#else /* K_OS == K_OS_WINDOWS */
87 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
88#endif
89 }
90
91#else
92# error "port me"
93#endif
94}
95
96
97KHLP_DECL(void) kHlpAssertMsg1(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction)
98{
99 char szLine[16];
100
101 kHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: ");
102 kHlpAssertWrite(pszExpr);
103 kHlpAssertWrite("\nAt: ");
104 kHlpAssertWrite(pszFile);
105 kHlpAssertWrite("(");
106 kHlpAssertWrite(kHlpInt2Ascii(szLine, sizeof(szLine), iLine, 10));
107 kHlpAssertWrite(") ");
108 kHlpAssertWrite(pszFunction);
109 kHlpAssertWrite("\n");
110}
111
112
113KHLP_DECL(void) kHlpAssertMsg2(const char *pszFormat, ...)
114{
115 kHlpAssertWrite(pszFormat);
116}
117
Note: See TracBrowser for help on using the repository browser.