1 /* 2 * irc_std.h: This is where we make up for operating system lossage 3 * Originally written by Matthew Green, Copyright 1993 4 * Various modifications by various people since then. 5 * 6 * See the copyright file, or do a help ircii copyright 7 */ 8 9 #ifndef __irc_std_h 10 #define __irc_std_h 11 12 #include "defs.h" 13 14 /* 15 * Try to turn back the IPv6 monster at the gate 16 */ 17 #ifdef DO_NOT_USE_IPV6 18 # undef INET6 19 #else 20 # define INET6 21 #endif 22 23 /* 24 * Everybody needs these ANSI headers... 25 */ 26 #include <stdio.h> 27 #include <string.h> 28 #include <stdlib.h> 29 #include <ctype.h> 30 #include <stdarg.h> 31 #ifdef HAVE_STDINT_H 32 #include <stdint.h> 33 #endif 34 #ifdef HAVE_INTTYPES_H 35 #include <inttypes.h> 36 #endif 37 38 /* 39 * Everybody needs these POSIX headers... 40 */ 41 #include <sys/types.h> 42 #include <unistd.h> 43 #include <signal.h> 44 #include <limits.h> 45 #include <sys/param.h> 46 #include <errno.h> 47 #include <sys/stat.h> 48 49 /* 50 * Everybody needs these INET headers... 51 */ 52 #include <sys/socket.h> 53 #include <netinet/in.h> 54 #include <arpa/inet.h> 55 #ifdef HAVE_NETDB_H 56 #include <netdb.h> 57 #endif 58 #ifdef USE_SOCKS5 59 # define INCLUDE_PROTOTYPES 60 # include <socks.h> 61 #endif 62 63 64 /* 65 * Some systems define tputs, etc in this header 66 */ 67 #ifdef HAVE_TERMCAP_H 68 #include <termcap.h> 69 #endif 70 71 72 /* 73 * Deal with brokenness in <time.h> and <sys/time.h> 74 */ 75 #ifdef TIME_WITH_SYS_TIME 76 # include <sys/time.h> 77 # include <time.h> 78 #else 79 # ifdef HAVE_SYS_TIME_H 80 # include <sys/time.h> 81 # else 82 # include <time.h> 83 # endif 84 #endif 85 86 /* 87 * Deal with brokenness in <fcntl.h> and <sys/fcntl.h> 88 */ 89 #ifdef HAVE_SYS_FCNTL_H 90 # include <sys/fcntl.h> 91 #else 92 # ifdef HAVE_FCNTL_H 93 # include <fcntl.h> 94 # endif 95 #endif 96 97 /* 98 * Deal with brokenness figuring out struct direct 99 */ 100 #if HAVE_DIRENT_H 101 # include <dirent.h> 102 # define NAMLEN(dirent) strlen((dirent)->d_name) 103 #else 104 # define dirent direct 105 # define NAMLEN(dirent) (dirent)->d_namlen 106 # if HAVE_SYS_NDIR_H 107 # include <sys/ndir.h> 108 # endif 109 # if HAVE_SYS_DIR_H 110 # include <sys/dir.h> 111 # endif 112 # if HAVE_NDIR_H 113 # include <ndir.h> 114 # endif 115 #endif 116 117 118 119 120 /* 121 * First try to figure out if we can use GNU CC special features... 122 */ 123 #ifndef __GNUC__ 124 # define __inline__ /* delete gcc keyword */ 125 # define __inline 126 # define __A(x) 127 # define __N 128 #else 129 # if (__GNUC__ >= 2) && (__GNUC_MINOR__ >= 7) 130 # define __A(x) __attribute__ ((format (printf, x, x + 1))) 131 # define __N __attribute__ ((noreturn)) 132 # else 133 # define __A(x) 134 # define __N 135 # endif 136 #endif 137 138 /* 139 * Figure out how to make alloca work 140 * I took this from the autoconf documentation 141 */ 142 #if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) 143 # ifndef alloca 144 # define alloca __builtin_alloca 145 # endif 146 #else 147 # if HAVE_ALLOCA_H 148 # include <alloca.h> 149 # else 150 # ifdef _AIX 151 #pragma alloca 152 # else 153 # ifndef alloca 154 char *alloca(); 155 # endif 156 # endif 157 # endif 158 #endif 159 160 /* 161 * Define the MIN and MAX macros if they don't already exist. 162 */ 163 #ifndef MIN 164 # define MIN(a,b) (((a)<(b))?(a):(b)) 165 #endif 166 #ifndef MAX 167 # define MAX(a,b) (((a)>(b))?(a):(b)) 168 #endif 169 170 171 /* 172 * Deal with brokenness with sys_errlist. 173 */ 174 #ifndef HAVE_STRERROR 175 # ifndef SYS_ERRLIST_DECLARED 176 extern char *sys_errlist[]; 177 # endif 178 #define strerror(x) sys_errlist[x] 179 #endif 180 181 /* 182 * Deal with brokenness with realpath. 183 */ 184 #ifdef HAVE_BROKEN_REALPATH 185 # define realpath my_realpath 186 #endif 187 188 /* 189 * Dont trust anyone else's NULLs. 190 */ 191 #ifdef NULL 192 #undef NULL 193 #endif 194 #define NULL (void *) 0 195 196 /* 197 * Make sure there is TRUE and FALSE 198 */ 199 #ifndef TRUE 200 #define TRUE 1 201 #define FALSE 0 202 #endif 203 204 /* 205 * Can you believe some systems done #define this? 206 * I was told that hurd doesn't, so this helps us on hurd. 207 */ 208 #ifndef MAXPATHLEN 209 # ifndef PATHSIZE 210 # define MAXPATHLEN 1024 211 # else 212 # define MAXPATHLEN PATHSIZE 213 # endif 214 #endif 215 216 /* 217 * Define generic macros for signal handlers and built in commands. 218 */ 219 typedef RETSIGTYPE sigfunc (int); 220 int block_signal (int); 221 int unblock_signal (int); 222 sigfunc *my_signal (int, sigfunc *); 223 #define SIGNAL_HANDLER(x) \ 224 RETSIGTYPE x (int unused) 225 226 #define BUILT_IN_COMMAND(x) \ 227 void x (const char *command, char *args, const char *subargs) 228 229 typedef char Filename[MAXPATHLEN + 1]; 230 231 /* 232 * It's really really important that you never use LOCAL_COPY in the actual 233 * argument list of a function call, because bad things can happen. Always 234 * do your LOCAL_COPY as a separate step before you call a function. 235 */ 236 #define LOCAL_COPY(y) strcpy(alloca(strlen((y)) + 1), y) 237 #define SAFE(x) (((x) && *(x)) ? (x) : empty_string) 238 239 /* 240 * Deal with our brokenness wrt ANSI. Sigh. 241 */ 242 #ifndef HAVE_MEMMOVE 243 #define memmove(x, y, z) bcopy(y, x, z) 244 #endif 245 246 /* 247 * DCC specification requires exactly a 32 bit checksum. 248 * Kind of lame, actually. 249 */ 250 #ifdef UNSIGNED_LONG32 251 typedef unsigned long u_32int_t; 252 #else 253 # ifdef UNSIGNED_INT32 254 typedef unsigned int u_32int_t; 255 # else 256 typedef unsigned long u_32int_t; 257 # endif 258 #endif 259 260 /* 261 * Some systems (AIX) have sys/select.h, but dont include it from sys/types.h 262 * Some systems (Solaris) have sys/select.h, but include it from sys/types.h 263 * and dont want you to do it again. Some systems dont have sys/select.h 264 * Configure has this all figured out for us already. 265 */ 266 #if defined(HAVE_SYS_SELECT_H) && defined(NEED_SYS_SELECT_H) 267 #include <sys/select.h> 268 #endif 269 270 /* 271 * Now we deal with lame systems that dont have correct select() 272 * support (like aix 3.2.5, and older linux systems.) 273 */ 274 #ifndef NBBY 275 # define NBBY 8 /* number of bits in a byte */ 276 #endif /* NBBY */ 277 278 #ifndef NFDBITS 279 # define NFDBITS (sizeof(long) * NBBY) /* bits per mask */ 280 #endif /* NFDBITS */ 281 282 #ifndef FD_SETSIZE 283 #define FD_SETSIZE 256 284 #endif 285 286 #ifndef howmany 287 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 288 #endif 289 290 #if defined(HAVE_SYS_SYSCTL_H) 291 #include <sys/sysctl.h> 292 #endif 293 294 /* 295 * Define an RFC2553 compatable "struct sockaddr_storage" if we do not 296 * already have one. 297 */ 298 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE 299 struct sockaddr_storage { 300 #ifdef HAVE_SA_LEN 301 u_char ss_len; 302 u_char ss_family; 303 #else 304 u_short ss_family; 305 #endif 306 u_char padding[128 - 2]; 307 }; 308 #endif 309 310 #ifndef HAVE_SOCKLEN_T 311 typedef int socklen_t; 312 #endif 313 314 #ifndef HAVE_STRUCT_SOCKADDR_IN6 315 #undef INET6 316 #endif 317 318 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO) || !defined(HAVE_STRUCT_ADDRINFO) 319 # define NEED_GAILIB 320 # undef INET6 321 # ifndef HAVE_GETADDRINFO 322 # define getaddrinfo getaddrinfo__compat 323 # define freeaddrinfo freeaddrinfo__compat 324 # define gai_strerror gai_strerror__compat 325 struct addrinfo__compat { 326 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 327 int ai_family; /* PF_xxx */ 328 int ai_socktype; /* SOCK_xxx */ 329 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 330 size_t ai_addrlen; /* length of ai_addr */ 331 char *ai_canonname; /* canonical name for hostname */ 332 struct sockaddr *ai_addr; /* binary address */ 333 struct addrinfo__compat *ai_next; /* next structure in linked list */ 334 }; 335 # define addrinfo addrinfo__compat 336 # endif 337 # ifndef HAVE_GETNAMEINFO 338 # define getnameinfo getnameinfo__compat 339 # endif 340 # include "gailib.h" 341 #endif 342 343 344 /* 345 * Define some lazy shorthand typedefs for commonly used structures 346 */ 347 typedef struct sockaddr SA; 348 typedef struct sockaddr_storage SS; 349 typedef struct sockaddr_in ISA; 350 typedef struct in_addr IA; 351 352 #ifdef INET6 353 typedef struct sockaddr_in6 ISA6; 354 typedef struct sockaddr_in6 I6SA; 355 typedef struct in6_addr IA6; 356 typedef struct in6_addr I6A; 357 #endif 358 359 typedef struct addrinfo AI; 360 typedef struct hostent Hostent; 361 typedef struct timeval Timeval; 362 typedef struct stat Stat; 363 364 /* 365 * Interix's getpgrp() does not take an argument, but the configure script 366 * detects it wrongly. 367 */ 368 #ifdef __INTERIX 369 # define GETPGRP_VOID 370 #endif 371 372 #endif /* __irc_std_h */ 373