diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-03-28 17:33:37 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-03-28 17:33:37 +0000 |
commit | 77e1d15a1afea1189e6aab66cc6e0ce30e3275ce (patch) | |
tree | 78849a20d1b650791f0a8d9d53404ef21057dd24 /iconvdata/utf-16.c | |
parent | b35e58e479cd23ff64ad83a30c6670e355a7d642 (diff) | |
download | glibc-77e1d15a1afea1189e6aab66cc6e0ce30e3275ce.tar.gz glibc-77e1d15a1afea1189e6aab66cc6e0ce30e3275ce.tar.xz glibc-77e1d15a1afea1189e6aab66cc6e0ce30e3275ce.zip |
Update.
2000-03-28 Ulrich Drepper <drepper@redhat.com> * iconvdata/TESTS: Use UCS-2BE instead of UCS2. * iconv/loop.c: Define get16, get32, put16, and put32 macros to allow as well reading from/writing to unaligned addresses on machines which don't support this in hardware. Use FCTNAME macro to define function name. Include the file a second time for platforms which need special unaligned handling. * iconv/skeleton.c: Define get16u, get32u, put16u, and put32u macros to access potentially unaligned addresses. These macros are intended to be used only outside the loops. (unaligned): New definition. In case the machine can handle unaligned access define as zero. Otherwise as a variable which is initialized as nonzero in case the buffer passed in at runtime is unaligned with respect to the character set encoding involved. Call aligned or unaligned looop functions according to unaligned variable. * iconvdata/8bit-gap.c: Use get16, get32, put16, and put32 instead of direct casting pointer to potentially handle unaligned memory accesses. * iconvdata/8bit-generic.c: Likewise. * iconvdata/ansi_x3.110.c: Likewise. * iconvdata/big5.c: Likewise. * iconvdata/euc-cn.c: Likewise. * iconvdata/euc-jp.c: Likewise. * iconvdata/euc-kr.c: Likewise. * iconvdata/euc-tw.c: Likewise. * iconvdata/gbk.c: Likewise. * iconvdata/iso-2022-cn.c: Likewise. * iconvdata/iso-2022-jp.c: Likewise. * iconvdata/iso-2022-kr.c: Likewise. * iconvdata/iso646.c: Likewise. * iconvdata/iso_6937-2.c: Likewise. * iconvdata/iso_6937.c: Likewise. * iconvdata/johab.c: Likewise. * iconvdata/sjis.c: Likewise. * iconvdata/t.61.c: Likewise. * iconvdata/uhc.c: Likewise. * iconvdata/unicode.c: Likewise. * iconvdata/utf-16.c: Likewise. * locale/programs/simple-hash.c: Little optimizations. Remove K&R prototypes. * malloc/Versions [libc] (GLIBC_2.2): Add mcheck_check_all. * malloc/mcheck.c (mcheck_check_all): Renamed from check_all and made public. * malloc/mcheck.h (mcheck_check_all): Declare. * stdio-common/Makefile (tests): Add tst-obprintf.
Diffstat (limited to 'iconvdata/utf-16.c')
-rw-r--r-- | iconvdata/utf-16.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/iconvdata/utf-16.c b/iconvdata/utf-16.c index c7e677e376..b0b9c47896 100644 --- a/iconvdata/utf-16.c +++ b/iconvdata/utf-16.c @@ -52,10 +52,10 @@ if (inptr + 2 > inbufend) \ return __GCONV_EMPTY_INPUT; \ \ - if (*(uint16_t *) inptr == BOM) \ + if (get16u (inptr) == BOM) \ /* Simply ignore the BOM character. */ \ inptr += 2; \ - else if (*(uint16_t *) inptr == BOM_OE) \ + else if (get16u (inptr) == BOM_OE) \ { \ ((struct utf16_data *) step->__data)->swap = 1; \ inptr += 2; \ @@ -69,7 +69,7 @@ if (outbuf + 2 > outend) \ return __GCONV_FULL_OUTPUT; \ \ - *(uint16_t *) outbuf = BOM; \ + put16u (outbuf, BOM); \ outbuf += 2; \ } #define EXTRA_LOOP_ARGS , var, data, swap @@ -193,7 +193,7 @@ gconv_end (struct __gconv_step *data) #define LOOPFCT TO_LOOP #define BODY \ { \ - uint32_t c = *((uint32_t *) inptr); \ + uint32_t c = get32 (inptr); \ \ if (swap) \ { \ @@ -213,12 +213,12 @@ gconv_end (struct __gconv_step *data) break; \ } \ \ - *((uint16_t *) outptr) = bswap_16 (0xd7c0 + (c >> 10)); \ + put16 (outptr, bswap_16 (0xd7c0 + (c >> 10))); \ outptr += 2; \ - *((uint16_t *) outptr) = bswap_16 (0xdc00 + (c & 0x3ff)); \ + put16 (outptr, bswap_16 (0xdc00 + (c & 0x3ff))); \ } \ else \ - *((uint16_t *) outptr) = bswap_16 (c); \ + put16 (outptr, bswap_16 (c)); \ } \ else \ { \ @@ -238,12 +238,12 @@ gconv_end (struct __gconv_step *data) break; \ } \ \ - *((uint16_t *) outptr) = 0xd7c0 + (c >> 10); \ + put16 (outptr, 0xd7c0 + (c >> 10)); \ outptr += 2; \ - *((uint16_t *) outptr) = 0xdc00 + (c & 0x3ff); \ + put16 (outptr, 0xdc00 + (c & 0x3ff)); \ } \ else \ - *((uint16_t *) outptr) = c; \ + put16 (outptr, c); \ } \ outptr += 2; \ inptr += 4; \ @@ -260,7 +260,7 @@ gconv_end (struct __gconv_step *data) #define LOOPFCT FROM_LOOP #define BODY \ { \ - uint16_t u1 = *(uint16_t *) inptr; \ + uint16_t u1 = get16 (inptr); \ \ if (swap) \ { \ @@ -269,7 +269,7 @@ gconv_end (struct __gconv_step *data) if (u1 < 0xd800 || u1 > 0xdfff) \ { \ /* No surrogate. */ \ - *((uint32_t *) outptr) = u1; \ + put32 (outptr, u1); \ inptr += 2; \ } \ else \ @@ -286,16 +286,18 @@ gconv_end (struct __gconv_step *data) break; \ } \ \ - u2 = bswap_16 (((uint16_t *) inptr)[1]); \ + inptr += 2; \ + u2 = bswap_16 (get16 (inptr)); \ if (u2 < 0xdc00 || u2 >= 0xdfff) \ { \ /* This is no valid second word for a surrogate. */ \ result = __GCONV_ILLEGAL_INPUT; \ + inptr -= 2; \ break; \ } \ \ - *((uint32_t *) outptr) = ((u1 - 0xd7c0) << 10) + (u2 - 0xdc00); \ - inptr += 4; \ + put32 (outptr, ((u1 - 0xd7c0) << 10) + (u2 - 0xdc00)); \ + inptr += 2; \ } \ } \ else \ @@ -303,7 +305,7 @@ gconv_end (struct __gconv_step *data) if (u1 < 0xd800 || u1 > 0xdfff) \ { \ /* No surrogate. */ \ - *((uint32_t *) outptr) = u1; \ + put32 (outptr, u1); \ inptr += 2; \ } \ else \ @@ -320,16 +322,18 @@ gconv_end (struct __gconv_step *data) break; \ } \ \ - u2 = ((uint16_t *) inptr)[1]; \ + inptr += 2; \ + u2 = get16 (inptr); \ if (u2 < 0xdc00 || u2 >= 0xdfff) \ { \ /* This is no valid second word for a surrogate. */ \ result = __GCONV_ILLEGAL_INPUT; \ + inptr -= 2; \ break; \ } \ \ - *((uint32_t *) outptr) = ((u1 - 0xd7c0) << 10) + (u2 - 0xdc00); \ - inptr += 4; \ + put32 (outptr, ((u1 - 0xd7c0) << 10) + (u2 - 0xdc00)); \ + inptr += 2; \ } \ } \ outptr += 4; \ |