applied suggested fix for xhv_array sizing, with portability tweaks
[p5sagit/p5-mst-13.2.git] / win32 / win32.h
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  */
9 #ifndef  _INC_WIN32_PERL5
10 #define  _INC_WIN32_PERL5
11
12 #ifdef PERL_OBJECT
13 #  define WIN32IO_IS_STDIO              /* don't pull in custom stdio layer */
14 #  ifdef PERL_GLOBAL_STRUCT
15 #    error PERL_GLOBAL_STRUCT cannot be defined with PERL_OBJECT
16 #  endif
17 #  define win32_get_privlib PerlEnv_lib_path
18 #  define win32_get_sitelib PerlEnv_sitelib_path
19 #endif
20
21 #ifdef __GNUC__
22 typedef long long __int64;
23 #define Win32_Winsock
24 #  ifdef __cplusplus
25 #undef __attribute__            /* seems broken in 2.8.0 */
26 #define __attribute__(p)
27 #  endif
28 /* GCC does not do __declspec() - render it a nop 
29  * and turn on options to avoid importing data 
30  */
31 #define __declspec(x)
32 #define PERL_GLOBAL_STRUCT
33 #define MULTIPLICITY
34 #endif
35
36 /* Define DllExport akin to perl's EXT, 
37  * If we are in the DLL or mimicing the DLL for Win95 work round
38  * then Export the symbol, 
39  * otherwise import it.
40  */
41
42 #if defined(PERL_OBJECT)
43 #define DllExport
44 #else
45 #if defined(PERLDLL) || defined(WIN95FIX)
46 #define DllExport
47 /*#define DllExport __declspec(dllexport)*/     /* noises with VC5+sp3 */
48 #else 
49 #define DllExport __declspec(dllimport)
50 #endif
51 #endif
52
53 #define  WIN32_LEAN_AND_MEAN
54 #include <windows.h>
55
56 #ifdef   WIN32_LEAN_AND_MEAN            /* C file is NOT a Perl5 original. */
57 #define  CONTEXT        PERL_CONTEXT    /* Avoid conflict of CONTEXT defs. */
58 #endif /*WIN32_LEAN_AND_MEAN */
59
60 #ifndef TLS_OUT_OF_INDEXES
61 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
62 #endif
63
64 #include <dirent.h>
65 #include <io.h>
66 #include <process.h>
67 #include <stdio.h>
68 #include <direct.h>
69 #include <stdlib.h>
70 #ifndef EXT
71 #include "EXTERN.h"
72 #endif
73
74 struct tms {
75         long    tms_utime;
76         long    tms_stime;
77         long    tms_cutime;
78         long    tms_cstime;
79 };
80
81 #ifndef START_EXTERN_C
82 #ifdef __cplusplus
83 #  define START_EXTERN_C extern "C" {
84 #  define END_EXTERN_C }
85 #  define EXTERN_C extern "C"
86 #else
87 #  define START_EXTERN_C 
88 #  define END_EXTERN_C 
89 #  define EXTERN_C
90 #endif
91 #endif
92
93 #define  STANDARD_C     1
94 #define  DOSISH         1               /* no escaping our roots */
95 #define  OP_BINARY      O_BINARY        /* mistake in in pp_sys.c? */
96
97 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
98  * real filehandles. XXX Should always be defined (the other version is untested) */
99 #define USE_SOCKETS_AS_HANDLES
100
101 /* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
102  * to read the environment, bypassing the runtime's (usually broken)
103  * facilities for accessing the same.  See note in util.c/my_setenv(). */
104 /*#define USE_WIN32_RTL_ENV */
105
106 /* Define USE_FIXED_OSFHANDLE to fix VC's _open_osfhandle() on W95.
107  * Can only enable it if not using the DLL CRT (it doesn't expose internals) */
108 #if defined(_MSC_VER) && !defined(_DLL) && defined(_M_IX86)
109 #define USE_FIXED_OSFHANDLE
110 #endif
111
112 #define ENV_IS_CASELESS
113
114 #ifndef VER_PLATFORM_WIN32_WINDOWS      /* VC-2.0 headers don't have this */
115 #define VER_PLATFORM_WIN32_WINDOWS      1
116 #endif
117
118 #ifndef FILE_SHARE_DELETE               /* VC-4.0 headers don't have this */
119 #define FILE_SHARE_DELETE               0x00000004
120 #endif
121
122 /* Compiler-specific stuff. */
123
124 #ifdef __BORLANDC__             /* Borland C++ */
125
126 #define _access access
127 #define _chdir chdir
128 #include <sys/types.h>
129
130 #ifndef DllMain
131 #define DllMain DllEntryPoint
132 #endif
133
134 #pragma warn -ccc       /* "condition is always true/false" */
135 #pragma warn -rch       /* "unreachable code" */
136 #pragma warn -sig       /* "conversion may lose significant digits" */
137 #pragma warn -pia       /* "possibly incorrect assignment" */
138 #pragma warn -par       /* "parameter 'foo' is never used" */
139 #pragma warn -aus       /* "'foo' is assigned a value that is never used" */
140 #pragma warn -use       /* "'foo' is declared but never used" */
141 #pragma warn -csu       /* "comparing signed and unsigned values" */
142 #pragma warn -pro       /* "call to function with no prototype" */
143
144 #define USE_RTL_WAIT    /* Borland has a working wait() */
145
146 /* Borland is picky about a bare member function name used as its ptr */
147 #ifdef PERL_OBJECT
148 #define FUNC_NAME_TO_PTR(name)  &(name)
149 #endif
150
151 #endif
152
153 #ifdef _MSC_VER                 /* Microsoft Visual C++ */
154
155 typedef long            uid_t;
156 typedef long            gid_t;
157 #pragma  warning(disable: 4018 4035 4101 4102 4244 4245 4761)
158
159 #ifndef PERL_OBJECT
160
161 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
162 #define STRUCT_MGVTBL_DEFINITION                                        \
163 struct mgvtbl {                                                         \
164     union {                                                             \
165         int         (CPERLscope(*svt_get))      _((SV *sv, MAGIC* mg)); \
166         char        handle_VC_problem1[16];                             \
167     };                                                                  \
168     union {                                                             \
169         int         (CPERLscope(*svt_set))      _((SV *sv, MAGIC* mg)); \
170         char        handle_VC_problem2[16];                             \
171     };                                                                  \
172     union {                                                             \
173         U32         (CPERLscope(*svt_len))      _((SV *sv, MAGIC* mg)); \
174         char        handle_VC_problem3[16];                             \
175     };                                                                  \
176     union {                                                             \
177         int         (CPERLscope(*svt_clear))    _((SV *sv, MAGIC* mg)); \
178         char        handle_VC_problem4[16];                             \
179     };                                                                  \
180     union {                                                             \
181         int         (CPERLscope(*svt_free))     _((SV *sv, MAGIC* mg)); \
182         char        handle_VC_problem5[16];                             \
183     };                                                                  \
184 }
185
186 #define BASEOP_DEFINITION               \
187     OP*         op_next;                \
188     OP*         op_sibling;             \
189     OP*         (CPERLscope(*op_ppaddr))_((ARGSproto));         \
190     char        handle_VC_problem[12];  \
191     PADOFFSET   op_targ;                \
192     OPCODE      op_type;                \
193     U16         op_seq;                 \
194     U8          op_flags;               \
195     U8          op_private;
196
197 #define UNION_ANY_DEFINITION union any {                \
198     void*       any_ptr;                                \
199     I32         any_i32;                                \
200     IV          any_iv;                                 \
201     long        any_long;                               \
202     void        (CPERLscope(*any_dptr)) _((void*));     \
203     char        handle_VC_problem[16];                  \
204 }
205
206 #endif /* PERL_OBJECT */
207
208 #endif /* _MSC_VER */
209
210 #ifdef __MINGW32__              /* Minimal Gnu-Win32 */
211
212 typedef long            uid_t;
213 typedef long            gid_t;
214 #define _environ        environ
215 #define flushall        _flushall
216 #define fcloseall       _fcloseall
217
218 #ifndef _O_NOINHERIT
219 #  define _O_NOINHERIT  0x0080
220 #  ifndef _NO_OLDNAMES
221 #    define O_NOINHERIT _O_NOINHERIT
222 #  endif
223 #endif
224
225 #ifndef _O_NOINHERIT
226 #  define _O_NOINHERIT  0x0080
227 #  ifndef _NO_OLDNAMES
228 #    define O_NOINHERIT _O_NOINHERIT
229 #  endif
230 #endif
231
232 #endif /* __MINGW32__ */
233
234 /* compatibility stuff for other compilers goes here */
235
236
237 START_EXTERN_C
238
239 /* For UNIX compatibility. */
240
241 extern  uid_t   getuid(void);
242 extern  gid_t   getgid(void);
243 extern  uid_t   geteuid(void);
244 extern  gid_t   getegid(void);
245 extern  int     setuid(uid_t uid);
246 extern  int     setgid(gid_t gid);
247 extern  int     kill(int pid, int sig);
248 extern  void    *sbrk(int need);
249 extern  char *  getlogin(void);
250 extern  int     chown(const char *p, uid_t o, gid_t g);
251
252 #undef   Stat
253 #define  Stat           win32_stat
254
255 #undef   init_os_extras
256 #define  init_os_extras Perl_init_os_extras
257
258 DllExport void          Perl_win32_init(int *argcp, char ***argvp);
259 DllExport void          Perl_init_os_extras(void);
260 DllExport void          win32_str_os_error(void *sv, DWORD err);
261
262 #ifndef USE_SOCKETS_AS_HANDLES
263 extern FILE *           my_fdopen(int, char *);
264 #endif
265 extern int              my_fclose(FILE *);
266 extern int              do_aspawn(void *really, void **mark, void **sp);
267 extern int              do_spawn(char *cmd);
268 extern int              do_spawn_nowait(char *cmd);
269 extern char             do_exec(char *cmd);
270 extern char *           win32_get_privlib(char *pl);
271 extern char *           win32_get_sitelib(char *pl);
272 extern int              IsWin95(void);
273 extern int              IsWinNT(void);
274
275 extern char *           staticlinkmodules[];
276
277 END_EXTERN_C
278
279 typedef  char *         caddr_t;        /* In malloc.c (core address). */
280
281 /*
282  * handle socket stuff, assuming socket is always available
283  */
284 #include <sys/socket.h>
285 #include <netdb.h>
286
287 #ifdef MYMALLOC
288 #define EMBEDMYMALLOC   /**/
289 /* #define USE_PERL_SBRK        /**/
290 /* #define PERL_SBRK_VIA_MALLOC /**/
291 #endif
292
293 #if defined(PERLDLL) && !defined(PERL_CORE)
294 #define PERL_CORE
295 #endif
296
297 #ifdef USE_BINMODE_SCRIPTS
298 #define PERL_SCRIPT_MODE "rb"
299 EXT void win32_strip_return(struct sv *sv);
300 #else
301 #define PERL_SCRIPT_MODE "r"
302 #define win32_strip_return(sv) NOOP
303 #endif
304
305 #define HAVE_INTERP_INTERN
306 struct interp_intern {
307     char *      w32_perlshell_tokens;
308     char **     w32_perlshell_vec;
309     long        w32_perlshell_items;
310     struct av * w32_fdpid;
311 #ifndef USE_RTL_WAIT
312     long        w32_num_children;
313     HANDLE      w32_child_pids[MAXIMUM_WAIT_OBJECTS];
314 #endif
315 };
316
317 #define w32_perlshell_tokens    (sys_intern.w32_perlshell_tokens)
318 #define w32_perlshell_vec       (sys_intern.w32_perlshell_vec)
319 #define w32_perlshell_items     (sys_intern.w32_perlshell_items)
320 #define w32_fdpid               (sys_intern.w32_fdpid)
321
322 #ifndef USE_RTL_WAIT
323 #  define w32_num_children      (sys_intern.w32_num_children)
324 #  define w32_child_pids        (sys_intern.w32_child_pids)
325 #endif
326
327 /* 
328  * Now Win32 specific per-thread data stuff 
329  */
330
331 #ifdef USE_THREADS
332 #  ifndef USE_DECLSPEC_THREAD
333 #    define HAVE_THREAD_INTERN
334
335 struct thread_intern {
336     /* XXX can probably use one buffer instead of several */
337     char                Wstrerror_buffer[512];
338     struct servent      Wservent;
339     char                Wgetlogin_buffer[128];
340     char                Ww32_perllib_root[MAX_PATH+1];
341 #    ifdef USE_SOCKETS_AS_HANDLES
342     int                 Winit_socktype;
343 #    endif
344 #    ifdef HAVE_DES_FCRYPT
345     char                Wcrypt_buffer[30];
346 #    endif
347 #    ifdef USE_RTL_THREAD_API
348     void *              retv;   /* slot for thread return value */
349 #    endif
350 };
351 #  endif /* !USE_DECLSPEC_THREAD */
352 #endif /* USE_THREADS */
353
354 #endif /* _INC_WIN32_PERL5 */