/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Daniel Stenberg, <[email protected]>, et al.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/2324#include "curl_setup.h"2526#include "curl_endian.h"2728/*29* Curl_read16_le()30*31* This function converts a 16-bit integer from the little endian format, as32* used in the incoming package to whatever endian format we are using33* natively.34*35* Parameters:36*37* buf [in] - A pointer to a 2 byte buffer.38*39* Returns the integer.40*/41unsigned short Curl_read16_le(const unsigned char *buf)42{43return (unsigned short)(((unsigned short)buf[0]) |44((unsigned short)buf[1] << 8));45}4647/*48* Curl_read32_le()49*50* This function converts a 32-bit integer from the little endian format, as51* used in the incoming package to whatever endian format we are using52* natively.53*54* Parameters:55*56* buf [in] - A pointer to a 4 byte buffer.57*58* Returns the integer.59*/60unsigned int Curl_read32_le(const unsigned char *buf)61{62return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |63((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);64}6566/*67* Curl_read16_be()68*69* This function converts a 16-bit integer from the big endian format, as70* used in the incoming package to whatever endian format we are using71* natively.72*73* Parameters:74*75* buf [in] - A pointer to a 2 byte buffer.76*77* Returns the integer.78*/79unsigned short Curl_read16_be(const unsigned char *buf)80{81return (unsigned short)(((unsigned short)buf[0] << 8) |82((unsigned short)buf[1]));83}848586