_open_osfhandle is expected to take the absence of either _O_TEXT or
[wine/gsoc_dplay.git] / dlls / msvcrt / wcs.c
blob62462767706eb6eec5034d8d3ffd80a444036c99
1 /*
2 * msvcrt.dll wide-char functions
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
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.
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.
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
21 #include <limits.h>
22 #include <stdio.h>
23 #include "msvcrt.h"
24 #include "winnls.h"
25 #include "wine/unicode.h"
27 #include "msvcrt/stdio.h"
28 #include "msvcrt/stdlib.h"
29 #include "msvcrt/string.h"
30 #include "msvcrt/wctype.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
37 /* INTERNAL: MSVCRT_malloc() based wstrndup */
38 MSVCRT_wchar_t* msvcrt_wstrndup(const MSVCRT_wchar_t *buf, unsigned int size)
40 MSVCRT_wchar_t* ret;
41 unsigned int len = strlenW(buf), max_len;
43 max_len = size <= len? size : len + 1;
45 ret = MSVCRT_malloc(max_len * sizeof (MSVCRT_wchar_t));
46 if (ret)
48 memcpy(ret,buf,max_len * sizeof (MSVCRT_wchar_t));
49 ret[max_len] = 0;
51 return ret;
54 /*********************************************************************
55 * _wcsdup (MSVCRT.@)
57 MSVCRT_wchar_t* _wcsdup( const MSVCRT_wchar_t* str )
59 MSVCRT_wchar_t* ret = NULL;
60 if (str)
62 int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
63 ret = MSVCRT_malloc( size );
64 if (ret) memcpy( ret, str, size );
66 return ret;
69 /*********************************************************************
70 * _wcsicoll (MSVCRT.@)
72 INT _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
74 /* FIXME: handle collates */
75 return strcmpiW( str1, str2 );
78 /*********************************************************************
79 * _wcsnset (MSVCRT.@)
81 MSVCRT_wchar_t* _wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
83 MSVCRT_wchar_t* ret = str;
84 while ((n-- > 0) && *str) *str++ = c;
85 return ret;
88 /*********************************************************************
89 * _wcsrev (MSVCRT.@)
91 MSVCRT_wchar_t* _wcsrev( MSVCRT_wchar_t* str )
93 MSVCRT_wchar_t* ret = str;
94 MSVCRT_wchar_t* end = str + strlenW(str) - 1;
95 while (end > str)
97 MSVCRT_wchar_t t = *end;
98 *end-- = *str;
99 *str++ = t;
101 return ret;
104 /*********************************************************************
105 * _wcsset (MSVCRT.@)
107 MSVCRT_wchar_t* _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
109 MSVCRT_wchar_t* ret = str;
110 while (*str) *str++ = c;
111 return ret;
114 /*********************************************************************
115 * _vsnwprintf (MSVCRT.@)
117 int _vsnwprintf(MSVCRT_wchar_t *str, unsigned int len,
118 const MSVCRT_wchar_t *format, va_list valist)
120 return vsnprintfW(str, len, format, valist);
123 /*********************************************************************
124 * vswprintf (MSVCRT.@)
126 int MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, va_list args )
128 return vsnprintfW( str, INT_MAX, format, args );
131 /*********************************************************************
132 * wcscoll (MSVCRT.@)
134 int MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
136 /* FIXME: handle collates */
137 return strcmpW( str1, str2 );
140 /*********************************************************************
141 * wcspbrk (MSVCRT.@)
143 MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
145 const MSVCRT_wchar_t* p;
146 while (*str)
148 for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
149 str++;
151 return NULL;
154 /*********************************************************************
155 * wctomb (MSVCRT.@)
157 INT MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
159 return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
162 /*********************************************************************
163 * iswalnum (MSVCRT.@)
165 INT MSVCRT_iswalnum( MSVCRT_wchar_t wc )
167 return isalnumW( wc );
170 /*********************************************************************
171 * iswalpha (MSVCRT.@)
173 INT MSVCRT_iswalpha( MSVCRT_wchar_t wc )
175 return isalphaW( wc );
178 /*********************************************************************
179 * iswcntrl (MSVCRT.@)
181 INT MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
183 return iscntrlW( wc );
186 /*********************************************************************
187 * iswdigit (MSVCRT.@)
189 INT MSVCRT_iswdigit( MSVCRT_wchar_t wc )
191 return isdigitW( wc );
194 /*********************************************************************
195 * iswgraph (MSVCRT.@)
197 INT MSVCRT_iswgraph( MSVCRT_wchar_t wc )
199 return isgraphW( wc );
202 /*********************************************************************
203 * iswlower (MSVCRT.@)
205 INT MSVCRT_iswlower( MSVCRT_wchar_t wc )
207 return islowerW( wc );
210 /*********************************************************************
211 * iswprint (MSVCRT.@)
213 INT MSVCRT_iswprint( MSVCRT_wchar_t wc )
215 return isprintW( wc );
218 /*********************************************************************
219 * iswpunct (MSVCRT.@)
221 INT MSVCRT_iswpunct( MSVCRT_wchar_t wc )
223 return ispunctW( wc );
226 /*********************************************************************
227 * iswspace (MSVCRT.@)
229 INT MSVCRT_iswspace( MSVCRT_wchar_t wc )
231 return isspaceW( wc );
234 /*********************************************************************
235 * iswupper (MSVCRT.@)
237 INT MSVCRT_iswupper( MSVCRT_wchar_t wc )
239 return isupperW( wc );
242 /*********************************************************************
243 * iswxdigit (MSVCRT.@)
245 INT MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
247 return isxdigitW( wc );