Changeset 28a5ebd in mainline for uspace/lib/c/generic/io/io.c


Ignore:
Timestamp:
2020-06-18T15:39:50Z (4 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce52c333
Parents:
4f663f3e
Message:

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/io.c

    r4f663f3e r28a5ebd  
    4848#include <adt/list.h>
    4949#include <wchar.h>
     50#include <uchar.h>
    5051#include "../private/io.h"
    5152#include "../private/stdio.h"
     
    749750}
    750751
     752wint_t fputuc(char32_t wc, FILE *stream)
     753{
     754        char buf[STR_BOUNDS(1)];
     755        size_t sz = 0;
     756
     757        if (chr_encode(wc, buf, &sz, STR_BOUNDS(1)) != EOK) {
     758                errno = EILSEQ;
     759                return WEOF;
     760        }
     761
     762        size_t wr = fwrite(buf, 1, sz, stream);
     763        if (wr < sz)
     764                return WEOF;
     765
     766        return wc;
     767}
     768
    751769wint_t putwchar(wchar_t wc)
    752770{
    753771        return fputwc(wc, stdout);
     772}
     773
     774wint_t putuchar(char32_t wc)
     775{
     776        return fputuc(wc, stdout);
    754777}
    755778
Note: See TracChangeset for help on using the changeset viewer.