- move _timezone to time.c, and correct its type
[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 "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
28
29 /* INTERNAL: MSVCRT_malloc() based strndup */
30 char* msvcrt_strndup(const char* buf, unsigned int size)
31 {
32   char* ret;
33   unsigned int len = strlen(buf), max_len;
34
35   max_len = size <= len? size : len + 1;
36
37   ret = MSVCRT_malloc(max_len);
38   if (ret)
39   {
40     memcpy(ret,buf,max_len);
41     ret[max_len] = 0;
42   }
43   return ret;
44 }
45
46 /*********************************************************************
47  *              _mbsdup (MSVCRT.@)
48  *              _strdup (MSVCRT.@)
49  */
50 char* _strdup(const char* str)
51 {
52     char * ret = MSVCRT_malloc(strlen(str)+1);
53     if (ret) strcpy( ret, str );
54     return ret;
55 }
56
57 /*********************************************************************
58  *              _strnset (MSVCRT.@)
59  */
60 char* _strnset(char* str, int value, unsigned int len)
61 {
62   if (len > 0 && str)
63     while (*str && len--)
64       *str++ = value;
65   return str;
66 }
67
68 /*********************************************************************
69  *              _strrev (MSVCRT.@)
70  */
71 char* _strrev(char* str)
72 {
73   char * p1;
74   char * p2;
75
76   if (str && *str)
77     for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
78     {
79       *p1 ^= *p2;
80       *p2 ^= *p1;
81       *p1 ^= *p2;
82     }
83
84   return str;
85 }
86
87 /*********************************************************************
88  *              _strset (MSVCRT.@)
89  */
90 char* _strset(char* str, int value)
91 {
92   char *ptr = str;
93   while (*ptr)
94     *ptr++ = value;
95
96   return str;
97 }
98
99 /*********************************************************************
100  *              _swab (MSVCRT.@)
101  */
102 void MSVCRT__swab(char* src, char* dst, int len)
103 {
104   if (len > 1)
105   {
106     len = (unsigned)len >> 1;
107
108     while (len--) {
109       *dst++ = src[1];
110       *dst++ = *src++;
111       src++;
112     }
113   }
114 }