source: trunk/kLdr/testcase/tstDllMain.c@ 2878

Last change on this file since 2878 was 2878, checked in by bird, 19 years ago

Keywords.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/* $Id: tstDllMain.c 2878 2006-11-12 12:41:15Z bird $ */
2/** @file
3 *
4 * kLdr testcase.
5 *
6 * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
7 *
8 *
9 * This file is part of kLdr.
10 *
11 * kLdr is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * kLdr 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
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with kLdr; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "tst.h"
32
33#ifdef __OS2__
34# define INCL_BASE
35# include <os2.h>
36# include <string.h>
37
38#elif defined(__WIN__)
39# include <windows.h>
40# include <string.h>
41
42#else
43# error "port me"
44#endif
45
46/*******************************************************************************
47* Internal Functions *
48*******************************************************************************/
49static void tstWrite(const char *psz);
50
51
52
53#ifdef __OS2__
54/**
55 * OS/2 DLL 'main'
56 */
57ULONG _System _DLL_InitTerm(HMODULE hmod, ULONG fFlag)
58{
59 switch (fFlags)
60 {
61 case 0:
62 tstWrite("init: ");
63 tstWrite(g_pszName);
64 tstWrite("\n");
65 return TRUE;
66
67 case 1:
68 tstWrite("term: ");
69 tstWrite(g_pszName);
70 tstWrite("\n");
71 return TRUE;
72
73 default:
74 tstWrite("!invalid!: ");
75 tstWrite(g_pszName);
76 tstWrite("\n");
77 return FALSE;
78 }
79}
80
81#elif defined(__WIN__)
82
83/**
84 * OS/2 DLL 'main'
85 */
86BOOL __stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
87{
88 switch (dwReason)
89 {
90 case DLL_PROCESS_ATTACH:
91 tstWrite("init: ");
92 tstWrite(g_pszName);
93 tstWrite("\n");
94 return TRUE;
95
96 case DLL_PROCESS_DETACH:
97 tstWrite("term: ");
98 tstWrite(g_pszName);
99 tstWrite("\n");
100 return TRUE;
101
102 case DLL_THREAD_ATTACH:
103 tstWrite("thread init: ");
104 tstWrite(g_pszName);
105 tstWrite("\n");
106 return TRUE;
107
108 case DLL_THREAD_DETACH:
109 tstWrite("thread term: ");
110 tstWrite(g_pszName);
111 tstWrite("\n");
112 return TRUE;
113
114 default:
115 tstWrite("!invalid!: ");
116 tstWrite(g_pszName);
117 tstWrite("\n");
118 return FALSE;
119 }
120}
121
122#else
123# error "port me"
124#endif
125
126
127/**
128 * Writes a string with unix lineendings.
129 *
130 * @param pszMsg The string.
131 */
132static void tstWrite(const char *pszMsg)
133{
134#if defined(__OS2__) || defined(__WIN__)
135 /*
136 * Line by line.
137 */
138 ULONG cbWritten;
139 const char *pszNl = strchr(pszMsg, '\n');
140
141 while (pszNl)
142 {
143 cbWritten = pszNl - pszMsg;
144
145#ifdef __OS2__
146 if (cbWritten)
147 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
148 DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
149#else /* __WIN32__ */
150 if (cbWritten)
151 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
152 WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
153#endif
154
155 /* next */
156 pszMsg = pszNl + 1;
157 pszNl = strchr(pszMsg, '\n');
158 }
159
160 /*
161 * Remaining incomplete line.
162 */
163 if (*pszMsg)
164 {
165 cbWritten = strlen(pszMsg);
166#ifdef __OS2__
167 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
168#else /* __WIN32__ */
169 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
170#endif
171 }
172
173#else
174# error "port me"
175#endif
176}
177
178
Note: See TracBrowser for help on using the repository browser.