xref: /onnv-gate/usr/src/lib/libast/common/comp/wc.c (revision 4887)
1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
18*4887Schin *                  David Korn <dgk@research.att.com>                   *
19*4887Schin *                   Phong Vo <kpv@research.att.com>                    *
20*4887Schin *                                                                      *
21*4887Schin ***********************************************************************/
22*4887Schin #pragma prototyped
23*4887Schin 
24*4887Schin /*
25*4887Schin  * NOTE: mbs* and wcs* are provided to avoid link errors only
26*4887Schin  */
27*4887Schin 
28*4887Schin #include <ast.h>
29*4887Schin #include <wchar.h>
30*4887Schin 
31*4887Schin #define STUB	1
32*4887Schin 
33*4887Schin #if !_lib_mbtowc
34*4887Schin #undef	STUB
35*4887Schin size_t
36*4887Schin mbtowc(wchar_t* t, const char* s, size_t n)
37*4887Schin {
38*4887Schin 	if (t && n > 0)
39*4887Schin 		*t = *s;
40*4887Schin 	return 1;
41*4887Schin }
42*4887Schin #endif
43*4887Schin 
44*4887Schin #if !_lib_mbrtowc
45*4887Schin #undef	STUB
46*4887Schin size_t
47*4887Schin mbrtowc(wchar_t* t, const char* s, size_t n, mbstate_t* q)
48*4887Schin {
49*4887Schin #if _lib_mbtowc
50*4887Schin #undef	STUB
51*4887Schin 	memset(q, 0, sizeof(*q));
52*4887Schin 	return mbtowc(t, s, n);
53*4887Schin #else
54*4887Schin 	*q = 0;
55*4887Schin 	if (t && n > 0)
56*4887Schin 		*t = *s;
57*4887Schin 	return 1;
58*4887Schin #endif
59*4887Schin }
60*4887Schin #endif
61*4887Schin 
62*4887Schin #if !_lib_mbstowcs
63*4887Schin #undef	STUB
64*4887Schin size_t
65*4887Schin mbstowcs(wchar_t* t, const char* s, size_t n)
66*4887Schin {
67*4887Schin 	register wchar_t*	p = t;
68*4887Schin 	register wchar_t*	e = t + n;
69*4887Schin 	register unsigned char*	u = (unsigned char*)s;
70*4887Schin 
71*4887Schin 	if (t)
72*4887Schin 		while (p < e && (*p++ = *u++));
73*4887Schin 	else
74*4887Schin 		while (p++, *u++);
75*4887Schin 	return p - t;
76*4887Schin }
77*4887Schin #endif
78*4887Schin 
79*4887Schin #if !_lib_wctomb
80*4887Schin #undef	STUB
81*4887Schin int
82*4887Schin wctomb(char* s, wchar_t c)
83*4887Schin {
84*4887Schin 	if (s)
85*4887Schin 		*s = c;
86*4887Schin 	return 1;
87*4887Schin }
88*4887Schin #endif
89*4887Schin 
90*4887Schin #if !_lib_wcrtomb
91*4887Schin #undef	STUB
92*4887Schin size_t
93*4887Schin wcrtomb(char* s, wchar_t c, mbstate_t* q)
94*4887Schin {
95*4887Schin #if _lib_wctomb
96*4887Schin #undef	STUB
97*4887Schin 	memset(q, 0, sizeof(*q));
98*4887Schin 	return wctomb(s, c);
99*4887Schin #else
100*4887Schin 	if (s)
101*4887Schin 		*s = c;
102*4887Schin 	*q = 0;
103*4887Schin 	return 1;
104*4887Schin #endif
105*4887Schin }
106*4887Schin #endif
107*4887Schin 
108*4887Schin #if !_lib_wcslen
109*4887Schin #undef	STUB
110*4887Schin size_t
111*4887Schin wcslen(const wchar_t* s)
112*4887Schin {
113*4887Schin 	register const wchar_t*	p = s;
114*4887Schin 
115*4887Schin 	while (*p)
116*4887Schin 		p++;
117*4887Schin 	return p - s;
118*4887Schin }
119*4887Schin #endif
120*4887Schin 
121*4887Schin #if !_lib_wcstombs
122*4887Schin #undef	STUB
123*4887Schin size_t
124*4887Schin wcstombs(char* t, register const wchar_t* s, size_t n)
125*4887Schin {
126*4887Schin 	register char*		p = t;
127*4887Schin 	register char*		e = t + n;
128*4887Schin 
129*4887Schin 	if (t)
130*4887Schin 		while (p < e && (*p++ = *s++));
131*4887Schin 	else
132*4887Schin 		while (p++, *s++);
133*4887Schin 	return p - t;
134*4887Schin }
135*4887Schin #endif
136*4887Schin 
137*4887Schin #if STUB
138*4887Schin NoN(wc)
139*4887Schin #endif
140