1 /* 2 * irc_std.h: header to define things used in all the programs ircii 3 * comes with 4 * 5 * hacked together from various other files by matthew green 6 * 7 * Copyright (c) 1992-1998 Matthew R. Green. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)$Id: irc_std.h,v 1.34 2000/04/04 03:10:48 mrg Exp $ 34 */ 35 36 #ifndef __irc_std_h 37 #define __irc_std_h 38 39 #undef _ 40 #if defined(__STDC__) || defined(__BORLANDC__) 41 # define _(a) a 42 #else 43 # define _(a) () 44 # ifdef const 45 # undef const 46 # endif /* cost */ 47 # define const 48 #endif /* __STDC__ */ 49 50 /* 51 * these things help with converting to/from char* and u_char* 52 */ 53 #define UP(s) ((u_char *)(s)) 54 #define CP(s) ((char *)(s)) 55 /* this makes u_char *0 look better */ 56 #define UNULL UP(0) 57 #define my_strsep(s,d) strsep((char **)s, (const char *)d) 58 #define my_strlen(s) strlen(CP(s)) 59 #define my_strcmp(d,s) strcmp(CP(d), CP(s)) 60 #define my_strncmp(d,s,n) strncmp(CP(d), CP(s), (n)) 61 #define my_strcat(d,s) strcat(CP(d), CP(s)) 62 #define my_strncat(d,s,n) strncat(CP(d), CP(s), (n)) 63 #define my_strmcat(d,s,n) strmcat(UP(d), UP(s), (n)) 64 #define my_strcpy(d,s) strcpy(CP(d), CP(s)) 65 #define my_strncpy(d,s,n) strncpy(CP(d), CP(s), (n)) 66 #define my_strmcpy(d,s,n) strmcpy(UP(d), UP(s), (n)) 67 #define my_index(s,c) UP(index(CP(s), (c))) 68 #define my_rindex(s,c) UP(rindex(CP(s), (c))) 69 #define my_atoi(s) atoi(CP(s)) 70 #define my_atol(s) atol(CP(s)) 71 #define my_getenv(s) UP(getenv(CP(s))) 72 73 #if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) 74 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 75 #endif 76 77 #ifndef lint 78 #define IRCII_RCSID(x) static const char rcsid[] __attribute__((__unused__)) = x 79 #else 80 #define IRCII_RCSID(x) 81 #endif 82 83 #ifdef _IBMR2 84 # include <sys/errno.h> 85 # include <sys/select.h> 86 #else 87 # include <errno.h> 88 #ifndef ERRNO_DECLARED 89 extern int errno; 90 #endif 91 #endif /* _IBMR2 */ 92 93 #ifndef NBBY 94 # define NBBY 8 /* number of bits in a byte */ 95 #endif /* NBBY */ 96 97 #ifndef NFDBITS 98 # define NFDBITS (sizeof(long) * NBBY) /* bits per mask */ 99 #endif /* NFDBITS */ 100 101 #ifndef FD_SET 102 # define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) 103 #endif /* FD_SET */ 104 105 #ifndef FD_CLR 106 # define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) 107 #endif /* FD_CLR */ 108 109 #ifndef FD_ISSET 110 # define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) 111 #endif /* FD_ISSET */ 112 113 #ifndef FD_ZERO 114 # define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) 115 #endif /* FD_ZERO */ 116 117 #ifndef FD_SETSIZE 118 # define FD_SETSIZE 32 119 #endif /* FD_SETSIZE */ 120 121 typedef RETSIGTYPE sigfunc _((void)); 122 123 #ifdef USE_SIGACTION 124 sigfunc *my_signal _((int, sigfunc *, int)); 125 # define MY_SIGNAL(s_n, s_h, m_f) my_signal(s_n, s_h, m_f) 126 #else 127 # if USE_SIGSET 128 # define MY_SIGNAL(s_n, s_h, m_f) sigset(s_n, s_h) 129 # else 130 # define MY_SIGNAL(s_n, s_h, m_f) signal(s_n, s_h) 131 # endif /* USE_SIGSET */ 132 #endif /* USE_SIGACTION */ 133 134 #if defined(USE_SIGACTION) || defined(USE_SIGSET) 135 # undef SYSVSIGNALS 136 #endif /* USE_SIGACTION || USE_SIGSET */ 137 138 #if defined(__svr4__) || defined(SVR4) || defined(__SVR4) 139 # if !defined(__svr4__) 140 # define __svr4__ 141 # endif /* __svr4__ */ 142 # if !defined(SVR4) 143 # define SVR4 144 # endif /* SVR4 */ 145 # if !defined(__SVR4) 146 # define __SVR4 147 # endif /* __SVR4 */ 148 #endif /* __svr4__ || SVR4 || __SVR4 */ 149 150 #ifdef _SEQUENT_ 151 # define u_short ushort 152 # define u_char unchar 153 # define u_long ulong 154 # define u_int uint 155 # define USE_TERMIO 156 # ifndef POSIX 157 # define POSIX 158 # endif /* POSIX */ 159 #endif /* _SEQUENT_ */ 160 161 #ifndef NeXT 162 # if defined(STDC_HEADERS) || defined(HAVE_STRING_H) 163 # include <string.h> 164 # if defined(STDC_HEADERS) 165 # include <stdlib.h> 166 # endif /* HAVE_STDLIB_H */ 167 # if defined(HAVE_MEMORY_H) 168 # include <memory.h> 169 # endif /* HAVE_MEMORY_H */ 170 # undef index 171 # undef rindex 172 # undef bcopy 173 # undef bzero 174 # undef bcmp 175 # define index strchr 176 # define rindex strrchr 177 # ifdef HAVE_MEMMOVE 178 # define bcopy(s, d, n) memmove((d), (s), (n)) 179 # else 180 # define bcopy(s, d, n) memcpy ((d), (s), (n)) 181 # endif /* HAVE_MEMMOVE */ 182 # define bcmp(s, t, n) memcmp ((s), (t), (n)) 183 # define bzero(s, n) memset ((s), 0, (n)) 184 # else /* STDC_HEADERS || HAVE_STRING_H */ 185 # include <strings.h> 186 # endif /* STDC_HEADERS || HAVE_STRING_H */ 187 #endif /* !NeXT */ 188 189 #ifdef _Windows 190 # define IS_ABSOLUTE_PATH(file) ((file)[0] == '/' || (file)[0] == '\\' || ((file)[0] && (file)[1] == ':')) 191 #else 192 # define IS_ABSOLUTE_PATH(file) ((file)[0] == '/') 193 #endif 194 195 #if !defined(SYS_ERRLIST_DECLARED) && !defined(_Windows) 196 extern char *sys_errlist[]; 197 extern int sys_nerr; 198 #endif 199 200 #ifdef _Windows 201 extern char FAR * FAR winsock_errors[]; 202 # define strerror(e) ((e) >= 0 && (e) < sys_nerr ? sys_errlist[e] : ((e) >=WSABASEERR ? winsock_errors[(e) - WSABASEERR] : "(unknown)")) 203 #else 204 # ifdef NEED_STRERROR 205 # undef strerror 206 # define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e]) 207 # endif 208 #endif 209 210 /* we need an unsigned 32 bit integer for dcc, how lame */ 211 212 #ifdef UNSIGNED_LONG32 213 214 typedef unsigned long u_32int; 215 216 #else 217 # ifdef UNSIGNED_INT32 218 219 typedef unsigned int u_32int; 220 221 # else 222 223 typedef unsigned long u_32int; 224 225 # endif /* UNSIGNED_INT32 */ 226 #endif /* UNSIGNED_LONG32 */ 227 228 #endif /* __irc_std_h */ 229