00001
00002
00003
00004
00005 #ifndef __SETUP_ONCE_H
00006 #define __SETUP_ONCE_H
00007
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include <stdarg.h>
00012 #include <ctype.h>
00013 #include <errno.h>
00014
00015 #ifdef HAVE_SYS_TYPES_H
00016 #include <sys/types.h>
00017 #endif
00018
00019 #ifdef HAVE_SYS_STAT_H
00020 #include <sys/stat.h>
00021 #endif
00022
00023 #ifdef HAVE_SYS_TIME_H
00024 #include <sys/time.h>
00025 #ifdef TIME_WITH_SYS_TIME
00026 #include <time.h>
00027 #endif
00028 #else
00029 #ifdef HAVE_TIME_H
00030 #include <time.h>
00031 #endif
00032 #endif
00033
00034 #ifdef WIN32
00035 #include <io.h>
00036 #include <fcntl.h>
00037 #endif
00038
00039 #ifdef HAVE_STDBOOL_H
00040 #include <stdbool.h>
00041 #endif
00042
00043 #ifndef HAVE_STRUCT_TIMEVAL
00044 struct timeval {
00045 long tv_sec;
00046 long tv_usec;
00047 };
00048 #endif
00049
00050 #ifdef HAVE_MSG_NOSIGNAL
00051 #define SEND_4TH_ARG MSG_NOSIGNAL
00052 #else
00053 #define SEND_4TH_ARG 0
00054 #endif
00055
00056 #ifdef HAVE_RECV
00057 #if !defined(RECV_TYPE_ARG1) || \
00058 !defined(RECV_TYPE_ARG2) || \
00059 !defined(RECV_TYPE_ARG3) || \
00060 !defined(RECV_TYPE_ARG4) || \
00061 !defined(RECV_TYPE_RETV)
00062
00063 Error Missing_definition_of_return_and_arguments_types_of_recv
00064
00065 #else
00066 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
00067 (RECV_TYPE_ARG2)(y), \
00068 (RECV_TYPE_ARG3)(z), \
00069 (RECV_TYPE_ARG4)(0))
00070 #endif
00071 #else
00072 #ifndef sread
00073
00074 Error Missing_definition_of_macro_sread
00075
00076 #endif
00077 #endif
00078
00079 #ifdef HAVE_SEND
00080 #if !defined(SEND_TYPE_ARG1) || \
00081 !defined(SEND_QUAL_ARG2) || \
00082 !defined(SEND_TYPE_ARG2) || \
00083 !defined(SEND_TYPE_ARG3) || \
00084 !defined(SEND_TYPE_ARG4) || \
00085 !defined(SEND_TYPE_RETV)
00086
00087 Error Missing_definition_of_return_and_arguments_types_of_send
00088
00089 #else
00090 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
00091 (SEND_TYPE_ARG2)(y), \
00092 (SEND_TYPE_ARG3)(z), \
00093 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
00094 #endif
00095 #else
00096 #ifndef swrite
00097
00098 Error Missing_definition_of_macro_swrite
00099
00100 #endif
00101 #endif
00102
00103 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
00104 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
00105 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
00106 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
00107 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
00108 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
00109 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
00110 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
00111 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
00112
00113 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
00114 (((unsigned char)x) == '\t'))
00115
00116 #ifndef HAVE_BOOL_T
00117 typedef unsigned char bool;
00118 #define HAVE_BOOL_T
00119 #endif
00120
00121 #ifndef TRUE
00122 #define TRUE 1
00123 #endif
00124 #ifndef FALSE
00125 #define FALSE 0
00126 #endif
00127
00128 #ifndef HAVE_SIG_ATOMIC_T
00129 typedef int sig_atomic_t;
00130 #define HAVE_SIG_ATOMIC_T
00131 #endif
00132
00133 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
00134 #define SIG_ATOMIC_T static sig_atomic_t
00135 #else
00136 #define SIG_ATOMIC_T static volatile sig_atomic_t
00137 #endif
00138
00139 #ifndef RETSIGTYPE
00140 #define RETSIGTYPE void
00141 #endif
00142
00143 #ifdef CURLDEBUG
00144 #define DEBUGF(x) x
00145 #else
00146 #define DEBUGF(x) do { } while (0)
00147 #endif
00148
00149 #if defined(CURLDEBUG) && defined(HAVE_ASSERT_H)
00150 #define DEBUGASSERT(x) assert(x)
00151 #else
00152 #define DEBUGASSERT(x) do { } while (0)
00153 #endif
00154
00155 #ifdef USE_WINSOCK
00156 #define SOCKERRNO ((int)WSAGetLastError())
00157 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
00158 #else
00159 #define SOCKERRNO (errno)
00160 #define SET_SOCKERRNO(x) (errno = (x))
00161 #endif
00162
00163 #ifdef WIN32
00164 #define ERRNO ((int)GetLastError())
00165 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
00166 #else
00167 #define ERRNO (errno)
00168 #define SET_ERRNO(x) (errno = (x))
00169 #endif
00170
00171 #ifdef USE_WINSOCK
00172 #undef EBADF
00173 #define EBADF WSAEBADF
00174 #undef EINTR
00175 #define EINTR WSAEINTR
00176 #undef EINVAL
00177 #define EINVAL WSAEINVAL
00178 #define EWOULDBLOCK WSAEWOULDBLOCK
00179 #define EINPROGRESS WSAEINPROGRESS
00180 #define EALREADY WSAEALREADY
00181 #define ENOTSOCK WSAENOTSOCK
00182 #define EDESTADDRREQ WSAEDESTADDRREQ
00183 #define EMSGSIZE WSAEMSGSIZE
00184 #define EPROTOTYPE WSAEPROTOTYPE
00185 #define ENOPROTOOPT WSAENOPROTOOPT
00186 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
00187 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
00188 #define EOPNOTSUPP WSAEOPNOTSUPP
00189 #define EPFNOSUPPORT WSAEPFNOSUPPORT
00190 #define EAFNOSUPPORT WSAEAFNOSUPPORT
00191 #define EADDRINUSE WSAEADDRINUSE
00192 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
00193 #define ENETDOWN WSAENETDOWN
00194 #define ENETUNREACH WSAENETUNREACH
00195 #define ENETRESET WSAENETRESET
00196 #define ECONNABORTED WSAECONNABORTED
00197 #define ECONNRESET WSAECONNRESET
00198 #define ENOBUFS WSAENOBUFS
00199 #define EISCONN WSAEISCONN
00200 #define ENOTCONN WSAENOTCONN
00201 #define ESHUTDOWN WSAESHUTDOWN
00202 #define ETOOMANYREFS WSAETOOMANYREFS
00203 #define ETIMEDOUT WSAETIMEDOUT
00204 #define ECONNREFUSED WSAECONNREFUSED
00205 #define ELOOP WSAELOOP
00206 #ifndef ENAMETOOLONG
00207 #define ENAMETOOLONG WSAENAMETOOLONG
00208 #endif
00209 #define EHOSTDOWN WSAEHOSTDOWN
00210 #define EHOSTUNREACH WSAEHOSTUNREACH
00211 #ifndef ENOTEMPTY
00212 #define ENOTEMPTY WSAENOTEMPTY
00213 #endif
00214 #define EPROCLIM WSAEPROCLIM
00215 #define EUSERS WSAEUSERS
00216 #define EDQUOT WSAEDQUOT
00217 #define ESTALE WSAESTALE
00218 #define EREMOTE WSAEREMOTE
00219 #endif
00220
00221 #if defined(VMS) && \
00222 defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
00223 #define getpwuid __32_getpwuid
00224 #endif
00225
00226 #ifdef VMS
00227 #define argv_item_t __char_ptr32
00228 #else
00229 #define argv_item_t char *
00230 #endif
00231
00232 #if defined (__LP64__) && defined(__hpux) && !defined(_XOPEN_SOURCE_EXTENDED)
00233 #include <sys/socket.h>
00234
00235 inline static int Curl_hp_getsockname(int s, struct sockaddr *name,
00236 socklen_t *namelen)
00237 {
00238 int rc;
00239 if(namelen) {
00240 int len = *namelen;
00241 rc = getsockname(s, name, &len);
00242 *namelen = len;
00243 }
00244 else
00245 rc = getsockname(s, name, 0);
00246 return rc;
00247 }
00248
00249 inline static int Curl_hp_getsockopt(int s, int level, int optname,
00250 void *optval, socklen_t *optlen)
00251 {
00252 int rc;
00253 if(optlen) {
00254 int len = *optlen;
00255 rc = getsockopt(s, level, optname, optval, &len);
00256 *optlen = len;
00257 }
00258 else
00259 rc = getsockopt(s, level, optname, optval, 0);
00260 return rc;
00261 }
00262
00263 inline static int Curl_hp_accept(int sockfd, struct sockaddr *addr,
00264 socklen_t *addrlen)
00265 {
00266 int rc;
00267 if(addrlen) {
00268 int len = *addrlen;
00269 rc = accept(sockfd, addr, &len);
00270 *addrlen = len;
00271 }
00272 else
00273 rc = accept(sockfd, addr, 0);
00274 return rc;
00275 }
00276
00277 inline static ssize_t Curl_hp_recvfrom(int s, void *buf, size_t len, int flags,
00278 struct sockaddr *from,
00279 socklen_t *fromlen)
00280 {
00281 ssize_t rc;
00282 if(fromlen) {
00283 int fromlen32 = *fromlen;
00284 rc = recvfrom(s, buf, len, flags, from, &fromlen32);
00285 *fromlen = fromlen32;
00286 }
00287 else {
00288 rc = recvfrom(s, buf, len, flags, from, 0);
00289 }
00290 return rc;
00291 }
00292
00293 #define getsockname(a,b,c) Curl_hp_getsockname((a),(b),(c))
00294 #define getsockopt(a,b,c,d,e) Curl_hp_getsockopt((a),(b),(c),(d),(e))
00295 #define accept(a,b,c) Curl_hp_accept((a),(b),(c))
00296 #define recvfrom(a,b,c,d,e,f) Curl_hp_recvfrom((a),(b),(c),(d),(e),(f))
00297
00298 #endif
00299
00300 #endif
00301