This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug localedata/23502] gconv(GB18030 to UTF-8)


https://sourceware.org/bugzilla/show_bug.cgi?id=23502

--- Comment #3 from lance <286000435 at qq dot com> ---
(In reply to Andreas Schwab from comment #2)
> What is the exact contents of the array s?

This is new code:

#include <iconv.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void print_buf(char* buf, size_t len)
{
        size_t i;
        for (i = 0; i < len; ++i) {
                printf("%02X ", (unsigned char)buf[i]);
        }
        printf("\n");
}

int main(int argc, char** argv)
{
        char s[] = "早見純";
        print_buf(s, sizeof(s));
        iconv_t cd = iconv_open("GB18030", "UTF-8");
        if (cd <= 0 ) {
                printf("iconv_open fail\n");
                return 0;
        }
        size_t inbytesleft = sizeof(s) - 1;
        char dst[6 * sizeof(s)] = { 0 };
        size_t outbytesleft = sizeof(dst) - 1;
        char* inbuf = s;
        char* outbuf = dst;

        if (iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft) ==
(size_t)-1) {
                printf("iconv fail: %d\n", errno);
        }
        iconv_close(cd);
        size_t n = strlen(dst);
        printf("inbytesleft: %u, outbytesleft: %u, dst len: %u\n", inbytesleft,
outbytesleft, n);
        print_buf(dst, n);
        return 0;
}

array s contents is :
E6 97 A9 E8 A6 8B E7 B4 94 EE A0 97 00

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]