Header And Logo

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

Functions

thread.c File Reference

#include "c.h"
#include <pwd.h>
Include dependency graph for thread.c:

Go to the source code of this file.

Functions

char * pqStrerror (int errnum, char *strerrbuf, size_t buflen)
int pqGetpwuid (uid_t uid, struct passwd *resultbuf, char *buffer, size_t buflen, struct passwd **result)
int pqGethostbyname (const char *name, struct hostent *resultbuf, char *buffer, size_t buflen, struct hostent **result, int *herrno)

Function Documentation

int pqGethostbyname ( const char *  name,
struct hostent *  resultbuf,
char *  buffer,
size_t  buflen,
struct hostent **  result,
int *  herrno 
)

Definition at line 122 of file thread.c.

References NULL.

Referenced by getaddrinfo().

{
#if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R)

    /*
     * broken (well early POSIX draft) gethostbyname_r() which returns 'struct
     * hostent *'
     */
    *result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno);
    return (*result == NULL) ? -1 : 0;
#else

    /* no gethostbyname_r(), just use gethostbyname() */
    *result = gethostbyname(name);

    if (*result != NULL)
        *herrno = h_errno;

    if (*result != NULL)
        return 0;
    else
        return -1;
#endif
}

int pqGetpwuid ( uid_t  uid,
struct passwd *  resultbuf,
char *  buffer,
size_t  buflen,
struct passwd **  result 
)

Definition at line 89 of file thread.c.

References NULL.

Referenced by get_home_path(), pg_fe_getauthname(), PQconnectPoll(), and pqGetHomeDirectory().

{
#if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETPWUID_R)

#ifdef GETPWUID_R_5ARG
    /* POSIX version */
    getpwuid_r(uid, resultbuf, buffer, buflen, result);
#else

    /*
     * Early POSIX draft of getpwuid_r() returns 'struct passwd *'.
     * getpwuid_r(uid, resultbuf, buffer, buflen)
     */
    *result = getpwuid_r(uid, resultbuf, buffer, buflen);
#endif
#else

    /* no getpwuid_r() available, just use getpwuid() */
    *result = getpwuid(uid);
#endif

    return (*result == NULL) ? -1 : 0;
}

char* pqStrerror ( int  errnum,
char *  strerrbuf,
size_t  buflen 
)

Definition at line 61 of file thread.c.

References strerror(), and strlcpy().

Referenced by lo_export(), lo_import_internal(), pg_local_sendauth(), and PQconnectPoll().

{
#if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_STRERROR_R)
    /* reentrant strerror_r is available */
#ifdef STRERROR_R_INT
    /* SUSv3 version */
    if (strerror_r(errnum, strerrbuf, buflen) == 0)
        return strerrbuf;
    else
        return "Unknown error";
#else
    /* GNU libc */
    return strerror_r(errnum, strerrbuf, buflen);
#endif
#else
    /* no strerror_r() available, just use strerror */
    strlcpy(strerrbuf, strerror(errnum), buflen);

    return strerrbuf;
#endif
}