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