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