1 // Time-stamp: <01/08/01 20:59:54 keuchel@w2k>
5 * (c) 1995 Microsoft Corporation. All rights reserved.
6 * Developed by hip communications inc., http://info.hip.com/info/
8 * You may distribute under the terms of either the GNU General Public
9 * License or the Artistic License, as specified in the README file.
12 #ifndef _INC_WIN32_PERL5
13 #define _INC_WIN32_PERL5
16 # define _WIN32_WINNT 0x0400 /* needed for TryEnterCriticalSection() etc. */
19 #if defined(PERL_IMPLICIT_SYS)
20 # define DYNAMIC_ENV_FETCH
21 # define ENV_HV_NAME "___ENV_HV_NAME___"
22 # define HAS_GETENV_LEN
23 # define prime_env_iter()
24 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
25 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
26 # ifdef PERL_GLOBAL_STRUCT
27 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
29 # define win32_get_privlib PerlEnv_lib_path
30 # define win32_get_sitelib PerlEnv_sitelib_path
31 # define win32_get_vendorlib PerlEnv_vendorlib_path
35 # ifndef __int64 /* some versions seem to #define it already */
36 # define __int64 long long
38 # define Win32_Winsock
41 /* Define DllExport akin to perl's EXT,
42 * If we are in the DLL or mimicing the DLL for Win95 work round
43 * then Export the symbol,
44 * otherwise import it.
47 /* now even GCC supports __declspec() */
49 #if defined(PERLDLL) || defined(WIN95FIX)
51 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
53 #define DllExport __declspec(dllimport)
56 #define WIN32_LEAN_AND_MEAN
59 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
60 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
61 #endif /*WIN32_LEAN_AND_MEAN */
63 #ifndef TLS_OUT_OF_INDEXES
64 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
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];
99 #ifndef START_EXTERN_C
102 # define START_EXTERN_C extern "C" {
103 # define END_EXTERN_C }
104 # define EXTERN_C extern "C"
106 # define START_EXTERN_C
107 # define END_EXTERN_C
113 #define DOSISH 1 /* no escaping our roots */
114 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
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) */
119 //#define USE_SOCKETS_AS_HANDLES
121 /* read() and write() aren't transparent for socket handles */
122 #define PERL_SOCK_SYSREAD_IS_RECV
123 #define PERL_SOCK_SYSWRITE_IS_SEND
125 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
127 /* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
128 * to read the environment, bypassing the runtime's (usually broken)
129 * facilities for accessing the same. See note in util.c/my_setenv(). */
130 /*#define USE_WIN32_RTL_ENV */
132 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
133 It now uses some black magic to work seamlessly with the DLL CRT and
134 works with MSVC++ 4.0+ or GCC/Mingw32
136 #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
137 #define USE_FIXED_OSFHANDLE
140 #define ENV_IS_CASELESS
142 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
143 #define VER_PLATFORM_WIN32_WINDOWS 1
146 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
147 #define FILE_SHARE_DELETE 0x00000004
150 /* access() mode bits */
158 #define PERL_GET_CONTEXT_DEFINED
160 /* Compiler-specific stuff. */
162 #ifdef __BORLANDC__ /* Borland C++ */
164 #define _access access
166 #define _getpid getpid
167 #define wcsicmp _wcsicmp
168 #include <sys/types.h>
171 #define DllMain DllEntryPoint
174 #pragma warn -ccc /* "condition is always true/false" */
175 #pragma warn -rch /* "unreachable code" */
176 #pragma warn -sig /* "conversion may lose significant digits" */
177 #pragma warn -pia /* "possibly incorrect assignment" */
178 #pragma warn -par /* "parameter 'foo' is never used" */
179 #pragma warn -aus /* "'foo' is assigned a value that is never used" */
180 #pragma warn -use /* "'foo' is declared but never used" */
181 #pragma warn -csu /* "comparing signed and unsigned values" */
182 #pragma warn -pro /* "call to function with no prototype" */
183 #pragma warn -stu /* "undefined structure 'foo'" */
185 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
186 #define PERL_MEMBER_PTR_SIZE 12
190 #ifdef _MSC_VER /* Microsoft Visual C++ */
192 #ifndef _MODE_T_DEFINED_
193 typedef unsigned long mode_t;
194 #define _MODE_T_DEFINED_
197 #pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
199 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
200 #define PERL_MEMBER_PTR_SIZE 16
202 #endif /* _MSC_VER */
204 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
209 #define _environ environ
211 #define flushall _flushall
212 #define fcloseall _fcloseall
215 # define _O_NOINHERIT 0x0080
216 # ifndef _NO_OLDNAMES
217 # define O_NOINHERIT _O_NOINHERIT
221 #endif /* __MINGW32__ */
223 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
225 # define CP_UTF8 65001
228 /* compatibility stuff for other compilers goes here */
233 #define Stat win32_stat
235 #undef init_os_extras
236 #define init_os_extras Perl_init_os_extras
238 DllExport void Perl_win32_init(int *argcp, char ***argvp);
239 DllExport void Perl_init_os_extras();
240 DllExport void win32_str_os_error(void *sv, DWORD err);
241 DllExport int RunPerl(int argc, char **argv, char **env);
248 * the following correspond to the fields of the same name
249 * in the STARTUPINFO structure. Embedders can use these to
250 * control the spawning process' look.
251 * Example - to hide the window of the spawned process:
252 * dwFlags = STARTF_USESHOWWINDOW;
253 * wShowWindow = SW_HIDE;
262 DWORD dwFillAttribute;
266 DllExport void win32_get_child_IO(child_IO_table* ptr);
268 #ifndef USE_SOCKETS_AS_HANDLES
269 extern FILE * my_fdopen(int, char *);
272 extern int my_fclose(FILE *);
273 extern int do_aspawn(void *really, void **mark, void **sp);
274 extern int do_spawn(char *cmd);
275 extern int do_spawn_nowait(char *cmd);
276 extern char * win32_get_privlib(const char *pl);
277 extern char * win32_get_sitelib(const char *pl);
278 extern char * win32_get_vendorlib(const char *pl);
279 extern int IsWin95(void);
280 extern int IsWinNT(void);
281 extern void win32_argv2utf8(int argc, char** argv);
283 #ifdef PERL_IMPLICIT_SYS
284 extern void win32_delete_internal_host(void *h);
287 extern char * staticlinkmodules[];
292 * handle socket stuff, assuming socket is always available
295 #include <sys/socket.h>
299 #define EMBEDMYMALLOC /**/
300 /* #define USE_PERL_SBRK /**/
301 /* #define PERL_SBRK_VIA_MALLOC /**/
304 #if defined(PERLDLL) && !defined(PERL_CORE)
308 #ifdef PERL_TEXTMODE_SCRIPTS
309 # define PERL_SCRIPT_MODE "r"
311 # define PERL_SCRIPT_MODE "rb"
315 * Now Win32 specific per-thread data stuff
318 struct thread_intern {
319 /* XXX can probably use one buffer instead of several */
320 char Wstrerror_buffer[512];
321 struct servent Wservent;
322 char Wgetlogin_buffer[128];
323 # ifdef USE_SOCKETS_AS_HANDLES
326 # ifdef HAVE_DES_FCRYPT
327 char Wcrypt_buffer[30];
329 # ifdef USE_RTL_THREAD_API
330 void * retv; /* slot for thread return value */
334 #ifdef USE_5005THREADS
335 # ifndef USE_DECLSPEC_THREAD
336 # define HAVE_THREAD_INTERN
337 # endif /* !USE_DECLSPEC_THREAD */
338 #endif /* USE_5005THREADS */
340 #define HAVE_INTERP_INTERN
343 DWORD pids[MAXIMUM_WAIT_OBJECTS];
344 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
347 struct interp_intern {
348 char * perlshell_tokens;
349 char ** perlshell_vec;
350 long perlshell_items;
352 child_tab * children;
355 child_tab * pseudo_children;
357 void * internal_host;
358 #ifndef USE_5005THREADS
359 struct thread_intern thr_intern;
364 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
365 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
366 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
367 #define w32_fdpid (PL_sys_intern.fdpid)
368 #define w32_children (PL_sys_intern.children)
369 #define w32_num_children (w32_children->num)
370 #define w32_child_pids (w32_children->pids)
371 #define w32_child_handles (w32_children->handles)
372 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
373 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
374 #define w32_num_pseudo_children (w32_pseudo_children->num)
375 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
376 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
377 #define w32_internal_host (PL_sys_intern.internal_host)
378 #ifdef USE_5005THREADS
379 # define w32_strerror_buffer (thr->i.Wstrerror_buffer)
380 # define w32_getlogin_buffer (thr->i.Wgetlogin_buffer)
381 # define w32_crypt_buffer (thr->i.Wcrypt_buffer)
382 # define w32_servent (thr->i.Wservent)
383 # define w32_init_socktype (thr->i.Winit_socktype)
385 # define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
386 # define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
387 # define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
388 # define w32_servent (PL_sys_intern.thr_intern.Wservent)
389 # define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
390 #endif /* USE_5005THREADS */
392 /* UNICODE<>ANSI translation helpers */
393 /* Use CP_ACP when mode is ANSI */
394 /* Use CP_UTF8 when mode is UTF8 */
396 #define A2WHELPER_LEN(lpa, alen, lpw, nBytes)\
397 (lpw[0] = 0, MultiByteToWideChar((IN_BYTE) ? CP_ACP : CP_UTF8, 0, \
398 lpa, alen, lpw, (nBytes/sizeof(WCHAR))))
399 #define A2WHELPER(lpa, lpw, nBytes) A2WHELPER_LEN(lpa, -1, lpw, nBytes)
401 #define W2AHELPER_LEN(lpw, wlen, lpa, nChars)\
402 (lpa[0] = '\0', WideCharToMultiByte((IN_BYTE) ? CP_ACP : CP_UTF8, 0, \
403 lpw, wlen, (LPSTR)lpa, nChars,NULL,NULL))
404 #define W2AHELPER(lpw, lpa, nChars) W2AHELPER_LEN(lpw, -1, lpa, nChars)
406 #define USING_WIDE() (PL_widesyscalls && PerlEnv_os_id() == VER_PLATFORM_WIN32_NT)
409 # define PERL_WAIT_FOR_CHILDREN \
411 if (w32_pseudo_children && w32_num_pseudo_children) { \
412 long children = w32_num_pseudo_children; \
413 WaitForMultipleObjects(children, \
414 w32_pseudo_child_handles, \
417 CloseHandle(w32_pseudo_child_handles[--children]); \
423 * This provides a layer of functions and macros to ensure extensions will
424 * get to use the same RTL functions as the core.
426 #include "win32iop.h"
428 #endif /* _INC_WIN32_PERL5 */