This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use the new utf8 to code point functions
[perl5.git] / cygwin / cygwin.c
CommitLineData
5db16f6a
FE
1/*
2 * Cygwin extras
3 */
4
5#include "EXTERN.h"
6#include "perl.h"
7#undef USE_DYNAMIC_LOADING
8#include "XSUB.h"
9
6b49d266 10#include <unistd.h>
b4bcd662 11#include <process.h>
49fd6edc 12#include <sys/cygwin.h>
803e389c 13#include <cygwin/version.h>
a25ce5f3 14#include <mntent.h>
6d7e4387 15#include <alloca.h>
9fb265f7 16#include <dlfcn.h>
803e389c
RU
17#if (CYGWIN_VERSION_API_MINOR >= 181)
18#include <wchar.h>
19#endif
5db16f6a 20
b4bcd662
GS
21/*
22 * pp_system() implemented via spawn()
23 * - more efficient and useful when embedding Perl in non-Cygwin apps
24 * - code mostly borrowed from djgpp.c
25 */
26static int
27do_spawnvp (const char *path, const char * const *argv)
28{
acfe0abc 29 dTHX;
b4bcd662
GS
30 Sigsave_t ihand,qhand;
31 int childpid, result, status;
32
ec1aec95
YST
33 rsignal_save(SIGINT, (Sighandler_t) SIG_IGN, &ihand);
34 rsignal_save(SIGQUIT, (Sighandler_t) SIG_IGN, &qhand);
b4bcd662
GS
35 childpid = spawnvp(_P_NOWAIT,path,argv);
36 if (childpid < 0) {
37 status = -1;
411caa50 38 if(ckWARN(WARN_EXEC))
f98bc0c6 39 Perl_warner(aTHX_ packWARN(WARN_EXEC),"Can't spawn \"%s\": %s",
b4bcd662 40 path,Strerror (errno));
b4bcd662
GS
41 } else {
42 do {
43 result = wait4pid(childpid, &status, 0);
44 } while (result == -1 && errno == EINTR);
45 if(result < 0)
46 status = -1;
47 }
48 (void)rsignal_restore(SIGINT, &ihand);
49 (void)rsignal_restore(SIGQUIT, &qhand);
50 return status;
51}
52
53int
54do_aspawn (SV *really, void **mark, void **sp)
55{
acfe0abc 56 dTHX;
b4bcd662 57 int rc;
a4ec4e68
JHR
58 char const **a;
59 char *tmps,**argv;
60 STRLEN n_a;
b4bcd662
GS
61
62 if (sp<=mark)
63 return -1;
a4ec4e68
JHR
64 argv=(char**) alloca ((sp-mark+3)*sizeof (char*));
65 a=(char const **)argv;
b4bcd662
GS
66
67 while (++mark <= sp)
68 if (*mark)
667e2948 69 *a++ = SvPVx((SV *)*mark, n_a);
b4bcd662
GS
70 else
71 *a++ = "";
dfe169ee 72 *a = (char*)NULL;
b4bcd662
GS
73
74 if (argv[0][0] != '/' && argv[0][0] != '\\'
75 && !(argv[0][0] && argv[0][1] == ':'
76 && (argv[0][2] == '/' || argv[0][2] != '\\'))
77 ) /* will swawnvp use PATH? */
78 TAINT_ENV(); /* testing IFS here is overkill, probably */
79
80 if (really && *(tmps = SvPV(really, n_a)))
81 rc=do_spawnvp (tmps,(const char * const *)argv);
82 else
83 rc=do_spawnvp (argv[0],(const char *const *)argv);
84
85 return rc;
86}
87
88int
89do_spawn (char *cmd)
90{
acfe0abc 91 dTHX;
3f5211dd 92 char const **a;
a4ec4e68
JHR
93 char *s;
94 char const *metachars = "$&*(){}[]'\";\\?>|<~`\n";
b4bcd662
GS
95 const char *command[4];
96
97 while (*cmd && isSPACE(*cmd))
98 cmd++;
99
100 if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7]))
101 cmd+=5;
102
103 /* save an extra exec if possible */
104 /* see if there are shell metacharacters in it */
105 if (strstr (cmd,"..."))
106 goto doshell;
107 if (*cmd=='.' && isSPACE (cmd[1]))
108 goto doshell;
109 if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4]))
110 goto doshell;
111 for (s=cmd; *s && isALPHA (*s); s++) ; /* catch VAR=val gizmo */
112 if (*s=='=')
113 goto doshell;
114
115 for (s=cmd; *s; s++)
116 if (strchr (metachars,*s))
117 {
118 if (*s=='\n' && s[1]=='\0')
119 {
120 *s='\0';
121 break;
122 }
123 doshell:
124 command[0] = "sh";
125 command[1] = "-c";
126 command[2] = cmd;
127 command[3] = NULL;
128
129 return do_spawnvp("sh",command);
130 }
131
803e389c 132 Newx (PL_Argv,(s-cmd)/2+2,char*);
b4bcd662
GS
133 PL_Cmd=savepvn (cmd,s-cmd);
134 a=PL_Argv;
135 for (s=PL_Cmd; *s;) {
136 while (*s && isSPACE (*s)) s++;
137 if (*s)
138 *(a++)=s;
139 while (*s && !isSPACE (*s)) s++;
140 if (*s)
141 *s++='\0';
142 }
dfe169ee 143 *a = (char*)NULL;
b4bcd662
GS
144 if (!PL_Argv[0])
145 return -1;
146
147 return do_spawnvp(PL_Argv[0],(const char * const *)PL_Argv);
148}
5db16f6a 149
803e389c
RU
150#if (CYGWIN_VERSION_API_MINOR >= 181)
151char*
152wide_to_utf8(const wchar_t *wbuf)
153{
154 char *buf;
155 int wlen = 0;
156 char *oldlocale = setlocale(LC_CTYPE, NULL);
157 setlocale(LC_CTYPE, "utf-8");
158
159 /* uvuni_to_utf8(buf, chr) or Encoding::_bytes_to_utf8(sv, "UCS-2BE"); */
160 wlen = wcsrtombs(NULL, (const wchar_t **)&wbuf, wlen, NULL);
161 buf = (char *) safemalloc(wlen+1);
162 wcsrtombs(buf, (const wchar_t **)&wbuf, wlen, NULL);
163
164 if (oldlocale) setlocale(LC_CTYPE, oldlocale);
165 else setlocale(LC_CTYPE, "C");
166 return buf;
167}
168
169wchar_t*
170utf8_to_wide(const char *buf)
171{
172 wchar_t *wbuf;
173 mbstate_t mbs;
174 char *oldlocale = setlocale(LC_CTYPE, NULL);
175 int wlen = sizeof(wchar_t)*strlen(buf);
176
177 setlocale(LC_CTYPE, "utf-8");
178 wbuf = (wchar_t *) safemalloc(wlen);
4b88fb76 179 /* utf8_to_uvuni_buf(pathname, pathname + wlen, wpath) or Encoding::_utf8_to_bytes(sv, "UCS-2BE"); */
803e389c
RU
180 wlen = mbsrtowcs(wbuf, (const char**)&buf, wlen, &mbs);
181
182 if (oldlocale) setlocale(LC_CTYPE, oldlocale);
183 else setlocale(LC_CTYPE, "C");
184 return wbuf;
185}
186#endif /* cygwin 1.7 */
187
5db16f6a 188/* see also Cwd.pm */
5db16f6a
FE
189XS(Cygwin_cwd)
190{
191 dXSARGS;
192 char *cwd;
193
482150a7
JH
194 /* See http://rt.perl.org/rt3/Ticket/Display.html?id=38628
195 There is Cwd->cwd() usage in the wild, and previous versions didn't die.
196 */
197 if(items > 1)
5db16f6a 198 Perl_croak(aTHX_ "Usage: Cwd::cwd()");
47dafe4d 199 if((cwd = getcwd(NULL, -1))) {
5db16f6a 200 ST(0) = sv_2mortal(newSVpv(cwd, 0));
a236cecb 201 free(cwd);
6be3b590
JH
202#ifndef INCOMPLETE_TAINTS
203 SvTAINTED_on(ST(0));
204#endif
5db16f6a
FE
205 XSRETURN(1);
206 }
207 XSRETURN_UNDEF;
208}
209
49fd6edc
YST
210XS(XS_Cygwin_pid_to_winpid)
211{
212 dXSARGS;
d2dc0126
YST
213 dXSTARG;
214 pid_t pid, RETVAL;
215
49fd6edc
YST
216 if (items != 1)
217 Perl_croak(aTHX_ "Usage: Cygwin::pid_to_winpid(pid)");
d2dc0126
YST
218
219 pid = (pid_t)SvIV(ST(0));
220
49fd6edc
YST
221 if ((RETVAL = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid)) > 0) {
222 XSprePUSH; PUSHi((IV)RETVAL);
223 XSRETURN(1);
224 }
225 XSRETURN_UNDEF;
226}
227
49fd6edc
YST
228XS(XS_Cygwin_winpid_to_pid)
229{
230 dXSARGS;
d2dc0126
YST
231 dXSTARG;
232 pid_t pid, RETVAL;
233
49fd6edc
YST
234 if (items != 1)
235 Perl_croak(aTHX_ "Usage: Cygwin::winpid_to_pid(pid)");
d2dc0126
YST
236
237 pid = (pid_t)SvIV(ST(0));
238
803e389c
RU
239#if (CYGWIN_VERSION_API_MINOR >= 181)
240 RETVAL = cygwin_winpid_to_pid(pid);
241#else
242 RETVAL = cygwin32_winpid_to_pid(pid);
243#endif
244 if (RETVAL > 0) {
49fd6edc
YST
245 XSprePUSH; PUSHi((IV)RETVAL);
246 XSRETURN(1);
247 }
248 XSRETURN_UNDEF;
249}
250
15414d2b 251XS(XS_Cygwin_win_to_posix_path)
803e389c 252
15414d2b
RU
253{
254 dXSARGS;
255 int absolute_flag = 0;
256 STRLEN len;
257 int err;
803e389c
RU
258 char *src_path;
259 char *posix_path;
260 int isutf8 = 0;
15414d2b
RU
261
262 if (items < 1 || items > 2)
263 Perl_croak(aTHX_ "Usage: Cygwin::win_to_posix_path(pathname, [absolute])");
264
803e389c 265 src_path = SvPV(ST(0), len);
15414d2b
RU
266 if (items == 2)
267 absolute_flag = SvTRUE(ST(1));
268
269 if (!len)
270 Perl_croak(aTHX_ "can't convert empty path");
803e389c 271 isutf8 = SvUTF8(ST(0));
15414d2b 272
803e389c
RU
273#if (CYGWIN_VERSION_API_MINOR >= 181)
274 /* Check utf8 flag and use wide api then.
275 Size calculation: On overflow let cygwin_conv_path calculate the final size.
276 */
277 if (isutf8) {
278 int what = absolute_flag ? CCP_WIN_W_TO_POSIX : CCP_WIN_W_TO_POSIX | CCP_RELATIVE;
279 int wlen = sizeof(wchar_t)*(len + 260 + 1001);
280 wchar_t *wpath = (wchar_t *) safemalloc(sizeof(wchar_t)*len);
281 wchar_t *wbuf = (wchar_t *) safemalloc(wlen);
282 if (!IN_BYTES) {
283 mbstate_t mbs;
284 char *oldlocale = setlocale(LC_CTYPE, NULL);
285 setlocale(LC_CTYPE, "utf-8");
4b88fb76 286 /* utf8_to_uvuni_buf(src_path, src_path + wlen, wpath) or Encoding::_utf8_to_bytes(sv, "UCS-2BE"); */
803e389c
RU
287 wlen = mbsrtowcs(wpath, (const char**)&src_path, wlen, &mbs);
288 if (wlen > 0)
289 err = cygwin_conv_path(what, wpath, wbuf, wlen);
290 if (oldlocale) setlocale(LC_CTYPE, oldlocale);
291 else setlocale(LC_CTYPE, "C");
292 } else { /* use bytes; assume already ucs-2 encoded bytestream */
293 err = cygwin_conv_path(what, src_path, wbuf, wlen);
294 }
295 if (err == ENOSPC) { /* our space assumption was wrong, not enough space */
296 int newlen = cygwin_conv_path(what, wpath, wbuf, 0);
297 wbuf = (wchar_t *) realloc(&wbuf, newlen);
298 err = cygwin_conv_path(what, wpath, wbuf, newlen);
299 wlen = newlen;
300 }
301 /* utf16_to_utf8(*p, *d, bytlen, *newlen) */
302 posix_path = (char *) safemalloc(wlen*3);
303 Perl_utf16_to_utf8(aTHX_ (U8*)&wpath, (U8*)posix_path, (I32)wlen*2, (I32*)&len);
304 /*
305 wlen = wcsrtombs(NULL, (const wchar_t **)&wbuf, wlen, NULL);
306 posix_path = (char *) safemalloc(wlen+1);
307 wcsrtombs(posix_path, (const wchar_t **)&wbuf, wlen, NULL);
308 */
309 } else {
310 int what = absolute_flag ? CCP_WIN_A_TO_POSIX : CCP_WIN_A_TO_POSIX | CCP_RELATIVE;
311 posix_path = (char *) safemalloc (len + 260 + 1001);
312 err = cygwin_conv_path(what, src_path, posix_path, len + 260 + 1001);
313 if (err == ENOSPC) { /* our space assumption was wrong, not enough space */
314 int newlen = cygwin_conv_path(what, src_path, posix_path, 0);
315 posix_path = (char *) realloc(&posix_path, newlen);
316 err = cygwin_conv_path(what, src_path, posix_path, newlen);
317 }
318 }
319#else
320 posix_path = (char *) safemalloc (len + 260 + 1001);
15414d2b 321 if (absolute_flag)
803e389c 322 err = cygwin_conv_to_full_posix_path(src_path, posix_path);
15414d2b 323 else
803e389c
RU
324 err = cygwin_conv_to_posix_path(src_path, posix_path);
325#endif
15414d2b 326 if (!err) {
803e389c
RU
327 EXTEND(SP, 1);
328 ST(0) = sv_2mortal(newSVpv(posix_path, 0));
329 if (isutf8) { /* src was utf-8, so result should also */
330 /* TODO: convert ANSI (local windows encoding) to utf-8 on cygwin-1.5 */
331 SvUTF8_on(ST(0));
332 }
333 safefree(posix_path);
334 XSRETURN(1);
15414d2b 335 } else {
803e389c 336 safefree(posix_path);
15414d2b
RU
337 XSRETURN_UNDEF;
338 }
339}
340
341XS(XS_Cygwin_posix_to_win_path)
342{
343 dXSARGS;
344 int absolute_flag = 0;
345 STRLEN len;
346 int err;
803e389c
RU
347 char *src_path, *win_path;
348 int isutf8 = 0;
15414d2b
RU
349
350 if (items < 1 || items > 2)
351 Perl_croak(aTHX_ "Usage: Cygwin::posix_to_win_path(pathname, [absolute])");
352
803e389c 353 src_path = SvPVx(ST(0), len);
15414d2b
RU
354 if (items == 2)
355 absolute_flag = SvTRUE(ST(1));
356
357 if (!len)
358 Perl_croak(aTHX_ "can't convert empty path");
803e389c
RU
359 isutf8 = SvUTF8(ST(0));
360#if (CYGWIN_VERSION_API_MINOR >= 181)
361 /* Check utf8 flag and use wide api then.
362 Size calculation: On overflow let cygwin_conv_path calculate the final size.
363 */
364 if (isutf8) {
365 int what = absolute_flag ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_W | CCP_RELATIVE;
366 int wlen = sizeof(wchar_t)*(len + 260 + 1001);
367 wchar_t *wpath = (wchar_t *) safemalloc(sizeof(wchar_t)*len);
368 wchar_t *wbuf = (wchar_t *) safemalloc(wlen);
369 char *oldlocale = setlocale(LC_CTYPE, NULL);
370 setlocale(LC_CTYPE, "utf-8");
371 if (!IN_BYTES) {
372 mbstate_t mbs;
4b88fb76 373 /* utf8_to_uvuni_buf(src_path, src_path + wlen, wpath) or Encoding::_utf8_to_bytes(sv, "UCS-2BE"); */
803e389c
RU
374 wlen = mbsrtowcs(wpath, (const char**)&src_path, wlen, &mbs);
375 if (wlen > 0)
376 err = cygwin_conv_path(what, wpath, wbuf, wlen);
377 } else { /* use bytes; assume already ucs-2 encoded bytestream */
378 err = cygwin_conv_path(what, src_path, wbuf, wlen);
379 }
380 if (err == ENOSPC) { /* our space assumption was wrong, not enough space */
381 int newlen = cygwin_conv_path(what, wpath, wbuf, 0);
382 wbuf = (wchar_t *) realloc(&wbuf, newlen);
383 err = cygwin_conv_path(what, wpath, wbuf, newlen);
384 wlen = newlen;
385 }
386 /* also see utf8.c: Perl_utf16_to_utf8() or Encoding::_bytes_to_utf8(sv, "UCS-2BE"); */
387 wlen = wcsrtombs(NULL, (const wchar_t **)&wbuf, wlen, NULL);
388 win_path = (char *) safemalloc(wlen+1);
389 wcsrtombs(win_path, (const wchar_t **)&wbuf, wlen, NULL);
390 if (oldlocale) setlocale(LC_CTYPE, oldlocale);
391 else setlocale(LC_CTYPE, "C");
392 } else {
393 int what = absolute_flag ? CCP_POSIX_TO_WIN_A : CCP_POSIX_TO_WIN_A | CCP_RELATIVE;
394 win_path = (char *) safemalloc(len + 260 + 1001);
395 err = cygwin_conv_path(what, src_path, win_path, len + 260 + 1001);
396 if (err == ENOSPC) { /* our space assumption was wrong, not enough space */
397 int newlen = cygwin_conv_path(what, src_path, win_path, 0);
398 win_path = (char *) realloc(&win_path, newlen);
399 err = cygwin_conv_path(what, src_path, win_path, newlen);
400 }
401 }
402#else
403 if (isutf8)
404 Perl_warn(aTHX_ "can't convert utf8 path");
405 win_path = (char *) safemalloc(len + 260 + 1001);
15414d2b 406 if (absolute_flag)
803e389c 407 err = cygwin_conv_to_full_win32_path(src_path, win_path);
15414d2b 408 else
803e389c
RU
409 err = cygwin_conv_to_win32_path(src_path, win_path);
410#endif
15414d2b 411 if (!err) {
803e389c
RU
412 EXTEND(SP, 1);
413 ST(0) = sv_2mortal(newSVpv(win_path, 0));
414 if (isutf8) {
415 SvUTF8_on(ST(0));
416 }
417 safefree(win_path);
418 XSRETURN(1);
15414d2b 419 } else {
803e389c 420 safefree(win_path);
15414d2b
RU
421 XSRETURN_UNDEF;
422 }
423}
424
a25ce5f3
RU
425XS(XS_Cygwin_mount_table)
426{
427 dXSARGS;
428 struct mntent *mnt;
429
430 if (items != 0)
431 Perl_croak(aTHX_ "Usage: Cygwin::mount_table");
432 /* => array of [mnt_dir mnt_fsname mnt_type mnt_opts] */
433
434 setmntent (0, 0);
435 while ((mnt = getmntent (0))) {
436 AV* av = newAV();
437 av_push(av, newSVpvn(mnt->mnt_dir, strlen(mnt->mnt_dir)));
438 av_push(av, newSVpvn(mnt->mnt_fsname, strlen(mnt->mnt_fsname)));
439 av_push(av, newSVpvn(mnt->mnt_type, strlen(mnt->mnt_type)));
440 av_push(av, newSVpvn(mnt->mnt_opts, strlen(mnt->mnt_opts)));
441 XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
442 }
443 endmntent (0);
444 PUTBACK;
445}
446
447XS(XS_Cygwin_mount_flags)
448{
449 dXSARGS;
450 char *pathname;
803e389c
RU
451 char flags[PATH_MAX];
452 flags[0] = '\0';
a25ce5f3
RU
453
454 if (items != 1)
803e389c 455 Perl_croak(aTHX_ "Usage: Cygwin::mount_flags( mnt_dir | '/cygdrive' )");
a25ce5f3
RU
456
457 pathname = SvPV_nolen(ST(0));
74dc058d 458
a25ce5f3 459 if (!strcmp(pathname, "/cygdrive")) {
803e389c
RU
460 char user[PATH_MAX];
461 char system[PATH_MAX];
462 char user_flags[PATH_MAX];
463 char system_flags[PATH_MAX];
74dc058d 464
803e389c
RU
465 cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system,
466 user_flags, system_flags);
74dc058d
JH
467
468 if (strlen(user) > 0) {
469 sprintf(flags, "%s,cygdrive,%s", user_flags, user);
470 } else {
471 sprintf(flags, "%s,cygdrive,%s", system_flags, system);
472 }
473
a25ce5f3
RU
474 ST(0) = sv_2mortal(newSVpv(flags, 0));
475 XSRETURN(1);
74dc058d 476
a25ce5f3
RU
477 } else {
478 struct mntent *mnt;
803e389c 479 int found = 0;
a25ce5f3
RU
480 setmntent (0, 0);
481 while ((mnt = getmntent (0))) {
482 if (!strcmp(pathname, mnt->mnt_dir)) {
483 strcpy(flags, mnt->mnt_type);
484 if (strlen(mnt->mnt_opts) > 0) {
485 strcat(flags, ",");
486 strcat(flags, mnt->mnt_opts);
487 }
803e389c 488 found++;
a25ce5f3
RU
489 break;
490 }
491 }
492 endmntent (0);
803e389c
RU
493
494 /* Check if arg is the current volume moint point if not default,
495 * and then use CW_GET_CYGDRIVE_INFO also.
496 */
497 if (!found) {
498 char user[PATH_MAX];
499 char system[PATH_MAX];
500 char user_flags[PATH_MAX];
501 char system_flags[PATH_MAX];
502
503 cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system,
504 user_flags, system_flags);
505
506 if (strlen(user) > 0) {
507 if (strcmp(user,pathname)) {
508 sprintf(flags, "%s,cygdrive,%s", user_flags, user);
509 found++;
510 }
511 } else {
512 if (strcmp(user,pathname)) {
513 sprintf(flags, "%s,cygdrive,%s", system_flags, system);
514 found++;
515 }
516 }
517 }
518 if (found) {
519 ST(0) = sv_2mortal(newSVpv(flags, 0));
520 XSRETURN(1);
521 } else {
522 XSRETURN_UNDEF;
523 }
a25ce5f3
RU
524 }
525}
526
15414d2b
RU
527XS(XS_Cygwin_is_binmount)
528{
529 dXSARGS;
530 char *pathname;
531
532 if (items != 1)
533 Perl_croak(aTHX_ "Usage: Cygwin::is_binmount(pathname)");
534
535 pathname = SvPV_nolen(ST(0));
536
537 ST(0) = boolSV(cygwin_internal(CW_GET_BINMODE, pathname));
538 XSRETURN(1);
539}
540
286f8194
RU
541XS(XS_Cygwin_sync_winenv){ cygwin_internal(CW_SYNC_WINENV); }
542
5db16f6a
FE
543void
544init_os_extras(void)
545{
5db16f6a 546 dTHX;
a4ec4e68 547 char const *file = __FILE__;
9fb265f7 548 void *handle;
5db16f6a
FE
549
550 newXS("Cwd::cwd", Cygwin_cwd, file);
15414d2b
RU
551 newXSproto("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file, "$");
552 newXSproto("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file, "$");
553 newXSproto("Cygwin::win_to_posix_path", XS_Cygwin_win_to_posix_path, file, "$;$");
554 newXSproto("Cygwin::posix_to_win_path", XS_Cygwin_posix_to_win_path, file, "$;$");
a25ce5f3
RU
555 newXSproto("Cygwin::mount_table", XS_Cygwin_mount_table, file, "");
556 newXSproto("Cygwin::mount_flags", XS_Cygwin_mount_flags, file, "$");
15414d2b 557 newXSproto("Cygwin::is_binmount", XS_Cygwin_is_binmount, file, "$");
286f8194 558 newXS("Cygwin::sync_winenv", XS_Cygwin_sync_winenv, file);
78ff2d7b 559
9fb265f7
JD
560 /* Initialize Win32CORE if it has been statically linked. */
561 handle = dlopen(NULL, RTLD_LAZY);
562 if (handle) {
563 void (*pfn_init)(pTHX);
564 pfn_init = (void (*)(pTHX))dlsym(handle, "init_Win32CORE");
565 if (pfn_init)
566 pfn_init(aTHX);
567 dlclose(handle);
78ff2d7b 568 }
5db16f6a 569}