1 /* 2 * (c) 1998-2018 by Columbia University; all rights reserved 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of the University nor the names of its contributors 15 * may be used to endorse or promote products derived from this software 16 * without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef SYSDEP_H 32 #define SYSDEP_H 33 34 35 #if defined(unix) || defined(__unix) || defined (__unix__) 36 /* Code for Unix. Any Unix compiler should define one of the above three 37 * symbols. */ 38 39 #ifndef startupSocket 40 #define startupSocket() 41 #endif 42 43 #ifndef closesocket 44 #define closesocket close 45 #endif 46 47 #ifndef write_socket 48 #define write_socket(r, s, l) write(r, s, l) 49 #endif 50 51 /* end of 'if unix' */ 52 53 #elif defined(WIN32) || defined(__WIN32__) 54 55 #include <winsock2.h> /* For NT socket */ 56 #include <ws2tcpip.h> /* IP_ADD_MEMBERSHIP */ 57 #include <windows.h> 58 #include <stdio.h> /* stderr */ 59 #include <time.h> /* time_t */ 60 61 #define HAVE_STDINT_H 1 62 #define RTP_LITTLE_ENDIAN 1 63 64 /* Determine if the C(++) compiler requires complete function prototype */ 65 #ifndef __P 66 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) 67 #define __P(x) x 68 #else 69 #define __P(x) () 70 #endif 71 #endif 72 73 #ifdef __BORLANDC__ 74 #include <io.h> 75 #define strcasecmp stricmp 76 #define strncasecmp strnicmp 77 #endif /* __BORLANDC__ */ 78 79 #ifdef _MSC_VER 80 #define strcasecmp _stricmp 81 #define strncasecmp _strnicmp 82 #define open _open 83 #define write _write 84 #define close _close 85 #define ftime _ftime 86 #define timeb _timeb 87 #endif /* _MSC_VER */ 88 89 #ifndef SIGBUS 90 #define SIGBUS SIGINT 91 #endif 92 93 #ifndef SIGHUP 94 #define SIGHUP SIGINT 95 #endif 96 97 #ifndef SIGPIPE 98 #define SIGPIPE SIGINT 99 #endif 100 101 #ifndef EADDRNOTAVAIL 102 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 103 #endif 104 105 typedef SSIZE_T ssize_t; 106 107 typedef INT32 pid_t; 108 typedef UINT32 gid_t; 109 typedef UINT32 uid_t; 110 111 typedef char * caddr_t; /* core address */ 112 typedef long fd_mask; 113 #define NBBY 8 /* number of bits in a byte */ 114 #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ 115 116 #ifndef howmany 117 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 118 #endif 119 120 struct iovec { 121 void *iov_base; /* Starting address */ 122 size_t iov_len; /* Number of bytes to transfer */ 123 }; 124 125 struct msghdr { 126 caddr_t msg_name; /* optional address */ 127 int msg_namelen; /* size of address */ 128 struct iovec *msg_iov; /* scatter/gather array */ 129 int msg_iovlen; /* # elements in msg_iov */ 130 caddr_t msg_accrights; /* access rights sent/received */ 131 int msg_accrightslen; 132 }; 133 134 struct passwd { 135 char *pw_name; 136 char *pw_passwd; 137 uid_t pw_uid; 138 gid_t pw_gid; 139 char *pw_age; 140 char *pw_comment; 141 char *pw_gecos; 142 char *pw_dir; 143 char *pw_shell; 144 }; 145 146 #define ITIMER_REAL 0 /* Decrements in real time */ 147 148 #ifndef _TIMESPEC_T 149 #define _TIMESPEC_T 150 typedef struct timespec { /* definition per POSIX.4 */ 151 time_t tv_sec; /* seconds */ 152 long tv_nsec; /* and nanoseconds */ 153 } timespec_t; 154 #endif /* _TIMESPEC_T */ 155 156 struct itimerval { 157 struct timeval it_interval; /* timer interval */ 158 struct timeval it_value; /* current value */ 159 }; 160 161 #ifndef timerisset 162 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 163 #endif 164 165 #ifndef timerclear 166 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 167 #endif 168 169 #ifndef timercmp 170 #define timercmp(a, b, CMP) \ 171 (((a)->tv_sec == (b)->tv_sec) ? \ 172 ((a)->tv_usec CMP (b)->tv_usec) : \ 173 ((a)->tv_sec CMP (b)->tv_sec)) 174 #endif 175 176 #ifndef timeradd 177 #define timeradd(a, b, result) \ 178 do { \ 179 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 180 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 181 if ((result)->tv_usec >= 1000000) \ 182 { \ 183 ++(result)->tv_sec; \ 184 (result)->tv_usec -= 1000000; \ 185 } \ 186 } while (0) 187 #endif 188 189 #ifndef timersub 190 #define timersub(a, b, result) \ 191 do { \ 192 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 193 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 194 if ((result)->tv_usec < 0) { \ 195 --(result)->tv_sec; \ 196 (result)->tv_usec += 1000000; \ 197 } \ 198 } while (0) 199 #endif 200 201 #ifndef ETIME 202 #define ETIME 1 203 #endif 204 205 #ifndef SIGKILL 206 #define SIGKILL SIGTERM 207 #endif 208 209 #define fork() 0 210 #define setsid() {} 211 212 #ifndef FILE_SOCKET 213 #define FILE_SOCKET int 214 #endif 215 216 #ifndef fdopen_socket 217 #define fdopen_socket(f, g) &f 218 #endif 219 220 #ifndef fclose_socket 221 #define fclose_socket(f) closesocket(*f) 222 #endif 223 224 extern int winfd_dummy; 225 extern char getc_socket(FILE_SOCKET *f); 226 extern ssize_t write_socket(int fildes, const void *buf, size_t nbyte); 227 extern int sendmsg(int s, const struct msghdr *msg, int flags); 228 229 /* end of 'ifdef WIN32' */ 230 #else 231 #error "Not Unix or WIN32 -- what system is this?" 232 #endif 233 234 #ifdef HAVE_STDINT_H 235 #include <stdint.h> 236 #endif 237 238 #if !defined(sun4) && !defined(hp) && !defined(nextstep) && !defined(linux) 239 #include <sys/select.h> /* select() */ 240 #endif 241 242 #endif /* end of ifdef SYSDEP_H */ 243