blob: f8a23b88d77936b1f267d0ae9197622f5f862db0 [file] [log] [blame]
Damien Miller6b85a7f2000-01-02 11:45:33 +11001#ifndef _DEFINES_H
2#define _DEFINES_H
3
Damien Miller74d0d4a1999-12-29 02:24:35 +11004/* Necessary headers */
5
Damien Miller1c67c992000-03-14 10:16:34 +11006#include <sys/types.h> /* For [u]intxx_t */
7
Damien Miller5a3e6831999-12-27 09:48:56 +11008#include <sys/socket.h> /* For SHUT_XXXX */
9
Damien Miller1c67c992000-03-14 10:16:34 +110010#include <netinet/in.h> /* For IPv6 macros */
11
Damien Millerbc7c7cc2000-04-08 17:48:56 +100012#include <netinet/ip.h> /* For IPTOS macros */
13
Damien Millerb29ea912000-01-15 14:12:03 +110014#ifdef HAVE_SYS_BITYPES_H
15# include <sys/bitypes.h> /* For u_intXX_t */
16#endif
17
Damien Miller5a3e6831999-12-27 09:48:56 +110018#ifdef HAVE_PATHS_H
19# include <paths.h> /* For _PATH_XXX */
20#endif
21
22#ifdef HAVE_UTMP_H
23# include <utmp.h> /* For _PATH_XXX */
24#endif
25
26#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
27# include <utmpx.h> /* For _PATH_XXX */
28#endif
29
30#ifdef HAVE_SYS_TIME_H
31# include <sys/time.h> /* For timersub */
32#endif
33
34#ifdef HAVE_MAILLOCK_H
Damien Millerbeb4ba51999-12-28 15:09:35 +110035# include <maillock.h> /* For _PATH_MAILDIR */
Damien Miller5a3e6831999-12-27 09:48:56 +110036#endif
37
Damien Millerbeb4ba51999-12-28 15:09:35 +110038#ifdef HAVE_SYS_CDEFS_H
39# include <sys/cdefs.h> /* For __P() */
40#endif
41
Damien Milleree1c0b32000-01-21 00:18:15 +110042#ifdef HAVE_SYS_SYSMACROS_H
43# include <sys/sysmacros.h> /* For MIN, MAX, etc */
44#endif
45
Damien Miller74d0d4a1999-12-29 02:24:35 +110046/* Constants */
47
Damien Miller5a3e6831999-12-27 09:48:56 +110048#ifndef SHUT_RDWR
49enum
50{
51 SHUT_RD = 0, /* No more receptions. */
52 SHUT_WR, /* No more transmissions. */
53 SHUT_RDWR /* No more receptions or transmissions. */
54};
55# define SHUT_RD SHUT_RD
56# define SHUT_WR SHUT_WR
57# define SHUT_RDWR SHUT_RDWR
58#endif
59
Damien Millerbc7c7cc2000-04-08 17:48:56 +100060#ifndef IPTOS_LOWDELAY
61# define IPTOS_LOWDELAY 0x10
62# define IPTOS_THROUGHPUT 0x08
63# define IPTOS_RELIABILITY 0x04
64# define IPTOS_LOWCOST 0x02
65# define IPTOS_MINCOST IPTOS_LOWCOST
66#endif /* IPTOS_LOWDELAY */
67
Damien Miller74d0d4a1999-12-29 02:24:35 +110068/* Types */
69
Damien Miller5a3e6831999-12-27 09:48:56 +110070/* If sys/types.h does not supply intXX_t, supply them ourselves */
71/* (or die trying) */
72#ifndef HAVE_INTXX_T
Damien Millere0f45742000-01-18 09:12:06 +110073# if (SIZEOF_CHAR == 1)
74typedef char int8_t;
75# else
76# error "8 bit int type not found."
77# endif
Damien Miller5a3e6831999-12-27 09:48:56 +110078# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +110079typedef short int int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110080# else
81# error "16 bit int type not found."
82# endif
83# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +110084typedef int int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110085# else
86# error "32 bit int type not found."
87# endif
Damien Miller70494d12000-04-03 15:57:06 +100088/*
Damien Miller5a3e6831999-12-27 09:48:56 +110089# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110090typedef long int int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110091# else
92# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110093typedef long long int int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110094# define HAVE_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110095# else
96# error "64 bit int type not found."
97# endif
98# endif
Damien Miller70494d12000-04-03 15:57:06 +100099*/
Damien Miller5a3e6831999-12-27 09:48:56 +1100100#endif
101
102/* If sys/types.h does not supply u_intXX_t, supply them ourselves */
103#ifndef HAVE_U_INTXX_T
104# ifdef HAVE_UINTXX_T
Damien Millere0f45742000-01-18 09:12:06 +1100105typedef uint8_t u_int8_t;
Damien Miller74d0d4a1999-12-29 02:24:35 +1100106typedef uint16_t u_int16_t;
107typedef uint32_t u_int32_t;
Damien Miller70494d12000-04-03 15:57:06 +1000108/*
Damien Miller74d0d4a1999-12-29 02:24:35 +1100109typedef uint64_t u_int64_t;
Damien Miller70494d12000-04-03 15:57:06 +1000110*/
Damien Miller6b85a7f2000-01-02 11:45:33 +1100111# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100112# else
Damien Millere0f45742000-01-18 09:12:06 +1100113# if (SIZEOF_CHAR == 1)
114typedef unsigned char u_int8_t;
115# else
116# error "8 bit int type not found."
117# endif
Damien Miller5a3e6831999-12-27 09:48:56 +1100118# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100119typedef unsigned short int u_int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100120# else
121# error "16 bit int type not found."
122# endif
123# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100124typedef unsigned int u_int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100125# else
126# error "32 bit int type not found."
127# endif
Damien Miller70494d12000-04-03 15:57:06 +1000128/*
Damien Miller5a3e6831999-12-27 09:48:56 +1100129# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100130typedef unsigned long int u_int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100131# else
132# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100133typedef unsigned long long int u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +1100134# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100135# else
136# error "64 bit int type not found."
137# endif
138# endif
Damien Miller70494d12000-04-03 15:57:06 +1000139*/
Damien Miller5a3e6831999-12-27 09:48:56 +1100140# endif
141#endif
142
Damien Miller74d0d4a1999-12-29 02:24:35 +1100143#ifndef HAVE_SOCKLEN_T
144typedef unsigned int socklen_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100145# define HAVE_SOCKLEN_T
Damien Miller74d0d4a1999-12-29 02:24:35 +1100146#endif /* HAVE_SOCKLEN_T */
147
Damien Miller95058511999-12-29 10:36:45 +1100148#ifndef HAVE_SIZE_T
149typedef unsigned int size_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100150# define HAVE_SIZE_T
Damien Miller95058511999-12-29 10:36:45 +1100151#endif /* HAVE_SIZE_T */
152
Damien Miller34132e52000-01-14 15:45:46 +1100153#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
154# define ss_family __ss_family
155#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
156
Damien Miller74d0d4a1999-12-29 02:24:35 +1100157/* Paths */
158
Damien Miller5a3e6831999-12-27 09:48:56 +1100159/* If _PATH_LASTLOG is not defined by system headers, set it to the */
160/* lastlog file detected by autoconf */
161#ifndef _PATH_LASTLOG
162# ifdef LASTLOG_LOCATION
163# define _PATH_LASTLOG LASTLOG_LOCATION
164# endif
165#endif
166
167#ifndef _PATH_UTMP
168# ifdef UTMP_FILE
169# define _PATH_UTMP UTMP_FILE
170# else
171# define _PATH_UTMP "/var/adm/utmp"
172# endif
173#endif
174
175#ifndef _PATH_WTMP
176# ifdef WTMP_FILE
177# define _PATH_WTMP WTMP_FILE
178# else
179# define _PATH_WTMP "/var/adm/wtmp"
180# endif
181#endif
182
183#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
184# ifndef _PATH_UTMPX
185# ifdef UTMPX_FILE
186# define _PATH_UTMPX UTMPX_FILE
187# else
188# define _PATH_UTMPX "/var/adm/utmpx"
189# endif
190# endif
191# ifndef _PATH_WTMPX
192# ifdef WTMPX_FILE
193# define _PATH_WTMPX WTMPX_FILE
194# else
195# define _PATH_WTMPX "/var/adm/wtmp"
196# endif
197# endif
198#endif
199
200#ifndef _PATH_BSHELL
201# define _PATH_BSHELL "/bin/sh"
202#endif
203
204#ifdef USER_PATH
205# ifdef _PATH_STDPATH
206# undef _PATH_STDPATH
207# endif
208# define _PATH_STDPATH USER_PATH
209#endif
210
211#ifndef _PATH_STDPATH
212# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
213#endif
214
215#ifndef _PATH_DEVNULL
216# define _PATH_DEVNULL "/dev/null"
217#endif
218
219#ifndef MAILDIR
220# define MAILDIR MAIL_DIRECTORY
221#endif
222
223#if !defined(_PATH_MAILDIR) && defined(MAILDIR)
224# define _PATH_MAILDIR MAILDIR
225#endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */
226
Damien Miller74d0d4a1999-12-29 02:24:35 +1100227#ifndef _PATH_RSH
228# ifdef RSH_PATH
229# define _PATH_RSH RSH_PATH
230# endif /* RSH_PATH */
231#endif /* _PATH_RSH */
232
233/* Macros */
234
Damien Miller5a3e6831999-12-27 09:48:56 +1100235#ifndef MAX
236# define MAX(a,b) (((a)>(b))?(a):(b))
237# define MIN(a,b) (((a)<(b))?(a):(b))
238#endif
239
240#ifndef timersub
241#define timersub(a, b, result) \
242 do { \
243 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
244 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
245 if ((result)->tv_usec < 0) { \
246 --(result)->tv_sec; \
247 (result)->tv_usec += 1000000; \
248 } \
249 } while (0)
250#endif
251
Damien Miller5a3e6831999-12-27 09:48:56 +1100252#ifndef __P
253# define __P(x) x
254#endif
255
Damien Miller1c67c992000-03-14 10:16:34 +1100256#if !defined(IN6_IS_ADDR_V4MAPPED)
257# define IN6_IS_ADDR_V4MAPPED(a) \
Damien Millerdb819592000-03-14 13:44:01 +1100258 ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
259 (((u_int32_t *) (a))[2] == htonl (0xffff)))
Damien Miller1c67c992000-03-14 10:16:34 +1100260#endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
261
Damien Miller5a3e6831999-12-27 09:48:56 +1100262#if !defined(__GNUC__) || (__GNUC__ < 2)
Damien Millere0f45742000-01-18 09:12:06 +1100263# define __attribute__(x)
Damien Miller5a3e6831999-12-27 09:48:56 +1100264#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
265
Damien Miller74d0d4a1999-12-29 02:24:35 +1100266#if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM)
267# define USE_PAM
268#endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */
269
270/* Function replacement / compatibility hacks */
271
272/* In older versions of libpam, pam_strerror takes a single argument */
273#ifdef HAVE_OLD_PAM
274# define PAM_STRERROR(a,b) pam_strerror((b))
275#else
276# define PAM_STRERROR(a,b) pam_strerror((a),(b))
277#endif
278
Damien Millereca71f82000-01-20 22:38:27 +1100279#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
280# undef HAVE_GETADDRINFO
281#endif /* defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) */
282
Damien Miller6b85a7f2000-01-02 11:45:33 +1100283#endif /* _DEFINES_H */