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

Go to the source code of this file.

Data Structures

struct  WSErrorEntry
 
struct  MessageDLL
 

Macros

#define VC_EXTRALEAN
 
#define NOGDI
 
#define NOCRYPT
 
#define libpq_gettext(x)   (x)
 
#define DLLS_SIZE   (sizeof(dlls)/sizeof(struct MessageDLL))
 

Functions

static int LookupWSErrorMessage (DWORD err, char *dest)
 
const char * winsock_strerror (int err, char *strerrbuf, size_t buflen)
 

Variables

static struct WSErrorEntry WSErrors []
 
struct MessageDLL dlls []
 

Macro Definition Documentation

#define DLLS_SIZE   (sizeof(dlls)/sizeof(struct MessageDLL))

Definition at line 268 of file win32.c.

Referenced by winsock_strerror().

#define libpq_gettext (   x)    (x)

Definition at line 39 of file win32.c.

Referenced by winsock_strerror().

#define NOCRYPT

Definition at line 29 of file win32.c.

#define NOGDI

Definition at line 27 of file win32.c.

#define VC_EXTRALEAN

Definition at line 25 of file win32.c.

Function Documentation

static int LookupWSErrorMessage ( DWORD  err,
char *  dest 
)
static

Definition at line 218 of file win32.c.

References WSErrorEntry::description, WSErrorEntry::error, and WSErrors.

Referenced by winsock_strerror().

219 {
220  struct WSErrorEntry *e;
221 
222  for (e = WSErrors; e->description; e++)
223  {
224  if (e->error == err)
225  {
226  strcpy(dest, e->description);
227  return 1;
228  }
229  }
230  return 0;
231 }
static struct WSErrorEntry WSErrors[]
e
Definition: preproc-init.c:82
DWORD error
Definition: win32.c:45
const char * description
Definition: win32.c:46
const char* winsock_strerror ( int  err,
char *  strerrbuf,
size_t  buflen 
)

Definition at line 281 of file win32.c.

References dlls, DLLS_SIZE, MessageDLL::handle, i, libpq_gettext, MessageDLL::loaded, LookupWSErrorMessage(), and success.

282 {
283  unsigned long flags;
284  int offs,
285  i;
286  int success = LookupWSErrorMessage(err, strerrbuf);
287 
288  for (i = 0; !success && i < DLLS_SIZE; i++)
289  {
290 
291  if (!dlls[i].loaded)
292  {
293  dlls[i].loaded = 1; /* Only load once */
294  dlls[i].handle = (void *) LoadLibraryEx(
295  dlls[i].dll_name,
296  0,
297  LOAD_LIBRARY_AS_DATAFILE);
298  }
299 
300  if (dlls[i].dll_name && !dlls[i].handle)
301  continue; /* Didn't load */
302 
303  flags = FORMAT_MESSAGE_FROM_SYSTEM
304  | FORMAT_MESSAGE_IGNORE_INSERTS
305  | (dlls[i].handle ? FORMAT_MESSAGE_FROM_HMODULE : 0);
306 
307  success = 0 != FormatMessage(
308  flags,
309  dlls[i].handle, err,
310  MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
311  strerrbuf, buflen - 64,
312  0
313  );
314  }
315 
316  if (!success)
317  sprintf(strerrbuf, libpq_gettext("unrecognized socket error: 0x%08X/%d"), err, err);
318  else
319  {
320  strerrbuf[buflen - 1] = '\0';
321  offs = strlen(strerrbuf);
322  if (offs > (int) buflen - 64)
323  offs = buflen - 64;
324  sprintf(strerrbuf + offs, " (0x%08X/%d)", err, err);
325  }
326  return strerrbuf;
327 }
#define libpq_gettext(x)
Definition: win32.c:39
struct MessageDLL dlls[]
static bool success
Definition: pg_basebackup.c:99
static int LookupWSErrorMessage(DWORD err, char *dest)
Definition: win32.c:218
#define DLLS_SIZE
Definition: win32.c:268
int loaded
Definition: win32.c:238
void * handle
Definition: win32.c:237
int i

Variable Documentation

struct MessageDLL dlls[]
Initial value:
=
{
{
"netmsg.dll", 0, 0
},
{
"winsock.dll", 0, 0
},
{
"ws2_32.dll", 0, 0
},
{
"wsock32n.dll", 0, 0
},
{
"mswsock.dll", 0, 0
},
{
"ws2help.dll", 0, 0
},
{
"ws2thk.dll", 0, 0
},
{
0, 0, 1
}
}

Referenced by winsock_strerror().

struct WSErrorEntry WSErrors[]
static

Referenced by LookupWSErrorMessage().