fixups for sundry warnings about function pointers
[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 #if defined(PERL_OBJECT) || 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_OBJECT
21 #  endif
22 #  define win32_get_privlib PerlEnv_lib_path
23 #  define win32_get_sitelib PerlEnv_sitelib_path
24 #endif
25
26 #if defined(PERL_IMPLICIT_CONTEXT)
27 #  define PERL_GET_INTERP       ((PerlInterpreter*)GetPerlInterpreter())
28 #  define PERL_SET_INTERP(i)    (SetPerlInterpreter(i))
29 #endif
30
31 #ifdef __GNUC__
32 typedef long long __int64;
33 #  define Win32_Winsock
34 /* GCC does not do __declspec() - render it a nop 
35  * and turn on options to avoid importing data 
36  */
37 #ifndef __declspec
38 #  define __declspec(x)
39 #endif
40 #  ifndef PERL_OBJECT
41 #    define PERL_GLOBAL_STRUCT
42 #    ifndef MULTIPLICITY
43 #      define MULTIPLICITY
44 #    endif
45 #  endif
46 #endif
47
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
54 #if defined(PERL_OBJECT)
55 #define DllExport
56 #else
57 #if defined(PERLDLL) || defined(WIN95FIX)
58 #define DllExport
59 /*#define DllExport __declspec(dllexport)*/     /* noises with VC5+sp3 */
60 #else 
61 #define DllExport __declspec(dllimport)
62 #endif
63 #endif
64
65 #define  WIN32_LEAN_AND_MEAN
66 #include <windows.h>
67
68 #ifdef   WIN32_LEAN_AND_MEAN            /* C file is NOT a Perl5 original. */
69 #define  CONTEXT        PERL_CONTEXT    /* Avoid conflict of CONTEXT defs. */
70 #endif /*WIN32_LEAN_AND_MEAN */
71
72 #ifndef TLS_OUT_OF_INDEXES
73 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
74 #endif
75
76 #include <dirent.h>
77 #include <io.h>
78 #include <process.h>
79 #include <stdio.h>
80 #include <direct.h>
81 #include <stdlib.h>
82 #ifndef EXT
83 #include "EXTERN.h"
84 #endif
85
86 struct tms {
87         long    tms_utime;
88         long    tms_stime;
89         long    tms_cutime;
90         long    tms_cstime;
91 };
92
93 #ifndef SYS_NMLN
94 #define SYS_NMLN        257
95 #endif
96
97 struct 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
105 #ifndef START_EXTERN_C
106 #undef EXTERN_C
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? */
121
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
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
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 */
135
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
142 #define ENV_IS_CASELESS
143
144 #ifndef VER_PLATFORM_WIN32_WINDOWS      /* VC-2.0 headers don't have this */
145 #define VER_PLATFORM_WIN32_WINDOWS      1
146 #endif
147
148 #ifndef FILE_SHARE_DELETE               /* VC-4.0 headers don't have this */
149 #define FILE_SHARE_DELETE               0x00000004
150 #endif
151
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
160 /* Compiler-specific stuff. */
161
162 #ifdef __BORLANDC__             /* Borland C++ */
163
164 #define _access access
165 #define _chdir chdir
166 #include <sys/types.h>
167
168 #ifndef DllMain
169 #define DllMain DllEntryPoint
170 #endif
171
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" */
181 #pragma warn -stu       /* "undefined structure 'foo'" */
182
183 /* Borland is picky about a bare member function name used as its ptr */
184 #ifdef PERL_OBJECT
185 #  define MEMBER_TO_FPTR(name)  &(name)
186 #endif
187
188 #endif
189
190 #ifdef _MSC_VER                 /* Microsoft Visual C++ */
191
192 typedef long            uid_t;
193 typedef long            gid_t;
194 typedef unsigned short  mode_t;
195 #pragma  warning(disable: 4018 4035 4101 4102 4244 4245 4761)
196
197 #ifndef PERL_OBJECT
198
199 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
200 #define STRUCT_MGVTBL_DEFINITION                                        \
201 struct mgvtbl {                                                         \
202     union {                                                             \
203         int         (CPERLscope(*svt_get))(pTHX_ SV *sv, MAGIC* mg);    \
204         char        handle_VC_problem1[16];                             \
205     };                                                                  \
206     union {                                                             \
207         int         (CPERLscope(*svt_set))(pTHX_ SV *sv, MAGIC* mg);    \
208         char        handle_VC_problem2[16];                             \
209     };                                                                  \
210     union {                                                             \
211         U32         (CPERLscope(*svt_len))(pTHX_ SV *sv, MAGIC* mg);    \
212         char        handle_VC_problem3[16];                             \
213     };                                                                  \
214     union {                                                             \
215         int         (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg);  \
216         char        handle_VC_problem4[16];                             \
217     };                                                                  \
218     union {                                                             \
219         int         (CPERLscope(*svt_free))(pTHX_ SV *sv, MAGIC* mg);   \
220         char        handle_VC_problem5[16];                             \
221     };                                                                  \
222 }
223
224 #define BASEOP_DEFINITION               \
225     OP*         op_next;                \
226     OP*         op_sibling;             \
227     OP*         (CPERLscope(*op_ppaddr))(pTHX);         \
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
235 #define UNION_ANY_DEFINITION union any {                \
236     void*       any_ptr;                                \
237     I32         any_i32;                                \
238     IV          any_iv;                                 \
239     long        any_long;                               \
240     void        (CPERLscope(*any_dptr)) (pTHX_ void*);  \
241     char        handle_VC_problem[16];                  \
242 }
243
244 #endif /* PERL_OBJECT */
245
246 #endif /* _MSC_VER */
247
248 #ifdef __MINGW32__              /* Minimal Gnu-Win32 */
249
250 typedef long            uid_t;
251 typedef long            gid_t;
252 #ifndef _environ
253 #define _environ        environ
254 #endif
255 #define flushall        _flushall
256 #define fcloseall       _fcloseall
257
258 #ifdef PERL_OBJECT
259 #  define MEMBER_TO_FPTR(name)  &(name)
260 #endif
261
262 #ifndef _O_NOINHERIT
263 #  define _O_NOINHERIT  0x0080
264 #  ifndef _NO_OLDNAMES
265 #    define O_NOINHERIT _O_NOINHERIT
266 #  endif
267 #endif
268
269 #ifndef _O_NOINHERIT
270 #  define _O_NOINHERIT  0x0080
271 #  ifndef _NO_OLDNAMES
272 #    define O_NOINHERIT _O_NOINHERIT
273 #  endif
274 #endif
275
276 #endif /* __MINGW32__ */
277
278 /* compatibility stuff for other compilers goes here */
279
280
281 START_EXTERN_C
282
283 /* For UNIX compatibility. */
284
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);
295
296 #undef   Stat
297 #define  Stat           win32_stat
298
299 #undef   init_os_extras
300 #define  init_os_extras Perl_init_os_extras
301
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);
308
309 #ifndef USE_SOCKETS_AS_HANDLES
310 extern FILE *           my_fdopen(int, char *);
311 #endif
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);
320
321 extern char *           staticlinkmodules[];
322
323 END_EXTERN_C
324
325 typedef  char *         caddr_t;        /* In malloc.c (core address). */
326
327 /*
328  * handle socket stuff, assuming socket is always available
329  */
330 #include <sys/socket.h>
331 #include <netdb.h>
332
333 #ifdef MYMALLOC
334 #define EMBEDMYMALLOC   /**/
335 /* #define USE_PERL_SBRK        /**/
336 /* #define PERL_SBRK_VIA_MALLOC /**/
337 #endif
338
339 #if defined(PERLDLL) && !defined(PERL_CORE)
340 #define PERL_CORE
341 #endif
342
343 #ifdef USE_BINMODE_SCRIPTS
344 #define PERL_SCRIPT_MODE "rb"
345 EXT void win32_strip_return(struct sv *sv);
346 #else
347 #define PERL_SCRIPT_MODE "r"
348 #define win32_strip_return(sv) NOOP
349 #endif
350
351 #define HAVE_INTERP_INTERN
352 typedef struct {
353     long        num;
354     DWORD       pids[MAXIMUM_WAIT_OBJECTS];
355 } child_tab;
356
357 struct host_link {
358     char *      nameId;
359     void *      host_data;
360     struct host_link *  next;
361 };
362
363 struct interp_intern {
364     char *      perlshell_tokens;
365     char **     perlshell_vec;
366     long        perlshell_items;
367     struct av * fdpid;
368     child_tab * children;
369     HANDLE      child_handles[MAXIMUM_WAIT_OBJECTS];
370     struct host_link *  hostlist;
371 };
372
373
374 #define w32_perlshell_tokens    (PL_sys_intern.perlshell_tokens)
375 #define w32_perlshell_vec       (PL_sys_intern.perlshell_vec)
376 #define w32_perlshell_items     (PL_sys_intern.perlshell_items)
377 #define w32_fdpid               (PL_sys_intern.fdpid)
378 #define w32_children            (PL_sys_intern.children)
379 #define w32_num_children        (w32_children->num)
380 #define w32_child_pids          (w32_children->pids)
381 #define w32_child_handles       (PL_sys_intern.child_handles)
382 #define w32_host_link           (PL_sys_intern.hostlist)
383
384 /* 
385  * Now Win32 specific per-thread data stuff 
386  */
387
388 #ifdef USE_THREADS
389 #  ifndef USE_DECLSPEC_THREAD
390 #    define HAVE_THREAD_INTERN
391
392 struct thread_intern {
393     /* XXX can probably use one buffer instead of several */
394     char                Wstrerror_buffer[512];
395     struct servent      Wservent;
396     char                Wgetlogin_buffer[128];
397     char                Ww32_perllib_root[MAX_PATH+1];
398 #    ifdef USE_SOCKETS_AS_HANDLES
399     int                 Winit_socktype;
400 #    endif
401 #    ifdef HAVE_DES_FCRYPT
402     char                Wcrypt_buffer[30];
403 #    endif
404 #    ifdef USE_RTL_THREAD_API
405     void *              retv;   /* slot for thread return value */
406 #    endif
407 };
408 #  endif /* !USE_DECLSPEC_THREAD */
409 #endif /* USE_THREADS */
410
411 /* UNICODE<>ANSI translation helpers */
412 /* Use CP_ACP when mode is ANSI */
413 /* Use CP_UTF8 when mode is UTF8 */
414
415 #define A2WHELPER(lpa, lpw, nBytes)\
416     lpw[0] = 0, MultiByteToWideChar((IN_UTF8) ? CP_UTF8 : CP_ACP, 0, lpa, -1, lpw, (nBytes/sizeof(WCHAR)))
417
418 #define W2AHELPER(lpw, lpa, nChars)\
419     lpa[0] = '\0', WideCharToMultiByte((IN_UTF8) ? CP_UTF8 : CP_ACP, 0, lpw, -1, (LPSTR)lpa, nChars, NULL, NULL)
420
421 #define USING_WIDE()    (PerlEnv_os_id() == VER_PLATFORM_WIN32_NT)
422
423 /*
424  * This provides a layer of functions and macros to ensure extensions will
425  * get to use the same RTL functions as the core.
426  */
427 #include "win32iop.h"
428
429 #endif /* _INC_WIN32_PERL5 */
430