Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Functions | Variables

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

Defines

#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 []

Define Documentation

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

Definition at line 273 of file win32.c.

#define libpq_gettext (   x  )     (x)

Definition at line 41 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 220 of file win32.c.

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

Referenced by winsock_strerror().

{
    struct WSErrorEntry *e;

    for (e = WSErrors; e->description; e++)
    {
        if (e->error == err)
        {
            strcpy(dest, e->description);
            return 1;
        }
    }
    return 0;
}

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

Definition at line 286 of file win32.c.

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

{
    unsigned long flags;
    int         offs,
                i;
    int         success = LookupWSErrorMessage(err, strerrbuf);

    for (i = 0; !success && i < DLLS_SIZE; i++)
    {

        if (!dlls[i].loaded)
        {
            dlls[i].loaded = 1; /* Only load once */
            dlls[i].handle = (void *) LoadLibraryEx(
                                                    dlls[i].dll_name,
                                                    0,
                                                    LOAD_LIBRARY_AS_DATAFILE);
        }

        if (dlls[i].dll_name && !dlls[i].handle)
            continue;           /* Didn't load */

        flags = FORMAT_MESSAGE_FROM_SYSTEM
            | FORMAT_MESSAGE_IGNORE_INSERTS
            | (dlls[i].handle ? FORMAT_MESSAGE_FROM_HMODULE : 0);

        success = 0 != FormatMessage(
                                     flags,
                                     dlls[i].handle, err,
                                   MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
                                     strerrbuf, buflen - 64,
                                     0
            );
    }

    if (!success)
        sprintf(strerrbuf, libpq_gettext("unrecognized socket error: 0x%08X/%d"), err, err);
    else
    {
        strerrbuf[buflen - 1] = '\0';
        offs = strlen(strerrbuf);
        if (offs > (int) buflen - 64)
            offs = buflen - 64;
        sprintf(strerrbuf + offs, " (0x%08X/%d)", err, err);
    }
    return strerrbuf;
}


Variable Documentation

struct MessageDLL dlls[]

Referenced by winsock_strerror().

struct WSErrorEntry WSErrors[] [static]

Referenced by LookupWSErrorMessage().