~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/msvcrt/string.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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 <errno.h>
 29 #include "msvcrt.h"
 30 #include "wine/debug.h"
 31 
 32 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 33 
 34 /*********************************************************************
 35  *              _mbsdup (MSVCRT.@)
 36  *              _strdup (MSVCRT.@)
 37  */
 38 char* CDECL _strdup(const char* str)
 39 {
 40     if(str)
 41     {
 42       char * ret = MSVCRT_malloc(strlen(str)+1);
 43       if (ret) strcpy( ret, str );
 44       return ret;
 45     }
 46     else return 0;
 47 }
 48 
 49 /*********************************************************************
 50  *              _strnset (MSVCRT.@)
 51  */
 52 char* CDECL _strnset(char* str, int value, MSVCRT_size_t len)
 53 {
 54   if (len > 0 && str)
 55     while (*str && len--)
 56       *str++ = value;
 57   return str;
 58 }
 59 
 60 /*********************************************************************
 61  *              _strrev (MSVCRT.@)
 62  */
 63 char* CDECL _strrev(char* str)
 64 {
 65   char * p1;
 66   char * p2;
 67 
 68   if (str && *str)
 69     for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
 70     {
 71       *p1 ^= *p2;
 72       *p2 ^= *p1;
 73       *p1 ^= *p2;
 74     }
 75 
 76   return str;
 77 }
 78 
 79 /*********************************************************************
 80  *              _strset (MSVCRT.@)
 81  */
 82 char* CDECL _strset(char* str, int value)
 83 {
 84   char *ptr = str;
 85   while (*ptr)
 86     *ptr++ = value;
 87 
 88   return str;
 89 }
 90 
 91 /*********************************************************************
 92  *              strtok  (MSVCRT.@)
 93  */
 94 char * CDECL MSVCRT_strtok( char *str, const char *delim )
 95 {
 96     thread_data_t *data = msvcrt_get_thread_data();
 97     char *ret;
 98 
 99     if (!str)
100         if (!(str = data->strtok_next)) return NULL;
101 
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;
109 }
110 
111 
112 /*********************************************************************
113  *              _swab (MSVCRT.@)
114  */
115 void CDECL MSVCRT__swab(char* src, char* dst, int len)
116 {
117   if (len > 1)
118   {
119     len = (unsigned)len >> 1;
120 
121     while (len--) {
122       char s0 = src[0];
123       char s1 = src[1];
124       *dst++ = s1;
125       *dst++ = s0;
126       src = src + 2;
127     }
128   }
129 }
130 
131 /*********************************************************************
132  *              atof  (MSVCRT.@)
133  */
134 double CDECL MSVCRT_atof( const char *str )
135 {
136     return atof( str );
137 }
138 
139 /*********************************************************************
140  *              strtod  (MSVCRT.@)
141  */
142 double CDECL MSVCRT_strtod( const char *str, char **end )
143 {
144     return strtod( str, end );
145 }
146 
147 /*********************************************************************
148  *              strcoll (MSVCRT.@)
149  */
150 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
151 {
152     /* FIXME: handle Windows locale */
153     return strcoll( str1, str2 );
154 }
155 
156 /*********************************************************************
157  *      strcpy_s (MSVCRT.@)
158  */
159 int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
160 {
161     MSVCRT_size_t i;
162     if(!elem) return MSVCRT_EINVAL;
163     if(!dst) return MSVCRT_EINVAL;
164     if(!src)
165     {
166         dst[0] = '\0';
167         return MSVCRT_EINVAL;
168     }
169 
170     for(i = 0; i < elem; i++)
171     {
172         if((dst[i] = src[i]) == '\0') return 0;
173     }
174     dst[0] = '\0';
175     return MSVCRT_ERANGE;
176 }
177 
178 /*********************************************************************
179  *      strcat_s (MSVCRT.@)
180  */
181 int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
182 {
183     MSVCRT_size_t i, j;
184     if(!dst) return MSVCRT_EINVAL;
185     if(elem == 0) return MSVCRT_EINVAL;
186     if(!src)
187     {
188         dst[0] = '\0';
189         return MSVCRT_EINVAL;
190     }
191 
192     for(i = 0; i < elem; i++)
193     {
194         if(dst[i] == '\0')
195         {
196             for(j = 0; (j + i) < elem; j++)
197             {
198                 if((dst[j + i] = src[j]) == '\0') return 0;
199             }
200         }
201     }
202     /* Set the first element to 0, not the first element after the skipped part */
203     dst[0] = '\0';
204     return MSVCRT_ERANGE;
205 }
206 
207 /*********************************************************************
208  *              strxfrm (MSVCRT.@)
209  */
210 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
211 {
212     /* FIXME: handle Windows locale */
213     return strxfrm( dest, src, len );
214 }
215 
216 /*********************************************************************
217  *              _stricoll (MSVCRT.@)
218  */
219 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
220 {
221   /* FIXME: handle collates */
222   TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
223   return lstrcmpiA( str1, str2 );
224 }
225 
226 /********************************************************************
227  *              _atoldbl (MSVCRT.@)
228  */
229 int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
230 {
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;
239 }
240 
241 /********************************************************************
242  *              __STRINGTOLD (MSVCRT.@)
243  */
244 int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
245 {
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;
253 }
254 
255 /******************************************************************
256  *              strtol (MSVCRT.@)
257  */
258 MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
259 {
260     /* wrapper to forward libc error code to msvcrt's error codes */
261     long ret;
262 
263     errno = 0;
264     ret = strtol(nptr, end, base);
265     switch (errno)
266     {
267     case ERANGE:        *MSVCRT__errno() = MSVCRT_ERANGE;       break;
268     case EINVAL:        *MSVCRT__errno() = MSVCRT_EINVAL;       break;
269     default:
270         /* cope with the fact that we may use 64bit long integers on libc
271          * while msvcrt always uses 32bit long integers
272          */
273         if (ret > MSVCRT_LONG_MAX)
274         {
275             ret = MSVCRT_LONG_MAX;
276             *MSVCRT__errno() = MSVCRT_ERANGE;
277         }
278         else if (ret < -MSVCRT_LONG_MAX - 1)
279         {
280             ret = -MSVCRT_LONG_MAX - 1;
281             *MSVCRT__errno() = MSVCRT_ERANGE;
282         }
283         break;
284     }
285 
286     return ret;
287 }
288 
289 /******************************************************************
290  *              strtoul (MSVCRT.@)
291  */
292 MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
293 {
294     /* wrapper to forward libc error code to msvcrt's error codes */
295     unsigned long ret;
296 
297     errno = 0;
298     ret = strtoul(nptr, end, base);
299     switch (errno)
300     {
301     case ERANGE:        *MSVCRT__errno() = MSVCRT_ERANGE;       break;
302     case EINVAL:        *MSVCRT__errno() = MSVCRT_EINVAL;       break;
303     default:
304         /* cope with the fact that we may use 64bit long integers on libc
305          * while msvcrt always uses 32bit long integers
306          */
307         if (ret > MSVCRT_ULONG_MAX)
308         {
309             ret = MSVCRT_ULONG_MAX;
310             *MSVCRT__errno() = MSVCRT_ERANGE;
311         }
312         break;
313     }
314 
315     return ret;
316 }
317 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.