Add RtlDowncaseUnicodeChar(), RtlEqualComputerName(),
[wine] / dlls / msvcrt / wcs.c
1 /*
2  * msvcrt.dll wide-char functions
3  *
4  * Copyright 1999 Alexandre Julliard
5  * Copyright 2000 Jon Griffiths
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 #include <limits.h>
22 #include <stdio.h>
23 #include "msvcrt.h"
24 #include "winnls.h"
25 #include "wine/unicode.h"
26
27 #include "msvcrt/stdio.h"
28 #include "msvcrt/stdlib.h"
29 #include "msvcrt/string.h"
30 #include "msvcrt/wctype.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
35
36
37 /* INTERNAL: MSVCRT_malloc() based wstrndup */
38 MSVCRT_wchar_t* msvcrt_wstrndup(const MSVCRT_wchar_t *buf, unsigned int size)
39 {
40   MSVCRT_wchar_t* ret;
41   unsigned int len = strlenW(buf), max_len;
42
43   max_len = size <= len? size : len + 1;
44
45   ret = MSVCRT_malloc(max_len * sizeof (MSVCRT_wchar_t));
46   if (ret)
47   {
48     memcpy(ret,buf,max_len * sizeof (MSVCRT_wchar_t));
49     ret[max_len] = 0;
50   }
51   return ret;
52 }
53
54 /*********************************************************************
55  *              _wcsdup (MSVCRT.@)
56  */
57 MSVCRT_wchar_t* _wcsdup( const MSVCRT_wchar_t* str )
58 {
59   MSVCRT_wchar_t* ret = NULL;
60   if (str)
61   {
62     int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
63     ret = MSVCRT_malloc( size );
64     if (ret) memcpy( ret, str, size );
65   }
66   return ret;
67 }
68
69 /*********************************************************************
70  *              _wcsicoll (MSVCRT.@)
71  */
72 INT _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
73 {
74   /* FIXME: handle collates */
75   return strcmpiW( str1, str2 );
76 }
77
78 /*********************************************************************
79  *              _wcsnset (MSVCRT.@)
80  */
81 MSVCRT_wchar_t* _wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
82 {
83   MSVCRT_wchar_t* ret = str;
84   while ((n-- > 0) && *str) *str++ = c;
85   return ret;
86 }
87
88 /*********************************************************************
89  *              _wcsrev (MSVCRT.@)
90  */
91 MSVCRT_wchar_t* _wcsrev( MSVCRT_wchar_t* str )
92 {
93   MSVCRT_wchar_t* ret = str;
94   MSVCRT_wchar_t* end = str + strlenW(str) - 1;
95   while (end > str)
96   {
97     MSVCRT_wchar_t t = *end;
98     *end--  = *str;
99     *str++  = t;
100   }
101   return ret;
102 }
103
104 /*********************************************************************
105  *              _wcsset (MSVCRT.@)
106  */
107 MSVCRT_wchar_t* _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
108 {
109   MSVCRT_wchar_t* ret = str;
110   while (*str) *str++ = c;
111   return ret;
112 }
113
114 /*********************************************************************
115  *              _vsnwprintf (MSVCRT.@)
116  */
117 int _vsnwprintf(MSVCRT_wchar_t *str, unsigned int len,
118                 const MSVCRT_wchar_t *format, va_list valist)
119 {
120     return vsnprintfW(str, len, format, valist);
121 }
122
123 /*********************************************************************
124  *              vswprintf (MSVCRT.@)
125  */
126 int MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, va_list args )
127 {
128     return vsnprintfW( str, INT_MAX, format, args );
129 }
130
131 /*********************************************************************
132  *              wcscoll (MSVCRT.@)
133  */
134 int MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
135 {
136   /* FIXME: handle collates */
137   return strcmpW( str1, str2 );
138 }
139
140 /*********************************************************************
141  *              wcspbrk (MSVCRT.@)
142  */
143 MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
144 {
145   const MSVCRT_wchar_t* p;
146   while (*str)
147   {
148     for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
149       str++;
150   }
151   return NULL;
152 }
153
154 /*********************************************************************
155  *              wctomb (MSVCRT.@)
156  */
157 INT MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
158 {
159   return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
160 }
161
162 /*********************************************************************
163  *              iswalnum (MSVCRT.@)
164  */
165 INT MSVCRT_iswalnum( MSVCRT_wchar_t wc )
166 {
167     return isalnumW( wc );
168 }
169
170 /*********************************************************************
171  *              iswalpha (MSVCRT.@)
172  */
173 INT MSVCRT_iswalpha( MSVCRT_wchar_t wc )
174 {
175     return isalphaW( wc );
176 }
177
178 /*********************************************************************
179  *              iswcntrl (MSVCRT.@)
180  */
181 INT MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
182 {
183     return iscntrlW( wc );
184 }
185
186 /*********************************************************************
187  *              iswdigit (MSVCRT.@)
188  */
189 INT MSVCRT_iswdigit( MSVCRT_wchar_t wc )
190 {
191     return isdigitW( wc );
192 }
193
194 /*********************************************************************
195  *              iswgraph (MSVCRT.@)
196  */
197 INT MSVCRT_iswgraph( MSVCRT_wchar_t wc )
198 {
199     return isgraphW( wc );
200 }
201
202 /*********************************************************************
203  *              iswlower (MSVCRT.@)
204  */
205 INT MSVCRT_iswlower( MSVCRT_wchar_t wc )
206 {
207     return islowerW( wc );
208 }
209
210 /*********************************************************************
211  *              iswprint (MSVCRT.@)
212  */
213 INT MSVCRT_iswprint( MSVCRT_wchar_t wc )
214 {
215     return isprintW( wc );
216 }
217
218 /*********************************************************************
219  *              iswpunct (MSVCRT.@)
220  */
221 INT MSVCRT_iswpunct( MSVCRT_wchar_t wc )
222 {
223     return ispunctW( wc );
224 }
225
226 /*********************************************************************
227  *              iswspace (MSVCRT.@)
228  */
229 INT MSVCRT_iswspace( MSVCRT_wchar_t wc )
230 {
231     return isspaceW( wc );
232 }
233
234 /*********************************************************************
235  *              iswupper (MSVCRT.@)
236  */
237 INT MSVCRT_iswupper( MSVCRT_wchar_t wc )
238 {
239     return isupperW( wc );
240 }
241
242 /*********************************************************************
243  *              iswxdigit (MSVCRT.@)
244  */
245 INT MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
246 {
247     return isxdigitW( wc );
248 }