dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / comp / wc.c
blob2175f2caeacab00104913209568bac7acd8c6b2d
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 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
25 * NOTE: mbs* and wcs* are provided to avoid link errors only
28 #include <ast.h>
29 #include <wchar.h>
31 #define STUB 1
33 #if !_lib_mbtowc
34 #undef STUB
35 size_t
36 mbtowc(wchar_t* t, const char* s, size_t n)
38 if (t && n > 0)
39 *t = *s;
40 return 1;
42 #endif
44 #if !_lib_mbrtowc
45 #undef STUB
46 size_t
47 mbrtowc(wchar_t* t, const char* s, size_t n, mbstate_t* q)
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
60 #endif
62 #if !_lib_mbstowcs
63 #undef STUB
64 size_t
65 mbstowcs(wchar_t* t, const char* s, size_t n)
67 register wchar_t* p = t;
68 register wchar_t* e = t + n;
69 register unsigned char* u = (unsigned char*)s;
71 if (t)
72 while (p < e && (*p++ = *u++));
73 else
74 while (p++, *u++);
75 return p - t;
77 #endif
79 #if !_lib_wctomb
80 #undef STUB
81 int
82 wctomb(char* s, wchar_t c)
84 if (s)
85 *s = c;
86 return 1;
88 #endif
90 #if !_lib_wcrtomb
91 #undef STUB
92 size_t
93 wcrtomb(char* s, wchar_t c, mbstate_t* q)
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
106 #endif
108 #if !_lib_wcslen
109 #undef STUB
110 size_t
111 wcslen(const wchar_t* s)
113 register const wchar_t* p = s;
115 while (*p)
116 p++;
117 return p - s;
119 #endif
121 #if !_lib_wcstombs
122 #undef STUB
123 size_t
124 wcstombs(char* t, register const wchar_t* s, size_t n)
126 register char* p = t;
127 register char* e = t + n;
129 if (t)
130 while (p < e && (*p++ = *s++));
131 else
132 while (p++, *s++);
133 return p - t;
135 #endif
137 #if STUB
138 NoN(wc)
139 #endif