Release 1.7.27.
[wine.git] / dlls / msvcrt / string.c
blobbe65675af7d28d687f85d413658f6d7119fdbcca
1 /*
2 * MSVCRT string functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define _ISOC99_SOURCE
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <math.h>
31 #include <limits.h>
32 #include <errno.h>
33 #include "msvcrt.h"
34 #include "winnls.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
39 /*********************************************************************
40 * _mbsdup (MSVCRT.@)
41 * _strdup (MSVCRT.@)
43 char* CDECL MSVCRT__strdup(const char* str)
45 if(str)
47 char * ret = MSVCRT_malloc(strlen(str)+1);
48 if (ret) strcpy( ret, str );
49 return ret;
51 else return 0;
54 /*********************************************************************
55 * _strlwr_s_l (MSVCRT.@)
57 int CDECL MSVCRT__strlwr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
59 char *ptr = str;
61 if (!str || !len)
63 *MSVCRT__errno() = MSVCRT_EINVAL;
64 return MSVCRT_EINVAL;
67 while (len && *ptr)
69 len--;
70 ptr++;
73 if (!len)
75 str[0] = '\0';
76 *MSVCRT__errno() = MSVCRT_EINVAL;
77 return MSVCRT_EINVAL;
80 while (*str)
82 *str = MSVCRT__tolower_l((unsigned char)*str, locale);
83 str++;
86 return 0;
89 /*********************************************************************
90 * _strlwr_s (MSVCRT.@)
92 int CDECL MSVCRT__strlwr_s(char *str, MSVCRT_size_t len)
94 return MSVCRT__strlwr_s_l(str, len, NULL);
97 /*********************************************************************
98 * _strlwr_l (MSVCRT.@)
100 char* CDECL _strlwr_l(char *str, MSVCRT__locale_t locale)
102 MSVCRT__strlwr_s_l(str, -1, locale);
103 return str;
106 /*********************************************************************
107 * _strlwr (MSVCRT.@)
109 char* CDECL MSVCRT__strlwr(char *str)
111 MSVCRT__strlwr_s_l(str, -1, NULL);
112 return str;
115 /*********************************************************************
116 * _strupr_s_l (MSVCRT.@)
118 int CDECL MSVCRT__strupr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
120 char *ptr = str;
122 if (!str || !len)
124 *MSVCRT__errno() = MSVCRT_EINVAL;
125 return MSVCRT_EINVAL;
128 while (len && *ptr)
130 len--;
131 ptr++;
134 if (!len)
136 str[0] = '\0';
137 *MSVCRT__errno() = MSVCRT_EINVAL;
138 return MSVCRT_EINVAL;
141 while (*str)
143 *str = MSVCRT__toupper_l((unsigned char)*str, locale);
144 str++;
147 return 0;
150 /*********************************************************************
151 * _strupr_s (MSVCRT.@)
153 int CDECL MSVCRT__strupr_s(char *str, MSVCRT_size_t len)
155 return MSVCRT__strupr_s_l(str, len, NULL);
158 /*********************************************************************
159 * _strupr_l (MSVCRT.@)
161 char* CDECL MSVCRT__strupr_l(char *str, MSVCRT__locale_t locale)
163 MSVCRT__strupr_s_l(str, -1, locale);
164 return str;
167 /*********************************************************************
168 * _strupr (MSVCRT.@)
170 char* CDECL MSVCRT__strupr(char *str)
172 MSVCRT__strupr_s_l(str, -1, NULL);
173 return str;
176 /*********************************************************************
177 * _strnset_s (MSVCRT.@)
179 int CDECL MSVCRT__strnset_s(char *str, MSVCRT_size_t size, int c, MSVCRT_size_t count)
181 MSVCRT_size_t i;
183 if(!str && !size && !count) return 0;
184 if(!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
185 if(!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
187 for(i=0; i<size-1 && i<count; i++) {
188 if(!str[i]) return 0;
189 str[i] = c;
191 for(; i<size; i++)
192 if(!str[i]) return 0;
194 str[0] = 0;
195 MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
196 *MSVCRT__errno() = MSVCRT_EINVAL;
197 return MSVCRT_EINVAL;
200 /*********************************************************************
201 * _strnset (MSVCRT.@)
203 char* CDECL MSVCRT__strnset(char* str, int value, MSVCRT_size_t len)
205 if (len > 0 && str)
206 while (*str && len--)
207 *str++ = value;
208 return str;
211 /*********************************************************************
212 * _strrev (MSVCRT.@)
214 char* CDECL MSVCRT__strrev(char* str)
216 char * p1;
217 char * p2;
219 if (str && *str)
220 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
222 *p1 ^= *p2;
223 *p2 ^= *p1;
224 *p1 ^= *p2;
227 return str;
230 /*********************************************************************
231 * _strset (MSVCRT.@)
233 char* CDECL _strset(char* str, int value)
235 char *ptr = str;
236 while (*ptr)
237 *ptr++ = value;
239 return str;
242 /*********************************************************************
243 * strtok (MSVCRT.@)
245 char * CDECL MSVCRT_strtok( char *str, const char *delim )
247 thread_data_t *data = msvcrt_get_thread_data();
248 char *ret;
250 if (!str)
251 if (!(str = data->strtok_next)) return NULL;
253 while (*str && strchr( delim, *str )) str++;
254 if (!*str) return NULL;
255 ret = str++;
256 while (*str && !strchr( delim, *str )) str++;
257 if (*str) *str++ = 0;
258 data->strtok_next = str;
259 return ret;
262 /*********************************************************************
263 * strtok_s (MSVCRT.@)
265 char * CDECL MSVCRT_strtok_s(char *str, const char *delim, char **ctx)
267 if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL;
268 if (!MSVCRT_CHECK_PMT(ctx != NULL)) return NULL;
269 if (!MSVCRT_CHECK_PMT(str != NULL || *ctx != NULL)) return NULL;
271 if(!str)
272 str = *ctx;
274 while(*str && strchr(delim, *str))
275 str++;
276 if(!*str)
277 return NULL;
279 *ctx = str+1;
280 while(**ctx && !strchr(delim, **ctx))
281 (*ctx)++;
282 if(**ctx)
283 *(*ctx)++ = 0;
285 return str;
288 /*********************************************************************
289 * _swab (MSVCRT.@)
291 void CDECL MSVCRT__swab(char* src, char* dst, int len)
293 if (len > 1)
295 len = (unsigned)len >> 1;
297 while (len--) {
298 char s0 = src[0];
299 char s1 = src[1];
300 *dst++ = s1;
301 *dst++ = s0;
302 src = src + 2;
307 static double strtod_helper(const char *str, char **end, MSVCRT__locale_t locale, int *err)
309 MSVCRT_pthreadlocinfo locinfo;
310 unsigned __int64 d=0, hlp;
311 unsigned fpcontrol;
312 int exp=0, sign=1;
313 const char *p;
314 double ret;
315 long double lret=1, expcnt = 10;
316 BOOL found_digit = FALSE, negexp;
318 if(err)
319 *err = 0;
320 else
321 if(!MSVCRT_CHECK_PMT(str != NULL)) return 0;
323 if(!locale)
324 locinfo = get_locinfo();
325 else
326 locinfo = locale->locinfo;
328 /* FIXME: use *_l functions */
329 p = str;
330 while(isspace(*p))
331 p++;
333 if(*p == '-') {
334 sign = -1;
335 p++;
336 } else if(*p == '+')
337 p++;
339 while(isdigit(*p)) {
340 found_digit = TRUE;
341 hlp = d*10+*(p++)-'0';
342 if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
343 exp++;
344 break;
345 } else
346 d = hlp;
348 while(isdigit(*p)) {
349 exp++;
350 p++;
353 if(*p == *locinfo->lconv->decimal_point)
354 p++;
356 while(isdigit(*p)) {
357 found_digit = TRUE;
358 hlp = d*10+*(p++)-'0';
359 if(d>MSVCRT_UI64_MAX/10 || hlp<d)
360 break;
362 d = hlp;
363 exp--;
365 while(isdigit(*p))
366 p++;
368 if(!found_digit) {
369 if(end)
370 *end = (char*)str;
371 return 0.0;
374 if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
375 int e=0, s=1;
377 p++;
378 if(*p == '-') {
379 s = -1;
380 p++;
381 } else if(*p == '+')
382 p++;
384 if(isdigit(*p)) {
385 while(isdigit(*p)) {
386 if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
387 e = INT_MAX;
388 p++;
390 e *= s;
392 if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
393 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
394 else exp += e;
395 } else {
396 if(*p=='-' || *p=='+')
397 p--;
398 p--;
402 fpcontrol = _control87(0, 0);
403 _control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
404 |MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
406 negexp = (exp < 0);
407 if(negexp)
408 exp = -exp;
409 while(exp) {
410 if(exp & 1)
411 lret *= expcnt;
412 exp /= 2;
413 expcnt = expcnt*expcnt;
415 ret = (long double)sign * (negexp ? d/lret : d*lret);
417 _control87(fpcontrol, 0xffffffff);
419 if((d && ret==0.0) || isinf(ret)) {
420 if(err)
421 *err = MSVCRT_ERANGE;
422 else
423 *MSVCRT__errno() = MSVCRT_ERANGE;
426 if(end)
427 *end = (char*)p;
429 return ret;
432 /*********************************************************************
433 * strtod_l (MSVCRT.@)
435 double CDECL MSVCRT_strtod_l(const char *str, char **end, MSVCRT__locale_t locale)
437 return strtod_helper(str, end, locale, NULL);
440 /*********************************************************************
441 * strtod (MSVCRT.@)
443 double CDECL MSVCRT_strtod( const char *str, char **end )
445 return MSVCRT_strtod_l( str, end, NULL );
448 /*********************************************************************
449 * atof (MSVCRT.@)
451 double CDECL MSVCRT_atof( const char *str )
453 return MSVCRT_strtod_l(str, NULL, NULL);
456 /*********************************************************************
457 * _atof_l (MSVCRT.@)
459 double CDECL MSVCRT__atof_l( const char *str, MSVCRT__locale_t locale)
461 return MSVCRT_strtod_l(str, NULL, locale);
464 /*********************************************************************
465 * _atoflt_l (MSVCRT.@)
467 int CDECL MSVCRT__atoflt_l( MSVCRT__CRT_FLOAT *value, char *str, MSVCRT__locale_t locale)
469 double d;
470 int err;
472 d = strtod_helper(str, NULL, locale, &err);
473 value->f = d;
474 if(isinf(value->f))
475 return MSVCRT__OVERFLOW;
476 if((d!=0 || err) && value->f>-MSVCRT_FLT_MIN && value->f<MSVCRT_FLT_MIN)
477 return MSVCRT__UNDERFLOW;
478 return 0;
481 /*********************************************************************
482 * _atoflt (MSVCR100.@)
484 int CDECL MSVCRT__atoflt(MSVCRT__CRT_FLOAT *value, char *str)
486 return MSVCRT__atoflt_l(value, str, NULL);
489 /*********************************************************************
490 * _atodbl_l (MSVCRT.@)
492 int CDECL MSVCRT__atodbl_l(MSVCRT__CRT_DOUBLE *value, char *str, MSVCRT__locale_t locale)
494 int err;
496 value->x = strtod_helper(str, NULL, locale, &err);
497 if(isinf(value->x))
498 return MSVCRT__OVERFLOW;
499 if((value->x!=0 || err) && value->x>-MSVCRT_DBL_MIN && value->x<MSVCRT_DBL_MIN)
500 return MSVCRT__UNDERFLOW;
501 return 0;
504 /*********************************************************************
505 * _atodbl (MSVCRT.@)
507 int CDECL MSVCRT__atodbl(MSVCRT__CRT_DOUBLE *value, char *str)
509 return MSVCRT__atodbl_l(value, str, NULL);
512 /*********************************************************************
513 * _strcoll_l (MSVCRT.@)
515 int CDECL MSVCRT_strcoll_l( const char* str1, const char* str2, MSVCRT__locale_t locale )
517 MSVCRT_pthreadlocinfo locinfo;
519 if(!locale)
520 locinfo = get_locinfo();
521 else
522 locinfo = locale->locinfo;
524 if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
525 return strcmp(str1, str2);
526 return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, -1, str2, -1)-CSTR_EQUAL;
529 /*********************************************************************
530 * strcoll (MSVCRT.@)
532 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
534 return MSVCRT_strcoll_l(str1, str2, NULL);
537 /*********************************************************************
538 * _stricoll_l (MSVCRT.@)
540 int CDECL MSVCRT__stricoll_l( const char* str1, const char* str2, MSVCRT__locale_t locale )
542 MSVCRT_pthreadlocinfo locinfo;
544 if(!locale)
545 locinfo = get_locinfo();
546 else
547 locinfo = locale->locinfo;
549 if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
550 return strcasecmp(str1, str2);
551 return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE,
552 str1, -1, str2, -1)-CSTR_EQUAL;
555 /*********************************************************************
556 * _stricoll (MSVCRT.@)
558 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
560 return MSVCRT__stricoll_l(str1, str2, NULL);
563 /*********************************************************************
564 * _strncoll_l (MSVCRT.@)
566 int CDECL MSVCRT__strncoll_l( const char* str1, const char* str2, MSVCRT_size_t count, MSVCRT__locale_t locale )
568 MSVCRT_pthreadlocinfo locinfo;
570 if(!locale)
571 locinfo = get_locinfo();
572 else
573 locinfo = locale->locinfo;
575 if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
576 return strncmp(str1, str2, count);
577 return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, count, str2, count)-CSTR_EQUAL;
580 /*********************************************************************
581 * _strncoll (MSVCRT.@)
583 int CDECL MSVCRT__strncoll( const char* str1, const char* str2, MSVCRT_size_t count )
585 return MSVCRT__strncoll_l(str1, str2, count, NULL);
588 /*********************************************************************
589 * _strnicoll_l (MSVCRT.@)
591 int CDECL MSVCRT__strnicoll_l( const char* str1, const char* str2, MSVCRT_size_t count, MSVCRT__locale_t locale )
593 MSVCRT_pthreadlocinfo locinfo;
595 if(!locale)
596 locinfo = get_locinfo();
597 else
598 locinfo = locale->locinfo;
600 if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
601 return strncasecmp(str1, str2, count);
602 return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE,
603 str1, count, str2, count)-CSTR_EQUAL;
606 /*********************************************************************
607 * _strnicoll (MSVCRT.@)
609 int CDECL MSVCRT__strnicoll( const char* str1, const char* str2, MSVCRT_size_t count )
611 return MSVCRT__strnicoll_l(str1, str2, count, NULL);
614 /*********************************************************************
615 * strncpy (MSVCRT.@)
617 char* __cdecl MSVCRT_strncpy(char *dst, const char *src, MSVCRT_size_t len)
619 MSVCRT_size_t i;
621 for(i=0; i<len; i++)
622 if((dst[i] = src[i]) == '\0') break;
624 while (i < len) dst[i++] = 0;
626 return dst;
629 /*********************************************************************
630 * strcpy_s (MSVCRT.@)
632 int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
634 MSVCRT_size_t i;
635 if(!elem) return MSVCRT_EINVAL;
636 if(!dst) return MSVCRT_EINVAL;
637 if(!src)
639 dst[0] = '\0';
640 return MSVCRT_EINVAL;
643 for(i = 0; i < elem; i++)
645 if((dst[i] = src[i]) == '\0') return 0;
647 dst[0] = '\0';
648 return MSVCRT_ERANGE;
651 /*********************************************************************
652 * strcat_s (MSVCRT.@)
654 int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
656 MSVCRT_size_t i, j;
657 if(!dst) return MSVCRT_EINVAL;
658 if(elem == 0) return MSVCRT_EINVAL;
659 if(!src)
661 dst[0] = '\0';
662 return MSVCRT_EINVAL;
665 for(i = 0; i < elem; i++)
667 if(dst[i] == '\0')
669 for(j = 0; (j + i) < elem; j++)
671 if((dst[j + i] = src[j]) == '\0') return 0;
675 /* Set the first element to 0, not the first element after the skipped part */
676 dst[0] = '\0';
677 return MSVCRT_ERANGE;
680 /*********************************************************************
681 * strncat_s (MSVCRT.@)
683 int CDECL MSVCRT_strncat_s( char* dst, MSVCRT_size_t elem, const char* src, MSVCRT_size_t count )
685 MSVCRT_size_t i, j;
687 if (!MSVCRT_CHECK_PMT(dst != 0)) return MSVCRT_EINVAL;
688 if (!MSVCRT_CHECK_PMT(elem != 0)) return MSVCRT_EINVAL;
689 if (!MSVCRT_CHECK_PMT(src != 0))
691 dst[0] = '\0';
692 return MSVCRT_EINVAL;
695 for(i = 0; i < elem; i++)
697 if(dst[i] == '\0')
699 for(j = 0; (j + i) < elem; j++)
701 if(count == MSVCRT__TRUNCATE && j + i == elem - 1)
703 dst[j + i] = '\0';
704 return MSVCRT_STRUNCATE;
706 if(j == count || (dst[j + i] = src[j]) == '\0')
708 dst[j + i] = '\0';
709 return 0;
714 /* Set the first element to 0, not the first element after the skipped part */
715 dst[0] = '\0';
716 return MSVCRT_ERANGE;
719 /*********************************************************************
720 * strncat (MSVCRT.@)
722 char* __cdecl MSVCRT_strncat(char *dst, const char *src, MSVCRT_size_t len)
724 return strncat(dst, src, len);
727 /*********************************************************************
728 * _strxfrm_l (MSVCRT.@)
730 MSVCRT_size_t CDECL MSVCRT__strxfrm_l( char *dest, const char *src,
731 MSVCRT_size_t len, MSVCRT__locale_t locale )
733 MSVCRT_pthreadlocinfo locinfo;
734 int ret;
736 if(!MSVCRT_CHECK_PMT(src)) return INT_MAX;
737 if(!MSVCRT_CHECK_PMT(dest || !len)) return INT_MAX;
739 if(len > INT_MAX) {
740 FIXME("len > INT_MAX not supported\n");
741 len = INT_MAX;
744 if(!locale)
745 locinfo = get_locinfo();
746 else
747 locinfo = locale->locinfo;
749 if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) {
750 MSVCRT_strncpy(dest, src, len);
751 return strlen(src);
754 ret = LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
755 LCMAP_SORTKEY, src, -1, NULL, 0);
756 if(!ret) {
757 if(len) dest[0] = 0;
758 *MSVCRT__errno() = MSVCRT_EILSEQ;
759 return INT_MAX;
761 if(!len) return ret-1;
763 if(ret > len) {
764 dest[0] = 0;
765 *MSVCRT__errno() = MSVCRT_ERANGE;
766 return ret-1;
769 return LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
770 LCMAP_SORTKEY, src, -1, dest, len) - 1;
773 /*********************************************************************
774 * strxfrm (MSVCRT.@)
776 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
778 return MSVCRT__strxfrm_l(dest, src, len, NULL);
781 /********************************************************************
782 * _atoldbl (MSVCRT.@)
784 int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
786 /* FIXME needs error checking for huge/small values */
787 #ifdef HAVE_STRTOLD
788 long double ld;
789 TRACE("str %s value %p\n",str,value);
790 ld = strtold(str,0);
791 memcpy(value, &ld, 10);
792 #else
793 FIXME("stub, str %s value %p\n",str,value);
794 #endif
795 return 0;
798 /********************************************************************
799 * __STRINGTOLD (MSVCRT.@)
801 int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
803 #ifdef HAVE_STRTOLD
804 long double ld;
805 FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
806 ld = strtold(str,0);
807 memcpy(value, &ld, 10);
808 #else
809 FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
810 #endif
811 return 0;
814 /*********************************************************************
815 * strlen (MSVCRT.@)
817 MSVCRT_size_t __cdecl MSVCRT_strlen(const char *str)
819 return strlen(str);
822 /******************************************************************
823 * strnlen (MSVCRT.@)
825 MSVCRT_size_t CDECL MSVCRT_strnlen(const char *s, MSVCRT_size_t maxlen)
827 MSVCRT_size_t i;
829 for(i=0; i<maxlen; i++)
830 if(!s[i]) break;
832 return i;
835 /*********************************************************************
836 * _strtoi64_l (MSVCRT.@)
838 * FIXME: locale parameter is ignored
840 __int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
842 BOOL negative = FALSE;
843 __int64 ret = 0;
845 TRACE("(%s %p %d %p)\n", debugstr_a(nptr), endptr, base, locale);
847 if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
848 if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
849 if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
851 while(isspace(*nptr)) nptr++;
853 if(*nptr == '-') {
854 negative = TRUE;
855 nptr++;
856 } else if(*nptr == '+')
857 nptr++;
859 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
860 base = 16;
861 nptr += 2;
864 if(base == 0) {
865 if(*nptr=='0')
866 base = 8;
867 else
868 base = 10;
871 while(*nptr) {
872 char cur = tolower(*nptr);
873 int v;
875 if(isdigit(cur)) {
876 if(cur >= '0'+base)
877 break;
878 v = cur-'0';
879 } else {
880 if(cur<'a' || cur>='a'+base-10)
881 break;
882 v = cur-'a'+10;
885 if(negative)
886 v = -v;
888 nptr++;
890 if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
891 ret = MSVCRT_I64_MAX;
892 *MSVCRT__errno() = MSVCRT_ERANGE;
893 } else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
894 ret = MSVCRT_I64_MIN;
895 *MSVCRT__errno() = MSVCRT_ERANGE;
896 } else
897 ret = ret*base + v;
900 if(endptr)
901 *endptr = (char*)nptr;
903 return ret;
906 /*********************************************************************
907 * _strtoi64 (MSVCRT.@)
909 __int64 CDECL MSVCRT_strtoi64(const char *nptr, char **endptr, int base)
911 return MSVCRT_strtoi64_l(nptr, endptr, base, NULL);
914 /*********************************************************************
915 * _atoi_l (MSVCRT.@)
917 int __cdecl MSVCRT__atoi_l(const char *str, MSVCRT__locale_t locale)
919 __int64 ret = MSVCRT_strtoi64_l(str, NULL, 10, locale);
921 if(ret > INT_MAX) {
922 ret = INT_MAX;
923 *MSVCRT__errno() = MSVCRT_ERANGE;
924 } else if(ret < INT_MIN) {
925 ret = INT_MIN;
926 *MSVCRT__errno() = MSVCRT_ERANGE;
928 return ret;
931 /*********************************************************************
932 * atoi (MSVCRT.@)
934 #if _MSVCR_VER == 0
935 int __cdecl MSVCRT_atoi(const char *str)
937 BOOL minus = FALSE;
938 int ret = 0;
940 if(!str)
941 return 0;
943 while(isspace(*str)) str++;
945 if(*str == '+') {
946 str++;
947 }else if(*str == '-') {
948 minus = TRUE;
949 str++;
952 while(*str>='0' && *str<='9') {
953 ret = ret*10+*str-'0';
954 str++;
957 return minus ? -ret : ret;
959 #else
960 int CDECL MSVCRT_atoi(const char *str)
962 return MSVCRT__atoi_l(str, NULL);
964 #endif
966 /******************************************************************
967 * strtol (MSVCRT.@)
969 MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
971 __int64 ret = MSVCRT_strtoi64_l(nptr, end, base, NULL);
973 if(ret > MSVCRT_LONG_MAX) {
974 ret = MSVCRT_LONG_MAX;
975 *MSVCRT__errno() = MSVCRT_ERANGE;
976 } else if(ret < MSVCRT_LONG_MIN) {
977 ret = MSVCRT_LONG_MIN;
978 *MSVCRT__errno() = MSVCRT_ERANGE;
981 return ret;
984 /******************************************************************
985 * strtoul (MSVCRT.@)
987 MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
989 __int64 ret = MSVCRT_strtoi64_l(nptr, end, base, NULL);
991 if(ret > MSVCRT_ULONG_MAX) {
992 ret = MSVCRT_ULONG_MAX;
993 *MSVCRT__errno() = MSVCRT_ERANGE;
994 }else if(ret < -(__int64)MSVCRT_ULONG_MAX) {
995 ret = 1;
996 *MSVCRT__errno() = MSVCRT_ERANGE;
999 return ret;
1002 /*********************************************************************
1003 * _strtoui64_l (MSVCRT.@)
1005 * FIXME: locale parameter is ignored
1007 unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
1009 BOOL negative = FALSE;
1010 unsigned __int64 ret = 0;
1012 TRACE("(%s %p %d %p)\n", debugstr_a(nptr), endptr, base, locale);
1014 if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
1015 if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
1016 if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
1018 while(isspace(*nptr)) nptr++;
1020 if(*nptr == '-') {
1021 negative = TRUE;
1022 nptr++;
1023 } else if(*nptr == '+')
1024 nptr++;
1026 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
1027 base = 16;
1028 nptr += 2;
1031 if(base == 0) {
1032 if(*nptr=='0')
1033 base = 8;
1034 else
1035 base = 10;
1038 while(*nptr) {
1039 char cur = tolower(*nptr);
1040 int v;
1042 if(isdigit(cur)) {
1043 if(cur >= '0'+base)
1044 break;
1045 v = *nptr-'0';
1046 } else {
1047 if(cur<'a' || cur>='a'+base-10)
1048 break;
1049 v = cur-'a'+10;
1052 nptr++;
1054 if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
1055 ret = MSVCRT_UI64_MAX;
1056 *MSVCRT__errno() = MSVCRT_ERANGE;
1057 } else
1058 ret = ret*base + v;
1061 if(endptr)
1062 *endptr = (char*)nptr;
1064 return negative ? -ret : ret;
1067 /*********************************************************************
1068 * _strtoui64 (MSVCRT.@)
1070 unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int base)
1072 return MSVCRT_strtoui64_l(nptr, endptr, base, NULL);
1075 static int ltoa_helper(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
1077 MSVCRT_ulong val;
1078 unsigned int digit;
1079 BOOL is_negative;
1080 char buffer[33], *pos;
1081 size_t len;
1083 if (value < 0 && radix == 10)
1085 is_negative = TRUE;
1086 val = -value;
1088 else
1090 is_negative = FALSE;
1091 val = value;
1094 pos = buffer + 32;
1095 *pos = '\0';
1099 digit = val % radix;
1100 val /= radix;
1102 if (digit < 10)
1103 *--pos = '0' + digit;
1104 else
1105 *--pos = 'a' + digit - 10;
1107 while (val != 0);
1109 if (is_negative)
1110 *--pos = '-';
1112 len = buffer + 33 - pos;
1113 if (len > size)
1115 size_t i;
1116 char *p = str;
1118 /* Copy the temporary buffer backwards up to the available number of
1119 * characters. Don't copy the negative sign if present. */
1121 if (is_negative)
1123 p++;
1124 size--;
1127 for (pos = buffer + 31, i = 0; i < size; i++)
1128 *p++ = *pos--;
1130 str[0] = '\0';
1131 MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
1132 return MSVCRT_ERANGE;
1135 memcpy(str, pos, len);
1136 return 0;
1139 /*********************************************************************
1140 * _ltoa_s (MSVCRT.@)
1142 int CDECL MSVCRT__ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
1144 if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
1145 if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
1146 if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
1148 str[0] = '\0';
1149 return MSVCRT_EINVAL;
1152 return ltoa_helper(value, str, size, radix);
1155 /*********************************************************************
1156 * _ltow_s (MSVCRT.@)
1158 int CDECL MSVCRT__ltow_s(MSVCRT_long value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1160 MSVCRT_ulong val;
1161 unsigned int digit;
1162 BOOL is_negative;
1163 MSVCRT_wchar_t buffer[33], *pos;
1164 size_t len;
1166 if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
1167 if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
1168 if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
1170 str[0] = '\0';
1171 return MSVCRT_EINVAL;
1174 if (value < 0 && radix == 10)
1176 is_negative = TRUE;
1177 val = -value;
1179 else
1181 is_negative = FALSE;
1182 val = value;
1185 pos = buffer + 32;
1186 *pos = '\0';
1190 digit = val % radix;
1191 val /= radix;
1193 if (digit < 10)
1194 *--pos = '0' + digit;
1195 else
1196 *--pos = 'a' + digit - 10;
1198 while (val != 0);
1200 if (is_negative)
1201 *--pos = '-';
1203 len = buffer + 33 - pos;
1204 if (len > size)
1206 size_t i;
1207 MSVCRT_wchar_t *p = str;
1209 /* Copy the temporary buffer backwards up to the available number of
1210 * characters. Don't copy the negative sign if present. */
1212 if (is_negative)
1214 p++;
1215 size--;
1218 for (pos = buffer + 31, i = 0; i < size; i++)
1219 *p++ = *pos--;
1221 str[0] = '\0';
1222 MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
1223 return MSVCRT_ERANGE;
1226 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
1227 return 0;
1230 /*********************************************************************
1231 * _itoa_s (MSVCRT.@)
1233 int CDECL MSVCRT__itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
1235 return MSVCRT__ltoa_s(value, str, size, radix);
1238 /*********************************************************************
1239 * _itoa (MSVCRT.@)
1241 char* CDECL MSVCRT__itoa(int value, char *str, int radix)
1243 return ltoa_helper(value, str, MSVCRT_SIZE_MAX, radix) ? NULL : str;
1246 /*********************************************************************
1247 * _itow_s (MSVCRT.@)
1249 int CDECL MSVCRT__itow_s(int value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1251 return MSVCRT__ltow_s(value, str, size, radix);
1254 /*********************************************************************
1255 * _ui64toa_s (MSVCRT.@)
1257 int CDECL MSVCRT__ui64toa_s(unsigned __int64 value, char *str,
1258 MSVCRT_size_t size, int radix)
1260 char buffer[65], *pos;
1261 int digit;
1263 if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
1264 if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
1265 if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
1267 str[0] = '\0';
1268 return MSVCRT_EINVAL;
1271 pos = buffer+64;
1272 *pos = '\0';
1274 do {
1275 digit = value%radix;
1276 value /= radix;
1278 if(digit < 10)
1279 *--pos = '0'+digit;
1280 else
1281 *--pos = 'a'+digit-10;
1282 }while(value != 0);
1284 if(buffer-pos+65 > size) {
1285 MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_EINVAL);
1286 return MSVCRT_EINVAL;
1289 memcpy(str, pos, buffer-pos+65);
1290 return 0;
1293 /*********************************************************************
1294 * _ui64tow_s (MSVCRT.@)
1296 int CDECL MSVCRT__ui64tow_s( unsigned __int64 value, MSVCRT_wchar_t *str,
1297 MSVCRT_size_t size, int radix )
1299 MSVCRT_wchar_t buffer[65], *pos;
1300 int digit;
1302 if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
1303 if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
1304 if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
1306 str[0] = '\0';
1307 return MSVCRT_EINVAL;
1310 pos = &buffer[64];
1311 *pos = '\0';
1313 do {
1314 digit = value % radix;
1315 value = value / radix;
1316 if (digit < 10)
1317 *--pos = '0' + digit;
1318 else
1319 *--pos = 'a' + digit - 10;
1320 } while (value != 0);
1322 if(buffer-pos+65 > size) {
1323 MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_EINVAL);
1324 return MSVCRT_EINVAL;
1327 memcpy(str, pos, (buffer-pos+65)*sizeof(MSVCRT_wchar_t));
1328 return 0;
1331 /*********************************************************************
1332 * _ultoa_s (MSVCRT.@)
1334 int CDECL MSVCRT__ultoa_s(MSVCRT_ulong value, char *str, MSVCRT_size_t size, int radix)
1336 MSVCRT_ulong digit;
1337 char buffer[33], *pos;
1338 size_t len;
1340 if (!str || !size || radix < 2 || radix > 36)
1342 if (str && size)
1343 str[0] = '\0';
1345 *MSVCRT__errno() = MSVCRT_EINVAL;
1346 return MSVCRT_EINVAL;
1349 pos = buffer + 32;
1350 *pos = '\0';
1354 digit = value % radix;
1355 value /= radix;
1357 if (digit < 10)
1358 *--pos = '0' + digit;
1359 else
1360 *--pos = 'a' + digit - 10;
1362 while (value != 0);
1364 len = buffer + 33 - pos;
1365 if (len > size)
1367 size_t i;
1368 char *p = str;
1370 /* Copy the temporary buffer backwards up to the available number of
1371 * characters. */
1373 for (pos = buffer + 31, i = 0; i < size; i++)
1374 *p++ = *pos--;
1376 str[0] = '\0';
1377 *MSVCRT__errno() = MSVCRT_ERANGE;
1378 return MSVCRT_ERANGE;
1381 memcpy(str, pos, len);
1382 return 0;
1385 /*********************************************************************
1386 * _ultow_s (MSVCRT.@)
1388 int CDECL MSVCRT__ultow_s(MSVCRT_ulong value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1390 MSVCRT_ulong digit;
1391 WCHAR buffer[33], *pos;
1392 size_t len;
1394 if (!str || !size || radix < 2 || radix > 36)
1396 if (str && size)
1397 str[0] = '\0';
1399 *MSVCRT__errno() = MSVCRT_EINVAL;
1400 return MSVCRT_EINVAL;
1403 pos = buffer + 32;
1404 *pos = '\0';
1408 digit = value % radix;
1409 value /= radix;
1411 if (digit < 10)
1412 *--pos = '0' + digit;
1413 else
1414 *--pos = 'a' + digit - 10;
1416 while (value != 0);
1418 len = buffer + 33 - pos;
1419 if (len > size)
1421 size_t i;
1422 WCHAR *p = str;
1424 /* Copy the temporary buffer backwards up to the available number of
1425 * characters. */
1427 for (pos = buffer + 31, i = 0; i < size; i++)
1428 *p++ = *pos--;
1430 str[0] = '\0';
1431 *MSVCRT__errno() = MSVCRT_ERANGE;
1432 return MSVCRT_ERANGE;
1435 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
1436 return 0;
1439 /*********************************************************************
1440 * _i64toa_s (MSVCRT.@)
1442 int CDECL MSVCRT__i64toa_s(__int64 value, char *str, MSVCRT_size_t size, int radix)
1444 unsigned __int64 val;
1445 unsigned int digit;
1446 BOOL is_negative;
1447 char buffer[65], *pos;
1448 size_t len;
1450 if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
1451 if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
1452 if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
1454 str[0] = '\0';
1455 return MSVCRT_EINVAL;
1458 if (value < 0 && radix == 10)
1460 is_negative = TRUE;
1461 val = -value;
1463 else
1465 is_negative = FALSE;
1466 val = value;
1469 pos = buffer + 64;
1470 *pos = '\0';
1474 digit = val % radix;
1475 val /= radix;
1477 if (digit < 10)
1478 *--pos = '0' + digit;
1479 else
1480 *--pos = 'a' + digit - 10;
1482 while (val != 0);
1484 if (is_negative)
1485 *--pos = '-';
1487 len = buffer + 65 - pos;
1488 if (len > size)
1490 size_t i;
1491 char *p = str;
1493 /* Copy the temporary buffer backwards up to the available number of
1494 * characters. Don't copy the negative sign if present. */
1496 if (is_negative)
1498 p++;
1499 size--;
1502 for (pos = buffer + 63, i = 0; i < size; i++)
1503 *p++ = *pos--;
1505 str[0] = '\0';
1506 MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
1507 return MSVCRT_ERANGE;
1510 memcpy(str, pos, len);
1511 return 0;
1514 /*********************************************************************
1515 * _i64tow_s (MSVCRT.@)
1517 int CDECL MSVCRT__i64tow_s(__int64 value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1519 unsigned __int64 val;
1520 unsigned int digit;
1521 BOOL is_negative;
1522 MSVCRT_wchar_t buffer[65], *pos;
1523 size_t len;
1525 if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
1526 if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
1527 if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
1529 str[0] = '\0';
1530 return MSVCRT_EINVAL;
1533 if (value < 0 && radix == 10)
1535 is_negative = TRUE;
1536 val = -value;
1538 else
1540 is_negative = FALSE;
1541 val = value;
1544 pos = buffer + 64;
1545 *pos = '\0';
1549 digit = val % radix;
1550 val /= radix;
1552 if (digit < 10)
1553 *--pos = '0' + digit;
1554 else
1555 *--pos = 'a' + digit - 10;
1557 while (val != 0);
1559 if (is_negative)
1560 *--pos = '-';
1562 len = buffer + 65 - pos;
1563 if (len > size)
1565 size_t i;
1566 MSVCRT_wchar_t *p = str;
1568 /* Copy the temporary buffer backwards up to the available number of
1569 * characters. Don't copy the negative sign if present. */
1571 if (is_negative)
1573 p++;
1574 size--;
1577 for (pos = buffer + 63, i = 0; i < size; i++)
1578 *p++ = *pos--;
1580 str[0] = '\0';
1581 MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
1582 return MSVCRT_ERANGE;
1585 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
1586 return 0;
1589 #define I10_OUTPUT_MAX_PREC 21
1590 /* Internal structure used by $I10_OUTPUT */
1591 struct _I10_OUTPUT_DATA {
1592 short pos;
1593 char sign;
1594 BYTE len;
1595 char str[I10_OUTPUT_MAX_PREC+1]; /* add space for '\0' */
1598 /*********************************************************************
1599 * $I10_OUTPUT (MSVCRT.@)
1600 * ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data
1601 * prec - precision of part, we're interested in
1602 * flag - 0 for first prec digits, 1 for fractional part
1603 * data - data to be populated
1605 * return value
1606 * 0 if given double is NaN or INF
1607 * 1 otherwise
1609 * FIXME
1610 * Native sets last byte of data->str to '0' or '9', I don't know what
1611 * it means. Current implementation sets it always to '0'.
1613 int CDECL MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
1615 static const char inf_str[] = "1#INF";
1616 static const char nan_str[] = "1#QNAN";
1618 /* MS' long double type wants 12 bytes for Intel's 80 bit FP format.
1619 * Some UNIX have sizeof(long double) == 16, yet only 80 bit are used.
1620 * Assume long double uses 80 bit FP, never seen 128 bit FP. */
1621 long double ld = 0;
1622 double d;
1623 char format[8];
1624 char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
1625 char *p;
1627 memcpy(&ld, &ld80, 10);
1628 d = ld;
1629 TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
1631 if(d<0) {
1632 data->sign = '-';
1633 d = -d;
1634 } else
1635 data->sign = ' ';
1637 if(isinf(d)) {
1638 data->pos = 1;
1639 data->len = 5;
1640 memcpy(data->str, inf_str, sizeof(inf_str));
1642 return 0;
1645 if(isnan(d)) {
1646 data->pos = 1;
1647 data->len = 6;
1648 memcpy(data->str, nan_str, sizeof(nan_str));
1650 return 0;
1653 if(flag&1) {
1654 int exp = 1+floor(log10(d));
1656 prec += exp;
1657 if(exp < 0)
1658 prec--;
1660 prec--;
1662 if(prec+1 > I10_OUTPUT_MAX_PREC)
1663 prec = I10_OUTPUT_MAX_PREC-1;
1664 else if(prec < 0) {
1665 d = 0.0;
1666 prec = 0;
1669 sprintf(format, "%%.%dle", prec);
1670 sprintf(buf, format, d);
1672 buf[1] = buf[0];
1673 data->pos = atoi(buf+prec+3);
1674 if(buf[1] != '0')
1675 data->pos++;
1677 for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
1678 data->len = p-buf;
1680 memcpy(data->str, buf+1, data->len);
1681 data->str[data->len] = '\0';
1683 if(buf[1]!='0' && prec-data->len+1>0)
1684 memcpy(data->str+data->len+1, buf+data->len+1, prec-data->len+1);
1686 return 1;
1688 #undef I10_OUTPUT_MAX_PREC
1690 /*********************************************************************
1691 * memcmp (MSVCRT.@)
1693 int __cdecl MSVCRT_memcmp(const void *ptr1, const void *ptr2, MSVCRT_size_t n)
1695 return memcmp(ptr1, ptr2, n);
1698 /*********************************************************************
1699 * memcpy (MSVCRT.@)
1701 void * __cdecl MSVCRT_memcpy(void *dst, const void *src, MSVCRT_size_t n)
1703 return memmove(dst, src, n);
1706 /*********************************************************************
1707 * memmove (MSVCRT.@)
1709 void * __cdecl MSVCRT_memmove(void *dst, const void *src, MSVCRT_size_t n)
1711 return memmove(dst, src, n);
1714 /*********************************************************************
1715 * memset (MSVCRT.@)
1717 void* __cdecl MSVCRT_memset(void *dst, int c, MSVCRT_size_t n)
1719 return memset(dst, c, n);
1722 /*********************************************************************
1723 * strchr (MSVCRT.@)
1725 char* __cdecl MSVCRT_strchr(const char *str, int c)
1727 return strchr(str, c);
1730 /*********************************************************************
1731 * strrchr (MSVCRT.@)
1733 char* __cdecl MSVCRT_strrchr(const char *str, int c)
1735 return strrchr(str, c);
1738 /*********************************************************************
1739 * memchr (MSVCRT.@)
1741 void* __cdecl MSVCRT_memchr(const void *ptr, int c, MSVCRT_size_t n)
1743 return memchr(ptr, c, n);
1746 /*********************************************************************
1747 * strcmp (MSVCRT.@)
1749 int __cdecl MSVCRT_strcmp(const char *str1, const char *str2)
1751 return strcmp(str1, str2);
1754 /*********************************************************************
1755 * strncmp (MSVCRT.@)
1757 int __cdecl MSVCRT_strncmp(const char *str1, const char *str2, MSVCRT_size_t len)
1759 return strncmp(str1, str2, len);
1762 /*********************************************************************
1763 * _strnicmp_l (MSVCRT.@)
1765 int __cdecl MSVCRT__strnicmp_l(const char *s1, const char *s2,
1766 MSVCRT_size_t count, MSVCRT__locale_t locale)
1768 MSVCRT_pthreadlocinfo locinfo;
1769 int c1, c2;
1771 if(s1==NULL || s2==NULL)
1772 return MSVCRT__NLSCMPERROR;
1774 if(!count)
1775 return 0;
1777 if(!locale)
1778 locinfo = get_locinfo();
1779 else
1780 locinfo = locale->locinfo;
1782 if(!locinfo->lc_handle[MSVCRT_LC_CTYPE])
1783 return strncasecmp(s1, s2, count);
1785 do {
1786 c1 = MSVCRT__tolower_l(*s1++, locale);
1787 c2 = MSVCRT__tolower_l(*s2++, locale);
1788 }while(--count && c1 && c1==c2);
1790 return c1-c2;
1793 /*********************************************************************
1794 * _stricmp_l (MSVCRT.@)
1796 int __cdecl MSVCRT__stricmp_l(const char *s1, const char *s2, MSVCRT__locale_t locale)
1798 return MSVCRT__strnicmp_l(s1, s2, -1, locale);
1801 /*********************************************************************
1802 * _strnicmp (MSVCRT.@)
1804 int __cdecl MSVCRT__strnicmp(const char *s1, const char *s2, MSVCRT_size_t count)
1806 return MSVCRT__strnicmp_l(s1, s2, count, NULL);
1809 /*********************************************************************
1810 * _stricmp (MSVCRT.@)
1812 int __cdecl MSVCRT__stricmp(const char *s1, const char *s2)
1814 return MSVCRT__strnicmp_l(s1, s2, -1, NULL);
1817 /*********************************************************************
1818 * strstr (MSVCRT.@)
1820 char* __cdecl MSVCRT_strstr(const char *haystack, const char *needle)
1822 return strstr(haystack, needle);