From: Steve Holme Date: Wed, 31 Dec 2014 15:58:07 +0000 (+0000) Subject: endian: Added 16-bit integer write function X-Git-Tag: curl-7_40_0~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5eae12fc804c677bc413a49c7bddaff30d249c9e;p=thirdparty%2Fcurl.git endian: Added 16-bit integer write function --- diff --git a/lib/curl_endian.c b/lib/curl_endian.c index 41202d73d9..2d291c84cf 100644 --- a/lib/curl_endian.c +++ b/lib/curl_endian.c @@ -62,6 +62,23 @@ unsigned int Curl_read32_le(unsigned char *buf) ((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24); } +/* + * Curl_write16_le() + * + * This function converts a 16-bit integer from the native endian format, + * to little endian format ready for sending down the wire. + * + * Parameters: + * + * value [in] - The 16-bit integer value. + * buffer [in] - A pointer to the output buffer. + */ +void Curl_write16_le(const short value, unsigned char *buffer) +{ + buffer[0] = (char)(value & 0x00FF); + buffer[1] = (char)((value & 0xFF00) >> 8); +} + /* * Curl_write32_le() * diff --git a/lib/curl_endian.h b/lib/curl_endian.h index a8811c9409..79eb3e8f63 100644 --- a/lib/curl_endian.h +++ b/lib/curl_endian.h @@ -28,6 +28,9 @@ unsigned short Curl_read16_le(unsigned char *buf); /* Converts a 32-bit integer from little endian */ unsigned int Curl_read32_le(unsigned char *buf); +/* Converts a 16-bit integer to little endian */ +void Curl_write16_le(const short value, unsigned char *buffer); + /* Converts a 32-bit integer to little endian */ void Curl_write32_le(const int value, unsigned char *buffer);