1 /* -*- C -*- ***********************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
33 This library implements dlopen() - functions for OS/2 using
34 DosLoadModule() and company.
38 #define INCL_DOSERRORS
39 #define INCL_DOSSESMGR
40 #define INCL_WINPROGRAMLIST
41 #define INCL_WINFRAMEMGR
49 /*-------------------------------------- Unix-like dynamic linking emulation -*/
51 typedef struct _track_rec
{
55 struct _track_rec
*next
;
56 } tDLLchain
, *DLLchain
;
58 static DLLchain dlload
= NULL
; /* A simple chained list of DLL names */
59 static char dlerr
[256]; /* last error text string */
62 static DLLchain
find_id(void *id
)
66 for (tmp
= dlload
; tmp
; tmp
= tmp
->next
)
73 /* load a dynamic-link library and return handle */
74 void *dlopen (char *filename
, int flags
)
80 int rc
= 0, set_chain
= 0;
82 for (tmp
= dlload
; tmp
; tmp
= tmp
->next
)
83 if (strnicmp(tmp
->name
, filename
, 999) == 0)
88 tmp
= (DLLchain
)malloc (sizeof (tDLLchain
));
91 tmp
->name
= strdup (filename
);
96 switch (rc
= DosLoadModule((PSZ
)&err
, sizeof(err
), filename
, &hm
))
103 } while ((last_id
== 0) || (find_id(last_id
)));
108 case ERROR_FILE_NOT_FOUND
:
109 case ERROR_PATH_NOT_FOUND
:
110 errtxt
= "module `%s' not found";
112 case ERROR_TOO_MANY_OPEN_FILES
:
113 case ERROR_NOT_ENOUGH_MEMORY
:
114 case ERROR_SHARING_BUFFER_EXCEEDED
:
116 errtxt
= "out of system resources";
118 case ERROR_ACCESS_DENIED
:
119 errtxt
= "access denied";
121 case ERROR_BAD_FORMAT
:
122 case ERROR_INVALID_SEGMENT_NUMBER
:
123 case ERROR_INVALID_ORDINAL
:
124 case ERROR_INVALID_MODULETYPE
:
125 case ERROR_INVALID_EXE_SIGNATURE
:
126 case ERROR_EXE_MARKED_INVALID
:
127 case ERROR_ITERATED_DATA_EXCEEDS_64K
:
128 case ERROR_INVALID_MINALLOCSIZE
:
129 case ERROR_INVALID_SEGDPL
:
130 case ERROR_AUTODATASEG_EXCEEDS_64K
:
131 case ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
:
132 errtxt
= "invalid module format";
134 case ERROR_INVALID_NAME
:
135 errtxt
= "filename doesn't match module name";
137 case ERROR_SHARING_VIOLATION
:
138 case ERROR_LOCK_VIOLATION
:
139 errtxt
= "sharing violation";
141 case ERROR_INIT_ROUTINE_FAILED
:
142 errtxt
= "module initialization failed";
145 errtxt
= "cause `%s', error code = %d";
148 snprintf (dlerr
, sizeof (dlerr
), errtxt
, &err
, rc
);
157 /* return a pointer to the `symbol' in DLL */
158 void *dlsym (void *handle
, char *symbol
)
164 DLLchain tmp
= find_id (handle
);
170 symord
= atoi (symbol
+ 1);
172 switch (rc
= DosQueryProcAddr(tmp
->handle
, symord
, symbol
, &addr
))
175 return ((void *)addr
);
176 case ERROR_INVALID_HANDLE
:
178 errtxt
= "invalid module handle";
180 case ERROR_PROC_NOT_FOUND
:
181 case ERROR_INVALID_NAME
:
182 errtxt
= "no symbol `%s' in module";
185 errtxt
= "symbol `%s', error code = %d";
188 snprintf (dlerr
, sizeof (dlerr
), errtxt
, symbol
, rc
);
192 /* free dynamicaly-linked library */
193 int dlclose (void *handle
)
196 DLLchain tmp
= find_id (handle
);
201 switch (rc
= DosFreeModule (tmp
->handle
))
208 case ERROR_INVALID_HANDLE
:
210 strcpy(dlerr
, "invalid module handle");
212 case ERROR_INVALID_ACCESS
:
213 strcpy (dlerr
, "access denied");
220 /* return a string describing last occured dl error */