ReactOS 0.4.16-dev-1946-g52006dd
wcs.c File Reference
#include <precomp.h>
#include <assert.h>
#include <internal/wine/msvcrt.h>
#include "wine/unicode.h"
Include dependency graph for wcs.c:

Go to the source code of this file.

Functions

wchar_t *CDECL _wcsdup (const wchar_t *str)
 
INT CDECL _wcsicoll (const wchar_t *str1, const wchar_t *str2)
 
wchar_t *CDECL _wcsnset (wchar_t *str, wchar_t c, size_t n)
 
wchar_t *CDECL _wcsrev (wchar_t *str)
 
wchar_t *CDECL _wcsset (wchar_t *str, wchar_t c)
 
INT CDECL _wcsupr_s (wchar_t *str, size_t n)
 
double CDECL wcstod (const wchar_t *lpszStr, wchar_t **end)
 
int CDECL wcscoll (const wchar_t *str1, const wchar_t *str2)
 
wchar_t *CDECL wcspbrk (const wchar_t *str, const wchar_t *accept)
 
INT CDECL wctomb (char *dst, wchar_t ch)
 
static size_t CDECL wcsrtombs_l (char *mbstr, const wchar_t **wcstr, size_t count, _locale_t locale)
 
size_t CDECL _wcstombs_l (char *mbstr, const wchar_t *wcstr, size_t count, _locale_t locale)
 
size_t CDECL wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
 
INT CDECL wcscpy_s (wchar_t *wcDest, size_t numElement, const wchar_t *wcSrc)
 
INT CDECL wcsncpy_s (wchar_t *wcDest, size_t numElement, const wchar_t *wcSrc, size_t count)
 
INT CDECL wcscat_s (wchar_t *dst, size_t elem, const wchar_t *src)
 
INT CDECL wcsncat_s (wchar_t *dst, size_t elem, const wchar_t *src, size_t count)
 

Function Documentation

◆ _wcsdup()

wchar_t *CDECL _wcsdup ( const wchar_t str)

Definition at line 53 of file wcs.c.

54{
55 wchar_t* ret = NULL;
56 if (str)
57 {
58 size_t size = (strlenW(str) + 1) * sizeof(wchar_t);
59 ret = malloc( size );
60 if (ret) memcpy( ret, str, size );
61 }
62 return ret;
63}
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
return ret
Definition: mutex.c:146
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
const WCHAR * str
#define strlenW(s)
Definition: unicode.h:34

◆ _wcsicoll()

INT CDECL _wcsicoll ( const wchar_t str1,
const wchar_t str2 
)

Definition at line 67 of file wcs.c.

68{
69 /* FIXME: handle collates */
70 return strcmpiW( str1, str2 );
71}
#define strcmpiW(s1, s2)
Definition: unicode.h:45

◆ _wcsnset()

wchar_t *CDECL _wcsnset ( wchar_t str,
wchar_t  c,
size_t  n 
)

Definition at line 77 of file wcs.c.

78{
79 wchar_t* ret = str;
80 while ((n-- > 0) && *str) *str++ = c;
81 return ret;
82}
GLdouble n
Definition: glext.h:7729
#define c
Definition: ke_i.h:80

◆ _wcsrev()

wchar_t *CDECL _wcsrev ( wchar_t str)

Definition at line 87 of file wcs.c.

88{
89 wchar_t* ret = str;
90 wchar_t* end = str + strlenW(str) - 1;
91 while (end > str)
92 {
93 wchar_t t = *end;
94 *end-- = *str;
95 *str++ = t;
96 }
97 return ret;
98}
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble t
Definition: gl.h:2047

◆ _wcsset()

wchar_t *CDECL _wcsset ( wchar_t str,
wchar_t  c 
)

Definition at line 104 of file wcs.c.

105{
106 wchar_t* ret = str;
107 while (*str) *str++ = c;
108 return ret;
109}

◆ _wcstombs_l()

size_t CDECL _wcstombs_l ( char mbstr,
const wchar_t wcstr,
size_t  count,
_locale_t  locale 
)

Definition at line 331 of file wcs.c.

332{
333 return wcsrtombs_l(mbstr, &wcstr, count, locale);
334}
Definition: _locale.h:75
GLuint GLuint GLsizei count
Definition: gl.h:1545
static size_t CDECL wcsrtombs_l(char *mbstr, const wchar_t **wcstr, size_t count, _locale_t locale)
Definition: wcs.c:263

◆ _wcsupr_s()

INT CDECL _wcsupr_s ( wchar_t str,
size_t  n 
)

Definition at line 115 of file wcs.c.

116{
117 wchar_t* ptr = str;
118
119 if (!str || !n)
120 {
121 if (str) *str = '\0';
123 return EINVAL;
124 }
125
126 while (n--)
127 {
128 if (!*ptr) return 0;
129 *ptr = toupperW(*ptr);
130 ptr++;
131 }
132
133 /* MSDN claims that the function should return and set errno to
134 * ERANGE, which doesn't seem to be true based on the tests. */
135 *str = '\0';
137 return EINVAL;
138}
#define EINVAL
Definition: acclib.h:90
static PVOID ptr
Definition: dispmode.c:27
errno_t __cdecl _set_errno(_In_ int _Value)
#define toupperW(n)
Definition: unicode.h:51

