2 * PgBouncer - Lightweight connection pooler for PostgreSQL.
4 * Copyright (c) 2007-2009 Marko Kreen, Skype Technologies OÜ
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * Required system headers
28 #include "win32support.h"
31 /* glibc is useless without it */
34 /* solaris is broken otherwise */
37 #define __EXTENSIONS__
41 #include <sys/types.h>
45 #ifdef HAVE_SYS_SOCKET_H
46 #include <sys/socket.h>
51 #ifdef HAVE_NETINET_IN_H
52 #include <netinet/in.h>
54 #ifdef HAVE_NETINET_TCP_H
55 #include <netinet/tcp.h>
57 #ifdef HAVE_ARPA_INET_H
58 #include <arpa/inet.h>
60 #ifdef HAVE_ARPA_INET_H
61 #include <sys/resource.h>
75 #ifdef HAVE_INTTYPES_H
91 /* how to specify array with unknown length */
92 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
94 #elif defined(__GNUC__)
100 #if defined(__GNUC__) && (__GNUC__ >= 4)
102 /* gcc has hew positive aspects too */
103 #define _MUSTCHECK __attribute__((warn_unused_result))
104 #define _DEPRECATED __attribute__((deprecated))
105 #define _PRINTF(fmtpos, argpos) __attribute__((format(printf, fmtpos, argpos)))
106 #define _MALLOC __attribute__((malloc))
108 /* those do not seem to work well */
109 #define unlikely(x) __builtin_expect(!!(x), 0)
110 #define likely(x) __builtin_expect(!!(x), 1)
118 #define unlikely(x) x
123 /* cant use assert() as we want to log too */
127 if (unlikely(!(e))) { \
128 fatal_noexit("Assert(%s) failed", #e); \
136 #ifndef UNIX_PATH_MAX
137 #define UNIX_PATH_MAX 128 /* actual sizeof() will be applied later anyway */
140 /* how many microseconds in a second */
141 #define USEC (1000000LL)
143 typedef uint64_t usec_t
;
149 typedef unsigned char bool;
154 * PostgreSQL type OIDs for resultsets.
162 * Make sure __func__ works.
165 #ifndef HAVE_FUNCNAME__FUNC
166 #define __func__ __FUNCTION__
170 * Some systems (Solaris) does not define INADDR_NONE
173 #define INADDR_NONE ((unsigned long) -1)
177 * libc compat functions.
181 size_t strlcpy(char *dst
, const char *src
, size_t n
) _MUSTCHECK
;
184 size_t strlcat(char *dst
, const char *src
, size_t n
) _MUSTCHECK
;
186 #ifndef HAVE_GETPEEREID
187 int getpeereid(int fd
, uid_t
*uid_p
, gid_t
*gid_p
) _MUSTCHECK
;
189 #ifndef HAVE_BASENAME
190 const char *basename(const char *path
);
193 static inline char *crypt(const char *p
, const char *s
) { return NULL
; }
195 #ifndef HAVE_INET_NTOP
196 const char *inet_ntop(int af
, const void *src
, char *dst
, socklen_t cnt
);
199 static inline int lstat(const char *path
, struct stat
*st
) { return stat(path
, st
); }
202 /* libevent 1.3 does not have event_loopbreak() */
203 #ifndef HAVE_EVENT_LOOPBREAK
204 static inline void event_loopbreak(void) { }
207 void change_user(const char *user
);