/*-------------------------------------------------------------------------
 *
 * libpq-reentrant.h
 *
 *        Prototypes and macros around system calls, used to help make
 *        libpq reentrant and safe to use from threaded applications.
 *
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 *
 * $Id:$
 *
 *-------------------------------------------------------------------------
 */

#ifndef LIBPQ_REENTRANT_H
#define LIBPQ_REENTRANT_H

/* _REENTRANT should always be defined when compiling reentrant sources,
 * normally set by compiler switches - but we test here to be sure.
 */
#if !defined _REENTRANT
#define _REENTRANT
#endif /* !_REENTRANT */

/* Setup _THREAD_SAFE and _POSIX_PTHREAD_SEMANTICS, this will disappear
 * in time once tests to determine correct compiler switches for threads
 * are added to configure.
 */
#if !defined _THREAD_SAFE
#define _THREAD_SAFE
#endif
#if !defined _POSIX_PTHREAD_SEMANTICS
#define _POSIX_PTHREAD_SEMANTICS
#endif

#include <sys/types.h>
#include <errno.h>
#include <pwd.h>
#include <netdb.h>

#include "pg_config.h"

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

#if defined HAVE_GETPWUID_R
#define pqGetpwuid getpwuid_r
#else
extern int pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer,
		      size_t buflen, struct passwd **result);
#endif /* HAVE_GETPWUID_R */

#if defined HAVE_GETHOSTBYNAME_R
#define pqGethostbyname gethostbyname_r
#else
extern int pqGethostbyname(const char *name,
			   struct hostent *resbuf,
			   char *buf, size_t buflen,
			   struct hostent **result,
			   int *herrno);
#endif /* HAVE_GETHOSTBYNAME_R */

#endif /* !LIBPQ_REENTRANT_H */
