PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 []
 
static struct MessageDLL dlls []
 

Macro Definition Documentation

◆ DLLS_SIZE

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

Definition at line 268 of file win32.c.

◆ libpq_gettext

#define libpq_gettext (   x)    (x)

Definition at line 39 of file win32.c.

◆ NOCRYPT

#define NOCRYPT

Definition at line 29 of file win32.c.

◆ NOGDI

#define NOGDI

Definition at line 27 of file win32.c.

◆ VC_EXTRALEAN

#define VC_EXTRALEAN

Definition at line 25 of file win32.c.

Function Documentation

◆ LookupWSErrorMessage()

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

Definition at line 218 of file win32.c.

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 }
void err(int eval, const char *fmt,...)
Definition: err.c:43
e
Definition: preproc-init.c:82
const char * description
Definition: win32.c:46
static struct WSErrorEntry WSErrors[]

References WSErrorEntry::description, generate_unaccent_rules::dest, err(), and WSErrors.

Referenced by winsock_strerror().

◆ winsock_strerror()

const char* winsock_strerror ( int  err,
char *  strerrbuf,
size_t  buflen 
)

Definition at line 277 of file win32.c.

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

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

Variable Documentation

◆ dlls

struct MessageDLL dlls[]
static
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().

◆ WSErrors

struct WSErrorEntry WSErrors[]
static

Referenced by LookupWSErrorMessage().