This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
some compatibility macros were busted
[perl5.git] / ext / DynaLoader / dl_cygwin.xs
CommitLineData
2c2d71f5 1/* dl_cygwin.xs
5aabfad6
PP
2 *
3 * Platform: Win32 (Windows NT/Windows 95)
4 * Author: Wei-Yuen Tan (wyt@hip.com)
5 * Created: A warm day in June, 1995
6 *
7 * Modified:
8 * August 23rd 1995 - rewritten after losing everything when I
9 * wiped off my NT partition (eek!)
10 */
2c2d71f5 11/* Modified from the original dl_win32.xs to work with cygwin
5aabfad6
PP
12 -John Cerney 3/26/97
13*/
14/* Porting notes:
15
16I merely took Paul's dl_dlopen.xs, took out extraneous stuff and
17replaced the appropriate SunOS calls with the corresponding Win32
18calls.
19
20*/
21
22#define WIN32_LEAN_AND_MEAN
23// Defines from windows needed for this function only. Can't include full
2c2d71f5 24// Cygwin windows headers because of problems with CONTEXT redefinition
5aabfad6
PP
25// Removed logic to tell not dynamically load static modules. It is assumed that all
26// modules are dynamically built. This should be similar to the behavoir on sunOS.
27// Leaving in the logic would have required changes to the standard perlmain.c code
28//
5aabfad6 29#include <stdio.h>
5aabfad6
PP
30
31//#include <windows.h>
32#define LOAD_WITH_ALTERED_SEARCH_PATH (8)
33typedef void *HANDLE;
34typedef HANDLE HINSTANCE;
35#define STDCALL __attribute__ ((stdcall))
36typedef int STDCALL (*FARPROC)();
f89d6eaa 37#define MAX_PATH 260
5aabfad6
PP
38
39HINSTANCE
40STDCALL
41LoadLibraryExA(
42 char* lpLibFileName,
43 HANDLE hFile,
44 unsigned int dwFlags
45 );
46unsigned int
47STDCALL
48GetLastError(
49 void
50 );
51FARPROC
52STDCALL
53GetProcAddress(
54 HINSTANCE hModule,
55 char* lpProcName
56 );
57
58#include <string.h>
59
60#include "EXTERN.h"
61#include "perl.h"
62#include "XSUB.h"
63
64#include "dlutils.c" /* SaveError() etc */
65
66static void
cea2e8a9 67dl_private_init(pTHX)
5aabfad6 68{
cea2e8a9 69 (void)dl_generic_private_init(aTHX);
5aabfad6
PP
70}
71
72
73MODULE = DynaLoader PACKAGE = DynaLoader
74
75BOOT:
cea2e8a9 76 (void)dl_private_init(aTHX);
5aabfad6
PP
77
78void *
79dl_load_file(filename,flags=0)
80 char * filename
81 int flags
82 PREINIT:
83 CODE:
f89d6eaa
FE
84 {
85 char win32_path[MAX_PATH];
86 cygwin_conv_to_full_win32_path(filename, win32_path);
87 filename = win32_path;
88
c78749f2 89 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(),"dl_load_file(%s):\n", filename));
5aabfad6
PP
90
91 RETVAL = (void*) LoadLibraryExA(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ;
92
c78749f2 93 DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," libref=%x\n", RETVAL));
5aabfad6
PP
94 ST(0) = sv_newmortal() ;
95 if (RETVAL == NULL){
cea2e8a9 96 SaveError(aTHX_ "%d",GetLastError()) ;
f89d6eaa 97 } else {
3175b8cd 98 sv_setiv( ST(0), PTR2IV(RETVAL) );
5aabfad6 99 }
5aabfad6
PP
100 }
101
102
103
104void *
105dl_find_symbol(libhandle, symbolname)
106 void * libhandle
107 char * symbolname
108 CODE:
c78749f2 109 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_find_symbol(handle=%x, symbol=%s)\n",
5aabfad6
PP
110 libhandle, symbolname));
111 RETVAL = (void*) GetProcAddress((HINSTANCE) libhandle, symbolname);
c78749f2 112 DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," symbolref = %x\n", RETVAL));
5aabfad6
PP
113 ST(0) = sv_newmortal() ;
114 if (RETVAL == NULL)
cea2e8a9 115 SaveError(aTHX_ "%d",GetLastError()) ;
5aabfad6 116 else
f66f545a 117 sv_setiv( ST(0), PTR2IV(RETVAL));
5aabfad6
PP
118
119
120void
121dl_undef_symbols()
122 PPCODE:
123
124
125
126# These functions should not need changing on any platform:
127
128void
129dl_install_xsub(perl_name, symref, filename="$Package")
130 char * perl_name
131 void * symref
132 char * filename
133 CODE:
c78749f2 134 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_install_xsub(name=%s, symref=%x)\n",
5aabfad6 135 perl_name, symref));
cea2e8a9
GS
136 ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name,
137 (void(*)(pTHX_ CV *))symref,
138 filename)));
5aabfad6
PP
139
140
141char *
142dl_error()
143 CODE:
144 RETVAL = LastError ;
145 OUTPUT:
146 RETVAL
147
148# end.