This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Disable lexical $_
[perl5.git] / ext / Win32CORE / Win32CORE.c
CommitLineData
78ff2d7b
YST
1/* Win32CORE.c
2 *
3 * Copyright (C) 2007 by Larry Wall and others
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 */
9
ef3b47fb
JH
10#define WIN32_LEAN_AND_MEAN
11#include <windows.h>
12
b1d302cb
RU
13#if defined(__CYGWIN__) && !defined(USEIMPORTLIB)
14 #undef WIN32
15#endif
2e94d732 16#define PERL_NO_GET_CONTEXT
78ff2d7b 17#include "EXTERN.h"
b1d302cb
RU
18#if defined(__CYGWIN__) && !defined(USEIMPORTLIB)
19 #define EXTCONST extern const
20#endif
78ff2d7b
YST
21#include "perl.h"
22#include "XSUB.h"
23
35f601d9
DD
24
25XS(w32_CORE_all){
f418f5b2
TC
26 /* I'd use dSAVE_ERRNO() here, but it doesn't save the Win32 error code
27 * under cygwin, if that changes this code should change to use that.
28 */
29 int saved_errno = errno;
dcd628c7 30 DWORD err = GetLastError();
35f601d9
DD
31 /* capture the XSANY value before Perl_load_module, the CV's any member will
32 * be overwritten by Perl_load_module and subsequent newXSes or pure perl
33 * subs
34 */
35 const char *function = (const char *) XSANY.any_ptr;
c2b90b61 36 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, newSVpvs("Win32"), newSVnv(0.27));
dcd628c7 37 SetLastError(err);
f418f5b2 38 errno = saved_errno;
23d1ca42 39 /* mark and SP from caller are passed through unchanged */
78ff2d7b
YST
40 call_pv(function, GIMME_V);
41}
42
e18249a5 43XS_EXTERNAL(boot_Win32CORE)
78ff2d7b 44{
9fb265f7
JD
45 /* This function only exists because writemain.SH, lib/ExtUtils/Embed.pm
46 * and win32/buildext.pl will all generate references to it. The function
47 * should never be called though, as Win32CORE.pm doesn't use DynaLoader.
48 */
49}
e4524c4c
DD
50
51EXTERN_C
903f2d70 52#if !defined(__CYGWIN__) || defined(USEIMPORTLIB)
9fb265f7
JD
53__declspec(dllexport)
54#endif
55void
56init_Win32CORE(pTHX)
57{
58 /* This function is called from init_os_extras(). The Perl interpreter
59 * is not yet fully initialized, so don't do anything fancy in here.
60 */
61
35f601d9
DD
62 static const struct {
63 char Win32__GetCwd [sizeof("Win32::GetCwd")];
64 char Win32__SetCwd [sizeof("Win32::SetCwd")];
65 char Win32__GetNextAvailDrive [sizeof("Win32::GetNextAvailDrive")];
66 char Win32__GetLastError [sizeof("Win32::GetLastError")];
67 char Win32__SetLastError [sizeof("Win32::SetLastError")];
68 char Win32__LoginName [sizeof("Win32::LoginName")];
69 char Win32__NodeName [sizeof("Win32::NodeName")];
70 char Win32__DomainName [sizeof("Win32::DomainName")];
71 char Win32__FsType [sizeof("Win32::FsType")];
72 char Win32__GetOSVersion [sizeof("Win32::GetOSVersion")];
73 char Win32__IsWinNT [sizeof("Win32::IsWinNT")];
74 char Win32__IsWin95 [sizeof("Win32::IsWin95")];
75 char Win32__FormatMessage [sizeof("Win32::FormatMessage")];
76 char Win32__Spawn [sizeof("Win32::Spawn")];
77 char Win32__GetTickCount [sizeof("Win32::GetTickCount")];
78 char Win32__GetShortPathName [sizeof("Win32::GetShortPathName")];
79 char Win32__GetFullPathName [sizeof("Win32::GetFullPathName")];
80 char Win32__GetLongPathName [sizeof("Win32::GetLongPathName")];
81 char Win32__CopyFile [sizeof("Win32::CopyFile")];
82 char Win32__Sleep [sizeof("Win32::Sleep")];
83 } fnname_table = {
84 "Win32::GetCwd",
85 "Win32::SetCwd",
86 "Win32::GetNextAvailDrive",
87 "Win32::GetLastError",
88 "Win32::SetLastError",
89 "Win32::LoginName",
90 "Win32::NodeName",
91 "Win32::DomainName",
92 "Win32::FsType",
93 "Win32::GetOSVersion",
94 "Win32::IsWinNT",
95 "Win32::IsWin95",
96 "Win32::FormatMessage",
97 "Win32::Spawn",
98 "Win32::GetTickCount",
99 "Win32::GetShortPathName",
100 "Win32::GetFullPathName",
101 "Win32::GetLongPathName",
102 "Win32::CopyFile",
103 "Win32::Sleep"
104 };
105
106 static const unsigned char fnname_lens [] = {
107 sizeof("Win32::GetCwd"),
108 sizeof("Win32::SetCwd"),
109 sizeof("Win32::GetNextAvailDrive"),
110 sizeof("Win32::GetLastError"),
111 sizeof("Win32::SetLastError"),
112 sizeof("Win32::LoginName"),
113 sizeof("Win32::NodeName"),
114 sizeof("Win32::DomainName"),
115 sizeof("Win32::FsType"),
116 sizeof("Win32::GetOSVersion"),
117 sizeof("Win32::IsWinNT"),
118 sizeof("Win32::IsWin95"),
119 sizeof("Win32::FormatMessage"),
120 sizeof("Win32::Spawn"),
121 sizeof("Win32::GetTickCount"),
122 sizeof("Win32::GetShortPathName"),
123 sizeof("Win32::GetFullPathName"),
124 sizeof("Win32::GetLongPathName"),
125 sizeof("Win32::CopyFile"),
126 sizeof("Win32::Sleep")
127 };
128 const unsigned char * len = (const unsigned char *)&fnname_lens;
129 const char * function = (char *)&fnname_table;
130 while (function < (char *)&fnname_table + sizeof(fnname_table)) {
131 const char * const file = __FILE__;
132 CV * const cv = newXS(function, w32_CORE_all, file);
133 XSANY.any_ptr = (void *)function;
134 function += *len++;
135 }
78ff2d7b 136
35f601d9
DD
137
138 /* Don't forward Win32::SetChildShowWindow(). It accesses the internal variable
139 * w32_showwindow in thread_intern and is therefore not implemented in Win32.xs.
140 */
78ff2d7b 141 /* newXS("Win32::SetChildShowWindow", w32_SetChildShowWindow, file); */
78ff2d7b 142}