PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 117 of file thread.c.

References NULL.

Referenced by getaddrinfo().

122 {
123 #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R)
124 
125  /*
126  * broken (well early POSIX draft) gethostbyname_r() which returns 'struct
127  * hostent *'
128  */
129  *result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno);
130  return (*result == NULL) ? -1 : 0;
131 #else
132 
133  /* no gethostbyname_r(), just use gethostbyname() */
134  *result = gethostbyname(name);
135 
136  if (*result != NULL)
137  *herrno = h_errno;
138 
139  if (*result != NULL)
140  return 0;
141  else
142  return -1;
143 #endif
144 }
return result
Definition: formatting.c:1633
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int pqGetpwuid ( uid_t  uid,
struct passwd *  resultbuf,
char *  buffer,
size_t  buflen,
struct passwd **  result 
)

Definition at line 95 of file thread.c.

References NULL.

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

97 {
98 #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETPWUID_R)
99  return getpwuid_r(uid, resultbuf, buffer, buflen, result);
100 #else
101  /* no getpwuid_r() available, just use getpwuid() */
102  errno = 0;
103  *result = getpwuid(uid);
104  /* paranoia: ensure we return zero on success */
105  return (*result == NULL) ? errno : 0;
106 #endif
107 }
return result
Definition: formatting.c:1633
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
char* pqStrerror ( int  errnum,
char *  strerrbuf,
size_t  buflen 
)

Definition at line 61 of file thread.c.

References strerror(), and strlcpy().

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

62 {
63 #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_STRERROR_R)
64  /* reentrant strerror_r is available */
65 #ifdef STRERROR_R_INT
66  /* SUSv3 version */
67  if (strerror_r(errnum, strerrbuf, buflen) == 0)
68  return strerrbuf;
69  else
70  return "Unknown error";
71 #else
72  /* GNU libc */
73  return strerror_r(errnum, strerrbuf, buflen);
74 #endif
75 #else
76  /* no strerror_r() available, just use strerror */
77  strlcpy(strerrbuf, strerror(errnum), buflen);
78 
79  return strerrbuf;
80 #endif
81 }
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * strerror(int errnum)
Definition: strerror.c:19