warnless.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. #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. return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
  120. #ifdef __INTEL_COMPILER
  121. # pragma warning(pop)
  122. #endif
  123. }
  124. /*
  125. ** unsigned long to unsigned char
  126. */
  127. unsigned char curlx_ultouc(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. return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
  134. #ifdef __INTEL_COMPILER
  135. # pragma warning(pop)
  136. #endif
  137. }
  138. /*
  139. ** unsigned size_t to signed int
  140. */
  141. int curlx_uztosi(size_t uznum)
  142. {
  143. #ifdef __INTEL_COMPILER
  144. # pragma warning(push)
  145. # pragma warning(disable:810) /* conversion may lose significant bits */
  146. #endif
  147. return (int)(uznum & (size_t) CURL_MASK_SINT);
  148. #ifdef __INTEL_COMPILER
  149. # pragma warning(pop)
  150. #endif
  151. }
  152. /*
  153. ** signed long to signed int
  154. */
  155. int curlx_sltosi(long slnum)
  156. {
  157. #ifdef __INTEL_COMPILER
  158. # pragma warning(push)
  159. # pragma warning(disable:810) /* conversion may lose significant bits */
  160. #endif
  161. DEBUGASSERT(slnum >= 0);
  162. return (int)(slnum & (long) CURL_MASK_SINT);
  163. #ifdef __INTEL_COMPILER
  164. # pragma warning(pop)
  165. #endif
  166. }
  167. /*
  168. ** signed long to unsigned int
  169. */
  170. unsigned int curlx_sltoui(long slnum)
  171. {
  172. #ifdef __INTEL_COMPILER
  173. # pragma warning(push)
  174. # pragma warning(disable:810) /* conversion may lose significant bits */
  175. #endif
  176. DEBUGASSERT(slnum >= 0);
  177. return (unsigned int)(slnum & (long) CURL_MASK_UINT);
  178. #ifdef __INTEL_COMPILER
  179. # pragma warning(pop)
  180. #endif
  181. }
  182. /*
  183. ** signed long to unsigned short
  184. */
  185. unsigned short curlx_sltous(long slnum)
  186. {
  187. #ifdef __INTEL_COMPILER
  188. # pragma warning(push)
  189. # pragma warning(disable:810) /* conversion may lose significant bits */
  190. #endif
  191. DEBUGASSERT(slnum >= 0);
  192. return (unsigned short)(slnum & (long) CURL_MASK_USHORT);
  193. #ifdef __INTEL_COMPILER
  194. # pragma warning(pop)
  195. #endif
  196. }
  197. /*
  198. ** unsigned size_t to signed ssize_t
  199. */
  200. ssize_t curlx_uztosz(size_t uznum)
  201. {
  202. #ifdef __INTEL_COMPILER
  203. # pragma warning(push)
  204. # pragma warning(disable:810) /* conversion may lose significant bits */
  205. #endif
  206. return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T);
  207. #ifdef __INTEL_COMPILER
  208. # pragma warning(pop)
  209. #endif
  210. }
  211. /*
  212. ** signed curl_off_t to unsigned size_t
  213. */
  214. size_t curlx_sotouz(curl_off_t sonum)
  215. {
  216. #ifdef __INTEL_COMPILER
  217. # pragma warning(push)
  218. # pragma warning(disable:810) /* conversion may lose significant bits */
  219. #endif
  220. DEBUGASSERT(sonum >= 0);
  221. return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T);
  222. #ifdef __INTEL_COMPILER
  223. # pragma warning(pop)
  224. #endif
  225. }
  226. /*
  227. ** signed int to unsigned size_t
  228. */
  229. size_t curlx_sitouz(int sinum)
  230. {
  231. #ifdef __INTEL_COMPILER
  232. # pragma warning(push)
  233. # pragma warning(disable:810) /* conversion may lose significant bits */
  234. #endif
  235. DEBUGASSERT(sinum >= 0);
  236. return (size_t) sinum;
  237. #ifdef __INTEL_COMPILER
  238. # pragma warning(pop)
  239. #endif
  240. }
  241. #if defined(__INTEL_COMPILER) && defined(__unix__)
  242. int curlx_FD_ISSET(int fd, fd_set *fdset)
  243. {
  244. #pragma warning(push)
  245. #pragma warning(disable:1469) /* clobber ignored */
  246. return FD_ISSET(fd, fdset);
  247. #pragma warning(pop)
  248. }
  249. void curlx_FD_SET(int fd, fd_set *fdset)
  250. {
  251. #pragma warning(push)
  252. #pragma warning(disable:1469) /* clobber ignored */
  253. FD_SET(fd, fdset);
  254. #pragma warning(pop)
  255. }
  256. void curlx_FD_ZERO(fd_set *fdset)
  257. {
  258. #pragma warning(push)
  259. #pragma warning(disable:593) /* variable was set but never used */
  260. FD_ZERO(fdset);
  261. #pragma warning(pop)
  262. }
  263. unsigned short curlx_htons(unsigned short usnum)
  264. {
  265. #if (__INTEL_COMPILER == 910) && defined(__i386__)
  266. return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
  267. #else
  268. #pragma warning(push)
  269. #pragma warning(disable:810) /* conversion may lose significant bits */
  270. return htons(usnum);
  271. #pragma warning(pop)
  272. #endif
  273. }
  274. unsigned short curlx_ntohs(unsigned short usnum)
  275. {
  276. #if (__INTEL_COMPILER == 910) && defined(__i386__)
  277. return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
  278. #else
  279. #pragma warning(push)
  280. #pragma warning(disable:810) /* conversion may lose significant bits */
  281. return ntohs(usnum);
  282. #pragma warning(pop)
  283. #endif
  284. }
  285. #endif /* __INTEL_COMPILER && __unix__ */