msvcrt: Test that some functions depends on locale codepage, not the one set by _setmbcp.
[wine] / dlls / msvcrt / string.c
1 /*
2  * MSVCRT string functions
3  *
4  * Copyright 1996,1998 Marcus Meissner
5  * Copyright 1996 Jukka Iivonen
6  * Copyright 1997,2000 Uwe Bonnes
7  * Copyright 2000 Jon Griffiths
8  *
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.
13  *
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.
18  *
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
22  */
23
24 #define _ISOC99_SOURCE
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include "msvcrt.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
32
33 /*********************************************************************
34  *              _mbsdup (MSVCRT.@)
35  *              _strdup (MSVCRT.@)
36  */
37 char* CDECL _strdup(const char* str)
38 {
39     if(str)
40     {
41       char * ret = MSVCRT_malloc(strlen(str)+1);
42       if (ret) strcpy( ret, str );
43       return ret;
44     }
45     else return 0;
46 }
47
48 /*********************************************************************
49  *              _strnset (MSVCRT.@)
50  */
51 char* CDECL _strnset(char* str, int value, MSVCRT_size_t len)
52 {
53   if (len > 0 && str)
54     while (*str && len--)
55       *str++ = value;
56   return str;
57 }
58
59 /*********************************************************************
60  *              _strrev (MSVCRT.@)
61  */
62 char* CDECL _strrev(char* str)
63 {
64   char * p1;
65   char * p2;
66
67   if (str && *str)
68     for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
69     {
70       *p1 ^= *p2;
71       *p2 ^= *p1;
72       *p1 ^= *p2;
73     }
74
75   return str;
76 }
77
78 /*********************************************************************
79  *              _strset (MSVCRT.@)
80  */
81 char* CDECL _strset(char* str, int value)
82 {
83   char *ptr = str;
84   while (*ptr)
85     *ptr++ = value;
86
87   return str;
88 }
89
90 /*********************************************************************
91  *              strtok  (MSVCRT.@)
92  */
93 char * CDECL MSVCRT_strtok( char *str, const char *delim )
94 {
95     thread_data_t *data = msvcrt_get_thread_data();
96     char *ret;
97
98     if (!str)
99         if (!(str = data->strtok_next)) return NULL;
100
101     while (*str && strchr( delim, *str )) str++;
102     if (!*str) return NULL;
103     ret = str++;
104     while (*str && !strchr( delim, *str )) str++;
105     if (*str) *str++ = 0;
106     data->strtok_next = str;
107     return ret;
108 }
109
110
111 /*********************************************************************
112  *              _swab (MSVCRT.@)
113  */
114 void CDECL MSVCRT__swab(char* src, char* dst, int len)
115 {
116   if (len > 1)
117   {
118     len = (unsigned)len >> 1;
119
120     while (len--) {
121       char s0 = src[0];
122       char s1 = src[1];
123       *dst++ = s1;
124       *dst++ = s0;
125       src = src + 2;
126     }
127   }
128 }
129
130 /*********************************************************************
131  *              atof  (MSVCRT.@)
132  */
133 double CDECL MSVCRT_atof( const char *str )
134 {
135     return atof( str );
136 }
137
138 /*********************************************************************
139  *              strtod  (MSVCRT.@)
140  */
141 double CDECL MSVCRT_strtod( const char *str, char **end )
142 {
143     return strtod( str, end );
144 }
145
146 /*********************************************************************
147  *              strcoll (MSVCRT.@)
148  */
149 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
150 {
151     /* FIXME: handle Windows locale */
152     return strcoll( str1, str2 );
153 }
154
155 /*********************************************************************
156  *              strxfrm (MSVCRT.@)
157  */
158 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
159 {
160     /* FIXME: handle Windows locale */
161     return strxfrm( dest, src, len );
162 }
163
164 /*********************************************************************
165  *              _stricoll (MSVCRT.@)
166  */
167 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
168 {
169   /* FIXME: handle collates */
170   TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
171   return lstrcmpiA( str1, str2 );
172 }
173
174 /********************************************************************
175  *              _atoldbl (MSVCRT.@)
176  */
177 int CDECL MSVCRT__atoldbl(_LDOUBLE * value, char * str)
178 {
179   /* FIXME needs error checking for huge/small values */
180 #ifdef HAVE_STRTOLD
181   TRACE("str %s value %p\n",str,value);
182   value->x = strtold(str,0);
183 #else
184   FIXME("stub, str %s value %p\n",str,value);
185 #endif
186   return 0;
187 }