kernel: Better support for detached processes.
[wine/gsoc_dplay.git] / dlls / msvcrt / string.c
blob579c9bd873090ae88358c568f8c7e4dfd8f3d3af
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <stdlib.h>
25 #include "msvcrt.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
30 /* INTERNAL: MSVCRT_malloc() based strndup */
31 char* msvcrt_strndup(const char* buf, unsigned int size)
33 char* ret;
34 unsigned int len = strlen(buf), max_len;
36 max_len = size <= len? size : len + 1;
38 ret = MSVCRT_malloc(max_len);
39 if (ret)
41 memcpy(ret,buf,max_len);
42 ret[max_len] = 0;
44 return ret;
47 /*********************************************************************
48 * _mbsdup (MSVCRT.@)
49 * _strdup (MSVCRT.@)
51 char* _strdup(const char* str)
53 char * ret = MSVCRT_malloc(strlen(str)+1);
54 if (ret) strcpy( ret, str );
55 return ret;
58 /*********************************************************************
59 * _strnset (MSVCRT.@)
61 char* _strnset(char* str, int value, MSVCRT_size_t len)
63 if (len > 0 && str)
64 while (*str && len--)
65 *str++ = value;
66 return str;
69 /*********************************************************************
70 * _strrev (MSVCRT.@)
72 char* _strrev(char* str)
74 char * p1;
75 char * p2;
77 if (str && *str)
78 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
80 *p1 ^= *p2;
81 *p2 ^= *p1;
82 *p1 ^= *p2;
85 return str;
88 /*********************************************************************
89 * _strset (MSVCRT.@)
91 char* _strset(char* str, int value)
93 char *ptr = str;
94 while (*ptr)
95 *ptr++ = value;
97 return str;
100 /*********************************************************************
101 * strtok (MSVCRT.@)
103 char *MSVCRT_strtok( char *str, const char *delim )
105 thread_data_t *data = msvcrt_get_thread_data();
106 char *ret;
108 if (!str)
109 if (!(str = data->strtok_next)) return NULL;
111 while (*str && strchr( delim, *str )) str++;
112 if (!*str) return NULL;
113 ret = str++;
114 while (*str && !strchr( delim, *str )) str++;
115 if (*str) *str++ = 0;
116 data->strtok_next = str;
117 return ret;
121 /*********************************************************************
122 * _swab (MSVCRT.@)
124 void MSVCRT__swab(char* src, char* dst, int len)
126 if (len > 1)
128 len = (unsigned)len >> 1;
130 while (len--) {
131 char s0 = src[0];
132 char s1 = src[1];
133 *dst++ = s1;
134 *dst++ = s0;
135 src = src + 2;
140 /*********************************************************************
141 * atof (MSVCRT.@)
143 double MSVCRT_atof( const char *str )
145 return atof( str );
148 /*********************************************************************
149 * strtod (MSVCRT.@)
151 double MSVCRT_strtod( const char *str, char **end )
153 return strtod( str, end );
156 /*********************************************************************
157 * strcoll (MSVCRT.@)
159 int MSVCRT_strcoll( const char* str1, const char* str2 )
161 /* FIXME: handle Windows locale */
162 return strcoll( str1, str2 );
165 /*********************************************************************
166 * strxfrm (MSVCRT.@)
168 MSVCRT_size_t MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
170 /* FIXME: handle Windows locale */
171 return strxfrm( dest, src, len );
174 /*********************************************************************
175 * _stricoll (MSVCRT.@)
177 INT MSVCRT__stricoll( const char* str1, const char* str2 )
179 /* FIXME: handle collates */
180 TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
181 return lstrcmpiA( str1, str2 );