blob: 831fbaa9e61b3e3b6f7396926a1913bd9cec9e85 [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 Millerb29ea912000-01-15 14:12:03 +110012#ifdef HAVE_SYS_BITYPES_H
13# include <sys/bitypes.h> /* For u_intXX_t */
14#endif
15
Damien Miller5a3e6831999-12-27 09:48:56 +110016#ifdef HAVE_PATHS_H
17# include <paths.h> /* For _PATH_XXX */
18#endif
19
20#ifdef HAVE_UTMP_H
21# include <utmp.h> /* For _PATH_XXX */
22#endif
23
24#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
25# include <utmpx.h> /* For _PATH_XXX */
26#endif
27
28#ifdef HAVE_SYS_TIME_H
29# include <sys/time.h> /* For timersub */
30#endif
31
32#ifdef HAVE_MAILLOCK_H
Damien Millerbeb4ba51999-12-28 15:09:35 +110033# include <maillock.h> /* For _PATH_MAILDIR */
Damien Miller5a3e6831999-12-27 09:48:56 +110034#endif
35
Damien Millerbeb4ba51999-12-28 15:09:35 +110036#ifdef HAVE_SYS_CDEFS_H
37# include <sys/cdefs.h> /* For __P() */
38#endif
39
Damien Milleree1c0b32000-01-21 00:18:15 +110040#ifdef HAVE_SYS_SYSMACROS_H
41# include <sys/sysmacros.h> /* For MIN, MAX, etc */
42#endif
43
Damien Miller74d0d4a1999-12-29 02:24:35 +110044/* Constants */
45
Damien Miller5a3e6831999-12-27 09:48:56 +110046#ifndef SHUT_RDWR
47enum
48{
49 SHUT_RD = 0, /* No more receptions. */
50 SHUT_WR, /* No more transmissions. */
51 SHUT_RDWR /* No more receptions or transmissions. */
52};
53# define SHUT_RD SHUT_RD
54# define SHUT_WR SHUT_WR
55# define SHUT_RDWR SHUT_RDWR
56#endif
57
Damien Miller74d0d4a1999-12-29 02:24:35 +110058/* Types */
59
Damien Miller5a3e6831999-12-27 09:48:56 +110060/* If sys/types.h does not supply intXX_t, supply them ourselves */
61/* (or die trying) */
62#ifndef HAVE_INTXX_T
Damien Millere0f45742000-01-18 09:12:06 +110063# if (SIZEOF_CHAR == 1)
64typedef char int8_t;
65# else
66# error "8 bit int type not found."
67# endif
Damien Miller5a3e6831999-12-27 09:48:56 +110068# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +110069typedef short int int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110070# else
71# error "16 bit int type not found."
72# endif
73# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +110074typedef int int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110075# else
76# error "32 bit int type not found."
77# endif
78# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110079typedef long int int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110080# else
81# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110082typedef long long int int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110083# define HAVE_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110084# else
85# error "64 bit int type not found."
86# endif
87# endif
88#endif
89
90/* If sys/types.h does not supply u_intXX_t, supply them ourselves */
91#ifndef HAVE_U_INTXX_T
92# ifdef HAVE_UINTXX_T
Damien Millere0f45742000-01-18 09:12:06 +110093typedef uint8_t u_int8_t;
Damien Miller74d0d4a1999-12-29 02:24:35 +110094typedef uint16_t u_int16_t;
95typedef uint32_t u_int32_t;
96typedef uint64_t u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110097# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110098# else
Damien Millere0f45742000-01-18 09:12:06 +110099# if (SIZEOF_CHAR == 1)
100typedef unsigned char u_int8_t;
101# else
102# error "8 bit int type not found."
103# endif
Damien Miller5a3e6831999-12-27 09:48:56 +1100104# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100105typedef unsigned short int u_int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100106# else
107# error "16 bit int type not found."
108# endif
109# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100110typedef unsigned int u_int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100111# else
112# error "32 bit int type not found."
113# endif
114# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100115typedef unsigned long int u_int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100116# else
117# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100118typedef unsigned long long int u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +1100119# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100120# else
121# error "64 bit int type not found."
122# endif
123# endif
124# endif
125#endif
126
Damien Miller74d0d4a1999-12-29 02:24:35 +1100127#ifndef HAVE_SOCKLEN_T
128typedef unsigned int socklen_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100129# define HAVE_SOCKLEN_T
Damien Miller74d0d4a1999-12-29 02:24:35 +1100130#endif /* HAVE_SOCKLEN_T */
131
Damien Miller95058511999-12-29 10:36:45 +1100132#ifndef HAVE_SIZE_T
133typedef unsigned int size_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100134# define HAVE_SIZE_T
Damien Miller95058511999-12-29 10:36:45 +1100135#endif /* HAVE_SIZE_T */
136
Damien Miller34132e52000-01-14 15:45:46 +1100137#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
138# define ss_family __ss_family
139#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
140
Damien Miller74d0d4a1999-12-29 02:24:35 +1100141/* Paths */
142
Damien Miller5a3e6831999-12-27 09:48:56 +1100143/* If _PATH_LASTLOG is not defined by system headers, set it to the */
144/* lastlog file detected by autoconf */
145#ifndef _PATH_LASTLOG
146# ifdef LASTLOG_LOCATION
147# define _PATH_LASTLOG LASTLOG_LOCATION
148# endif
149#endif
150
151#ifndef _PATH_UTMP
152# ifdef UTMP_FILE
153# define _PATH_UTMP UTMP_FILE
154# else
155# define _PATH_UTMP "/var/adm/utmp"
156# endif
157#endif
158
159#ifndef _PATH_WTMP
160# ifdef WTMP_FILE
161# define _PATH_WTMP WTMP_FILE
162# else
163# define _PATH_WTMP "/var/adm/wtmp"
164# endif
165#endif
166
167#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
168# ifndef _PATH_UTMPX
169# ifdef UTMPX_FILE
170# define _PATH_UTMPX UTMPX_FILE
171# else
172# define _PATH_UTMPX "/var/adm/utmpx"
173# endif
174# endif
175# ifndef _PATH_WTMPX
176# ifdef WTMPX_FILE
177# define _PATH_WTMPX WTMPX_FILE
178# else
179# define _PATH_WTMPX "/var/adm/wtmp"
180# endif
181# endif
182#endif
183
184#ifndef _PATH_BSHELL
185# define _PATH_BSHELL "/bin/sh"
186#endif
187
188#ifdef USER_PATH
189# ifdef _PATH_STDPATH
190# undef _PATH_STDPATH
191# endif
192# define _PATH_STDPATH USER_PATH
193#endif
194
195#ifndef _PATH_STDPATH
196# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
197#endif
198
199#ifndef _PATH_DEVNULL
200# define _PATH_DEVNULL "/dev/null"
201#endif
202
203#ifndef MAILDIR
204# define MAILDIR MAIL_DIRECTORY
205#endif
206
207#if !defined(_PATH_MAILDIR) && defined(MAILDIR)
208# define _PATH_MAILDIR MAILDIR
209#endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */
210
Damien Miller74d0d4a1999-12-29 02:24:35 +1100211#ifndef _PATH_RSH
212# ifdef RSH_PATH
213# define _PATH_RSH RSH_PATH
214# endif /* RSH_PATH */
215#endif /* _PATH_RSH */
216
217/* Macros */
218
Damien Miller5a3e6831999-12-27 09:48:56 +1100219#ifndef MAX
220# define MAX(a,b) (((a)>(b))?(a):(b))
221# define MIN(a,b) (((a)<(b))?(a):(b))
222#endif
223
224#ifndef timersub
225#define timersub(a, b, result) \
226 do { \
227 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
228 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
229 if ((result)->tv_usec < 0) { \
230 --(result)->tv_sec; \
231 (result)->tv_usec += 1000000; \
232 } \
233 } while (0)
234#endif
235
Damien Miller5a3e6831999-12-27 09:48:56 +1100236#ifndef __P
237# define __P(x) x
238#endif
239
Damien Miller1c67c992000-03-14 10:16:34 +1100240#if !defined(IN6_IS_ADDR_V4MAPPED)
241# define IN6_IS_ADDR_V4MAPPED(a) \
Damien Millerdb819592000-03-14 13:44:01 +1100242 ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
243 (((u_int32_t *) (a))[2] == htonl (0xffff)))
Damien Miller1c67c992000-03-14 10:16:34 +1100244#endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
245
Damien Miller5a3e6831999-12-27 09:48:56 +1100246#if !defined(__GNUC__) || (__GNUC__ < 2)
Damien Millere0f45742000-01-18 09:12:06 +1100247# define __attribute__(x)
Damien Miller5a3e6831999-12-27 09:48:56 +1100248#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
249
Damien Miller74d0d4a1999-12-29 02:24:35 +1100250#if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM)
251# define USE_PAM
252#endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */
253
254/* Function replacement / compatibility hacks */
255
256/* In older versions of libpam, pam_strerror takes a single argument */
257#ifdef HAVE_OLD_PAM
258# define PAM_STRERROR(a,b) pam_strerror((b))
259#else
260# define PAM_STRERROR(a,b) pam_strerror((a),(b))
261#endif
262
Damien Millereca71f82000-01-20 22:38:27 +1100263#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
264# undef HAVE_GETADDRINFO
265#endif /* defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) */
266
Damien Miller6b85a7f2000-01-02 11:45:33 +1100267#endif /* _DEFINES_H */