d3dx8: Implement D3DXPlaneTransform.
[wine/wine-kai.git] / dlls / msvcrt / string.c
blob660b94d89a00e3d73b7c3c91e4866b3b5e09c41b
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"
27 #include <stdlib.h>
28 #include "msvcrt.h"
29 #include "msvcrt/errno.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
34 /*********************************************************************
35 * _mbsdup (MSVCRT.@)
36 * _strdup (MSVCRT.@)
38 char* CDECL _strdup(const char* str)
40 if(str)
42 char * ret = MSVCRT_malloc(strlen(str)+1);
43 if (ret) strcpy( ret, str );
44 return ret;
46 else return 0;
49 /*********************************************************************
50 * _strnset (MSVCRT.@)
52 char* CDECL _strnset(char* str, int value, MSVCRT_size_t len)
54 if (len > 0 && str)
55 while (*str && len--)
56 *str++ = value;
57 return str;
60 /*********************************************************************
61 * _strrev (MSVCRT.@)
63 char* CDECL _strrev(char* str)
65 char * p1;
66 char * p2;
68 if (str && *str)
69 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
71 *p1 ^= *p2;
72 *p2 ^= *p1;
73 *p1 ^= *p2;
76 return str;
79 /*********************************************************************
80 * _strset (MSVCRT.@)
82 char* CDECL _strset(char* str, int value)
84 char *ptr = str;
85 while (*ptr)
86 *ptr++ = value;
88 return str;
91 /*********************************************************************
92 * strtok (MSVCRT.@)
94 char * CDECL MSVCRT_strtok( char *str, const char *delim )
96 thread_data_t *data = msvcrt_get_thread_data();
97 char *ret;
99 if (!str)
100 if (!(str = data->strtok_next)) return NULL;
102 while (*str && strchr( delim, *str )) str++;
103 if (!*str) return NULL;
104 ret = str++;
105 while (*str && !strchr( delim, *str )) str++;
106 if (*str) *str++ = 0;
107 data->strtok_next = str;
108 return ret;
112 /*********************************************************************
113 * _swab (MSVCRT.@)
115 void CDECL MSVCRT__swab(char* src, char* dst, int len)
117 if (len > 1)
119 len = (unsigned)len >> 1;
121 while (len--) {
122 char s0 = src[0];
123 char s1 = src[1];
124 *dst++ = s1;
125 *dst++ = s0;
126 src = src + 2;
131 /*********************************************************************
132 * atof (MSVCRT.@)
134 double CDECL MSVCRT_atof( const char *str )
136 return atof( str );
139 /*********************************************************************
140 * strtod (MSVCRT.@)
142 double CDECL MSVCRT_strtod( const char *str, char **end )
144 return strtod( str, end );
147 /*********************************************************************
148 * strcoll (MSVCRT.@)
150 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
152 /* FIXME: handle Windows locale */
153 return strcoll( str1, str2 );
156 /*********************************************************************
157 * strcpy_s (MSVCRT.@)
159 int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
161 MSVCRT_size_t i;
162 if(!elem) return EINVAL;
163 if(!dst) return EINVAL;
164 if(!src)
166 dst[0] = '\0';
167 return EINVAL;
170 for(i = 0; i < elem; i++)
172 if((dst[i] = src[i]) == '\0') return 0;
174 dst[0] = '\0';
175 return ERANGE;
178 /*********************************************************************
179 * strcat_s (MSVCRT.@)
181 int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
183 MSVCRT_size_t i, j;
184 if(!dst) return EINVAL;
185 if(elem == 0) return EINVAL;
186 if(!src)
188 dst[0] = '\0';
189 return EINVAL;
192 for(i = 0; i < elem; i++)
194 if(dst[i] == '\0')
196 for(j = 0; (j + i) < elem; j++)
198 if((dst[j + i] = src[j]) == '\0') return 0;
202 /* Set the first element to 0, not the first element after the skipped part */
203 dst[0] = '\0';
204 return ERANGE;
207 /*********************************************************************
208 * strxfrm (MSVCRT.@)
210 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
212 /* FIXME: handle Windows locale */
213 return strxfrm( dest, src, len );
216 /*********************************************************************
217 * _stricoll (MSVCRT.@)
219 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
221 /* FIXME: handle collates */
222 TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
223 return lstrcmpiA( str1, str2 );
226 /********************************************************************
227 * _atoldbl (MSVCRT.@)
229 int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
231 /* FIXME needs error checking for huge/small values */
232 #ifdef HAVE_STRTOLD
233 TRACE("str %s value %p\n",str,value);
234 value->x = strtold(str,0);
235 #else
236 FIXME("stub, str %s value %p\n",str,value);
237 #endif
238 return 0;
241 /********************************************************************
242 * __STRINGTOLD (MSVCRT.@)
244 int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
246 #ifdef HAVE_STRTOLD
247 FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
248 value->x = strtold(str,endptr);
249 #else
250 FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
251 #endif
252 return 0;