1 /* $NetBSD: src/lib/libc/locale/multibyte.h,v 1.3 2003/04/29 14:53:12 scw Exp $ */
2 /* $DragonFly: src/lib/libc/locale/multibyte.h,v 1.1 2005/03/16 06:54:41 joerg Exp $ */
5 * Copyright (c)2002 Citrus Project,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 /* mbstate_t private */
35 #ifndef _MBSTATE_T_DECLARED
36 #define _MBSTATE_T_DECLARED
37 typedef __mbstate_t
mbstate_t;
40 typedef struct _RuneStatePriv
{
41 _RuneLocale
*__runelocale
;
42 char __private
__attribute__((__aligned__
));
45 typedef union _RuneState
{
47 struct _RuneStatePriv __priv
;
48 #define rs_runelocale __priv.__runelocale
49 #define rs_private __priv.__private
51 #define _PRIVSIZE (sizeof(mbstate_t)-offsetof(_RuneStatePriv, __private))
53 static __inline _citrus_ctype_t
56 return(_CurrentRuneLocale
->rl_citrus_ctype
);
59 static __inline _RuneState
*
60 _ps_to_runestate(mbstate_t *ps
)
62 return((_RuneState
*)(void *)ps
);
65 static __inline
const _RuneState
*
66 _ps_to_runestate_const(const mbstate_t *ps
)
68 return((const _RuneState
*)(const void *)ps
);
71 static __inline _RuneLocale
*
72 _ps_to_runelocale(const mbstate_t *ps
)
74 return(_ps_to_runestate_const(ps
)->rs_runelocale
);
77 static __inline _citrus_ctype_t
78 _ps_to_ctype(const mbstate_t *ps
)
81 return(_to_cur_ctype());
83 _DIAGASSERT(_ps_to_runelocale(ps
) != NULL
);
85 return(_ps_to_runelocale(ps
)->rl_citrus_ctype
);
88 static __inline
void *
89 _ps_to_private(mbstate_t *ps
)
93 return((void *)&_ps_to_runestate(ps
)->rs_private
);
96 static __inline
const void *
97 _ps_to_private_const(const mbstate_t *ps
)
101 return((const void *)&_ps_to_runestate_const(ps
)->rs_private
);
105 _init_ps(_RuneLocale
*rl
, mbstate_t *ps
)
108 _ps_to_runestate(ps
)->rs_runelocale
= rl
;
109 _citrus_ctype_mbrtowc(rl
->rl_citrus_ctype
, NULL
, NULL
, 0,
110 _ps_to_private(ps
), &dum
);
114 _fixup_ps(_RuneLocale
*rl
, mbstate_t *ps
, int forceinit
)
116 /* for future multi-locale facility */
117 _DIAGASSERT(rl
!= NULL
);
119 if (ps
!= NULL
&& (_ps_to_runelocale(ps
) == NULL
|| forceinit
))