ReactOS  0.4.14-dev-552-g2fad488
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 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define malloc
Definition: debug_ros.c:4

◆ _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:39

◆ _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
const WCHAR * str
int ret
#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 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
GLdouble GLdouble t
Definition: gl.h:2047
GLuint GLuint end
Definition: gl.h:1545
const WCHAR * str
int ret

◆ _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 }
const WCHAR * str
int ret
#define c
Definition: ke_i.h:80

◆ _wcstombs_l()

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

Definition at line 305 of file wcs.c.

306 {
307  return wcsrtombs_l(mbstr, &wcstr, count, locale);
308 }
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:260
Definition: _locale.h:75

◆ _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 }
errno_t __cdecl _set_errno(_In_ int _Value)
Definition: arc.h:39
GLdouble n
Definition: glext.h:7729
static PVOID ptr
Definition: dispmode.c:27
const WCHAR * str
WINE_UNICODE_INLINE WCHAR toupperW(WCHAR ch)
Definition: unicode.h:141

◆ wcscat_s()

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

Definition at line 383 of file wcs.c.

384 {
385  wchar_t* ptr = dst;
386 
387  if (!dst || elem == 0) return EINVAL;
388  if (!src)
389  {
390  dst[0] = '\0';
391  return EINVAL;
392  }
393 
394  /* seek to end of dst string (or elem if no end of string is found */
395  while (ptr < dst + elem && *ptr != '\0') ptr++;
396  while (ptr < dst + elem)
397  {
398  if ((*ptr++ = *src++) == '\0') return 0;
399  }
400  /* not enough space */
401  dst[0] = '\0';
402  return ERANGE;
403 }
Definition: arc.h:39
static size_t elem
Definition: string.c:68
static PVOID ptr
Definition: dispmode.c:27
#define ERANGE
Definition: acclib.h:92
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

◆ 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 }
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229

◆ wcscpy_s()

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

Definition at line 322 of file wcs.c.

