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