blob: 519ebbaa21685356b8ddf3cc4ddd785eb49675b6 [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 Millerb29ea912000-01-15 14:12:03 +11006#include <sys/types.h>
Damien Miller5a3e6831999-12-27 09:48:56 +11007#include <sys/socket.h> /* For SHUT_XXXX */
8
Damien Millerb29ea912000-01-15 14:12:03 +11009#ifdef HAVE_SYS_BITYPES_H
10# include <sys/bitypes.h> /* For u_intXX_t */
11#endif
12
Damien Miller5a3e6831999-12-27 09:48:56 +110013#ifdef HAVE_PATHS_H
14# include <paths.h> /* For _PATH_XXX */
15#endif
16
17#ifdef HAVE_UTMP_H
18# include <utmp.h> /* For _PATH_XXX */
19#endif
20
21#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
22# include <utmpx.h> /* For _PATH_XXX */
23#endif
24
25#ifdef HAVE_SYS_TIME_H
26# include <sys/time.h> /* For timersub */
27#endif
28
29#ifdef HAVE_MAILLOCK_H
Damien Millerbeb4ba51999-12-28 15:09:35 +110030# include <maillock.h> /* For _PATH_MAILDIR */
Damien Miller5a3e6831999-12-27 09:48:56 +110031#endif
32
Damien Millerbeb4ba51999-12-28 15:09:35 +110033#ifdef HAVE_SYS_CDEFS_H
34# include <sys/cdefs.h> /* For __P() */
35#endif
36
Damien Milleree1c0b32000-01-21 00:18:15 +110037#ifdef HAVE_SYS_SYSMACROS_H
38# include <sys/sysmacros.h> /* For MIN, MAX, etc */
39#endif
40
Damien Miller74d0d4a1999-12-29 02:24:35 +110041/* Constants */
42
Damien Miller5a3e6831999-12-27 09:48:56 +110043#ifndef SHUT_RDWR
44enum
45{
46 SHUT_RD = 0, /* No more receptions. */
47 SHUT_WR, /* No more transmissions. */
48 SHUT_RDWR /* No more receptions or transmissions. */
49};
50# define SHUT_RD SHUT_RD
51# define SHUT_WR SHUT_WR
52# define SHUT_RDWR SHUT_RDWR
53#endif
54
Damien Miller74d0d4a1999-12-29 02:24:35 +110055/* Types */
56
Damien Miller5a3e6831999-12-27 09:48:56 +110057/* If sys/types.h does not supply intXX_t, supply them ourselves */
58/* (or die trying) */
59#ifndef HAVE_INTXX_T
Damien Millere0f45742000-01-18 09:12:06 +110060# if (SIZEOF_CHAR == 1)
61typedef char int8_t;
62# else
63# error "8 bit int type not found."
64# endif
Damien Miller5a3e6831999-12-27 09:48:56 +110065# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +110066typedef short int int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110067# else
68# error "16 bit int type not found."
69# endif
70# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +110071typedef int int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110072# else
73# error "32 bit int type not found."
74# endif
75# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110076typedef long int int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110077# else
78# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110079typedef long long int int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110080# define HAVE_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110081# else
82# error "64 bit int type not found."
83# endif
84# endif
85#endif
86
87/* If sys/types.h does not supply u_intXX_t, supply them ourselves */
88#ifndef HAVE_U_INTXX_T
89# ifdef HAVE_UINTXX_T
Damien Millere0f45742000-01-18 09:12:06 +110090typedef uint8_t u_int8_t;
Damien Miller74d0d4a1999-12-29 02:24:35 +110091typedef uint16_t u_int16_t;
92typedef uint32_t u_int32_t;
93typedef uint64_t u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110094# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110095# else
Damien Millere0f45742000-01-18 09:12:06 +110096# if (SIZEOF_CHAR == 1)
97typedef unsigned char u_int8_t;
98# else
99# error "8 bit int type not found."
100# endif
Damien Miller5a3e6831999-12-27 09:48:56 +1100101# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100102typedef unsigned short int u_int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100103# else
104# error "16 bit int type not found."
105# endif
106# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100107typedef unsigned int u_int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100108# else
109# error "32 bit int type not found."
110# endif
111# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100112typedef unsigned long int u_int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100113# else
114# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100115typedef unsigned long long int u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +1100116# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100117# else
118# error "64 bit int type not found."
119# endif
120# endif
121# endif
122#endif
123
Damien Miller74d0d4a1999-12-29 02:24:35 +1100124#ifndef HAVE_SOCKLEN_T
125typedef unsigned int socklen_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100126# define HAVE_SOCKLEN_T
Damien Miller74d0d4a1999-12-29 02:24:35 +1100127#endif /* HAVE_SOCKLEN_T */
128
Damien Miller95058511999-12-29 10:36:45 +1100129#ifndef HAVE_SIZE_T
130typedef unsigned int size_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100131# define HAVE_SIZE_T
Damien Miller95058511999-12-29 10:36:45 +1100132#endif /* HAVE_SIZE_T */
133
Damien Miller34132e52000-01-14 15:45:46 +1100134#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
135# define ss_family __ss_family
136#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
137
Damien Miller74d0d4a1999-12-29 02:24:35 +1100138/* Paths */
139
Damien Miller5a3e6831999-12-27 09:48:56 +1100140/* If _PATH_LASTLOG is not defined by system headers, set it to the */
141/* lastlog file detected by autoconf */
142#ifndef _PATH_LASTLOG
143# ifdef LASTLOG_LOCATION
144# define _PATH_LASTLOG LASTLOG_LOCATION
145# endif
146#endif
147
148#ifndef _PATH_UTMP
149# ifdef UTMP_FILE
150# define _PATH_UTMP UTMP_FILE
151# else
152# define _PATH_UTMP "/var/adm/utmp"
153# endif
154#endif
155
156#ifndef _PATH_WTMP
157# ifdef WTMP_FILE
158# define _PATH_WTMP WTMP_FILE
159# else
160# define _PATH_WTMP "/var/adm/wtmp"
161# endif
162#endif
163
164#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
165# ifndef _PATH_UTMPX
166# ifdef UTMPX_FILE
167# define _PATH_UTMPX UTMPX_FILE
168# else
169# define _PATH_UTMPX "/var/adm/utmpx"
170# endif
171# endif
172# ifndef _PATH_WTMPX
173# ifdef WTMPX_FILE
174# define _PATH_WTMPX WTMPX_FILE
175# else
176# define _PATH_WTMPX "/var/adm/wtmp"
177# endif
178# endif
179#endif
180
181#ifndef _PATH_BSHELL
182# define _PATH_BSHELL "/bin/sh"
183#endif
184
185#ifdef USER_PATH
186# ifdef _PATH_STDPATH
187# undef _PATH_STDPATH
188# endif
189# define _PATH_STDPATH USER_PATH
190#endif
191
192#ifndef _PATH_STDPATH
193# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
194#endif
195
196#ifndef _PATH_DEVNULL
197# define _PATH_DEVNULL "/dev/null"
198#endif
199
200#ifndef MAILDIR
201# define MAILDIR MAIL_DIRECTORY
202#endif
203
204#if !defined(_PATH_MAILDIR) && defined(MAILDIR)
205# define _PATH_MAILDIR MAILDIR
206#endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */
207
Damien Miller74d0d4a1999-12-29 02:24:35 +1100208#ifndef _PATH_RSH
209# ifdef RSH_PATH
210# define _PATH_RSH RSH_PATH
211# endif /* RSH_PATH */
212#endif /* _PATH_RSH */
213
214/* Macros */
215
Damien Miller5a3e6831999-12-27 09:48:56 +1100216#ifndef MAX
217# define MAX(a,b) (((a)>(b))?(a):(b))
218# define MIN(a,b) (((a)<(b))?(a):(b))
219#endif
220
221#ifndef timersub
222#define timersub(a, b, result) \
223 do { \
224 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
225 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
226 if ((result)->tv_usec < 0) { \
227 --(result)->tv_sec; \
228 (result)->tv_usec += 1000000; \
229 } \
230 } while (0)
231#endif
232
Damien Miller5a3e6831999-12-27 09:48:56 +1100233#ifndef __P
234# define __P(x) x
235#endif
236
237#if !defined(__GNUC__) || (__GNUC__ < 2)
Damien Millere0f45742000-01-18 09:12:06 +1100238# define __attribute__(x)
Damien Miller5a3e6831999-12-27 09:48:56 +1100239#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
240
Damien Miller74d0d4a1999-12-29 02:24:35 +1100241#if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM)
242# define USE_PAM
243#endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */
244
245/* Function replacement / compatibility hacks */
246
247/* In older versions of libpam, pam_strerror takes a single argument */
248#ifdef HAVE_OLD_PAM
249# define PAM_STRERROR(a,b) pam_strerror((b))
250#else
251# define PAM_STRERROR(a,b) pam_strerror((a),(b))
252#endif
253
Damien Millereca71f82000-01-20 22:38:27 +1100254#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
255# undef HAVE_GETADDRINFO
256#endif /* defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) */
257
Damien Miller6b85a7f2000-01-02 11:45:33 +1100258#endif /* _DEFINES_H */