about summary refs log tree commit diff
path: root/iconv/gconv_simple.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-03-21 20:18:34 +0000
committerUlrich Drepper <drepper@redhat.com>2000-03-21 20:18:34 +0000
commit8d617a716df0ed5fd9ea1c8e65dd8e59b168573e (patch)
tree9bae23f82c38958c166ca3d65bb308f52ab2d14c /iconv/gconv_simple.c
parentbc4831b956f96efd9f4185b739b8ce8f3fa4dae6 (diff)
downloadglibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.tar.gz
glibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.tar.xz
glibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.zip
Update.
	* iconv/gconv_builtin.c: Include <endian.h>.
	* iconv/gconv_builtin.h: Add UCS-BE aliases.
	Add UCS-4LE transformation.  Define UNICODEBIG and UNICODELITTLE
	according to current platform.
	* iconv/gconv_int.h: Declare __gconv_transform_ucs2reverse_internal,
	__gconv_transform_internal_ucs2reverse, and
	__gconv_transform_internal_ucs4le.
	* iconv/gconv_simple.c: Implement __gconv_transform_internal_ucs4le,
	__gconv_transform_ucs2reverse_internal and
	__gconv_transform_internal_ucs2reverse.
	* iconvdata/Makefile (modules): Add UNICODE.
	(distribute): Add unicode.c.
	* iconvdata/gconv-modules: Add definitions for UNICODE module.
	* iconvdata/unicode.c: New file.

	* iconvdata/utf-16.c: Rewrite code to emit BOM.  Correct code to
	determine byte order of input and convert accordingly.
Diffstat (limited to 'iconv/gconv_simple.c')
-rw-r--r--iconv/gconv_simple.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/iconv/gconv_simple.c b/iconv/gconv_simple.c
index 31e7970847..89c0384b8d 100644
--- a/iconv/gconv_simple.c
+++ b/iconv/gconv_simple.c
@@ -105,6 +105,61 @@ internal_ucs4_loop (const unsigned char **inptrp, const unsigned char *inend,
 #include <iconv/skeleton.c>
 
 
+/* Similarly for the other byte order.  */
+#define DEFINE_INIT		0
+#define DEFINE_FINI		0
+#define MIN_NEEDED_FROM		4
+#define MIN_NEEDED_TO		4
+#define FROM_DIRECTION		1
+#define FROM_LOOP		internal_ucs4le_loop
+#define TO_LOOP			internal_ucs4le_loop /* This is not used.  */
+#define FUNCTION_NAME		__gconv_transform_internal_ucs4le
+
+
+static inline int
+internal_ucs4le_loop (const unsigned char **inptrp, const unsigned char *inend,
+		      unsigned char **outptrp, unsigned char *outend,
+		      mbstate_t *state, void *data, size_t *converted)
+{
+  const unsigned char *inptr = *inptrp;
+  unsigned char *outptr = *outptrp;
+  size_t n_convert = MIN (inend - inptr, outend - outptr) / 4;
+  int result;
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+  /* Sigh, we have to do some real work.  */
+  size_t cnt;
+
+  for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
+    *((uint32_t *) outptr)++ = bswap_32 (*(uint32_t *) inptr);
+
+  *inptrp = inptr;
+  *outptrp = outptr;
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+  /* Simply copy the data.  */
+  *inptrp = inptr + n_convert * 4;
+  *outptrp = __mempcpy (outptr, inptr, n_convert * 4);
+#else
+# error "This endianess is not supported."
+#endif
+
+  /* Determine the status.  */
+  if (*outptrp == outend)
+    result = __GCONV_FULL_OUTPUT;
+  else if (*inptrp == inend)
+    result = __GCONV_EMPTY_INPUT;
+  else
+    result = __GCONV_INCOMPLETE_INPUT;
+
+  if (converted != NULL)
+    converted += n_convert;
+
+  return result;
+}
+
+#include <iconv/skeleton.c>
+
+
 /* Convert from ISO 646-IRV to the internal (UCS4-like) format.  */
 #define DEFINE_INIT		0
 #define DEFINE_FINI		0
@@ -408,7 +463,7 @@ internal_ucs4_loop (const unsigned char **inptrp, const unsigned char *inend,
 #define FROM_DIRECTION		1
 #define FROM_LOOP		ucs2little_internal_loop
 #define TO_LOOP			ucs2little_internal_loop /* This is not used.*/
-#define FUNCTION_NAME		__gconv_transform_ucs2little_internal
+#define FUNCTION_NAME		__gconv_transform_ucs2reverse_internal
 
 #define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
 #define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
@@ -433,7 +488,7 @@ internal_ucs4_loop (const unsigned char **inptrp, const unsigned char *inend,
 #define FROM_DIRECTION		1
 #define FROM_LOOP		internal_ucs2little_loop
 #define TO_LOOP			internal_ucs2little_loop /* This is not used.*/
-#define FUNCTION_NAME		__gconv_transform_internal_ucs2little
+#define FUNCTION_NAME		__gconv_transform_internal_ucs2reverse
 
 #define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
 #define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO