Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmcurl/lib/curl_endian.c
5020 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, 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 https://curl.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
* SPDX-License-Identifier: curl
22
*
23
***************************************************************************/
24
#include "curl_setup.h"
25
26
#include "curl_endian.h"
27
28
/*
29
* Curl_read16_le()
30
*
31
* This function converts a 16-bit integer from the little endian format, as
32
* used in the incoming package to whatever endian format we are using
33
* natively.
34
*
35
* Parameters:
36
*
37
* buf [in] - A pointer to a 2 byte buffer.
38
*
39
* Returns the integer.
40
*/
41
unsigned short Curl_read16_le(const unsigned char *buf)
42
{
43
return (unsigned short)(((unsigned short)buf[0]) |
44
((unsigned short)buf[1] << 8));
45
}
46
47
/*
48
* Curl_read32_le()
49
*
50
* This function converts a 32-bit integer from the little endian format, as
51
* used in the incoming package to whatever endian format we are using
52
* natively.
53
*
54
* Parameters:
55
*
56
* buf [in] - A pointer to a 4 byte buffer.
57
*
58
* Returns the integer.
59
*/
60
unsigned int Curl_read32_le(const unsigned char *buf)
61
{
62
return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |
63
((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);
64
}
65
66
/*
67
* Curl_read16_be()
68
*
69
* This function converts a 16-bit integer from the big endian format, as
70
* used in the incoming package to whatever endian format we are using
71
* natively.
72
*
73
* Parameters:
74
*
75
* buf [in] - A pointer to a 2 byte buffer.
76
*
77
* Returns the integer.
78
*/
79
unsigned short Curl_read16_be(const unsigned char *buf)
80
{
81
return (unsigned short)(((unsigned short)buf[0] << 8) |
82
((unsigned short)buf[1]));
83
}
84
85