1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
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 https://curl.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 ***************************************************************************/
25 #include "curl_setup.h"
27 #include "curl_endian.h"
32 * This function converts a 16-bit integer from the little endian format, as
33 * used in the incoming package to whatever endian format we're using
38 * buf [in] - A pointer to a 2 byte buffer.
40 * Returns the integer.
42 unsigned short Curl_read16_le(const unsigned char *buf)
44 return (unsigned short)(((unsigned short)buf[0]) |
45 ((unsigned short)buf[1] << 8));
51 * This function converts a 32-bit integer from the little endian format, as
52 * used in the incoming package to whatever endian format we're using
57 * buf [in] - A pointer to a 4 byte buffer.
59 * Returns the integer.
61 unsigned int Curl_read32_le(const unsigned char *buf)
63 return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |
64 ((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);
70 * This function converts a 16-bit integer from the big endian format, as
71 * used in the incoming package to whatever endian format we're using
76 * buf [in] - A pointer to a 2 byte buffer.
78 * Returns the integer.
80 unsigned short Curl_read16_be(const unsigned char *buf)
82 return (unsigned short)(((unsigned short)buf[0] << 8) |
83 ((unsigned short)buf[1]));