warnless.c 10 KB

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