Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #include "curl_endian.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
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
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
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
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
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
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
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
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
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
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
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
00198
00199
00200
00201
00202
00203
00204
00205
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
00218
00219
00220
00221
00222
00223
00224
00225
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