This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a test.taintwarn makefile target,
[perl5.git] / win32 / win32.h
CommitLineData
68dc0745 1/* WIN32.H
2 *
3fadfdf1 3 * (c) 1995 Microsoft Corporation. All rights reserved.
68dc0745 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
5db10396
GS
12#ifndef _WIN32_WINNT
13# define _WIN32_WINNT 0x0400 /* needed for TryEnterCriticalSection() etc. */
14#endif
638eceb6 15
acfe0abc 16#if defined(PERL_IMPLICIT_SYS)
e9ee4811 17# define DYNAMIC_ENV_FETCH
a6c40364 18# define HAS_GETENV_LEN
e9ee4811 19# define prime_env_iter()
ab39fa9d 20# define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
c5be433b 21# define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
ab39fa9d 22# ifdef PERL_GLOBAL_STRUCT
32e30700 23# error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
ab39fa9d 24# endif
e5a95ffb 25# define win32_get_privlib PerlEnv_lib_path
ab39fa9d 26# define win32_get_sitelib PerlEnv_sitelib_path
4ea817c6 27# define win32_get_vendorlib PerlEnv_vendorlib_path
9d8a25dc
DL
28#endif
29
a835ef8a 30#ifdef __GNUC__
b7c82df9
GS
31# ifndef __int64 /* some versions seem to #define it already */
32# define __int64 long long
33# endif
db15561c 34# define Win32_Winsock
1c85e96a
NIS
35#ifdef __cplusplus
36/* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
3fadfdf1
NIS
37#undef PERL_UNUSED_DECL
38#define PERL_UNUSED_DECL
a835ef8a 39#endif
1c85e96a
NIS
40#endif
41
a835ef8a 42
3fadfdf1 43/* Define DllExport akin to perl's EXT,
22239a37 44 * If we are in the DLL or mimicing the DLL for Win95 work round
3fadfdf1 45 * then Export the symbol,
22239a37
NIS
46 * otherwise import it.
47 */
48
5db10396
GS
49/* now even GCC supports __declspec() */
50
22239a37 51#if defined(PERLDLL) || defined(WIN95FIX)
852c2e52
GS
52#define DllExport
53/*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
3fadfdf1 54#else
22239a37
NIS
55#define DllExport __declspec(dllimport)
56#endif
c69f112c 57
0a753a76 58#define WIN32_LEAN_AND_MEAN
59#include <windows.h>
60
68dc0745 61#ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
62#define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
68dc0745 63#endif /*WIN32_LEAN_AND_MEAN */
0a753a76 64
eda5ff31
GS
65#ifndef TLS_OUT_OF_INDEXES
66#define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
67#endif
68
0a753a76 69#include <dirent.h>
70#include <io.h>
71#include <process.h>
72#include <stdio.h>
73#include <direct.h>
390b85e7 74#include <stdlib.h>
c623ac67 75#include <stddef.h>
7a1f88ac 76#include <fcntl.h>
390b85e7
GS
77#ifndef EXT
78#include "EXTERN.h"
79#endif
80
c69f112c
NIS
81struct tms {
82 long tms_utime;
83 long tms_stime;
84 long tms_cutime;
85 long tms_cstime;
86};
87
b2af26b1
GS
88#ifndef SYS_NMLN
89#define SYS_NMLN 257
90#endif
91
92struct utsname {
93 char sysname[SYS_NMLN];
94 char nodename[SYS_NMLN];
95 char release[SYS_NMLN];
96 char version[SYS_NMLN];
97 char machine[SYS_NMLN];
98};
99
390b85e7 100#ifndef START_EXTERN_C
b3e5c95e 101#undef EXTERN_C
390b85e7
GS
102#ifdef __cplusplus
103# define START_EXTERN_C extern "C" {
104# define END_EXTERN_C }
105# define EXTERN_C extern "C"
106#else
3fadfdf1
NIS
107# define START_EXTERN_C
108# define END_EXTERN_C
390b85e7
GS
109# define EXTERN_C
110#endif
111#endif
112
113#define STANDARD_C 1
114#define DOSISH 1 /* no escaping our roots */
115#define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
0a753a76 116
f3986ebb
GS
117/* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
118 * real filehandles. XXX Should always be defined (the other version is untested) */
119#define USE_SOCKETS_AS_HANDLES
120
a7092146
GS
121/* read() and write() aren't transparent for socket handles */
122#define PERL_SOCK_SYSREAD_IS_RECV
123#define PERL_SOCK_SYSWRITE_IS_SEND
124
682fc664 125#define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
a7092146 126
9e5f57de
GS
127/* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
128 It now uses some black magic to work seamlessly with the DLL CRT and
129 works with MSVC++ 4.0+ or GCC/Mingw32
130 -- BKS 1-24-2000 */
131#if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
f3986ebb
GS
132#define USE_FIXED_OSFHANDLE
133#endif
134
6940069f
GS
135/* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
136 DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
137 -- BKS 5-29-2000 */
138#if !(defined(_M_IX86) && _MSC_VER >= 1200)
139#define PERL_WIN32_SOCK_DLOAD
140#endif
902173a3
GS
141#define ENV_IS_CASELESS
142
479b2847
GS
143#define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
144
d41de25a 145#ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
f3986ebb
GS
146#define VER_PLATFORM_WIN32_WINDOWS 1
147#endif
148
d41de25a
GS
149#ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
150#define FILE_SHARE_DELETE 0x00000004
151#endif
152
327c3667
GS
153/* access() mode bits */
154#ifndef R_OK
155# define R_OK 4
156# define W_OK 2
157# define X_OK 1
158# define F_OK 0
159#endif
160
cc236deb
GS
161/* for waitpid() */
162#ifndef WNOHANG
163# define WNOHANG 1
164#endif
165
c44d3fdb
GS
166#define PERL_GET_CONTEXT_DEFINED
167
f3986ebb
GS
168/* Compiler-specific stuff. */
169
910dfcc8 170#ifdef __BORLANDC__ /* Borland C++ */
3e3baf6d 171
cb359b41 172#if (__BORLANDC__ <= 0x520)
3e3baf6d
TB
173#define _access access
174#define _chdir chdir
cb359b41
JH
175#endif
176
4ce4f76e 177#define _getpid getpid
26871e0a 178#define wcsicmp _wcsicmp
3e3baf6d
TB
179#include <sys/types.h>
180
84902520
TB
181#ifndef DllMain
182#define DllMain DllEntryPoint
183#endif
184
189b2af5
GS
185#pragma warn -ccc /* "condition is always true/false" */
186#pragma warn -rch /* "unreachable code" */
187#pragma warn -sig /* "conversion may lose significant digits" */
188#pragma warn -pia /* "possibly incorrect assignment" */
189#pragma warn -par /* "parameter 'foo' is never used" */
190#pragma warn -aus /* "'foo' is assigned a value that is never used" */
191#pragma warn -use /* "'foo' is declared but never used" */
192#pragma warn -csu /* "comparing signed and unsigned values" */
3e3baf6d 193
cd183fd9
GS
194/* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
195#define PERL_MEMBER_PTR_SIZE 12
196
1307044d
VK
197#define isnan _isnan
198
910dfcc8 199#endif
3e3baf6d 200
f3986ebb
GS
201#ifdef _MSC_VER /* Microsoft Visual C++ */
202
0a753a76 203typedef long uid_t;
204typedef long gid_t;
a6c40364 205typedef unsigned short mode_t;
c623ac67 206#pragma warning(disable: 4102) /* "unreferenced label" */
f3986ebb 207
0f4eea8f 208/* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
cd183fd9 209#define PERL_MEMBER_PTR_SIZE 16
0f4eea8f 210
5fb4d820
GS
211#define isnan _isnan
212
f3986ebb
GS
213#endif /* _MSC_VER */
214
910dfcc8
GS
215#ifdef __MINGW32__ /* Minimal Gnu-Win32 */
216
217typedef long uid_t;
218typedef long gid_t;
b1d1613b 219#ifndef _environ
3730b96e 220#define _environ environ
b1d1613b 221#endif
3730b96e
GS
222#define flushall _flushall
223#define fcloseall _fcloseall
6940069f 224#define isnan _isnan /* ...same libraries as MSVC */
910dfcc8 225
ac4c12e7
GS
226#ifndef _O_NOINHERIT
227# define _O_NOINHERIT 0x0080
228# ifndef _NO_OLDNAMES
229# define O_NOINHERIT _O_NOINHERIT
230# endif
231#endif
232
910dfcc8
GS
233#endif /* __MINGW32__ */
234
f8fb7c90
GS
235/* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
236#ifndef CP_UTF8
237# define CP_UTF8 65001
238#endif
239
f3986ebb 240/* compatibility stuff for other compilers goes here */
0a753a76 241
c623ac67
GS
242#ifndef _INTPTR_T_DEFINED
243typedef int intptr_t;
244# define _INTPTR_T_DEFINED
245#endif
246
247#ifndef _UINTPTR_T_DEFINED
248typedef unsigned int uintptr_t;
249# define _UINTPTR_T_DEFINED
250#endif
251
390b85e7 252START_EXTERN_C
f3986ebb
GS
253
254/* For UNIX compatibility. */
255
0a753a76 256extern uid_t getuid(void);
257extern gid_t getgid(void);
258extern uid_t geteuid(void);
259extern gid_t getegid(void);
0a753a76 260extern int setuid(uid_t uid);
261extern int setgid(gid_t gid);
262extern int kill(int pid, int sig);
c623ac67
GS
263#ifndef USE_PERL_SBRK
264extern void *sbrk(ptrdiff_t need);
265# define HAS_SBRK_PROTO
266#endif
e34ffe5a 267extern char * getlogin(void);
b990f8c8 268extern int chown(const char *p, uid_t o, gid_t g);
00b02797 269extern int mkstemp(const char *path);
d55594ae 270
f3986ebb
GS
271#undef Stat
272#define Stat win32_stat
3e3baf6d 273
f3986ebb
GS
274#undef init_os_extras
275#define init_os_extras Perl_init_os_extras
390b85e7 276
22239a37 277DllExport void Perl_win32_init(int *argcp, char ***argvp);
23f519f0 278DllExport void Perl_win32_term(void);
cb359b41 279DllExport void Perl_init_os_extras(void);
c5be433b
GS
280DllExport void win32_str_os_error(void *sv, DWORD err);
281DllExport int RunPerl(int argc, char **argv, char **env);
0551aaa8 282
635bbe87
GS
283typedef struct {
284 HANDLE childStdIn;
285 HANDLE childStdOut;
286 HANDLE childStdErr;
f83751a7
GS
287 /*
288 * the following correspond to the fields of the same name
289 * in the STARTUPINFO structure. Embedders can use these to
290 * control the spawning process' look.
291 * Example - to hide the window of the spawned process:
292 * dwFlags = STARTF_USESHOWWINDOW;
293 * wShowWindow = SW_HIDE;
294 */
295 DWORD dwFlags;
3fadfdf1
NIS
296 DWORD dwX;
297 DWORD dwY;
298 DWORD dwXSize;
299 DWORD dwYSize;
300 DWORD dwXCountChars;
301 DWORD dwYCountChars;
f83751a7 302 DWORD dwFillAttribute;
3fadfdf1 303 WORD wShowWindow;
635bbe87
GS
304} child_IO_table;
305
306DllExport void win32_get_child_IO(child_IO_table* ptr);
307
f3986ebb
GS
308#ifndef USE_SOCKETS_AS_HANDLES
309extern FILE * my_fdopen(int, char *);
d55594ae 310#endif
f3986ebb 311extern int my_fclose(FILE *);
c623ac67 312extern int my_fstat(int fd, Stat_t *sbufptr);
4ea817c6
GS
313extern char * win32_get_privlib(const char *pl);
314extern char * win32_get_sitelib(const char *pl);
315extern char * win32_get_vendorlib(const char *pl);
f3986ebb
GS
316extern int IsWin95(void);
317extern int IsWinNT(void);
c0932edc 318extern void win32_argv2utf8(int argc, char** argv);
d55594ae 319
1c0ca838
GS
320#ifdef PERL_IMPLICIT_SYS
321extern void win32_delete_internal_host(void *h);
322#endif
323
f3986ebb 324extern char * staticlinkmodules[];
390b85e7
GS
325
326END_EXTERN_C
d55594ae 327
68dc0745 328typedef char * caddr_t; /* In malloc.c (core address). */
0a753a76 329
68dc0745 330/*
68dc0745 331 * handle socket stuff, assuming socket is always available
332 */
0a753a76 333#include <sys/socket.h>
334#include <netdb.h>
335
bbc8f9de
NIS
336#ifdef MYMALLOC
337#define EMBEDMYMALLOC /**/
338/* #define USE_PERL_SBRK /**/
339/* #define PERL_SBRK_VIA_MALLOC /**/
340#endif
341
c31fac66 342#if defined(PERLDLL) && !defined(PERL_CORE)
bbc8f9de
NIS
343#define PERL_CORE
344#endif
345
e68cb057 346#ifdef PERL_TEXTMODE_SCRIPTS
c39cd008 347# define PERL_SCRIPT_MODE "r"
a868473f 348#else
c39cd008 349# define PERL_SCRIPT_MODE "rb"
a868473f
NIS
350#endif
351
3fadfdf1
NIS
352/*
353 * Now Win32 specific per-thread data stuff
3352bfcb
GS
354 */
355
356struct 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# ifdef USE_SOCKETS_AS_HANDLES
362 int Winit_socktype;
363# endif
364# ifdef HAVE_DES_FCRYPT
365 char Wcrypt_buffer[30];
366# endif
367# ifdef USE_RTL_THREAD_API
368 void * retv; /* slot for thread return value */
369# endif
02637f4c
JD
370 BOOL Wuse_showwindow;
371 WORD Wshowwindow;
3352bfcb
GS
372};
373
4b556e6c 374#define HAVE_INTERP_INTERN
0aaad0ff
GS
375typedef struct {
376 long num;
377 DWORD pids[MAXIMUM_WAIT_OBJECTS];
7766f137 378 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
0aaad0ff
GS
379} child_tab;
380
3fadfdf1
NIS
381#ifndef Sighandler_t
382typedef Signal_t (*Sighandler_t) (int);
383#define Sighandler_t Sighandler_t
384#endif
385
4b556e6c 386struct interp_intern {
0aaad0ff
GS
387 char * perlshell_tokens;
388 char ** perlshell_vec;
389 long perlshell_items;
390 struct av * fdpid;
391 child_tab * children;
7766f137
GS
392#ifdef USE_ITHREADS
393 DWORD pseudo_id;
394 child_tab * pseudo_children;
395#endif
396 void * internal_host;
3352bfcb 397 struct thread_intern thr_intern;
8fb3fcfb 398 UINT timerid;
05ec9bb3 399 unsigned poll_count;
3fadfdf1 400 Sighandler_t sigtable[SIG_SIZE];
4b556e6c
JD
401};
402
8fb3fcfb
NIS
403DllExport int win32_async_check(pTHX);
404
05ec9bb3 405#define WIN32_POLL_INTERVAL 32768
8fb3fcfb 406#define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
4b556e6c 407
0aaad0ff
GS
408#define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
409#define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
410#define w32_perlshell_items (PL_sys_intern.perlshell_items)
411#define w32_fdpid (PL_sys_intern.fdpid)
412#define w32_children (PL_sys_intern.children)
413#define w32_num_children (w32_children->num)
414#define w32_child_pids (w32_children->pids)
7766f137
GS
415#define w32_child_handles (w32_children->handles)
416#define w32_pseudo_id (PL_sys_intern.pseudo_id)
417#define w32_pseudo_children (PL_sys_intern.pseudo_children)
418#define w32_num_pseudo_children (w32_pseudo_children->num)
419#define w32_pseudo_child_pids (w32_pseudo_children->pids)
420#define w32_pseudo_child_handles (w32_pseudo_children->handles)
421#define w32_internal_host (PL_sys_intern.internal_host)
8fb3fcfb 422#define w32_timerid (PL_sys_intern.timerid)
3fadfdf1 423#define w32_sighandler (PL_sys_intern.sigtable)
05ec9bb3
NIS
424#define w32_poll_count (PL_sys_intern.poll_count)
425#define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
3db8f154
MB
426#define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
427#define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
428#define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
429#define w32_servent (PL_sys_intern.thr_intern.Wservent)
430#define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
431#define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
432#define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
c53bd28a 433
7fac1903
GS
434/* UNICODE<>ANSI translation helpers */
435/* Use CP_ACP when mode is ANSI */
436/* Use CP_UTF8 when mode is UTF8 */
437
e9ff6d27 438#define A2WHELPER_LEN(lpa, alen, lpw, nBytes)\
c8f3d7f8 439 (lpw[0] = 0, MultiByteToWideChar((IN_BYTES) ? CP_ACP : CP_UTF8, 0, \
e9ff6d27
GS
440 lpa, alen, lpw, (nBytes/sizeof(WCHAR))))
441#define A2WHELPER(lpa, lpw, nBytes) A2WHELPER_LEN(lpa, -1, lpw, nBytes)
442
443#define W2AHELPER_LEN(lpw, wlen, lpa, nChars)\
c8f3d7f8 444 (lpa[0] = '\0', WideCharToMultiByte((IN_BYTES) ? CP_ACP : CP_UTF8, 0, \
e9ff6d27
GS
445 lpw, wlen, (LPSTR)lpa, nChars,NULL,NULL))
446#define W2AHELPER(lpw, lpa, nChars) W2AHELPER_LEN(lpw, -1, lpa, nChars)
7fac1903 447
581883cd 448#define USING_WIDE() (0)
7fac1903 449
7766f137
GS
450#ifdef USE_ITHREADS
451# define PERL_WAIT_FOR_CHILDREN \
452 STMT_START { \
453 if (w32_pseudo_children && w32_num_pseudo_children) { \
454 long children = w32_num_pseudo_children; \
455 WaitForMultipleObjects(children, \
456 w32_pseudo_child_handles, \
457 TRUE, INFINITE); \
458 while (children) \
459 CloseHandle(w32_pseudo_child_handles[--children]); \
460 } \
461 } STMT_END
462#endif
463
a10b7b7e
GS
464#if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
465#ifdef PERL_CORE
466
467/* C doesn't like repeat struct definitions */
468#ifndef _CRTIMP
469#define _CRTIMP __declspec(dllimport)
470#endif
471
472/*
473 * Control structure for lowio file handles
474 */
475typedef struct {
c623ac67 476 intptr_t osfhnd;/* underlying OS file HANDLE */
a10b7b7e
GS
477 char osfile; /* attributes of file (e.g., open in text mode?) */
478 char pipech; /* one char buffer for handles opened on pipes */
479 int lockinitflag;
480 CRITICAL_SECTION lock;
481} ioinfo;
482
483
484/*
485 * Array of arrays of control structures for lowio files.
486 */
487EXTERN_C _CRTIMP ioinfo* __pioinfo[];
488
489/*
490 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
491 * array of ioinfo structs.
492 */
493#define IOINFO_L2E 5
494
495/*
496 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
497 */
498#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
499
500/*
501 * Access macros for getting at an ioinfo struct and its fields from a
502 * file handle
503 */
504#define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
505#define _osfhnd(i) (_pioinfo(i)->osfhnd)
506#define _osfile(i) (_pioinfo(i)->osfile)
507#define _pipech(i) (_pioinfo(i)->pipech)
508
509/* since we are not doing a dup2(), this works fine */
c623ac67 510#define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
a10b7b7e
GS
511#endif
512#endif
513
3fadfdf1 514/* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
6e22d046
JH
515#if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
516#undef PERLIO_NOT_STDIO
517#endif
adb71456
NIS
518#define PERLIO_NOT_STDIO 0
519
520#include "perlio.h"
521
4f63d024
GS
522/*
523 * This provides a layer of functions and macros to ensure extensions will
524 * get to use the same RTL functions as the core.
525 */
526#include "win32iop.h"
527
b4748376
NIS
528#define EXEC_ARGV_CAST(x) ((const char *const *) x)
529
4fb841ef
NIS
530#if !defined(ECONNABORTED) && defined(WSAECONNABORTED)
531#define ECONNABORTED WSAECONNABORTED
532#endif
f2b62286
AT
533#if !defined(ECONNRESET) && defined(WSAECONNRESET)
534#define ECONNRESET WSAECONNRESET
535#endif
4fb841ef
NIS
536#if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT)
537#define EAFNOSUPPORT WSAEAFNOSUPPORT
538#endif
f2b62286 539/* Why not needed for ECONNREFUSED? --abe */
4fb841ef 540
f4958739 541DllExport void *win32_signal_context(void);
1018e26f
NIS
542#define PERL_GET_SIG_CONTEXT win32_signal_context()
543
68dc0745 544#endif /* _INC_WIN32_PERL5 */
7a9ec5a3 545