/***************************************************************************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***************************************************************************/23#include "curl_setup.h"2425#include "curl_endian.h"2627/*28* Curl_read16_le()29*30* This function converts a 16-bit integer from the little endian format, as31* used in the incoming package to whatever endian format we are using32* natively.33*34* Parameters:35*36* buf [in] - A pointer to a 2 byte buffer.37*38* Returns the integer.39*/40unsigned short Curl_read16_le(const unsigned char *buf)41{42return (unsigned short)(((unsigned short)buf[0]) |43((unsigned short)buf[1] << 8));44}4546/*47* Curl_read32_le()48*49* This function converts a 32-bit integer from the little endian format, as50* used in the incoming package to whatever endian format we are using51* natively.52*53* Parameters:54*55* buf [in] - A pointer to a 4 byte buffer.56*57* Returns the integer.58*/59unsigned int Curl_read32_le(const unsigned char *buf)60{61return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |62((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);63}6465/*66* Curl_read16_be()67*68* This function converts a 16-bit integer from the big endian format, as69* used in the incoming package to whatever endian format we are using70* natively.71*72* Parameters:73*74* buf [in] - A pointer to a 2 byte buffer.75*76* Returns the integer.77*/78unsigned short Curl_read16_be(const unsigned char *buf)79{80return (unsigned short)(((unsigned short)buf[0] << 8) |81((unsigned short)buf[1]));82}838485