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