Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/bionic_mbstate.h
38825 views
/*1* Copyright (C) 2014 The Android Open Source Project2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* * Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* * Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in11* the documentation and/or other materials provided with the12* distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS15* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT16* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS17* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE18* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,20* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS21* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED22* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,23* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT24* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/27#ifndef _BIONIC_MBSTATE_H28#define _BIONIC_MBSTATE_H29#include <errno.h>30#include <wchar.h>31__BEGIN_DECLS32/*33* These return values are specified by POSIX for multibyte conversion34* functions.35*/3637#ifdef __cplusplus38#define __MB_ERR_ILLEGAL_SEQUENCE static_cast<size_t>(-1)39#define __MB_ERR_INCOMPLETE_SEQUENCE static_cast<size_t>(-2)40#else41#define __MB_ERR_ILLEGAL_SEQUENCE (size_t)(-1)42#define __MB_ERR_INCOMPLETE_SEQUENCE (size_t)(-2)43#endif // __cplusplus44#define __MB_IS_ERR(rv) (rv == __MB_ERR_ILLEGAL_SEQUENCE || \45rv == __MB_ERR_INCOMPLETE_SEQUENCE)46static inline __wur size_t mbstate_bytes_so_far(const mbstate_t* ps) {47return48(ps->__seq[2] != 0) ? 3 :49(ps->__seq[1] != 0) ? 2 :50(ps->__seq[0] != 0) ? 1 : 0;51}52static inline void mbstate_set_byte(mbstate_t* ps, int i, char byte) {53ps->__seq[i] = (uint8_t)(byte);54}55static inline __wur uint8_t mbstate_get_byte(const mbstate_t* ps, int n) {56return ps->__seq[n];57}58static inline __wur size_t mbstate_reset_and_return_illegal(int _errno, mbstate_t* ps) {59errno = _errno;60#ifdef __cplusplus61*(reinterpret_cast<uint32_t*>(ps->__seq)) = 0;62#else63*(uint32_t*)(ps->__seq) = 0;64#endif // __cplusplus65return __MB_ERR_ILLEGAL_SEQUENCE;66}67static inline __wur size_t mbstate_reset_and_return(int _return, mbstate_t* ps) {68#ifdef __cplusplus69*(reinterpret_cast<uint32_t*>(ps->__seq)) = 0;70#else71*(uint32_t*)(ps->__seq) = 0;72#endif // __cplusplus73return _return;74}75__END_DECLS76#endif // _BIONIC_MBSTATE_H777879