Use AC_PROG_INSTALL & ./install-sh
[pgbouncer.git] / include / system.h
blob6df24e14a59edf1f235d727b4c515cad8c9e3fe5
1 /*
2 * PgBouncer - Lightweight connection pooler for PostgreSQL.
3 *
4 * Copyright (c) 2007-2009 Marko Kreen, Skype Technologies OÜ
5 *
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.
9 *
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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #ifdef WIN32
28 #include "win32support.h"
29 #endif
31 /* glibc is useless without it */
32 #define _GNU_SOURCE
34 /* solaris is broken otherwise */
35 #if defined(__sun)
36 #define _XPG4_2
37 #define __EXTENSIONS__
38 #endif
40 #include <errno.h>
41 #include <sys/types.h>
42 #include <sys/time.h>
43 #include <sys/stat.h>
45 #ifdef HAVE_SYS_SOCKET_H
46 #include <sys/socket.h>
47 #endif
48 #ifdef HAVE_SYS_UN_H
49 #include <sys/un.h>
50 #endif
51 #ifdef HAVE_NETINET_IN_H
52 #include <netinet/in.h>
53 #endif
54 #ifdef HAVE_NETINET_TCP_H
55 #include <netinet/tcp.h>
56 #endif
57 #ifdef HAVE_ARPA_INET_H
58 #include <arpa/inet.h>
59 #endif
60 #ifdef HAVE_ARPA_INET_H
61 #include <sys/resource.h>
62 #endif
64 #include <time.h>
65 #include <fcntl.h>
66 #include <unistd.h>
67 #include <stddef.h>
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include <string.h>
71 #include <stdarg.h>
72 #include <ctype.h>
73 #include <limits.h>
75 #ifdef HAVE_INTTYPES_H
76 #include <inttypes.h>
77 #endif
78 #ifdef HAVE_STDINT_H
79 #include <stdint.h>
80 #endif
81 #ifdef HAVE_CRYPT_H
82 #include <crypt.h>
83 #endif
84 #ifdef HAVE_LIBGEN_H
85 #include <libgen.h>
86 #endif
87 #ifdef HAVE_SYS_UIO_H
88 #include <sys/uio.h>
89 #endif
91 /* how to specify array with unknown length */
92 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
93 #define FLEX_ARRAY
94 #elif defined(__GNUC__)
95 #define FLEX_ARRAY
96 #else
97 #define FLEX_ARRAY 1
98 #endif
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)
112 #else
114 #define _MUSTCHECK
115 #define _DEPRECATED
116 #define _PRINTF(x,y)
117 #define _MALLOC
118 #define unlikely(x) x
119 #define likely(x) x
121 #endif
123 /* cant use assert() as we want to log too */
124 #ifdef CASSERT
125 #define Assert(e) \
126 do { \
127 if (unlikely(!(e))) { \
128 fatal_noexit("Assert(%s) failed", #e); \
129 abort(); \
131 } while (0)
132 #else
133 #define Assert(e)
134 #endif
136 #ifndef UNIX_PATH_MAX
137 #define UNIX_PATH_MAX 128 /* actual sizeof() will be applied later anyway */
138 #endif
140 /* how many microseconds in a second */
141 #define USEC (1000000LL)
143 typedef uint64_t usec_t;
146 * bool type.
149 typedef unsigned char bool;
150 #define false 0
151 #define true 1
154 * PostgreSQL type OIDs for resultsets.
157 #define INT8OID 20
158 #define INT4OID 23
159 #define TEXTOID 25
162 * Make sure __func__ works.
165 #ifndef HAVE_FUNCNAME__FUNC
166 #define __func__ __FUNCTION__
167 #endif
170 * Some systems (Solaris) does not define INADDR_NONE
172 #ifndef INADDR_NONE
173 #define INADDR_NONE ((unsigned long) -1)
174 #endif
177 * libc compat functions.
180 #ifndef HAVE_STRLCPY
181 size_t strlcpy(char *dst, const char *src, size_t n) _MUSTCHECK;
182 #endif
183 #ifndef HAVE_STRLCAT
184 size_t strlcat(char *dst, const char *src, size_t n) _MUSTCHECK;
185 #endif
186 #ifndef HAVE_GETPEEREID
187 int getpeereid(int fd, uid_t *uid_p, gid_t *gid_p) _MUSTCHECK;
188 #endif
189 #ifndef HAVE_BASENAME
190 const char *basename(const char *path);
191 #endif
192 #ifndef HAVE_CRYPT
193 static inline char *crypt(const char *p, const char *s) { return NULL; }
194 #endif
195 #ifndef HAVE_INET_NTOP
196 const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
197 #endif
198 #ifndef HAVE_LSTAT
199 static inline int lstat(const char *path, struct stat *st) { return stat(path, st); }
200 #endif
202 /* libevent 1.3 does not have event_loopbreak() */
203 #ifndef HAVE_EVENT_LOOPBREAK
204 static inline void event_loopbreak(void) { }
205 #endif
207 void change_user(const char *user);