323 {
324  size_t size = 0;
325 
326  if(!wcDest || !numElement)
327  return EINVAL;
328 
329  wcDest[0] = 0;
330 
331  if(!wcSrc)
332  {
333  return EINVAL;
334  }
335 
336  size = strlenW(wcSrc) + 1;
337 
338  if(size > numElement)
339  {
340  return ERANGE;
341  }
342 
343  memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
344 
345  return 0;
346 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
Definition: arc.h:39
static const unsigned char *static size_t const wchar_t * wcSrc
Definition: string.c:66
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ERANGE
Definition: acclib.h:92
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ wcsncat_s()

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

Definition at line 409 of file wcs.c.

411 {
412  size_t srclen;
413  wchar_t dststart;
414  INT ret = 0;
415 
416  if (!MSVCRT_CHECK_PMT(dst != NULL) || !MSVCRT_CHECK_PMT(elem > 0))
417  {
418 #ifndef _LIBCNT_
420 #endif
421  return EINVAL;
422  }
423  if (!MSVCRT_CHECK_PMT(src != NULL || count == 0))
424  return EINVAL;
425  if (count == 0)
426  return 0;
427 
428  for (dststart = 0; dststart < elem; dststart++)
429  {
430  if (dst[dststart] == '\0')
431  break;
432  }
433  if (dststart == elem)
434  {
435  MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", EINVAL);
436  return EINVAL;
437  }
438 
439  if (count == _TRUNCATE)
440  {
441  srclen = strlenW(src);
442  if (srclen >= (elem - dststart))
443  {
444  srclen = elem - dststart - 1;
445  ret = STRUNCATE;
446  }
447  }
448  else
449  srclen = min(strlenW(src), count);
450  if (srclen < (elem - dststart))
451  {
452  memcpy(&dst[dststart], src, srclen*sizeof(wchar_t));
453  dst[dststart+srclen] = '\0';
454  return ret;
455  }
456  MSVCRT_INVALID_PMT("dst[elem] is too small", ERANGE);
457  dst[0] = '\0';
458  return ERANGE;
459 }
errno_t __cdecl _set_errno(_In_ int _Value)
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define STRUNCATE
Definition: errno.h:110
int32_t INT
Definition: typedefs.h:56
static size_t elem
Definition: string.c:68
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
smooth NULL
Definition: ftsmooth.c:416
#define _TRUNCATE
Definition: crtdefs.h:241
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
#define ERANGE
Definition: acclib.h:92
int ret
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define min(a, b)
Definition: monoChain.cc:55

◆ wcsncpy_s()

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

Definition at line 351 of file wcs.c.

353 {
354  size_t size = 0;
355 
356  if (!wcDest || !numElement)
357  return EINVAL;
358 
359  wcDest[0] = 0;
360 
361  if (!wcSrc)
362  {
363  return EINVAL;
364  }
365 
366  size = min(strlenW(wcSrc), count);
367 
368  if (size >= numElement)
369  {
370  return ERANGE;
371  }
372 
373  memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
374  wcDest[size] = '\0';
375 
376  return 0;
377 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
static const unsigned char *static size_t const wchar_t * wcSrc
Definition: string.c:66
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ERANGE
Definition: acclib.h:92
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55

◆ 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 }
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
GLfloat GLfloat p
Definition: glext.h:8902

◆ wcsrtombs_l()

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

Definition at line 260 of file wcs.c.

261 {
263  size_t tmp = 0;
264  BOOL used_default;
265 
266  if(!locale)
267  locinfo = get_locinfo();
268  else
269  locinfo = ((MSVCRT__locale_t)locale)->locinfo;
270 
271  if(!mbstr) {
273  *wcstr, -1, NULL, 0, NULL, &used_default)-1;
274  if(used_default)
275  return -1;
276  return tmp;
277  }
278 
279  while(**wcstr) {
280  char buf[3];
281  size_t i, size;
282 
284  *wcstr, 1, buf, 3, NULL, &used_default);
285  if(used_default)
286  return -1;
287  if(tmp+size > count)
288  return tmp;
289 
290  for(i=0; i<size; i++)
291  mbstr[tmp++] = buf[i];
292  (*wcstr)++;
293  }
294 
295  if(tmp < count) {
296  mbstr[tmp] = '\0';
297  *wcstr = NULL;
298  }
299  return tmp;
300 }
struct MSVCRT_localeinfo_struct * MSVCRT__locale_t
#define WideCharToMultiByte
Definition: compat.h:101
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLuint GLsizei count
Definition: gl.h:1545
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
Definition: _locale.h:75
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define get_locinfo()
Definition: winesup.h:25
GLsizeiptr size
Definition: glext.h:5919
#define WC_NO_BEST_FIT_CHARS
Definition: unicode.h:46
else locinfo
Definition: scanf.h:159

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 }
WINE_UNICODE_INLINE int isspaceW(WCHAR wc)
Definition: unicode.h:165
GLuint GLuint end
Definition: gl.h:1545
float pow(float __x, int __y)
Definition: _cmath.h:458
#define debugstr_w
Definition: kernel32.h:32
const WCHAR * str
#define TRACE(s)
Definition: solgame.cpp:4
int ret
GLuint divisor
Definition: glext.h:6313
WINE_UNICODE_INLINE int isdigitW(WCHAR wc)
Definition: unicode.h:170

◆ wcstombs()

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

Definition at line 313 of file wcs.c.

314 {
315  return wcsrtombs_l(mbstr, &wcstr, count, NULL);
316 }
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:260
smooth NULL
Definition: ftsmooth.c:416

◆ 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  size = WideCharToMultiByte(get_locinfo()->lc_codepage, 0, &ch, 1, dst, dst ? 6 : 0, NULL, &error);
250  if(!size || error) {
251  *_errno() = EINVAL;
252  return EOF;
253  }
254  return size;
255 }
#define WideCharToMultiByte
Definition: compat.h:101
#define error(str)
Definition: mkdosfs.c:1605
Definition: arc.h:39
int32_t INT
Definition: typedefs.h:56
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define get_locinfo()
Definition: winesup.h:25
GLsizeiptr size
Definition: glext.h:5919
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
GLenum GLenum dst
Definition: glext.h:6340
#define EOF
Definition: stdio.h:24