From 4c2a24514db6bb5b59423b5d8184d1931296b368 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Fri, 6 Jul 2012 17:33:45 +0200 Subject: [PATCH] Replaced use of ntohs() and htons() by iso_ntohs() and iso_htons(). --- libisofs/hfsplus.c | 23 ++++++++--------------- libisofs/util.c | 14 ++++++++++++++ libisofs/util.h | 8 ++++++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/libisofs/hfsplus.c b/libisofs/hfsplus.c index ff0102f..47a5a9b 100644 --- a/libisofs/hfsplus.c +++ b/libisofs/hfsplus.c @@ -72,13 +72,6 @@ #define HFSPLUS_MAX_BLOCK_SIZE 2048 -#include -/* For these prototypes: -uint16_t ntohs(uint16_t netshort); -uint16_t htons(uint16_t hostshort); -*/ - - #ifdef Libisofs_mangle_while_set_hfsplus_namE static int set_mangled_hfsplus_name(Ecma119Image *t, char *name, uint32_t idx); #endif @@ -136,7 +129,7 @@ uint8_t get_class (uint16_t v) { uint16_t s; uint8_t high, low; - s = ntohs (v); + s = iso_ntohs (v); high = s >> 8; low = v & 0xff; if (!hfsplus_class_pages[high]) @@ -172,13 +165,13 @@ int set_hfsplus_name(Ecma119Image *t, char *name, HFSPlusNode *node) for (iptr = ucs_name, optr = node->name; *iptr; iptr++) { const uint16_t *dptr; - uint16_t val = ntohs (*iptr); + uint16_t val = iso_ntohs (*iptr); uint8_t high = val >> 8; uint8_t low = val & 0xff; if (val == ':') { - *optr++ = htons ('/'); + *optr++ = iso_htons ('/'); continue; } @@ -189,10 +182,10 @@ int set_hfsplus_name(Ecma119Image *t, char *name, HFSPlusNode *node) l = s / (21 * 28); v = (s % (21 * 28)) / 28; t = s % 28; - *optr++ = htons (l + 0x1100); - *optr++ = htons (v + 0x1161); + *optr++ = iso_htons (l + 0x1100); + *optr++ = iso_htons (v + 0x1161); if (t) - *optr++ = htons (t + 0x11a7); + *optr++ = iso_htons (t + 0x11a7); continue; } if (!hfsplus_decompose_pages[high]) @@ -207,7 +200,7 @@ int set_hfsplus_name(Ecma119Image *t, char *name, HFSPlusNode *node) continue; } for (; *dptr; dptr++) - *optr++ = htons (*dptr); + *optr++ = iso_htons (*dptr); } *optr = 0; @@ -251,7 +244,7 @@ int set_hfsplus_name(Ecma119Image *t, char *name, HFSPlusNode *node) } if (!hfsplus_casefold[hfsplus_casefold[high] + low]) continue; - *optr++ = ntohs (hfsplus_casefold[hfsplus_casefold[high] + low]); + *optr++ = iso_ntohs (hfsplus_casefold[hfsplus_casefold[high] + low]); } *optr = 0; diff --git a/libisofs/util.c b/libisofs/util.c index 26bdfbf..095b24a 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -2078,3 +2078,17 @@ void *iso_alloc_mem(size_t size, size_t count, int flag) } +uint16_t iso_ntohs(uint16_t v) +{ + return iso_read_msb((uint8_t *) &v, 2); +} + +uint16_t iso_htons(uint16_t v) +{ + uint16_t ret; + + iso_msb((uint8_t *) &ret, (uint32_t) v, 2); + + return ret; +} + diff --git a/libisofs/util.h b/libisofs/util.h index 473ae6b..904ebe5 100644 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -577,4 +577,12 @@ void *iso_alloc_mem(size_t size, size_t count, int flag); } +/* ------------------------------------------------------------------------- */ + + +/* To avoid the need to include more system header files */ +uint16_t iso_ntohs(uint16_t v); +uint16_t iso_htons(uint16_t v); + + #endif /*LIBISO_UTIL_H_*/