aboutsummaryrefslogtreecommitdiffstats
path: root/src/arpa/inet/ntohs.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-20 14:31:40 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-20 14:31:40 +0100
commit679b8bdb5c40ca1909b025db10ddb5a98967c60e (patch)
treef0c051e0569138a5c292e30892001604b65f851f /src/arpa/inet/ntohs.c
parentfix issue #8 on github (diff)
downloadslibc-679b8bdb5c40ca1909b025db10ddb5a98967c60e.tar.gz
slibc-679b8bdb5c40ca1909b025db10ddb5a98967c60e.tar.bz2
slibc-679b8bdb5c40ca1909b025db10ddb5a98967c60e.tar.xz
optimise implementations of {hton,ntoh}{s,l,ll}
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src/arpa/inet/ntohs.c')
-rw-r--r--src/arpa/inet/ntohs.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/arpa/inet/ntohs.c b/src/arpa/inet/ntohs.c
index 7aea8a0..6bf95a5 100644
--- a/src/arpa/inet/ntohs.c
+++ b/src/arpa/inet/ntohs.c
@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <arpa/inet.h>
+#include <bits/intconf.h>
+
/**
@@ -31,10 +33,10 @@
*/
uint16_t _ntohs(uint16_t value)
{
- unsigned char* v = (unsigned char*)&value;
- uint16_t rc = 0;
- rc |= (uint16_t)(v[0]) << 8;
- rc |= (uint16_t)(v[1]) << 0;
- return rc;
+#if __INT16_BYTEORDER == 0x0102
+ return value;
+#else
+ return (value >> 8) | (value << 8);
+#endif
}