blob: 9c88f2e85ce56522a23fa3ef51cbe3c4ffb914ac [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 Miller74d0d4a1999-12-29 02:24:35 +110037/* Constants */
38
Damien Miller5a3e6831999-12-27 09:48:56 +110039#ifndef SHUT_RDWR
40enum
41{
42 SHUT_RD = 0, /* No more receptions. */
43 SHUT_WR, /* No more transmissions. */
44 SHUT_RDWR /* No more receptions or transmissions. */
45};
46# define SHUT_RD SHUT_RD
47# define SHUT_WR SHUT_WR
48# define SHUT_RDWR SHUT_RDWR
49#endif
50
Damien Miller74d0d4a1999-12-29 02:24:35 +110051/* Types */
52
Damien Miller5a3e6831999-12-27 09:48:56 +110053/* If sys/types.h does not supply intXX_t, supply them ourselves */
54/* (or die trying) */
55#ifndef HAVE_INTXX_T
56# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +110057typedef short int int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110058# else
59# error "16 bit int type not found."
60# endif
61# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +110062typedef int int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110063# else
64# error "32 bit int type not found."
65# endif
66# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110067typedef long int int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110068# else
69# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110070typedef long long int int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110071# define HAVE_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110072# else
73# error "64 bit int type not found."
74# endif
75# endif
76#endif
77
78/* If sys/types.h does not supply u_intXX_t, supply them ourselves */
79#ifndef HAVE_U_INTXX_T
80# ifdef HAVE_UINTXX_T
Damien Miller74d0d4a1999-12-29 02:24:35 +110081typedef uint16_t u_int16_t;
82typedef uint32_t u_int32_t;
83typedef uint64_t u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +110084# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +110085# else
86# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +110087typedef unsigned short int u_int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110088# else
89# error "16 bit int type not found."
90# endif
91# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +110092typedef unsigned int u_int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110093# else
94# error "32 bit int type not found."
95# endif
96# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +110097typedef unsigned long int u_int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +110098# else
99# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100100typedef unsigned long long int u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +1100101# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100102# else
103# error "64 bit int type not found."
104# endif
105# endif
106# endif
107#endif
108
Damien Miller74d0d4a1999-12-29 02:24:35 +1100109#ifndef HAVE_SOCKLEN_T
110typedef unsigned int socklen_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100111# define HAVE_SOCKLEN_T
Damien Miller74d0d4a1999-12-29 02:24:35 +1100112#endif /* HAVE_SOCKLEN_T */
113
Damien Miller95058511999-12-29 10:36:45 +1100114#ifndef HAVE_SIZE_T
115typedef unsigned int size_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100116# define HAVE_SIZE_T
Damien Miller95058511999-12-29 10:36:45 +1100117#endif /* HAVE_SIZE_T */
118
Damien Miller34132e52000-01-14 15:45:46 +1100119#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
120# define ss_family __ss_family
121#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
122
Damien Miller74d0d4a1999-12-29 02:24:35 +1100123/* Paths */
124
Damien Miller5a3e6831999-12-27 09:48:56 +1100125/* If _PATH_LASTLOG is not defined by system headers, set it to the */
126/* lastlog file detected by autoconf */
127#ifndef _PATH_LASTLOG
128# ifdef LASTLOG_LOCATION
129# define _PATH_LASTLOG LASTLOG_LOCATION
130# endif
131#endif
132
133#ifndef _PATH_UTMP
134# ifdef UTMP_FILE
135# define _PATH_UTMP UTMP_FILE
136# else
137# define _PATH_UTMP "/var/adm/utmp"
138# endif
139#endif
140
141#ifndef _PATH_WTMP
142# ifdef WTMP_FILE
143# define _PATH_WTMP WTMP_FILE
144# else
145# define _PATH_WTMP "/var/adm/wtmp"
146# endif
147#endif
148
149#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
150# ifndef _PATH_UTMPX
151# ifdef UTMPX_FILE
152# define _PATH_UTMPX UTMPX_FILE
153# else
154# define _PATH_UTMPX "/var/adm/utmpx"
155# endif
156# endif
157# ifndef _PATH_WTMPX
158# ifdef WTMPX_FILE
159# define _PATH_WTMPX WTMPX_FILE
160# else
161# define _PATH_WTMPX "/var/adm/wtmp"
162# endif
163# endif
164#endif
165
166#ifndef _PATH_BSHELL
167# define _PATH_BSHELL "/bin/sh"
168#endif
169
170#ifdef USER_PATH
171# ifdef _PATH_STDPATH
172# undef _PATH_STDPATH
173# endif
174# define _PATH_STDPATH USER_PATH
175#endif
176
177#ifndef _PATH_STDPATH
178# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
179#endif
180
181#ifndef _PATH_DEVNULL
182# define _PATH_DEVNULL "/dev/null"
183#endif
184
185#ifndef MAILDIR
186# define MAILDIR MAIL_DIRECTORY
187#endif
188
189#if !defined(_PATH_MAILDIR) && defined(MAILDIR)
190# define _PATH_MAILDIR MAILDIR
191#endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */
192
Damien Miller74d0d4a1999-12-29 02:24:35 +1100193#ifndef _PATH_RSH
194# ifdef RSH_PATH
195# define _PATH_RSH RSH_PATH
196# endif /* RSH_PATH */
197#endif /* _PATH_RSH */
198
199/* Macros */
200
Damien Miller5a3e6831999-12-27 09:48:56 +1100201#ifndef MAX
202# define MAX(a,b) (((a)>(b))?(a):(b))
203# define MIN(a,b) (((a)<(b))?(a):(b))
204#endif
205
206#ifndef timersub
207#define timersub(a, b, result) \
208 do { \
209 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
210 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
211 if ((result)->tv_usec < 0) { \
212 --(result)->tv_sec; \
213 (result)->tv_usec += 1000000; \
214 } \
215 } while (0)
216#endif
217
Damien Miller5a3e6831999-12-27 09:48:56 +1100218#ifndef __P
219# define __P(x) x
220#endif
221
222#if !defined(__GNUC__) || (__GNUC__ < 2)
223# define __attribute__(x)
224#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
225
Damien Miller74d0d4a1999-12-29 02:24:35 +1100226#if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM)
227# define USE_PAM
228#endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */
229
230/* Function replacement / compatibility hacks */
231
232/* In older versions of libpam, pam_strerror takes a single argument */
233#ifdef HAVE_OLD_PAM
234# define PAM_STRERROR(a,b) pam_strerror((b))
235#else
236# define PAM_STRERROR(a,b) pam_strerror((a),(b))
237#endif
238
Damien Millerb29ea912000-01-15 14:12:03 +1100239/* Solaris doesn't have a public [v]snprintf() function, but it has */
240/* __[v]snprintf() */
241#if !defined(HAVE_SNPRINTF) && defined(HAVE___SNPRINTF)
242# define snprintf __snprintf
243#endif /* !defined(HAVE_SNPRINTF) && defined(HAVE___SNPRINTF) */
244#if !defined(HAVE_VSNPRINTF) && defined(HAVE___VSNPRINTF)
245# define vsnprintf __vsnprintf
246#endif /* !defined(HAVE_VSNPRINTF) && defined(HAVE___VSNPRINTF) */
247
Damien Miller6b85a7f2000-01-02 11:45:33 +1100248#endif /* _DEFINES_H */