◆ wcscat_s()

INT CDECL wcscat_s ( wchar_t dst,
size_t  elem,
const wchar_t src 
)

Definition at line 409 of file wcs.c.

410{
411 wchar_t* ptr = dst;
412
413 if (!dst || elem == 0) return EINVAL;
414 if (!src)
415 {
416 dst[0] = '\0';
417 return EINVAL;
418 }
419
420 /* seek to end of dst string (or elem if no end of string is found */
421 while (ptr < dst + elem && *ptr != '\0') ptr++;
422 while (ptr < dst + elem)
423 {
424 if ((*ptr++ = *src++) == '\0') return 0;
425 }
426 /* not enough space */
427 dst[0] = '\0';
428 return ERANGE;
429}
#define ERANGE
Definition: acclib.h:92
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
static size_t elem
Definition: string.c:71

Referenced by __acrt_report_runtime_error(), _VCrtDbgReportW(), _wcscats(), and _wsetlocale_get_all().

◆ wcscoll()

int CDECL wcscoll ( const wchar_t str1,
const wchar_t str2 
)

Definition at line 216 of file wcs.c.

217{
218 /* FIXME: handle collates */
219 return strcmpW( str1, str2 );
220}
#define strcmpW(s1, s2)
Definition: unicode.h:44

◆ wcscpy_s()

INT CDECL wcscpy_s ( wchar_t wcDest,
size_t  numElement,
const wchar_t wcSrc 
)

Definition at line 348 of file wcs.c.

349{
350 size_t size = 0;
351
352 if(!wcDest || !numElement)
353 return EINVAL;
354
355 wcDest[0] = 0;
356
357 if(!wcSrc)
358 {
359 return EINVAL;
360 }
361
362 size = strlenW(wcSrc) + 1;
363
364 if(size > numElement)
365 {
366 return ERANGE;
367 }
368
369 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
370
371 return 0;
372}
static const unsigned char *static size_t const wchar_t * wcSrc
Definition: string.c:76
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ wcsncat_s()

INT CDECL wcsncat_s ( wchar_t dst,
size_t  elem,
const wchar_t src,
size_t  count 
)

Definition at line 435 of file wcs.c.

437{
438 size_t srclen;
439 wchar_t dststart;
440 INT ret = 0;
441
443 {
444#ifndef _LIBCNT_
446#endif
447 return EINVAL;
448 }
449 if (!MSVCRT_CHECK_PMT(src != NULL || count == 0))
450 return EINVAL;
451 if (count == 0)
452 return 0;
453
454 for (dststart = 0; dststart < elem; dststart++)
455 {
456 if (dst[dststart] == '\0')
457 break;
458 }
459 if (dststart == elem)
460 {
461 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", EINVAL);
462 return EINVAL;
463 }
464
465 if (count == _TRUNCATE)
466 {
467 srclen = strlenW(src);
468 if (srclen >= (elem - dststart))
469 {
470 srclen = elem - dststart - 1;
471 ret = STRUNCATE;
472 }
473 }
474 else
476 if (srclen < (elem - dststart))
477 {
478 memcpy(&dst[dststart], src, srclen*sizeof(wchar_t));
479 dst[dststart+srclen] = '\0';
480 return ret;
481 }
482 MSVCRT_INVALID_PMT("dst[elem] is too small", ERANGE);
483 dst[0] = '\0';
484 return ERANGE;
485}
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:52
#define min(a, b)
Definition: monoChain.cc:55
#define STRUNCATE
Definition: errno.h:110
int32_t INT
Definition: typedefs.h:58
static transitiondate dststart
Definition: tzset.cpp:59
#define _TRUNCATE
Definition: corecrt.h:278

◆ wcsncpy_s()

INT CDECL wcsncpy_s ( wchar_t wcDest,
size_t  numElement,
const wchar_t wcSrc,
size_t  count 
)

Definition at line 377 of file wcs.c.

379{
380 size_t size = 0;
381
382 if (!wcDest || !numElement)
383 return EINVAL;
384
385 wcDest[0] = 0;
386
387 if (!wcSrc)
388 {
389 return EINVAL;
390 }
391
393
394 if (size >= numElement)
395 {
396 return ERANGE;
397 }
398
399 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
400 wcDest[size] = '\0';
401
402 return 0;
403}

◆ wcspbrk()

wchar_t *CDECL wcspbrk ( const wchar_t str,
const wchar_t accept 
)

Definition at line 225 of file wcs.c.

226{
227 const wchar_t* p;
228 while (*str)
229 {
230 for (p = accept; *p; p++) if (*p == *str) return (wchar_t*)str;
231 str++;
232 }
233 return NULL;
234}
GLfloat GLfloat p
Definition: glext.h:8902
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23

