Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 1 | #ifndef _DEFINES_H |
| 2 | #define _DEFINES_H |
| 3 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 4 | /* Necessary headers */ |
| 5 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 6 | #include <sys/types.h> /* For u_intXX_t */ |
| 7 | #include <sys/socket.h> /* For SHUT_XXXX */ |
| 8 | |
| 9 | #ifdef HAVE_PATHS_H |
| 10 | # include <paths.h> /* For _PATH_XXX */ |
| 11 | #endif |
| 12 | |
| 13 | #ifdef HAVE_UTMP_H |
| 14 | # include <utmp.h> /* For _PATH_XXX */ |
| 15 | #endif |
| 16 | |
| 17 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
| 18 | # include <utmpx.h> /* For _PATH_XXX */ |
| 19 | #endif |
| 20 | |
| 21 | #ifdef HAVE_SYS_TIME_H |
| 22 | # include <sys/time.h> /* For timersub */ |
| 23 | #endif |
| 24 | |
| 25 | #ifdef HAVE_MAILLOCK_H |
Damien Miller | beb4ba5 | 1999-12-28 15:09:35 +1100 | [diff] [blame] | 26 | # include <maillock.h> /* For _PATH_MAILDIR */ |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 27 | #endif |
| 28 | |
Damien Miller | beb4ba5 | 1999-12-28 15:09:35 +1100 | [diff] [blame] | 29 | #ifdef HAVE_SYS_CDEFS_H |
| 30 | # include <sys/cdefs.h> /* For __P() */ |
| 31 | #endif |
| 32 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 33 | /* Constants */ |
| 34 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 35 | #ifndef SHUT_RDWR |
| 36 | enum |
| 37 | { |
| 38 | SHUT_RD = 0, /* No more receptions. */ |
| 39 | SHUT_WR, /* No more transmissions. */ |
| 40 | SHUT_RDWR /* No more receptions or transmissions. */ |
| 41 | }; |
| 42 | # define SHUT_RD SHUT_RD |
| 43 | # define SHUT_WR SHUT_WR |
| 44 | # define SHUT_RDWR SHUT_RDWR |
| 45 | #endif |
| 46 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 47 | /* Types */ |
| 48 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 49 | /* If sys/types.h does not supply intXX_t, supply them ourselves */ |
| 50 | /* (or die trying) */ |
| 51 | #ifndef HAVE_INTXX_T |
| 52 | # if (SIZEOF_SHORT_INT == 2) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 53 | typedef short int int16_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 54 | # else |
| 55 | # error "16 bit int type not found." |
| 56 | # endif |
| 57 | # if (SIZEOF_INT == 4) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 58 | typedef int int32_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 59 | # else |
| 60 | # error "32 bit int type not found." |
| 61 | # endif |
| 62 | # if (SIZEOF_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 63 | typedef long int int64_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 64 | # else |
| 65 | # if (SIZEOF_LONG_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 66 | typedef long long int int64_t; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 67 | # define HAVE_INTXX_T 1 |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 68 | # else |
| 69 | # error "64 bit int type not found." |
| 70 | # endif |
| 71 | # endif |
| 72 | #endif |
| 73 | |
| 74 | /* If sys/types.h does not supply u_intXX_t, supply them ourselves */ |
| 75 | #ifndef HAVE_U_INTXX_T |
| 76 | # ifdef HAVE_UINTXX_T |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 77 | typedef uint16_t u_int16_t; |
| 78 | typedef uint32_t u_int32_t; |
| 79 | typedef uint64_t u_int64_t; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 80 | # define HAVE_U_INTXX_T 1 |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 81 | # else |
| 82 | # if (SIZEOF_SHORT_INT == 2) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 83 | typedef unsigned short int u_int16_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 84 | # else |
| 85 | # error "16 bit int type not found." |
| 86 | # endif |
| 87 | # if (SIZEOF_INT == 4) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 88 | typedef unsigned int u_int32_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 89 | # else |
| 90 | # error "32 bit int type not found." |
| 91 | # endif |
| 92 | # if (SIZEOF_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 93 | typedef unsigned long int u_int64_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 94 | # else |
| 95 | # if (SIZEOF_LONG_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 96 | typedef unsigned long long int u_int64_t; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 97 | # define HAVE_U_INTXX_T 1 |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 98 | # else |
| 99 | # error "64 bit int type not found." |
| 100 | # endif |
| 101 | # endif |
| 102 | # endif |
| 103 | #endif |
| 104 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 105 | #ifndef HAVE_SOCKLEN_T |
| 106 | typedef unsigned int socklen_t; |
Damien Miller | b2532b3 | 1999-12-31 09:18:12 +1100 | [diff] [blame] | 107 | # define HAVE_SOCKLEN_T |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 108 | #endif /* HAVE_SOCKLEN_T */ |
| 109 | |
Damien Miller | 9505851 | 1999-12-29 10:36:45 +1100 | [diff] [blame] | 110 | #ifndef HAVE_SIZE_T |
| 111 | typedef unsigned int size_t; |
Damien Miller | b2532b3 | 1999-12-31 09:18:12 +1100 | [diff] [blame] | 112 | # define HAVE_SIZE_T |
Damien Miller | 9505851 | 1999-12-29 10:36:45 +1100 | [diff] [blame] | 113 | #endif /* HAVE_SIZE_T */ |
| 114 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 115 | /* Paths */ |
| 116 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 117 | /* If _PATH_LASTLOG is not defined by system headers, set it to the */ |
| 118 | /* lastlog file detected by autoconf */ |
| 119 | #ifndef _PATH_LASTLOG |
| 120 | # ifdef LASTLOG_LOCATION |
| 121 | # define _PATH_LASTLOG LASTLOG_LOCATION |
| 122 | # endif |
| 123 | #endif |
| 124 | |
| 125 | #ifndef _PATH_UTMP |
| 126 | # ifdef UTMP_FILE |
| 127 | # define _PATH_UTMP UTMP_FILE |
| 128 | # else |
| 129 | # define _PATH_UTMP "/var/adm/utmp" |
| 130 | # endif |
| 131 | #endif |
| 132 | |
| 133 | #ifndef _PATH_WTMP |
| 134 | # ifdef WTMP_FILE |
| 135 | # define _PATH_WTMP WTMP_FILE |
| 136 | # else |
| 137 | # define _PATH_WTMP "/var/adm/wtmp" |
| 138 | # endif |
| 139 | #endif |
| 140 | |
| 141 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
| 142 | # ifndef _PATH_UTMPX |
| 143 | # ifdef UTMPX_FILE |
| 144 | # define _PATH_UTMPX UTMPX_FILE |
| 145 | # else |
| 146 | # define _PATH_UTMPX "/var/adm/utmpx" |
| 147 | # endif |
| 148 | # endif |
| 149 | # ifndef _PATH_WTMPX |
| 150 | # ifdef WTMPX_FILE |
| 151 | # define _PATH_WTMPX WTMPX_FILE |
| 152 | # else |
| 153 | # define _PATH_WTMPX "/var/adm/wtmp" |
| 154 | # endif |
| 155 | # endif |
| 156 | #endif |
| 157 | |
| 158 | #ifndef _PATH_BSHELL |
| 159 | # define _PATH_BSHELL "/bin/sh" |
| 160 | #endif |
| 161 | |
| 162 | #ifdef USER_PATH |
| 163 | # ifdef _PATH_STDPATH |
| 164 | # undef _PATH_STDPATH |
| 165 | # endif |
| 166 | # define _PATH_STDPATH USER_PATH |
| 167 | #endif |
| 168 | |
| 169 | #ifndef _PATH_STDPATH |
| 170 | # define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" |
| 171 | #endif |
| 172 | |
| 173 | #ifndef _PATH_DEVNULL |
| 174 | # define _PATH_DEVNULL "/dev/null" |
| 175 | #endif |
| 176 | |
| 177 | #ifndef MAILDIR |
| 178 | # define MAILDIR MAIL_DIRECTORY |
| 179 | #endif |
| 180 | |
| 181 | #if !defined(_PATH_MAILDIR) && defined(MAILDIR) |
| 182 | # define _PATH_MAILDIR MAILDIR |
| 183 | #endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */ |
| 184 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 185 | #ifndef _PATH_RSH |
| 186 | # ifdef RSH_PATH |
| 187 | # define _PATH_RSH RSH_PATH |
| 188 | # endif /* RSH_PATH */ |
| 189 | #endif /* _PATH_RSH */ |
| 190 | |
| 191 | /* Macros */ |
| 192 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 193 | #ifndef MAX |
| 194 | # define MAX(a,b) (((a)>(b))?(a):(b)) |
| 195 | # define MIN(a,b) (((a)<(b))?(a):(b)) |
| 196 | #endif |
| 197 | |
| 198 | #ifndef timersub |
| 199 | #define timersub(a, b, result) \ |
| 200 | do { \ |
| 201 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
| 202 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
| 203 | if ((result)->tv_usec < 0) { \ |
| 204 | --(result)->tv_sec; \ |
| 205 | (result)->tv_usec += 1000000; \ |
| 206 | } \ |
| 207 | } while (0) |
| 208 | #endif |
| 209 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 210 | #ifndef __P |
| 211 | # define __P(x) x |
| 212 | #endif |
| 213 | |
| 214 | #if !defined(__GNUC__) || (__GNUC__ < 2) |
| 215 | # define __attribute__(x) |
| 216 | #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ |
| 217 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 218 | #if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) |
| 219 | # define USE_PAM |
| 220 | #endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */ |
| 221 | |
| 222 | /* Function replacement / compatibility hacks */ |
| 223 | |
| 224 | /* In older versions of libpam, pam_strerror takes a single argument */ |
| 225 | #ifdef HAVE_OLD_PAM |
| 226 | # define PAM_STRERROR(a,b) pam_strerror((b)) |
| 227 | #else |
| 228 | # define PAM_STRERROR(a,b) pam_strerror((a),(b)) |
| 229 | #endif |
| 230 | |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 231 | #endif /* _DEFINES_H */ |