Consistently use "superuser" instead of "super user"
[pgsql.git] / src / port / dlopen.c
blobf7948b861f0061ae289758761f0d88eaed85b125
1 /*-------------------------------------------------------------------------
3 * dlopen.c
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
10 * IDENTIFICATION
11 * src/port/dlopen.c
13 *-------------------------------------------------------------------------
16 #include "c.h"
18 #if defined(__hpux)
20 /* System includes */
21 #include <a.out.h>
22 #include <dl.h>
24 void *
25 dlopen(const char *file, int mode)
27 int flags = 0;
29 if (mode & RTLD_NOW)
30 flags |= BIND_IMMEDIATE;
31 #ifdef NOT_USED
32 if (mode & RTLD_LAZY)
33 flags |= BIND_DEFERRED;
34 #endif
36 return shl_load(file, flags | BIND_VERBOSE, 0L);
39 void *
40 dlsym(void *handle, const char *symbol)
42 void *value;
44 if (shl_findsym((shl_t *) & handle, symbol, TYPE_PROCEDURE, &value) == -1)
45 return NULL;
46 return value;
49 int
50 dlclose(void *handle)
52 return shl_unload((shl_t) handle);
55 char *
56 dlerror(void)
58 static char errmsg[] = "shl_load failed";
60 if (errno)
61 return strerror(errno);
63 return errmsg;
66 #elif defined(WIN32)
68 static char last_dyn_error[512];
70 static void
71 set_dl_error(void)
73 DWORD err = GetLastError();
75 if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
76 FORMAT_MESSAGE_FROM_SYSTEM,
77 NULL,
78 err,
79 MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
80 last_dyn_error,
81 sizeof(last_dyn_error) - 1,
82 NULL) == 0)
84 snprintf(last_dyn_error, sizeof(last_dyn_error) - 1,
85 "unknown error %lu", err);
89 char *
90 dlerror(void)
92 if (last_dyn_error[0])
93 return last_dyn_error;
94 else
95 return NULL;
98 int
99 dlclose(void *handle)
101 if (!FreeLibrary((HMODULE) handle))
103 set_dl_error();
104 return 1;
106 last_dyn_error[0] = 0;
107 return 0;
110 void *
111 dlsym(void *handle, const char *symbol)
113 void *ptr;
115 ptr = GetProcAddress((HMODULE) handle, symbol);
116 if (!ptr)
118 set_dl_error();
119 return NULL;
121 last_dyn_error[0] = 0;
122 return ptr;
125 void *
126 dlopen(const char *file, int mode)
128 HMODULE h;
129 int prevmode;
131 /* Disable popup error messages when loading DLLs */
132 prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
133 h = LoadLibrary(file);
134 SetErrorMode(prevmode);
136 if (!h)
138 set_dl_error();
139 return NULL;
141 last_dyn_error[0] = 0;
142 return (void *) h;
145 #endif