source: trunk/make/testcase/dll-c.c@ 10367

Last change on this file since 10367 was 9063, checked in by bird, 23 years ago

Bugfixes.

File size: 3.9 KB
Line 
1/* $Id: dll-c.c,v 1.2 2002-08-20 21:14:29 bird Exp $
2 *
3 * Test DLL.
4 *
5 * Copyright (c) 2002 knut st. osmundsen (bird@anduin.net)
6 *
7 * GPL
8 *
9 */
10
11/*******************************************************************************
12* Defined Constants And Macros *
13*******************************************************************************/
14#ifdef DEBUG
15#define _STR "\"DEBUG\" "
16#else
17#define _STR ""
18#endif
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#if (defined(__IBMCPP__) || defined(__IBMC__))
25/*
26 * IBM C/C++
27 */
28#define DLLENTRYPOINT_CCONV _System
29#define DLLENTRYPOINT_NAME _DLL_InitTerm
30
31#if (__IBMCPP__ == 300) || (__IBMC__ == 300)
32void _Optlink __ctordtorInit( void );
33#define ctordtorInit() __ctordtorInit()
34
35void _Optlink __ctordtorTerm( void );
36#define ctordtorTerm() __ctordtorTerm()
37
38#elif (__IBMCPP__ >= 360) || (__IBMC__ >= 360)
39void _Optlink __ctordtorInit( int flag );
40#define ctordtorInit() __ctordtorInit(0)
41
42void _Optlink __ctordtorTerm( int flag );
43#define ctordtorTerm() __ctordtorTerm(0)
44
45#else
46#error "Unknown IBM compiler!"
47#endif
48
49int _Optlink _CRT_init(void);
50void _Optlink _CRT_term(void);
51
52
53#elif defined(__WATCOMC__)
54/*
55 * Watcom C
56 */
57#define DLLENTRYPOINT_CCONV _syscall
58#define DLLENTRYPOINT_NAME LibMain
59
60#define ctordtorInit() ((void)0)
61#define ctordtorTerm() ((void)0)
62
63#define _CRT_init() ((void)0)
64#define _CRT_term() ((void)0)
65
66#ifdef __16BIT__
67#define LOADDS _loadds
68#endif
69
70
71#elif defined(_MSC_VER)
72/*
73 * MS C
74 */
75#ifdef __16BIT__
76#define LOADDS _loadds
77#endif
78
79#elif defined(__GNUC__) && defined(__EMX__)
80/*
81 * GCC+EMX
82 */
83#define DLLENTRYPOINT_CCONV _System
84#define DLLENTRYPOINT_NAME _DLL_InitTerm
85
86#define ctordtorInit() ((void)0)
87#define ctordtorTerm() ((void)0)
88
89int _CRT_init(void);
90void _CRT_term(void);
91
92
93#endif /* compilers */
94
95#ifdef __cplusplus
96}
97#endif
98
99
100#ifndef LOADDS
101#ifdef __16BIT__
102#error "16-bit compiles must must define LOADDS!"
103#else
104#define LOADDS
105#endif
106#endif
107
108
109
110/*******************************************************************************
111* Header Files *
112*******************************************************************************/
113#include <stdio.h>
114#include <math.h>
115
116#ifdef OS2
117#include <os2.h>
118#define OSCALL APIENTRY LOADDS
119#endif
120
121/**
122 * Testprogram.
123 * @returns 0 on success.
124 */
125int OSCALL LOADDS FOO42(void)
126{
127 long double lrd = asin(cos(0));
128 lrd = lrd;
129
130 #if !defined(DLLENTRYPOINT_NAME)
131 puts("DLLInit");
132 #endif
133
134 #ifdef __cplusplus
135 puts("Hello \"C++\" "_STR"World!");
136 #else
137 puts("Hello \"C\" "_STR"World!");
138 #endif
139
140/*
141 * Define assertions.
142 */
143#ifdef __32BIT__
144# ifdef __16BIT__
145 puts("error: __16BIT__ && __32BIT__ is defined!");
146# else
147 puts("__32BIT__");
148# endif
149#else
150# ifdef __16BIT__
151 puts("__16BIT__");
152# else
153 puts("error: __16BIT__ nor __32BIT__ is defined!");
154# endif
155
156#endif
157
158#if !defined(OS2) && !defined(WIN32) && !defined(LINUX)
159 puts("error: OS is not defined!");
160#endif
161
162 return 0;
163}
164
165
166int OSCALL LOADDS FOONAME(void)
167{
168 puts("FOOName");
169 #if !defined(DLLENTRYPOINT_NAME)
170 puts("DLLTerm");
171 #endif
172 return 0;
173}
174
175
176#if defined(DLLENTRYPOINT_NAME) && defined(OS2)
177int DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(int hmod, int fFlags)
178{
179 switch (fFlags)
180 {
181 case 0:
182 {
183 ctordtorInit();
184 _CRT_init();
185 puts("DLLInit");
186 break;
187 }
188
189 case 1:
190 {
191 #ifdef __WATCOMC__
192 /* probably already terminated by now. */
193 #ifdef __16BIT__
194 USHORT Dummy;
195 #else
196 ULONG Dummy;
197 #endif
198 DosWrite((HFILE)1 /*HF_STDOUT*/, "DLLTerm\r\n", 9, &Dummy);
199 #else
200 puts("DLLTerm");
201 #endif
202 ctordtorTerm();
203 _CRT_term();
204 break;
205 }
206
207 default:
208 return 0;
209 }
210 return 1;
211}
212#endif
Note: See TracBrowser for help on using the repository browser.