Added regedit unit test, a couple minor changes to regedit.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "msvcrt.h"
25 #include "msvcrt/stdlib.h"
26 #include "msvcrt/string.h"
27
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
31
32 /* INTERNAL: MSVCRT_malloc() based strndup */
33 char* msvcrt_strndup(const char* buf, unsigned int size)
34 {
35   char* ret;
36   unsigned int len = strlen(buf), max_len;
37
38   max_len = size <= len? size : len + 1;
39
40   ret = MSVCRT_malloc(max_len);
41   if (ret)
42   {
43     memcpy(ret,buf,max_len);
44     ret[max_len] = 0;
45   }
46   return ret;
47 }
48
49 /*********************************************************************
50  *              _strdec (MSVCRT.@)
51  */
52 char* _strdec(const char* str1, const char* str2)
53 {
54   /* Hmm. While the docs suggest that the following should work... */
55   /*  return (str2<=str1?0:str2-1); */
56   /* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
57   str1 = str1; /* remove warning */
58   return (char *)str2-1;
59 }
60
61 /*********************************************************************
62  *              _mbsdup (MSVCRT.@)
63  *              _strdup (MSVCRT.@)
64  */
65 char* _strdup(const char* str)
66 {
67     char * ret = MSVCRT_malloc(strlen(str)+1);
68     if (ret) strcpy( ret, str );
69     return ret;
70 }
71
72 /*********************************************************************
73  *              _strinc (MSVCRT.@)
74  */
75 char* _strinc(const char* str)
76 {
77   return (char*)str+1;
78 }
79
80 /*********************************************************************
81  *              _strnextc (MSVCRT.@)
82  */
83 unsigned int _strnextc(const char* str)
84 {
85   return (unsigned int)*str;
86 }
87
88 /*********************************************************************
89  *              _strninc (MSVCRT.@)
90  *
91  * Return a pointer to the 'n'th character in a string
92  */
93 char* _strninc(char* str, unsigned int n)
94 {
95   return str + n;
96 }
97
98 /*********************************************************************
99  *              _strnset (MSVCRT.@)
100  */
101 char* _strnset(char* str, int value, unsigned int len)
102 {
103   if (len > 0 && str)
104     while (*str && len--)
105       *str++ = value;
106   return str;
107 }
108
109 /*********************************************************************
110  *              _strrev (MSVCRT.@)
111  */
112 char* _strrev(char* str)
113 {
114   char * p1;
115   char * p2;
116
117   if (str && *str)
118     for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
119     {
120       *p1 ^= *p2;
121       *p2 ^= *p1;
122       *p1 ^= *p2;
123     }
124
125   return str;
126 }
127
128 /*********************************************************************
129  *              _strset (MSVCRT.@)
130  */
131 char* _strset(char* str, int value)
132 {
133   char *ptr = str;
134   while (*ptr)
135     *ptr++ = value;
136
137   return str;
138 }
139
140 /*********************************************************************
141  *              _strncnt (MSVCRT.@)
142  */
143 unsigned int _strncnt(char* str, unsigned int max)
144 {
145   unsigned int len = strlen(str);
146   return (len > max? max : len);
147 }
148
149 /*********************************************************************
150  *              _strspnp (MSVCRT.@)
151  */
152 char* _strspnp(char* str1, char* str2)
153 {
154   str1 += strspn(str1,str2);
155   return *str1? str1 : 0;
156 }
157
158 /*********************************************************************
159  *              _swab (MSVCRT.@)
160  */
161 void _swab(char* src, char* dst, int len)
162 {
163   if (len > 1)
164   {
165     len = (unsigned)len >> 1;
166
167     while (len--) {
168       *dst++ = src[1];
169       *dst++ = *src++;
170       src++;
171     }
172   }
173 }