]> arthur.barton.de Git - netatalk.git/commitdiff
unicode endian fixes
authorbfernhomberg <bfernhomberg>
Thu, 6 Nov 2003 09:23:35 +0000 (09:23 +0000)
committerbfernhomberg <bfernhomberg>
Thu, 6 Nov 2003 09:23:35 +0000 (09:23 +0000)
libatalk/unicode/byteorder.h
libatalk/unicode/charcnv.c
libatalk/unicode/iconv.c
libatalk/unicode/util_unistr.c

index 11e6681e424f650c5396a716f918796836abed31..3cf3dccf4b84c5a6f10ec5cc8a0095fa29039399 100644 (file)
@@ -20,6 +20,7 @@
 
 #ifndef _BYTEORDER_H
 #define _BYTEORDER_H
+#include <netatalk/endian.h>
 
 /*
    This file implements macros for machine independent short and 
@@ -113,6 +114,21 @@ it also defines lots of intermediate macros, just ignore those :-)
 
 #if CAREFUL_ALIGNMENT
 
+#if BYTE_ORDER==BIG_ENDIAN
+
+#define SVAL(buf,pos) (PVAL(buf,(pos)+1)|PVAL(buf,pos)<<8)
+#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
+#define SSVALX(buf,pos,val) (CVAL_NC(buf,pos+1)=(unsigned char)((val)&0xFF),CVAL_NC(buf,pos)=(unsigned char)((val)>>8))
+#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
+#define SVALS(buf,pos) ((int16)SVAL(buf,pos))
+#define IVALS(buf,pos) ((int32_t)IVAL(buf,pos))
+#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((u_int16_t)(val)))
+#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((u_int32_t)(val)))
+#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
+#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
+
+#else
+
 #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
 #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
 #define SSVALX(buf,pos,val) (CVAL_NC(buf,pos)=(unsigned char)((val)&0xFF),CVAL_NC(buf,pos+1)=(unsigned char)((val)>>8))
@@ -124,6 +140,8 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
 
+#endif
+
 #else /* CAREFUL_ALIGNMENT */
 
 /* this handles things for architectures like the 386 that can handle
index 797c6b752c908b2faddd2505c5c095d6f62e5cb0..c6dd068e5ad5869f2b41f566f1ac437bf8c5909f 100644 (file)
@@ -116,7 +116,7 @@ static const char *charset_name(charset_t ch)
                ret = ln;
        }
 #else /* system doesn't have LOCALE support */
-ret = NULL;
+if (ch == CH_UNIX) ret = NULL;
 #endif
 
        if (!ret || !*ret) ret = "ASCII";
@@ -423,12 +423,12 @@ convert:
 
        /* Terminate the string */
        if (to == CH_UCS2 && destlen-o_len >= 2) {
-               *(++outbuf) = 0;
-               *outbuf = 0;
+               ob[destlen] = 0;
+               ob[destlen+1] = 0;
                *dest = (char *)realloc(ob,destlen+2);
        }
        else if ( destlen-o_len > 0) {
-               *(++outbuf) = 0;
+               ob[destlen] = 0;
                *dest = (char *)realloc(ob,destlen+1);
        }
 
index 924f2d436c0a2e1ed0e825e25bb9d96c2a5ad62b..6411c9030ef8fca3827f704ee7177c6af10e855c 100644 (file)
@@ -380,10 +380,11 @@ static size_t ascii_pull(void *cd, char **inbuf, size_t *inbytesleft,
                         char **outbuf, size_t *outbytesleft)
 {
        ucs2_t curchar;
+
        while (*inbytesleft >= 1 && *outbytesleft >= 2) {
                if ((unsigned char)(*inbuf)[0] < 0x80) {
                        curchar = (ucs2_t) (*inbuf)[0];
-                       SSVAL((*outbuf),0,curchar);     
+                       SSVAL((*outbuf),0,curchar);
                }
                else {
                        errno = EILSEQ;
index 7276b95c548e5b296ed151558a1b9e3d8ef41f70..92ee1b3f736c4d1fd8e8ad4ef965825f24b8dd9b 100644 (file)
@@ -15,6 +15,7 @@
 #include <atalk/unicode.h>
 #include "ucs2_casetable.h"
 #include "precompose.h"
+#include "byteorder.h"
 
 
 ucs2_t toupper_w(ucs2_t val)