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