3 * (c) 1995 Microsoft Corporation. All rights reserved.
4 * Developed by hip communications inc., http://info.hip.com/info/
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.
9 #ifndef _INC_WIN32_PERL5
10 #define _INC_WIN32_PERL5
12 #if defined(PERL_OBJECT) || defined(PERL_IMPLICIT_SYS) || defined(PERL_CAPI)
13 # define DYNAMIC_ENV_FETCH
14 # define ENV_HV_NAME "___ENV_HV_NAME___"
15 # define HAS_GETENV_LEN
16 # define prime_env_iter()
17 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
18 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
19 # ifdef PERL_GLOBAL_STRUCT
20 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
22 # define win32_get_privlib PerlEnv_lib_path
23 # define win32_get_sitelib PerlEnv_sitelib_path
26 #if defined(PERL_IMPLICIT_CONTEXT)
27 # define PERL_GET_INTERP ((PerlInterpreter*)GetPerlInterpreter())
28 # define PERL_SET_INTERP(i) (SetPerlInterpreter(i))
32 # ifndef __int64 /* some versions seem to #define it already */
33 # define __int64 long long
35 # define Win32_Winsock
36 /* GCC does not do __declspec() - render it a nop
37 * and turn on options to avoid importing data
40 # define __declspec(x)
43 # define PERL_GLOBAL_STRUCT
50 /* Define DllExport akin to perl's EXT,
51 * If we are in the DLL or mimicing the DLL for Win95 work round
52 * then Export the symbol,
53 * otherwise import it.
56 #if defined(PERL_OBJECT)
59 #if defined(PERLDLL) || defined(WIN95FIX)
61 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
63 #define DllExport __declspec(dllimport)
67 #define WIN32_LEAN_AND_MEAN
70 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
71 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
72 #endif /*WIN32_LEAN_AND_MEAN */
74 #ifndef TLS_OUT_OF_INDEXES
75 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
100 char sysname[SYS_NMLN];
101 char nodename[SYS_NMLN];
102 char release[SYS_NMLN];
103 char version[SYS_NMLN];
104 char machine[SYS_NMLN];
107 #ifndef START_EXTERN_C
110 # define START_EXTERN_C extern "C" {
111 # define END_EXTERN_C }
112 # define EXTERN_C extern "C"
114 # define START_EXTERN_C
115 # define END_EXTERN_C
121 #define DOSISH 1 /* no escaping our roots */
122 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
124 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
125 * real filehandles. XXX Should always be defined (the other version is untested) */
126 #define USE_SOCKETS_AS_HANDLES
128 /* read() and write() aren't transparent for socket handles */
129 #define PERL_SOCK_SYSREAD_IS_RECV
130 #define PERL_SOCK_SYSWRITE_IS_SEND
133 /* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
134 * to read the environment, bypassing the runtime's (usually broken)
135 * facilities for accessing the same. See note in util.c/my_setenv(). */
136 /*#define USE_WIN32_RTL_ENV */
138 /* Define USE_FIXED_OSFHANDLE to fix VC's _open_osfhandle() on W95.
139 * Can only enable it if not using the DLL CRT (it doesn't expose internals) */
140 #if defined(_MSC_VER) && !defined(_DLL) && defined(_M_IX86)
141 #define USE_FIXED_OSFHANDLE
144 #define ENV_IS_CASELESS
146 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
147 #define VER_PLATFORM_WIN32_WINDOWS 1
150 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
151 #define FILE_SHARE_DELETE 0x00000004
154 /* access() mode bits */
162 /* Compiler-specific stuff. */
164 #ifdef __BORLANDC__ /* Borland C++ */
166 #define _access access
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 is picky about a bare member function name used as its ptr */
187 # define MEMBER_TO_FPTR(name) &(name)
192 #ifdef _MSC_VER /* Microsoft Visual C++ */
196 typedef unsigned short mode_t;
197 #pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
201 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
202 #define STRUCT_MGVTBL_DEFINITION \
205 int (CPERLscope(*svt_get))(pTHX_ SV *sv, MAGIC* mg); \
206 char handle_VC_problem1[16]; \
209 int (CPERLscope(*svt_set))(pTHX_ SV *sv, MAGIC* mg); \
210 char handle_VC_problem2[16]; \
213 U32 (CPERLscope(*svt_len))(pTHX_ SV *sv, MAGIC* mg); \
214 char handle_VC_problem3[16]; \
217 int (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg); \
218 char handle_VC_problem4[16]; \
221 int (CPERLscope(*svt_free))(pTHX_ SV *sv, MAGIC* mg); \
222 char handle_VC_problem5[16]; \
226 #define BASEOP_DEFINITION \
229 OP* (CPERLscope(*op_ppaddr))(pTHX); \
230 char handle_VC_problem[12]; \
237 #endif /* PERL_OBJECT */
239 #endif /* _MSC_VER */
241 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
246 #define _environ environ
248 #define flushall _flushall
249 #define fcloseall _fcloseall
252 #define __attribute__(x)
255 # define CP_UTF8 65001
259 # define MEMBER_TO_FPTR(name) &(name)
263 # define _O_NOINHERIT 0x0080
264 # ifndef _NO_OLDNAMES
265 # define O_NOINHERIT _O_NOINHERIT
270 # define _O_NOINHERIT 0x0080
271 # ifndef _NO_OLDNAMES
272 # define O_NOINHERIT _O_NOINHERIT
276 #endif /* __MINGW32__ */
278 /* compatibility stuff for other compilers goes here */
283 /* For UNIX compatibility. */
285 extern uid_t getuid(void);
286 extern gid_t getgid(void);
287 extern uid_t geteuid(void);
288 extern gid_t getegid(void);
289 extern int setuid(uid_t uid);
290 extern int setgid(gid_t gid);
291 extern int kill(int pid, int sig);
292 extern void *sbrk(int need);
293 extern char * getlogin(void);
294 extern int chown(const char *p, uid_t o, gid_t g);
297 #define Stat win32_stat
299 #undef init_os_extras
300 #define init_os_extras Perl_init_os_extras
302 DllExport void Perl_win32_init(int *argcp, char ***argvp);
303 DllExport void Perl_init_os_extras();
304 DllExport void win32_str_os_error(void *sv, DWORD err);
305 DllExport int RunPerl(int argc, char **argv, char **env);
306 DllExport bool SetPerlInterpreter(void* interp);
307 DllExport void* GetPerlInterpreter(void);
309 #ifndef USE_SOCKETS_AS_HANDLES
310 extern FILE * my_fdopen(int, char *);
312 extern int my_fclose(FILE *);
313 extern int do_aspawn(void *really, void **mark, void **sp);
314 extern int do_spawn(char *cmd);
315 extern int do_spawn_nowait(char *cmd);
316 extern char * win32_get_privlib(char *pl);
317 extern char * win32_get_sitelib(char *pl);
318 extern int IsWin95(void);
319 extern int IsWinNT(void);
321 extern char * staticlinkmodules[];
325 typedef char * caddr_t; /* In malloc.c (core address). */
328 * handle socket stuff, assuming socket is always available
330 #include <sys/socket.h>
334 #define EMBEDMYMALLOC /**/
335 /* #define USE_PERL_SBRK /**/
336 /* #define PERL_SBRK_VIA_MALLOC /**/
339 #if defined(PERLDLL) && !defined(PERL_CORE)
343 #ifdef USE_BINMODE_SCRIPTS
344 #define PERL_SCRIPT_MODE "rb"
345 EXT void win32_strip_return(struct sv *sv);
347 #define PERL_SCRIPT_MODE "r"
348 #define win32_strip_return(sv) NOOP
352 * Now Win32 specific per-thread data stuff
355 struct thread_intern {
356 /* XXX can probably use one buffer instead of several */
357 char Wstrerror_buffer[512];
358 struct servent Wservent;
359 char Wgetlogin_buffer[128];
360 # ifdef USE_SOCKETS_AS_HANDLES
363 # ifdef HAVE_DES_FCRYPT
364 char Wcrypt_buffer[30];
366 # ifdef USE_RTL_THREAD_API
367 void * retv; /* slot for thread return value */
372 # ifndef USE_DECLSPEC_THREAD
373 # define HAVE_THREAD_INTERN
374 # endif /* !USE_DECLSPEC_THREAD */
375 #endif /* USE_THREADS */
377 #define HAVE_INTERP_INTERN
380 DWORD pids[MAXIMUM_WAIT_OBJECTS];
386 struct host_link * next;
389 struct interp_intern {
390 char * perlshell_tokens;
391 char ** perlshell_vec;
392 long perlshell_items;
394 child_tab * children;
395 HANDLE child_handles[MAXIMUM_WAIT_OBJECTS];
396 struct host_link * hostlist;
398 struct thread_intern thr_intern;
403 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
404 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
405 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
406 #define w32_fdpid (PL_sys_intern.fdpid)
407 #define w32_children (PL_sys_intern.children)
408 #define w32_num_children (w32_children->num)
409 #define w32_child_pids (w32_children->pids)
410 #define w32_child_handles (PL_sys_intern.child_handles)
411 #define w32_host_link (PL_sys_intern.hostlist)
413 # define w32_strerror_buffer (thr->i.Wstrerror_buffer)
414 # define w32_getlogin_buffer (thr->i.Wgetlogin_buffer)
415 # define w32_crypt_buffer (thr->i.Wcrypt_buffer)
416 # define w32_servent (thr->i.Wservent)
417 # define w32_init_socktype (thr->i.Winit_socktype)
419 # define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
420 # define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
421 # define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
422 # define w32_servent (PL_sys_intern.thr_intern.Wservent)
423 # define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
424 #endif /* USE_THREADS */
426 /* UNICODE<>ANSI translation helpers */
427 /* Use CP_ACP when mode is ANSI */
428 /* Use CP_UTF8 when mode is UTF8 */
430 #define A2WHELPER(lpa, lpw, nBytes)\
431 lpw[0] = 0, MultiByteToWideChar((IN_UTF8) ? CP_UTF8 : CP_ACP, 0, lpa, -1, lpw, (nBytes/sizeof(WCHAR)))
433 #define W2AHELPER(lpw, lpa, nChars)\
434 lpa[0] = '\0', WideCharToMultiByte((IN_UTF8) ? CP_UTF8 : CP_ACP, 0, lpw, -1, (LPSTR)lpa, nChars, NULL, NULL)
436 #define USING_WIDE() (PerlEnv_os_id() == VER_PLATFORM_WIN32_NT)
439 * This provides a layer of functions and macros to ensure extensions will
440 * get to use the same RTL functions as the core.
442 #include "win32iop.h"
444 #endif /* _INC_WIN32_PERL5 */