Commit | Line | Data |
68dc0745 |
1 | /* WIN32.H |
2 | * |
3 | * (c) 1995 Microsoft Corporation. All rights reserved. |
4 | * Developed by hip communications inc., http://info.hip.com/info/ |
5 | * |
6 | * You may distribute under the terms of either the GNU General Public |
7 | * License or the Artistic License, as specified in the README file. |
8 | */ |
0a753a76 |
9 | #ifndef _INC_WIN32_PERL5 |
10 | #define _INC_WIN32_PERL5 |
11 | |
9d8a25dc |
12 | #ifdef PERL_OBJECT |
e9ee4811 |
13 | # define DYNAMIC_ENV_FETCH |
14 | # define ENV_HV_NAME "___ENV_HV_NAME___" |
a6c40364 |
15 | # define HAS_GETENV_LEN |
e9ee4811 |
16 | # define prime_env_iter() |
ab39fa9d |
17 | # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */ |
18 | # ifdef PERL_GLOBAL_STRUCT |
19 | # error PERL_GLOBAL_STRUCT cannot be defined with PERL_OBJECT |
20 | # endif |
e5a95ffb |
21 | # define win32_get_privlib PerlEnv_lib_path |
ab39fa9d |
22 | # define win32_get_sitelib PerlEnv_sitelib_path |
9d8a25dc |
23 | #endif |
24 | |
a835ef8a |
25 | #ifdef __GNUC__ |
2d63fa08 |
26 | typedef long long __int64; |
db15561c |
27 | # define Win32_Winsock |
22239a37 |
28 | /* GCC does not do __declspec() - render it a nop |
29 | * and turn on options to avoid importing data |
30 | */ |
b1d1613b |
31 | #ifndef __declspec |
db15561c |
32 | # define __declspec(x) |
b1d1613b |
33 | #endif |
db15561c |
34 | # ifndef PERL_OBJECT |
35 | # define PERL_GLOBAL_STRUCT |
b86a2fa7 |
36 | # ifndef MULTIPLICITY |
37 | # define MULTIPLICITY |
38 | # endif |
db15561c |
39 | # endif |
a835ef8a |
40 | #endif |
41 | |
22239a37 |
42 | /* Define DllExport akin to perl's EXT, |
43 | * If we are in the DLL or mimicing the DLL for Win95 work round |
44 | * then Export the symbol, |
45 | * otherwise import it. |
46 | */ |
47 | |
c69f6586 |
48 | #if defined(PERL_OBJECT) |
49 | #define DllExport |
50 | #else |
22239a37 |
51 | #if defined(PERLDLL) || defined(WIN95FIX) |
852c2e52 |
52 | #define DllExport |
53 | /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */ |
22239a37 |
54 | #else |
55 | #define DllExport __declspec(dllimport) |
56 | #endif |
c69f6586 |
57 | #endif |
c69f112c |
58 | |
0a753a76 |
59 | #define WIN32_LEAN_AND_MEAN |
60 | #include <windows.h> |
61 | |
68dc0745 |
62 | #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */ |
63 | #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */ |
68dc0745 |
64 | #endif /*WIN32_LEAN_AND_MEAN */ |
0a753a76 |
65 | |
eda5ff31 |
66 | #ifndef TLS_OUT_OF_INDEXES |
67 | #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF |
68 | #endif |
69 | |
0a753a76 |
70 | #include <dirent.h> |
71 | #include <io.h> |
72 | #include <process.h> |
73 | #include <stdio.h> |
74 | #include <direct.h> |
390b85e7 |
75 | #include <stdlib.h> |
76 | #ifndef EXT |
77 | #include "EXTERN.h" |
78 | #endif |
79 | |
c69f112c |
80 | struct tms { |
81 | long tms_utime; |
82 | long tms_stime; |
83 | long tms_cutime; |
84 | long tms_cstime; |
85 | }; |
86 | |
b2af26b1 |
87 | #ifndef SYS_NMLN |
88 | #define SYS_NMLN 257 |
89 | #endif |
90 | |
91 | struct utsname { |
92 | char sysname[SYS_NMLN]; |
93 | char nodename[SYS_NMLN]; |
94 | char release[SYS_NMLN]; |
95 | char version[SYS_NMLN]; |
96 | char machine[SYS_NMLN]; |
97 | }; |
98 | |
390b85e7 |
99 | #ifndef START_EXTERN_C |
b3e5c95e |
100 | #undef EXTERN_C |
390b85e7 |
101 | #ifdef __cplusplus |
102 | # define START_EXTERN_C extern "C" { |
103 | # define END_EXTERN_C } |
104 | # define EXTERN_C extern "C" |
105 | #else |
106 | # define START_EXTERN_C |
107 | # define END_EXTERN_C |
108 | # define EXTERN_C |
109 | #endif |
110 | #endif |
111 | |
112 | #define STANDARD_C 1 |
113 | #define DOSISH 1 /* no escaping our roots */ |
114 | #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */ |
0a753a76 |
115 | |
f3986ebb |
116 | /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as |
117 | * real filehandles. XXX Should always be defined (the other version is untested) */ |
118 | #define USE_SOCKETS_AS_HANDLES |
119 | |
a7092146 |
120 | /* read() and write() aren't transparent for socket handles */ |
121 | #define PERL_SOCK_SYSREAD_IS_RECV |
122 | #define PERL_SOCK_SYSWRITE_IS_SEND |
123 | |
124 | |
f3986ebb |
125 | /* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls |
126 | * to read the environment, bypassing the runtime's (usually broken) |
127 | * facilities for accessing the same. See note in util.c/my_setenv(). */ |
128 | /*#define USE_WIN32_RTL_ENV */ |
0a753a76 |
129 | |
f3986ebb |
130 | /* Define USE_FIXED_OSFHANDLE to fix VC's _open_osfhandle() on W95. |
131 | * Can only enable it if not using the DLL CRT (it doesn't expose internals) */ |
132 | #if defined(_MSC_VER) && !defined(_DLL) && defined(_M_IX86) |
133 | #define USE_FIXED_OSFHANDLE |
134 | #endif |
135 | |
902173a3 |
136 | #define ENV_IS_CASELESS |
137 | |
d41de25a |
138 | #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */ |
f3986ebb |
139 | #define VER_PLATFORM_WIN32_WINDOWS 1 |
140 | #endif |
141 | |
d41de25a |
142 | #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */ |
143 | #define FILE_SHARE_DELETE 0x00000004 |
144 | #endif |
145 | |
327c3667 |
146 | /* access() mode bits */ |
147 | #ifndef R_OK |
148 | # define R_OK 4 |
149 | # define W_OK 2 |
150 | # define X_OK 1 |
151 | # define F_OK 0 |
152 | #endif |
153 | |
f3986ebb |
154 | /* Compiler-specific stuff. */ |
155 | |
910dfcc8 |
156 | #ifdef __BORLANDC__ /* Borland C++ */ |
3e3baf6d |
157 | |
158 | #define _access access |
159 | #define _chdir chdir |
160 | #include <sys/types.h> |
161 | |
84902520 |
162 | #ifndef DllMain |
163 | #define DllMain DllEntryPoint |
164 | #endif |
165 | |
189b2af5 |
166 | #pragma warn -ccc /* "condition is always true/false" */ |
167 | #pragma warn -rch /* "unreachable code" */ |
168 | #pragma warn -sig /* "conversion may lose significant digits" */ |
169 | #pragma warn -pia /* "possibly incorrect assignment" */ |
170 | #pragma warn -par /* "parameter 'foo' is never used" */ |
171 | #pragma warn -aus /* "'foo' is assigned a value that is never used" */ |
172 | #pragma warn -use /* "'foo' is declared but never used" */ |
173 | #pragma warn -csu /* "comparing signed and unsigned values" */ |
174 | #pragma warn -pro /* "call to function with no prototype" */ |
327c3667 |
175 | #pragma warn -stu /* "undefined structure 'foo'" */ |
3e3baf6d |
176 | |
ac4c12e7 |
177 | /* Borland is picky about a bare member function name used as its ptr */ |
178 | #ifdef PERL_OBJECT |
179 | #define FUNC_NAME_TO_PTR(name) &(name) |
180 | #endif |
181 | |
910dfcc8 |
182 | #endif |
3e3baf6d |
183 | |
f3986ebb |
184 | #ifdef _MSC_VER /* Microsoft Visual C++ */ |
185 | |
0a753a76 |
186 | typedef long uid_t; |
187 | typedef long gid_t; |
a6c40364 |
188 | typedef unsigned short mode_t; |
f3986ebb |
189 | #pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761) |
190 | |
0cb96387 |
191 | #ifdef PERL_OBJECT |
192 | extern CPerlObj* GetPerlInter(void); |
193 | #define dPERLOBJ CPerlObj* pPerl = GetPerlInter() |
194 | #else /* PERL_OBJECT */ |
0f4eea8f |
195 | |
196 | /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */ |
197 | #define STRUCT_MGVTBL_DEFINITION \ |
198 | struct mgvtbl { \ |
199 | union { \ |
4f63d024 |
200 | int (CPERLscope(*svt_get))(pTHX_ SV *sv, MAGIC* mg); \ |
0f4eea8f |
201 | char handle_VC_problem1[16]; \ |
202 | }; \ |
203 | union { \ |
4f63d024 |
204 | int (CPERLscope(*svt_set))(pTHX_ SV *sv, MAGIC* mg); \ |
0f4eea8f |
205 | char handle_VC_problem2[16]; \ |
206 | }; \ |
207 | union { \ |
4f63d024 |
208 | U32 (CPERLscope(*svt_len))(pTHX_ SV *sv, MAGIC* mg); \ |
0f4eea8f |
209 | char handle_VC_problem3[16]; \ |
210 | }; \ |
211 | union { \ |
4f63d024 |
212 | int (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg); \ |
0f4eea8f |
213 | char handle_VC_problem4[16]; \ |
214 | }; \ |
215 | union { \ |
4f63d024 |
216 | int (CPERLscope(*svt_free))(pTHX_ SV *sv, MAGIC* mg); \ |
0f4eea8f |
217 | char handle_VC_problem5[16]; \ |
218 | }; \ |
219 | } |
220 | |
221 | #define BASEOP_DEFINITION \ |
222 | OP* op_next; \ |
223 | OP* op_sibling; \ |
4f63d024 |
224 | OP* (CPERLscope(*op_ppaddr))(pTHX); \ |
0f4eea8f |
225 | char handle_VC_problem[12]; \ |
226 | PADOFFSET op_targ; \ |
227 | OPCODE op_type; \ |
228 | U16 op_seq; \ |
229 | U8 op_flags; \ |
230 | U8 op_private; |
231 | |
232 | #define UNION_ANY_DEFINITION union any { \ |
233 | void* any_ptr; \ |
234 | I32 any_i32; \ |
235 | IV any_iv; \ |
236 | long any_long; \ |
4f63d024 |
237 | void (CPERLscope(*any_dptr)) (pTHX_ void*); \ |
0f4eea8f |
238 | char handle_VC_problem[16]; \ |
239 | } |
240 | |
0cb96387 |
241 | |
242 | #define dPERLOBJ |
0f4eea8f |
243 | #endif /* PERL_OBJECT */ |
244 | |
f3986ebb |
245 | #endif /* _MSC_VER */ |
246 | |
910dfcc8 |
247 | #ifdef __MINGW32__ /* Minimal Gnu-Win32 */ |
248 | |
249 | typedef long uid_t; |
250 | typedef long gid_t; |
b1d1613b |
251 | #ifndef _environ |
3730b96e |
252 | #define _environ environ |
b1d1613b |
253 | #endif |
3730b96e |
254 | #define flushall _flushall |
255 | #define fcloseall _fcloseall |
910dfcc8 |
256 | |
db15561c |
257 | #ifdef PERL_OBJECT |
258 | #define FUNC_NAME_TO_PTR(name) &(name) |
259 | #endif |
260 | |
ac4c12e7 |
261 | #ifndef _O_NOINHERIT |
262 | # define _O_NOINHERIT 0x0080 |
263 | # ifndef _NO_OLDNAMES |
264 | # define O_NOINHERIT _O_NOINHERIT |
265 | # endif |
266 | #endif |
267 | |
ba3eb2af |
268 | #ifndef _O_NOINHERIT |
269 | # define _O_NOINHERIT 0x0080 |
270 | # ifndef _NO_OLDNAMES |
271 | # define O_NOINHERIT _O_NOINHERIT |
272 | # endif |
273 | #endif |
274 | |
910dfcc8 |
275 | #endif /* __MINGW32__ */ |
276 | |
f3986ebb |
277 | /* compatibility stuff for other compilers goes here */ |
0a753a76 |
278 | |
0a753a76 |
279 | |
390b85e7 |
280 | START_EXTERN_C |
f3986ebb |
281 | |
282 | /* For UNIX compatibility. */ |
283 | |
0a753a76 |
284 | extern uid_t getuid(void); |
285 | extern gid_t getgid(void); |
286 | extern uid_t geteuid(void); |
287 | extern gid_t getegid(void); |
0a753a76 |
288 | extern int setuid(uid_t uid); |
289 | extern int setgid(gid_t gid); |
290 | extern int kill(int pid, int sig); |
161b471a |
291 | extern void *sbrk(int need); |
e34ffe5a |
292 | extern char * getlogin(void); |
b990f8c8 |
293 | extern int chown(const char *p, uid_t o, gid_t g); |
d55594ae |
294 | |
f3986ebb |
295 | #undef Stat |
296 | #define Stat win32_stat |
3e3baf6d |
297 | |
f3986ebb |
298 | #undef init_os_extras |
299 | #define init_os_extras Perl_init_os_extras |
390b85e7 |
300 | |
22239a37 |
301 | DllExport void Perl_win32_init(int *argcp, char ***argvp); |
4f63d024 |
302 | DllExport void Perl_init_os_extras(pTHX); |
303 | DllExport void win32_str_os_error(pTHX_ void *sv, DWORD err); |
0551aaa8 |
304 | |
f3986ebb |
305 | #ifndef USE_SOCKETS_AS_HANDLES |
306 | extern FILE * my_fdopen(int, char *); |
d55594ae |
307 | #endif |
f3986ebb |
308 | extern int my_fclose(FILE *); |
4f63d024 |
309 | extern int do_aspawn(pTHX_ void *really, void **mark, void **sp); |
310 | extern int do_spawn(pTHX_ char *cmd); |
311 | extern int do_spawn_nowait(pTHX_ char *cmd); |
312 | extern char * win32_get_privlib(pTHX_ char *pl); |
313 | extern char * win32_get_sitelib(pTHX_ char *pl); |
f3986ebb |
314 | extern int IsWin95(void); |
315 | extern int IsWinNT(void); |
d55594ae |
316 | |
f3986ebb |
317 | extern char * staticlinkmodules[]; |
390b85e7 |
318 | |
319 | END_EXTERN_C |
d55594ae |
320 | |
68dc0745 |
321 | typedef char * caddr_t; /* In malloc.c (core address). */ |
0a753a76 |
322 | |
68dc0745 |
323 | /* |
68dc0745 |
324 | * handle socket stuff, assuming socket is always available |
325 | */ |
0a753a76 |
326 | #include <sys/socket.h> |
327 | #include <netdb.h> |
328 | |
bbc8f9de |
329 | #ifdef MYMALLOC |
330 | #define EMBEDMYMALLOC /**/ |
331 | /* #define USE_PERL_SBRK /**/ |
332 | /* #define PERL_SBRK_VIA_MALLOC /**/ |
333 | #endif |
334 | |
c31fac66 |
335 | #if defined(PERLDLL) && !defined(PERL_CORE) |
bbc8f9de |
336 | #define PERL_CORE |
337 | #endif |
338 | |
a868473f |
339 | #ifdef USE_BINMODE_SCRIPTS |
340 | #define PERL_SCRIPT_MODE "rb" |
341 | EXT void win32_strip_return(struct sv *sv); |
342 | #else |
343 | #define PERL_SCRIPT_MODE "r" |
344 | #define win32_strip_return(sv) NOOP |
345 | #endif |
346 | |
4b556e6c |
347 | #define HAVE_INTERP_INTERN |
0aaad0ff |
348 | typedef struct { |
349 | long num; |
350 | DWORD pids[MAXIMUM_WAIT_OBJECTS]; |
351 | } child_tab; |
352 | |
0cb96387 |
353 | struct host_link { |
354 | char * nameId; |
355 | void * host_data; |
356 | struct host_link * next; |
357 | }; |
358 | |
4b556e6c |
359 | struct interp_intern { |
0aaad0ff |
360 | char * perlshell_tokens; |
361 | char ** perlshell_vec; |
362 | long perlshell_items; |
363 | struct av * fdpid; |
364 | child_tab * children; |
365 | HANDLE child_handles[MAXIMUM_WAIT_OBJECTS]; |
0cb96387 |
366 | struct host_link * hostlist; |
4b556e6c |
367 | }; |
368 | |
4b556e6c |
369 | |
0aaad0ff |
370 | #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens) |
371 | #define w32_perlshell_vec (PL_sys_intern.perlshell_vec) |
372 | #define w32_perlshell_items (PL_sys_intern.perlshell_items) |
373 | #define w32_fdpid (PL_sys_intern.fdpid) |
374 | #define w32_children (PL_sys_intern.children) |
375 | #define w32_num_children (w32_children->num) |
376 | #define w32_child_pids (w32_children->pids) |
377 | #define w32_child_handles (PL_sys_intern.child_handles) |
0cb96387 |
378 | #define w32_host_link (PL_sys_intern.hostlist) |
4b556e6c |
379 | |
c53bd28a |
380 | /* |
381 | * Now Win32 specific per-thread data stuff |
382 | */ |
383 | |
384 | #ifdef USE_THREADS |
e34ffe5a |
385 | # ifndef USE_DECLSPEC_THREAD |
386 | # define HAVE_THREAD_INTERN |
387 | |
388 | struct thread_intern { |
389 | /* XXX can probably use one buffer instead of several */ |
390 | char Wstrerror_buffer[512]; |
391 | struct servent Wservent; |
392 | char Wgetlogin_buffer[128]; |
4b556e6c |
393 | char Ww32_perllib_root[MAX_PATH+1]; |
401ef382 |
394 | # ifdef USE_SOCKETS_AS_HANDLES |
395 | int Winit_socktype; |
396 | # endif |
e34ffe5a |
397 | # ifdef HAVE_DES_FCRYPT |
398 | char Wcrypt_buffer[30]; |
399 | # endif |
2d7a9237 |
400 | # ifdef USE_RTL_THREAD_API |
401 | void * retv; /* slot for thread return value */ |
402 | # endif |
c53bd28a |
403 | }; |
e34ffe5a |
404 | # endif /* !USE_DECLSPEC_THREAD */ |
405 | #endif /* USE_THREADS */ |
c53bd28a |
406 | |
7fac1903 |
407 | /* UNICODE<>ANSI translation helpers */ |
408 | /* Use CP_ACP when mode is ANSI */ |
409 | /* Use CP_UTF8 when mode is UTF8 */ |
410 | |
0cb96387 |
411 | #define A2WHELPER(lpa, lpw, nChars)\ |
412 | lpw[0] = 0, MultiByteToWideChar((IN_UTF8) ? CP_UTF8 : CP_ACP, 0, lpa, -1, lpw, nChars) |
7fac1903 |
413 | |
0cb96387 |
414 | #define W2AHELPER(lpw, lpa, nChars)\ |
415 | lpa[0] = '\0', WideCharToMultiByte((IN_UTF8) ? CP_UTF8 : CP_ACP, 0, lpw, -1, (LPSTR)lpa, nChars, NULL, NULL) |
7fac1903 |
416 | |
0cb96387 |
417 | #define USING_WIDE() (PerlEnv_os_id() == VER_PLATFORM_WIN32_NT) |
7fac1903 |
418 | |
4f63d024 |
419 | /* |
420 | * This provides a layer of functions and macros to ensure extensions will |
421 | * get to use the same RTL functions as the core. |
422 | */ |
423 | #include "win32iop.h" |
424 | |
68dc0745 |
425 | #endif /* _INC_WIN32_PERL5 */ |
7a9ec5a3 |
426 | |