unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

sys.h (5831B)

      1 /*
      2  *   Unreal Internet Relay Chat Daemon, include/sys.h
      3  *   Copyright (C) 1990 University of Oulu, Computing Center
      4  *
      5  *   This program is free software; you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 1, or (at your option)
      8  *   any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  *   GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program; if not, write to the Free Software
     17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18  *   
     19  *   $Id$
     20  */
     21 
     22 #ifndef	__sys_include__
     23 #define __sys_include__
     24 
     25 /* PATH_MAX */
     26 #include <limits.h>
     27 
     28 #ifdef ISC202
     29 #include <net/errno.h>
     30 #else
     31 #include <errno.h>
     32 #endif
     33 #include "setup.h"
     34 #include <stdio.h>
     35 #include <sys/types.h>
     36 #ifndef _WIN32
     37 #include <sys/param.h>
     38 #else
     39 #include <stdarg.h>
     40 #include <process.h>
     41 #endif
     42 #include <stdlib.h>
     43 #ifndef _WIN32
     44 #include <unistd.h>
     45 #include <strings.h>
     46 #include <sys/resource.h>
     47 #endif
     48 
     49 /* get intptr_t if the system provides it -- otherwise, ./configure will define it for us */
     50 #ifdef HAVE_STDINT_H
     51 #include <stdint.h>
     52 #else
     53 #ifdef HAVE_INTTYPES_H
     54 #include <inttypes.h>
     55 #endif /* HAVE_INTTYPES_H */
     56 #endif /* HAVE_STDINT_H */
     57 
     58 #ifndef _WIN32
     59 #include <netinet/in.h>
     60 #include <sys/socket.h>
     61 #include <sys/un.h>
     62 #include <arpa/inet.h>
     63 #else
     64 #include <winsock2.h>
     65 #include <ws2tcpip.h>
     66 #include <afunix.h>
     67 #endif
     68 
     69 #ifndef _WIN32
     70 #include <sys/time.h>
     71 #endif
     72 #include <time.h>
     73 
     74 #ifndef _WIN32
     75 #include <sys/wait.h>
     76 #ifndef WEXITSTATUS
     77 #define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
     78 #endif
     79 #ifndef WIFEXITED
     80 #define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
     81 #endif
     82 #endif
     83 
     84 /*
     85  * Different name on NetBSD, FreeBSD, and BSDI
     86  */
     87 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__bsdi__) || defined(__linux__) || defined(__APPLE__)
     88 #define dn_skipname  __dn_skipname
     89 #endif
     90 
     91 /*
     92  * Mac OS X Tiger Support (Intel Only)
     93  */
     94 #if defined(macosx) || defined(__APPLE__)
     95 #define OSXTIGER
     96 #endif
     97 
     98 #ifndef _WIN32
     99 extern void dummy();
    100 #endif
    101 
    102 #ifdef	NO_U_TYPES
    103 typedef unsigned char u_char;
    104 typedef unsigned short u_short;
    105 typedef unsigned long u_long;
    106 typedef unsigned int u_int;
    107 #endif
    108 
    109 #ifdef _WIN32
    110 #define MYOSNAME OSName
    111 extern char OSName[256];
    112 #define PATH_MAX MAX_PATH
    113 #define getpid _getpid
    114 #else
    115 #define MYOSNAME getosname()
    116 #endif
    117 
    118 #define MYDUMMY_SIZE 128
    119 
    120 /*
    121  * Socket, File, and Error portability macros
    122  */
    123 #ifndef _WIN32
    124 #define SET_ERRNO(x) errno = x
    125 #define READ_SOCK(fd, buf, len) read((fd), (buf), (len))
    126 #define WRITE_SOCK(fd, buf, len) write((fd), (buf), (len))
    127 #define CLOSE_SOCK(fd) close(fd)
    128 #define IOCTL(x, y, z) ioctl((x), (y), (z))
    129 #define ERRNO errno
    130 #define STRERROR(x) strerror(x)
    131 
    132 /* error constant portability */
    133 #define P_EMFILE        EMFILE
    134 #define P_ENOBUFS       ENOBUFS
    135 #define P_EWOULDBLOCK   EWOULDBLOCK
    136 #define P_EAGAIN        EAGAIN
    137 #define P_EINPROGRESS   EINPROGRESS
    138 #define P_EWORKING		EINPROGRESS
    139 #define P_EINTR         EINTR
    140 #define P_ETIMEDOUT     ETIMEDOUT
    141 #define P_ENOTSOCK	ENOTSOCK
    142 #define P_EIO		EIO
    143 #define P_ECONNABORTED	ECONNABORTED
    144 #define P_ECONNRESET	ECONNRESET
    145 #define P_ENOTCONN	ENOTCONN
    146 #define P_EMSGSIZE	EMSGSIZE
    147 #else
    148 /* WIN32 */
    149 
    150 #define NETDB_INTERNAL  -1  /* see errno */
    151 #define NETDB_SUCCESS   0   /* no problem */
    152 
    153 /* IO and Error portability macros */
    154 #define READ_SOCK(fd, buf, len) recv((fd), (buf), (len), 0)
    155 #define WRITE_SOCK(fd, buf, len) send((fd), (buf), (len), 0)
    156 #define CLOSE_SOCK(fd) closesocket(fd)
    157 #define IOCTL(x, y, z) ioctlsocket((x), (y), (z))
    158 #define ERRNO WSAGetLastError()
    159 #define STRERROR(x) sock_strerror(x)
    160 #define SET_ERRNO(x) WSASetLastError(x)
    161 /* Error constant portability */
    162 #define P_EMFILE        WSAEMFILE
    163 #define P_ENOBUFS       WSAENOBUFS
    164 #define P_EWOULDBLOCK   WSAEWOULDBLOCK
    165 #define P_EAGAIN        WSAEWOULDBLOCK
    166 #define P_EINPROGRESS   WSAEINPROGRESS
    167 #define P_EWORKING		WSAEWOULDBLOCK
    168 #define P_EINTR         WSAEINTR
    169 #define P_ETIMEDOUT     WSAETIMEDOUT
    170 #define P_ENOTSOCK	WSAENOTSOCK
    171 #define P_EIO		EIO
    172 #define P_ECONNABORTED	WSAECONNABORTED
    173 #define P_ECONNRESET	WSAECONNRESET
    174 #define P_ENOTCONN	WSAENOTCONN
    175 #define P_EMSGSIZE	WSAEMSGSIZE
    176 #endif
    177 
    178 #ifndef __GNUC__
    179 #define __attribute__(x) /* nothing */
    180 #endif
    181 
    182 #undef FORMAT_STRING
    183 #if _MSC_VER >= 1400
    184 # include <sal.h>
    185 # if _MSC_VER > 1400
    186 #  define FORMAT_STRING(p) _Printf_format_string_ p
    187 # else
    188 #  define FORMAT_STRING(p) __format_string p
    189 # endif /* FORMAT_STRING */
    190 #else
    191 # define FORMAT_STRING(p) p
    192 #endif /* _MSC_VER */
    193 
    194 /* A normal abort() on windows causes the crucial stack frame to be missing
    195  * from the stack trace, IOTW: you don't see where abort() was called!
    196  * It's silly but this works:
    197  */
    198 #ifdef _WIN32
    199  #define abort()  do { char *crash = NULL; *crash = 'x'; exit(1); } while(0)
    200 #endif
    201 
    202 #ifndef SOMAXCONN
    203 # define LISTEN_SIZE	(5)
    204 #else
    205 # define LISTEN_SIZE	(SOMAXCONN)
    206 #endif
    207 
    208 /*
    209  * Try and find the correct name to use with getrlimit() for setting the max.
    210  * number of files allowed to be open by this process.
    211  */
    212 #ifdef RLIMIT_FDMAX
    213 # define RLIMIT_FD_MAX   RLIMIT_FDMAX
    214 #else
    215 # ifdef RLIMIT_NOFILE
    216 #  define RLIMIT_FD_MAX RLIMIT_NOFILE
    217 # else
    218 #  ifdef RLIMIT_OPEN_MAX
    219 #   define RLIMIT_FD_MAX RLIMIT_OPEN_MAX
    220 #  else
    221 #   undef RLIMIT_FD_MAX
    222 #  endif
    223 # endif
    224 #endif
    225 
    226 #ifdef NATIVE_BIG_ENDIAN
    227  #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
    228   #include <sys/endian.h>
    229   #define bswap_64 bswap64
    230   #define bswap_32 bswap32
    231   #define bswap_16 bswap16
    232  #else
    233   #include <byteswap.h>
    234  #endif
    235 #endif
    236 
    237 #endif /* __sys_include__ */