◆ wcsrtombs_l()

static size_t CDECL wcsrtombs_l ( char mbstr,
const wchar_t **  wcstr,
size_t  count,
_locale_t  locale 
)
static

Definition at line 263 of file wcs.c.

265{
267 size_t tmp = 0;
268 BOOL used_default;
269
270 if(!locale)
272 else
273 locinfo = ((MSVCRT__locale_t)locale)->locinfo;
274
275 if(!locinfo->lc_codepage) {
276 size_t i;
277
278 if(!mbstr)
279 return strlenW(*wcstr);
280
281 for(i=0; i<count; i++) {
282 if((*wcstr)[i] > 255) {
284 return -1;
285 }
286
287 mbstr[i] = (*wcstr)[i];
288 if(!(*wcstr)[i]) break;
289 }
290 return i;
291 }
292
293 if(!mbstr) {
295 *wcstr, -1, NULL, 0, NULL, &used_default);
296 if(!tmp || used_default) {
298 return -1;
299 }
300 return tmp-1;
301 }
302
303 while(**wcstr) {
304 char buf[3];
305 size_t i, size;
306
308 *wcstr, 1, buf, 3, NULL, &used_default);
309 if(!size || used_default) {
311 return -1;
312 }
313 if(tmp+size > count)
314 return tmp;
315
316 for(i=0; i<size; i++)
317 mbstr[tmp++] = buf[i];
318 (*wcstr)++;
319 }
320
321 if(tmp < count) {
322 mbstr[tmp] = '\0';
323 *wcstr = NULL;
324 }
325 return tmp;
326}
#define WideCharToMultiByte
Definition: compat.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define WC_NO_BEST_FIT_CHARS
Definition: unicode.h:46
struct MSVCRT_localeinfo_struct * MSVCRT__locale_t
else locinfo
Definition: scanf.h:159
#define EILSEQ
Definition: errno.h:109
#define get_locinfo()
Definition: winesup.h:25

Referenced by _wcstombs_l(), and wcstombs().

◆ wcstod()

double CDECL wcstod ( const wchar_t lpszStr,
wchar_t **  end 
)

Definition at line 143 of file wcs.c.

144{
145 const wchar_t* str = lpszStr;
146 int negative = 0;
147 double ret = 0, divisor = 10.0;
148
149 TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr), end);
150
151 /* FIXME:
152 * - Should set errno on failure
153 * - Should fail on overflow
154 * - Need to check which input formats are allowed
155 */
156 while (isspaceW(*str))
157 str++;
158
159 if (*str == '-')
160 {
161 negative = 1;
162 str++;
163 }
164
165 while (isdigitW(*str))
166 {
167 ret = ret * 10.0 + (*str - '0');
168 str++;
169 }
170 if (*str == '.')
171 str++;
172 while (isdigitW(*str))
173 {
174 ret = ret + (*str - '0') / divisor;
175 divisor *= 10;
176 str++;
177 }
178
179 if (*str == 'E' || *str == 'e' || *str == 'D' || *str == 'd')
180 {
181 int negativeExponent = 0;
182 int exponent = 0;
183 if (*(++str) == '-')
184 {
185 negativeExponent = 1;
186 str++;
187 }
188 while (isdigitW(*str))
189 {
190 exponent = exponent * 10 + (*str - '0');
191 str++;
192 }
193 if (exponent != 0)
194 {
195 if (negativeExponent)
196 ret = ret / pow(10.0, exponent);
197 else
198 ret = ret * pow(10.0, exponent);
199 }
200 }
201
202 if (negative)
203 ret = -ret;
204
205 if (end)
206 *end = (wchar_t*)str;
207
208 TRACE("returning %g\n", ret);
209 return ret;
210}
__int64 exponent
Definition: cvt.cpp:529
double pow(double x, double y)
Definition: freeldr.c:178
GLuint divisor
Definition: glext.h:6313
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define isdigitW(n)
Definition: unicode.h:56
#define isspaceW(n)
Definition: unicode.h:58

◆ wcstombs()

size_t CDECL wcstombs ( char mbstr,
const wchar_t wcstr,
size_t  count 
)

Definition at line 339 of file wcs.c.

340{
341 return wcsrtombs_l(mbstr, &wcstr, count, NULL);
342}

◆ wctomb()

INT CDECL wctomb ( char dst,
wchar_t  ch 
)

Definition at line 244 of file wcs.c.

245{
246 BOOL error;
247 INT size;
248
249 if (!dst)
250 return 0;
251
252 size = WideCharToMultiByte(get_locinfo()->lc_codepage, 0, &ch, 1, dst, dst ? 6 : 0, NULL, &error);
253 if(!size || error) {
254 *_errno() = EINVAL;
255 return EOF;
256 }
257 return size;
258}
#define EOF
Definition: stdio.h:24
#define error(str)
Definition: mkdosfs.c:1605
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17