1 /*-------------------------------------------------------------------------
4 * dynamic loader for platforms without dlopen()
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
13 *-------------------------------------------------------------------------
25 dlopen(const char *file
, int mode
)
30 flags
|= BIND_IMMEDIATE
;
33 flags
|= BIND_DEFERRED
;
36 return shl_load(file
, flags
| BIND_VERBOSE
, 0L);
40 dlsym(void *handle
, const char *symbol
)
44 if (shl_findsym((shl_t
*) & handle
, symbol
, TYPE_PROCEDURE
, &value
) == -1)
52 return shl_unload((shl_t
) handle
);
58 static char errmsg
[] = "shl_load failed";
61 return strerror(errno
);
68 static char last_dyn_error
[512];
73 DWORD err
= GetLastError();
75 if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS
|
76 FORMAT_MESSAGE_FROM_SYSTEM
,
79 MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
),
81 sizeof(last_dyn_error
) - 1,
84 snprintf(last_dyn_error
, sizeof(last_dyn_error
) - 1,
85 "unknown error %lu", err
);
92 if (last_dyn_error
[0])
93 return last_dyn_error
;
101 if (!FreeLibrary((HMODULE
) handle
))
106 last_dyn_error
[0] = 0;
111 dlsym(void *handle
, const char *symbol
)
115 ptr
= GetProcAddress((HMODULE
) handle
, symbol
);
121 last_dyn_error
[0] = 0;
126 dlopen(const char *file
, int mode
)
131 /* Disable popup error messages when loading DLLs */
132 prevmode
= SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOOPENFILEERRORBOX
);
133 h
= LoadLibrary(file
);
134 SetErrorMode(prevmode
);
141 last_dyn_error
[0] = 0;