utf8.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:13 +0200
changeset 59 a7ba10b68915
parent 48 b94d657a9acb
child 77 49e0babccb23
permissions -rw-r--r--
getpwnam_error.c: * The memory hole can be fixed with two different approaches 1) Change /etc/nsswitch.conf: passwd: compat to passwd: files 2) LD_PRELOAD=/lib/libnss_compat.so.2 valgrind ./getpwnam_error GLIBC loads libnss_compat on the fly and unloads it. Thanks to telexicon for reporting this... committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/utf8.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>

#ifndef u_char
typedef unsigned char u_char;
#endif

int main ()
{
    char dest[4];

    wchar_t *str = L"Unicode Example with german umlauts: ÄÖÜäöü߀\n";

    if (!setlocale (LC_CTYPE, "")) {
        perror ("SETLOCALE");
        return EXIT_FAILURE;
    }

    printf ("%ls", str);

    while (*str != '\n') {
        dest[0] = 0;
        dest[1] = 0;
        dest[2] = 0;
        dest[3] = 0;
        if (wctomb (dest, (*str)) == -1)
            return EXIT_FAILURE;

        printf ("%lc -> [%4X] (%2X:%2X:%2X:%2X)\n",
                *str, *str, (u_char) dest[0], (u_char) dest[1], (u_char) dest[2], (u_char) dest[3]);
        str++;
    }

    printf ("DIFF: %d : 0x%2X\n", 0x40, 0x40);

    return EXIT_SUCCESS;
}