d3dxof: Support also xfile version 3.03.
[wine/hacks.git] / dlls / msvcrt / string.c
blob74beefbd7a4e01185140b2e93dc5982aaace5ebd
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 "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
33 /*********************************************************************
34 * _mbsdup (MSVCRT.@)
35 * _strdup (MSVCRT.@)
37 char* CDECL _strdup(const char* str)
39 if(str)
41 char * ret = MSVCRT_malloc(strlen(str)+1);
42 if (ret) strcpy( ret, str );
43 return ret;
45 else return 0;
48 /*********************************************************************
49 * _strnset (MSVCRT.@)
51 char* CDECL _strnset(char* str, int value, MSVCRT_size_t len)
53 if (len > 0 && str)
54 while (*str && len--)
55 *str++ = value;
56 return str;
59 /*********************************************************************
60 * _strrev (MSVCRT.@)
62 char* CDECL _strrev(char* str)
64 char * p1;
65 char * p2;
67 if (str && *str)
68 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
70 *p1 ^= *p2;
71 *p2 ^= *p1;
72 *p1 ^= *p2;
75 return str;
78 /*********************************************************************
79 * _strset (MSVCRT.@)
81 char* CDECL _strset(char* str, int value)
83 char *ptr = str;
84 while (*ptr)
85 *ptr++ = value;
87 return str;
90 /*********************************************************************
91 * strtok (MSVCRT.@)
93 char * CDECL MSVCRT_strtok( char *str, const char *delim )
95 thread_data_t *data = msvcrt_get_thread_data();
96 char *ret;
98 if (!str)
99 if (!(str = data->strtok_next)) return NULL;
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;
111 /*********************************************************************
112 * _swab (MSVCRT.@)
114 void CDECL MSVCRT__swab(char* src, char* dst, int len)
116 if (len > 1)
118 len = (unsigned)len >> 1;
120 while (len--) {
121 char s0 = src[0];
122 char s1 = src[1];
123 *dst++ = s1;
124 *dst++ = s0;
125 src = src + 2;
130 /*********************************************************************
131 * atof (MSVCRT.@)
133 double CDECL MSVCRT_atof( const char *str )
135 return atof( str );
138 /*********************************************************************
139 * strtod (MSVCRT.@)
141 double CDECL MSVCRT_strtod( const char *str, char **end )
143 return strtod( str, end );
146 /*********************************************************************
147 * strcoll (MSVCRT.@)
149 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
151 /* FIXME: handle Windows locale */
152 return strcoll( str1, str2 );
155 /*********************************************************************
156 * strcpy_s (MSVCRT.@)
158 int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
160 MSVCRT_size_t i;
161 if(!elem) return MSVCRT_EINVAL;
162 if(!dst) return MSVCRT_EINVAL;
163 if(!src)
165 dst[0] = '\0';
166 return MSVCRT_EINVAL;
169 for(i = 0; i < elem; i++)
171 if((dst[i] = src[i]) == '\0') return 0;
173 dst[0] = '\0';
174 return MSVCRT_ERANGE;
177 /*********************************************************************
178 * strcat_s (MSVCRT.@)
180 int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
182 MSVCRT_size_t i, j;
183 if(!dst) return MSVCRT_EINVAL;
184 if(elem == 0) return MSVCRT_EINVAL;
185 if(!src)
187 dst[0] = '\0';
188 return MSVCRT_EINVAL;
191 for(i = 0; i < elem; i++)
193 if(dst[i] == '\0')
195 for(j = 0; (j + i) < elem; j++)
197 if((dst[j + i] = src[j]) == '\0') return 0;
201 /* Set the first element to 0, not the first element after the skipped part */
202 dst[0] = '\0';
203 return MSVCRT_ERANGE;
206 /*********************************************************************
207 * strxfrm (MSVCRT.@)
209 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
211 /* FIXME: handle Windows locale */
212 return strxfrm( dest, src, len );
215 /*********************************************************************
216 * _stricoll (MSVCRT.@)
218 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
220 /* FIXME: handle collates */
221 TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
222 return lstrcmpiA( str1, str2 );
225 /********************************************************************
226 * _atoldbl (MSVCRT.@)
228 int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
230 /* FIXME needs error checking for huge/small values */
231 #ifdef HAVE_STRTOLD
232 TRACE("str %s value %p\n",str,value);
233 value->x = strtold(str,0);
234 #else
235 FIXME("stub, str %s value %p\n",str,value);
236 #endif
237 return 0;
240 /********************************************************************
241 * __STRINGTOLD (MSVCRT.@)
243 int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
245 #ifdef HAVE_STRTOLD
246 FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
247 value->x = strtold(str,endptr);
248 #else
249 FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
250 #endif
251 return 0;