Ticket #13954: 0001-uchar-Introduce-C11-uchar.h.patch

File 0001-uchar-Introduce-C11-uchar.h.patch, 1.6 KB (added by leorize, 7 years ago)

[RFC] Implementation of C11 uchar.h for Haiku

  • new file headers/posix/uchar.h

    From 2c52688f850f44952646a511b9e7ca155f6f9bc9 Mon Sep 17 00:00:00 2001
    From: Leorize <alaviss@users.noreply.github.com>
    Date: Sat, 13 Jan 2018 11:22:51 +0700
    Subject: [PATCH] uchar: Introduce C11 uchar.h
    
    Currently this implementation only supports UTF-32
    ---
     headers/posix/uchar.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
     1 file changed, 45 insertions(+)
     create mode 100644 headers/posix/uchar.h
    
    diff --git a/headers/posix/uchar.h b/headers/posix/uchar.h
    new file mode 100644
    index 00000000..72f3ac18
    - +  
     1/*
     2 * Copyright 2018 Haiku, Inc. All Right Reserved
     3 * Distributed under the terms of MIT license.
     4 */
     5#ifndef _UCHAR_H
     6#define _UCHAR_H
     7
     8#include <wchar.h>
     9
     10#ifdef __cplusplus
     11extern "C" {
     12#else
     13typedef wchar_t char32_t; /* our wchar_t is utf32 */
     14typedef wchar_t char16_t;
     15#endif
     16
     17#define __STD_UTF_32__ 1
     18
     19/* We don't define __STD_UTF_16__, so the format of char16_t is unspecified */
     20static __inline size_t
     21c16rtomb(char *dest, char16_t wc, mbstate_t *mbState)
     22{
     23    return wcrtomb(dest, wc, mbState);
     24}
     25static __inline size_t
     26mbrtoc16(char16_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
     27{
     28    return mbrtowc(dest, src, srcLength, mbState);
     29}
     30
     31static __inline size_t
     32c32rtomb(char *dest, char32_t wc, mbstate_t *mbState)
     33{
     34    return wcrtomb(dest, wc, mbState);
     35}
     36static __inline size_t
     37mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
     38{
     39    return mbrtowc(dest, src, srcLength, mbState);
     40}
     41
     42#ifdef __cplusplus
     43}
     44#endif
     45#endif /* _UCHAR_H */