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