--- win_unicode.c.org  Sat Sep  1 01:40:10 2007
+++ win_unicode.c  Fri Jul 25 12:52:06 2008
@@ -54,6 +54,13 @@

+int is_big_endian()
+{
+  union { long l; char c[sizeof (long)]; } u;
+    u.l = 1;
+    return (u.c[sizeof (long) - 1] == 1);
+}
+
  SQLULEN  ucs2strlen(const SQLWCHAR *ucs2str)
  {
    SQLULEN  len;
@@ -66,6 +73,17 @@
    char *  utf8str;

+  static int is_endian_calc = 0;
+  static int big_endian = 0;
+  if(!is_endian_calc)
+  {
+    big_endian = is_big_endian();
+    is_endian_calc = 1;
+  }
+
    if (!ucs2str)
    {
      *olen = SQL_NULL_DATA;
@@ -78,8 +96,8 @@
    if (utf8str)
    {
      int  i, len = 0;
-    UInt2  byte2code;
-    Int4  byte4code, surrd1, surrd2;
+    union { UInt2 i; char c[sizeof (UInt2)]; } byte2code;
+    union { Int4 i;  char c[sizeof (Int4)]; } byte4code, surrd1, surrd2;
      const SQLWCHAR  *wstr;

      for (i = 0, wstr = ucs2str; i < ilen; i++, wstr++)
@@ -95,35 +113,62 @@
        }
        else if ((*wstr & byte3check) == 0)
        {
-        byte2code = byte2_base |
+        byte2code.i = byte2_base |
                ((byte2_mask1 & *wstr) >> 6) |
                ((byte2_mask2 & *wstr) << 8);
-        memcpy(utf8str + len, (char *) &byte2code, sizeof(byte2code));
-        len += sizeof(byte2code);
+        if(big_endian)
+        {
+          memcpy(utf8str + len, (char *) &byte2code.c[1], 1);
+          memcpy(utf8str + len + 1, (char *) &byte2code.c[0], 1);
        }
+        else
+        {
+          memcpy(utf8str + len, (char *) &byte2code.i, 
