source: trunk/essentials/sys-apps/gawk/pc/dlfcn.c

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

File size: 2.2 KB
Line 
1/*
2** dlfcn.c -- limited implementation of posix dynamic loading functions
3*/
4
5/*
6 * Copyright (C) 2003 the Free Software Foundation, Inc.
7 *
8 * This file is part of GAWK, the GNU implementation of the
9 * AWK Programming Language.
10 *
11 * GAWK is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * GAWK is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <dlfcn.h>
27#include <errno.h>
28#include <windows.h>
29
30/* open the library file. We currently ignore flags. */
31void *dlopen(const char * libname, int flags)
32{
33 HMODULE libH;
34
35
36 /* if libname is specified, we need to load a library of that name */
37 if (libname) {
38 libH = LoadLibrary(libname);
39 }
40
41 /* otherwise, we're supposed to return a handle to global symbol
42 * information, which includes the executable and all libraries loaded
43 * with RTLD_GLOBAL. For our purposes, it doesn't really matter, so
44 * we simply return the handle to the .exe */
45 else {
46 libH = GetModuleHandle(NULL);
47 }
48
49 return (void *)libH;
50}
51
52
53/* don't need the library any more */
54int dlclose(void * libH)
55{
56 int rc;
57
58 if (FreeLibrary((HMODULE)libH)) {
59 rc = 0;
60 }
61 else {
62 rc = -1;
63 }
64
65 return rc;
66}
67
68/* find the symbol */
69void *dlsym(void * /*restrict*/ libH, const char * /*restrict*/ fnName)
70{
71 return (void *)GetProcAddress((HMODULE)libH, fnName);
72}
73
74char *dlerror(void)
75{
76 static char errbuf[1024];
77
78 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
79 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errbuf, sizeof(errbuf), NULL);
80
81 return errbuf;
82}
83
84
Note: See TracBrowser for help on using the repository browser.