1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at http://curl.haxx.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ***************************************************************************/ 22 23#include "setup.h" 24 25#if defined(__INTEL_COMPILER) && defined(__unix__) 26 27#ifdef HAVE_SYS_SOCKET_H 28# include <sys/socket.h> 29#endif 30#ifdef HAVE_NETINET_IN_H 31# include <netinet/in.h> 32#endif 33#ifdef HAVE_ARPA_INET_H 34# include <arpa/inet.h> 35#endif 36 37#endif /* __INTEL_COMPILER && __unix__ */ 38 39#define BUILDING_WARNLESS_C 1 40 41#include "warnless.h" 42 43#define CURL_MASK_SCHAR 0x7F 44#define CURL_MASK_UCHAR 0xFF 45 46#if (SIZEOF_SHORT == 2) 47# define CURL_MASK_SSHORT 0x7FFF 48# define CURL_MASK_USHORT 0xFFFF 49#elif (SIZEOF_SHORT == 4) 50# define CURL_MASK_SSHORT 0x7FFFFFFF 51# define CURL_MASK_USHORT 0xFFFFFFFF 52#elif (SIZEOF_SHORT == 8) 53# define CURL_MASK_SSHORT 0x7FFFFFFFFFFFFFFF 54# define CURL_MASK_USHORT 0xFFFFFFFFFFFFFFFF 55#else 56# error "SIZEOF_SHORT not defined" 57#endif 58 59#if (SIZEOF_INT == 2) 60# define CURL_MASK_SINT 0x7FFF 61# define CURL_MASK_UINT 0xFFFF 62#elif (SIZEOF_INT == 4) 63# define CURL_MASK_SINT 0x7FFFFFFF 64# define CURL_MASK_UINT 0xFFFFFFFF 65#elif (SIZEOF_INT == 8) 66# define CURL_MASK_SINT 0x7FFFFFFFFFFFFFFF 67# define CURL_MASK_UINT 0xFFFFFFFFFFFFFFFF 68#elif (SIZEOF_INT == 16) 69# define CURL_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 70# define CURL_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 71#else 72# error "SIZEOF_INT not defined" 73#endif 74 75#if (CURL_SIZEOF_LONG == 2) 76# define CURL_MASK_SLONG 0x7FFFL 77# define CURL_MASK_ULONG 0xFFFFUL 78#elif (CURL_SIZEOF_LONG == 4) 79# define CURL_MASK_SLONG 0x7FFFFFFFL 80# define CURL_MASK_ULONG 0xFFFFFFFFUL 81#elif (CURL_SIZEOF_LONG == 8) 82# define CURL_MASK_SLONG 0x7FFFFFFFFFFFFFFFL 83# define CURL_MASK_ULONG 0xFFFFFFFFFFFFFFFFUL 84#elif (CURL_SIZEOF_LONG == 16) 85# define CURL_MASK_SLONG 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL 86# define CURL_MASK_ULONG 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL 87#else 88# error "CURL_SIZEOF_LONG not defined" 89#endif 90 91#if (CURL_SIZEOF_CURL_OFF_T == 2) 92# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFF) 93# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFF) 94#elif (CURL_SIZEOF_CURL_OFF_T == 4) 95# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFFFFFF) 96# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFFFFFF) 97#elif (CURL_SIZEOF_CURL_OFF_T == 8) 98# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF) 99# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFF) 100#elif (CURL_SIZEOF_CURL_OFF_T == 16) 101# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) 102# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) 103#else 104# error "CURL_SIZEOF_CURL_OFF_T not defined" 105#endif 106 107#if (SIZEOF_SIZE_T == SIZEOF_SHORT) 108# define CURL_MASK_SSIZE_T CURL_MASK_SSHORT 109# define CURL_MASK_USIZE_T CURL_MASK_USHORT 110#elif (SIZEOF_SIZE_T == SIZEOF_INT) 111# define CURL_MASK_SSIZE_T CURL_MASK_SINT 112# define CURL_MASK_USIZE_T CURL_MASK_UINT 113#elif (SIZEOF_SIZE_T == CURL_SIZEOF_LONG) 114# define CURL_MASK_SSIZE_T CURL_MASK_SLONG 115# define CURL_MASK_USIZE_T CURL_MASK_ULONG 116#elif (SIZEOF_SIZE_T == CURL_SIZEOF_CURL_OFF_T) 117# define CURL_MASK_SSIZE_T CURL_MASK_SCOFFT 118# define CURL_MASK_USIZE_T CURL_MASK_UCOFFT 119#else 120# error "SIZEOF_SIZE_T not defined" 121#endif 122 123/* 124** unsigned long to unsigned short 125*/ 126 127unsigned short curlx_ultous(unsigned long ulnum) 128{ 129#ifdef __INTEL_COMPILER 130# pragma warning(push) 131# pragma warning(disable:810) /* conversion may lose significant bits */ 132#endif 133 134 return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT); 135 136#ifdef __INTEL_COMPILER 137# pragma warning(pop) 138#endif 139} 140 141/* 142** unsigned long to unsigned char 143*/ 144 145unsigned char curlx_ultouc(unsigned long ulnum) 146{ 147#ifdef __INTEL_COMPILER 148# pragma warning(push) 149# pragma warning(disable:810) /* conversion may lose significant bits */ 150#endif 151 152 return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR); 153 154#ifdef __INTEL_COMPILER 155# pragma warning(pop) 156#endif 157} 158 159/* 160** unsigned size_t to signed int 161*/ 162 163int curlx_uztosi(size_t uznum) 164{ 165#ifdef __INTEL_COMPILER 166# pragma warning(push) 167# pragma warning(disable:810) /* conversion may lose significant bits */ 168#endif 169 170 return (int)(uznum & (size_t) CURL_MASK_SINT); 171 172#ifdef __INTEL_COMPILER 173# pragma warning(pop) 174#endif 175} 176 177/* 178** signed long to signed int 179*/ 180 181int curlx_sltosi(long slnum) 182{ 183#ifdef __INTEL_COMPILER 184# pragma warning(push) 185# pragma warning(disable:810) /* conversion may lose significant bits */ 186#endif 187 188 DEBUGASSERT(slnum >= 0); 189 return (int)(slnum & (long) CURL_MASK_SINT); 190 191#ifdef __INTEL_COMPILER 192# pragma warning(pop) 193#endif 194} 195 196/* 197** signed long to unsigned int 198*/ 199 200unsigned int curlx_sltoui(long slnum) 201{ 202#ifdef __INTEL_COMPILER 203# pragma warning(push) 204# pragma warning(disable:810) /* conversion may lose significant bits */ 205#endif 206 207 DEBUGASSERT(slnum >= 0); 208 return (unsigned int)(slnum & (long) CURL_MASK_UINT); 209 210#ifdef __INTEL_COMPILER 211# pragma warning(pop) 212#endif 213} 214 215/* 216** signed long to unsigned short 217*/ 218 219unsigned short curlx_sltous(long slnum) 220{ 221#ifdef __INTEL_COMPILER 222# pragma warning(push) 223# pragma warning(disable:810) /* conversion may lose significant bits */ 224#endif 225 226 DEBUGASSERT(slnum >= 0); 227 return (unsigned short)(slnum & (long) CURL_MASK_USHORT); 228 229#ifdef __INTEL_COMPILER 230# pragma warning(pop) 231#endif 232} 233 234/* 235** unsigned size_t to signed ssize_t 236*/ 237 238ssize_t curlx_uztosz(size_t uznum) 239{ 240#ifdef __INTEL_COMPILER 241# pragma warning(push) 242# pragma warning(disable:810) /* conversion may lose significant bits */ 243#endif 244 245 return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T); 246 247#ifdef __INTEL_COMPILER 248# pragma warning(pop) 249#endif 250} 251 252/* 253** signed curl_off_t to unsigned size_t 254*/ 255 256size_t curlx_sotouz(curl_off_t sonum) 257{ 258#ifdef __INTEL_COMPILER 259# pragma warning(push) 260# pragma warning(disable:810) /* conversion may lose significant bits */ 261#endif 262 263 DEBUGASSERT(sonum >= 0); 264 return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T); 265 266#ifdef __INTEL_COMPILER 267# pragma warning(pop) 268#endif 269} 270 271/* 272** signed int to unsigned size_t 273*/ 274 275size_t curlx_sitouz(int sinum) 276{ 277#ifdef __INTEL_COMPILER 278# pragma warning(push) 279# pragma warning(disable:810) /* conversion may lose significant bits */ 280#endif 281 282 DEBUGASSERT(sinum >= 0); 283 return (size_t) sinum; 284 285#ifdef __INTEL_COMPILER 286# pragma warning(pop) 287#endif 288} 289 290#if defined(__INTEL_COMPILER) && defined(__unix__) 291 292int curlx_FD_ISSET(int fd, fd_set *fdset) 293{ 294 #pragma warning(push) 295 #pragma warning(disable:1469) /* clobber ignored */ 296 return FD_ISSET(fd, fdset); 297 #pragma warning(pop) 298} 299 300void curlx_FD_SET(int fd, fd_set *fdset) 301{ 302 #pragma warning(push) 303 #pragma warning(disable:1469) /* clobber ignored */ 304 FD_SET(fd, fdset); 305 #pragma warning(pop) 306} 307 308void curlx_FD_ZERO(fd_set *fdset) 309{ 310 #pragma warning(push) 311 #pragma warning(disable:593) /* variable was set but never used */ 312 FD_ZERO(fdset); 313 #pragma warning(pop) 314} 315 316unsigned short curlx_htons(unsigned short usnum) 317{ 318#if (__INTEL_COMPILER == 910) && defined(__i386__) 319 return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF)); 320#else 321 #pragma warning(push) 322 #pragma warning(disable:810) /* conversion may lose significant bits */ 323 return htons(usnum); 324 #pragma warning(pop) 325#endif 326} 327 328unsigned short curlx_ntohs(unsigned short usnum) 329{ 330#if (__INTEL_COMPILER == 910) && defined(__i386__) 331 return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF)); 332#else 333 #pragma warning(push) 334 #pragma warning(disable:810) /* conversion may lose significant bits */ 335 return ntohs(usnum); 336 #pragma warning(pop) 337#endif 338} 339 340#endif /* __INTEL_COMPILER && __unix__ */ 341