Ticket #130: iconv.patch

File iconv.patch, 2.7 KB (added by KO Myung-Hun, 14 years ago)

Patch for DBCS path separator

  • lib/iconv.c

     
    128128        }
    129129}
    130130
    131 #ifdef __OS2__
    132 // i could have done a static variable w/o this function. but i feel it's nicer this way. SCS
    133 // the purpose of this function is to save the to_name to get the korean and japanese code set working
    134 char * save_toname(char *toname, bool what)
     131#if defined(__OS2__) && defined(__INNOTEK_LIBC__)
     132#include <uconv.h>
     133
     134typedef struct os2_iconv_t
    135135{
    136    static char *to_name=NULL;
     136    UconvObject from;
     137} os2_iconv_t;
    137138
    138    if ( what == 0 )
    139         to_name = SMB_STRDUP(toname);
     139iconv_t os2_iconv_open (const char *tocode, const char *fromcode)
     140{
     141    os2_iconv_t *os2_cd = (os2_iconv_t *)iconv_open(tocode, fromcode);
    140142
    141         return to_name;
     143    if (os2_cd != (iconv_t)(-1)) {
     144        /* Assume strings contain pathnames */
     145        uconv_attribute_t attr;
     146
     147        UniQueryUconvObject(os2_cd->from, &attr,
     148                            sizeof(uconv_attribute_t),
     149                            NULL, NULL, NULL );
     150        attr.converttype |= CVTTYPE_PATH;
     151        UniSetUconvObject(os2_cd->from, &attr);
    142152}
     153
     154    return (iconv_t)os2_cd;
     155}
     156
     157#define iconv_open  os2_iconv_open
    143158#endif
    144159
    145160#ifdef HAVE_NATIVE_ICONV
     
    150165                        const char **inbuf, size_t *inbytesleft,
    151166                        char **outbuf, size_t *outbytesleft)
    152167{
    153 #ifdef __OS2__
    154         uint16 *outbuf_uc = ( uint16 * )*outbuf;
    155         char *to_name = save_toname(NULL, 1);
    156 #endif
    157 
    158168        size_t ret = iconv((iconv_t)cd,
    159169                           (char **)inbuf, inbytesleft,
    160170                           outbuf, outbytesleft);
     
    163173                iconv(cd, NULL, NULL, NULL, NULL);
    164174                errno = saved_errno;
    165175        }
    166 #ifdef __OS2__
    167         /* Workaround for path separator on OS/2 */
    168         else
    169         {
    170         if( (strstr(to_name, "949") != NULL) ||     /* Korean CP */
    171                    (strstr(to_name, "932") != NULL) ||      /* Japanese CP */
    172                    (strstr(to_name, "942") != NULL) ||      /* Japanese CP */
    173                    (strstr(to_name, "943") != NULL) )       /* Japanese CP */
    174         {
    175         while(( char * )outbuf_uc < *outbuf )
    176         {
    177             if( *outbuf_uc == 0x20a9 ||     /* Korean WON */
    178                 *outbuf_uc == 0x00a5 )      /* Japanese YEN */
    179                 *outbuf_uc = '\\';
    180 
    181             outbuf_uc++;
    182         }
    183         }
    184         }
    185 #endif
    186176        return ret;
    187177}
    188178#endif
     
    201191        char *bufp = cvtbuf;
    202192        size_t bufsize;
    203193
    204 #ifdef __OS2__
    205         save_toname(cd->to_name, 0);
    206 #endif
    207 
    208194        /* in many cases we can go direct */
    209195        if (cd->direct) {
    210196                return cd->direct(cd->cd_direct,