curl_endian.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #include "curl_endian.h"
00026 
00027 /*
00028  * Curl_read16_le()
00029  *
00030  * This function converts a 16-bit integer from the little endian format, as
00031  * used in the incoming package to whatever endian format we're using
00032  * natively.
00033  *
00034  * Parameters:
00035  *
00036  * buf      [in]     - A pointer to a 2 byte buffer.
00037  *
00038  * Returns the integer.
00039  */
00040 unsigned short Curl_read16_le(const unsigned char *buf)
00041 {
00042   return (unsigned short)(((unsigned short)buf[0]) |
00043                           ((unsigned short)buf[1] << 8));
00044 }
00045 
00046 /*
00047  * Curl_read32_le()
00048  *
00049  * This function converts a 32-bit integer from the little endian format, as
00050  * used in the incoming package to whatever endian format we're using
00051  * natively.
00052  *
00053  * Parameters:
00054  *
00055  * buf      [in]     - A pointer to a 4 byte buffer.
00056  *
00057  * Returns the integer.
00058  */
00059 unsigned int Curl_read32_le(const unsigned char *buf)
00060 {
00061   return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |
00062          ((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);
00063 }
00064 
00065 #if (CURL_SIZEOF_CURL_OFF_T > 4)
00066 /*
00067  * Curl_read64_le()
00068  *
00069  * This function converts a 64-bit integer from the little endian format, as
00070  * used in the incoming package to whatever endian format we're using
00071  * natively.
00072  *
00073  * Parameters:
00074  *
00075  * buf      [in]     - A pointer to a 8 byte buffer.
00076  *
00077  * Returns the integer.
00078  */
00079 #if defined(HAVE_LONGLONG)
00080 unsigned long long Curl_read64_le(const unsigned char *buf)
00081 {
00082   return ((unsigned long long)buf[0]) |
00083          ((unsigned long long)buf[1] << 8) |
00084          ((unsigned long long)buf[2] << 16) |
00085          ((unsigned long long)buf[3] << 24) |
00086          ((unsigned long long)buf[4] << 32) |
00087          ((unsigned long long)buf[5] << 40) |
00088          ((unsigned long long)buf[6] << 48) |
00089          ((unsigned long long)buf[7] << 56);
00090 }
00091 #else
00092 unsigned __int64 Curl_read64_le(const unsigned char *buf)
00093 {
00094   return ((unsigned __int64)buf[0]) | ((unsigned __int64)buf[1] << 8) |
00095          ((unsigned __int64)buf[2] << 16) | ((unsigned __int64)buf[3] << 24) |
00096          ((unsigned __int64)buf[4] << 32) | ((unsigned __int64)buf[5] << 40) |
00097          ((unsigned __int64)buf[6] << 48) | ((unsigned __int64)buf[7] << 56);
00098 }
00099 #endif
00100 
00101 #endif /* CURL_SIZEOF_CURL_OFF_T > 4 */
00102 
00103 /*
00104  * Curl_read16_be()
00105  *
00106  * This function converts a 16-bit integer from the big endian format, as
00107  * used in the incoming package to whatever endian format we're using
00108  * natively.
00109  *
00110  * Parameters:
00111  *
00112  * buf      [in]     - A pointer to a 2 byte buffer.
00113  *
00114  * Returns the integer.
00115  */
00116 unsigned short Curl_read16_be(const unsigned char *buf)
00117 {
00118   return (unsigned short)(((unsigned short)buf[0] << 8) |
00119                           ((unsigned short)buf[1]));
00120 }
00121 
00122 /*
00123  * Curl_read32_be()
00124  *
00125  * This function converts a 32-bit integer from the big endian format, as
00126  * used in the incoming package to whatever endian format we're using
00127  * natively.
00128  *
00129  * Parameters:
00130  *
00131  * buf      [in]     - A pointer to a 4 byte buffer.
00132  *
00133  * Returns the integer.
00134  */
00135 unsigned int Curl_read32_be(const unsigned char *buf)
00136 {
00137   return ((unsigned int)buf[0] << 24) | ((unsigned int)buf[1] << 16) |
00138          ((unsigned int)buf[2] << 8) | ((unsigned int)buf[3]);
00139 }
00140 
00141 #if (CURL_SIZEOF_CURL_OFF_T > 4)
00142 /*
00143  * Curl_read64_be()
00144  *
00145  * This function converts a 64-bit integer from the big endian format, as
00146  * used in the incoming package to whatever endian format we're using
00147  * natively.
00148  *
00149  * Parameters:
00150  *
00151  * buf      [in]     - A pointer to a 8 byte buffer.
00152  *
00153  * Returns the integer.
00154  */
00155 #if defined(HAVE_LONGLONG)
00156 unsigned long long Curl_read64_be(const unsigned char *buf)
00157 {
00158   return ((unsigned long long)buf[0] << 56) |
00159          ((unsigned long long)buf[1] << 48) |
00160          ((unsigned long long)buf[2] << 40) |
00161          ((unsigned long long)buf[3] << 32) |
00162          ((unsigned long long)buf[4] << 24) |
00163          ((unsigned long long)buf[5] << 16) |
00164          ((unsigned long long)buf[6] << 8) |
00165          ((unsigned long long)buf[7]);
00166 }
00167 #else
00168 unsigned __int64 Curl_read64_be(const unsigned char *buf)
00169 {
00170   return ((unsigned __int64)buf[0] << 56) | ((unsigned __int64)buf[1] << 48) |
00171          ((unsigned __int64)buf[2] << 40) | ((unsigned __int64)buf[3] << 32) |
00172          ((unsigned __int64)buf[4] << 24) | ((unsigned __int64)buf[5] << 16) |
00173          ((unsigned __int64)buf[6] << 8) | ((unsigned __int64)buf[7]);
00174 }
00175 #endif
00176 
00177 #endif /* CURL_SIZEOF_CURL_OFF_T > 4 */
00178 
00179 /*
00180  * Curl_write16_le()
00181  *
00182  * This function converts a 16-bit integer from the native endian format,
00183  * to little endian format ready for sending down the wire.
00184  *
00185  * Parameters:
00186  *
00187  * value    [in]     - The 16-bit integer value.
00188  * buffer   [in]     - A pointer to the output buffer.
00189  */
00190 void Curl_write16_le(const short value, unsigned char *buffer)
00191 {
00192   buffer[0] = (char)(value & 0x00FF);
00193   buffer[1] = (char)((value & 0xFF00) >> 8);
00194 }
00195 
00196 /*
00197  * Curl_write32_le()
00198  *
00199  * This function converts a 32-bit integer from the native endian format,
00200  * to little endian format ready for sending down the wire.
00201  *
00202  * Parameters:
00203  *
00204  * value    [in]     - The 32-bit integer value.
00205  * buffer   [in]     - A pointer to the output buffer.
00206  */
00207 void Curl_write32_le(const int value, unsigned char *buffer)
00208 {
00209   buffer[0] = (char)(value & 0x000000FF);
00210   buffer[1] = (char)((value & 0x0000FF00) >> 8);
00211   buffer[2] = (char)((value & 0x00FF0000) >> 16);
00212   buffer[3] = (char)((value & 0xFF000000) >> 24);
00213 }
00214 
00215 #if (CURL_SIZEOF_CURL_OFF_T > 4)
00216 /*
00217  * Curl_write64_le()
00218  *
00219  * This function converts a 64-bit integer from the native endian format,
00220  * to little endian format ready for sending down the wire.
00221  *
00222  * Parameters:
00223  *
00224  * value    [in]     - The 64-bit integer value.
00225  * buffer   [in]     - A pointer to the output buffer.
00226  */
00227 #if defined(HAVE_LONGLONG)
00228 void Curl_write64_le(const long long value, unsigned char *buffer)
00229 #else
00230 void Curl_write64_le(const __int64 value, unsigned char *buffer)
00231 #endif
00232 {
00233   Curl_write32_le((int)value, buffer);
00234   Curl_write32_le((int)(value >> 32), buffer + 4);
00235 }
00236 #endif /* CURL_SIZEOF_CURL_OFF_T > 4 */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02