PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
win32dlopen.c File Reference
#include "c.h"
Include dependency graph for win32dlopen.c:

Go to the source code of this file.

Functions

static void set_dl_error (void)
 
char * dlerror (void)
 
int dlclose (void *handle)
 
void * dlsym (void *handle, const char *symbol)
 
void * dlopen (const char *file, int mode)
 

Variables

static char last_dyn_error [512]
 

Function Documentation

◆ dlclose()

int dlclose ( void *  handle)

Definition at line 49 of file win32dlopen.c.

50 {
51  if (!FreeLibrary((HMODULE) handle))
52  {
53  set_dl_error();
54  return 1;
55  }
56  last_dyn_error[0] = 0;
57  return 0;
58 }
static char last_dyn_error[512]
Definition: win32dlopen.c:18
static void set_dl_error(void)
Definition: win32dlopen.c:21

References last_dyn_error, and set_dl_error().

Referenced by internal_load_library().

◆ dlerror()

char* dlerror ( void  )

Definition at line 40 of file win32dlopen.c.

41 {
42  if (last_dyn_error[0])
43  return last_dyn_error;
44  else
45  return NULL;
46 }

References last_dyn_error.

Referenced by internal_load_library().

◆ dlopen()

void* dlopen ( const char *  file,
int  mode 
)

Definition at line 76 of file win32dlopen.c.

77 {
78  HMODULE h;
79  int prevmode;
80 
81  /* Disable popup error messages when loading DLLs */
82  prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
83  h = LoadLibrary(file);
84  SetErrorMode(prevmode);
85 
86  if (!h)
87  {
88  set_dl_error();
89  return NULL;
90  }
91  last_dyn_error[0] = 0;
92  return (void *) h;
93 }

References last_dyn_error, and set_dl_error().

Referenced by internal_load_library().

◆ dlsym()

void* dlsym ( void *  handle,
const char *  symbol 
)

Definition at line 61 of file win32dlopen.c.

62 {
63  void *ptr;
64 
65  ptr = GetProcAddress((HMODULE) handle, symbol);
66  if (!ptr)
67  {
68  set_dl_error();
69  return NULL;
70  }
71  last_dyn_error[0] = 0;
72  return ptr;
73 }
unsigned char symbol
Definition: api.h:2

References last_dyn_error, and set_dl_error().

Referenced by internal_load_library(), load_external_function(), and lookup_external_function().

◆ set_dl_error()

static void set_dl_error ( void  )
static

Definition at line 21 of file win32dlopen.c.

22 {
23  DWORD err = GetLastError();
24 
25  if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
26  FORMAT_MESSAGE_FROM_SYSTEM,
27  NULL,
28  err,
29  MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
31  sizeof(last_dyn_error) - 1,
32  NULL) == 0)
33  {
35  "unknown error %lu", err);
36  }
37 }
void err(int eval, const char *fmt,...)
Definition: err.c:43
#define snprintf
Definition: port.h:238

References err(), last_dyn_error, and snprintf.

Referenced by dlclose(), dlopen(), and dlsym().

Variable Documentation

◆ last_dyn_error

char last_dyn_error[512]
static

Definition at line 18 of file win32dlopen.c.

Referenced by dlclose(), dlerror(), dlopen(), dlsym(), and set_dl_error().