Release 20030408.
[wine/gsoc-2012-control.git] / dlls / msvcrt / string.c
blob8bb9be83590afa83efb9ad80305ec4f9b2dbd5f7
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 "msvcrt.h"
25 #include "msvcrt/stdlib.h"
26 #include "msvcrt/string.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
32 /* INTERNAL: MSVCRT_malloc() based strndup */
33 char* msvcrt_strndup(const char* buf, unsigned int size)
35 char* ret;
36 unsigned int len = strlen(buf), max_len;
38 max_len = size <= len? size : len + 1;
40 ret = MSVCRT_malloc(max_len);
41 if (ret)
43 memcpy(ret,buf,max_len);
44 ret[max_len] = 0;
46 return ret;
49 /*********************************************************************
50 * _mbsdup (MSVCRT.@)
51 * _strdup (MSVCRT.@)
53 char* _strdup(const char* str)
55 char * ret = MSVCRT_malloc(strlen(str)+1);
56 if (ret) strcpy( ret, str );
57 return ret;
60 /*********************************************************************
61 * _strnset (MSVCRT.@)
63 char* _strnset(char* str, int value, unsigned int len)
65 if (len > 0 && str)
66 while (*str && len--)
67 *str++ = value;
68 return str;
71 /*********************************************************************
72 * _strrev (MSVCRT.@)
74 char* _strrev(char* str)
76 char * p1;
77 char * p2;
79 if (str && *str)
80 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
82 *p1 ^= *p2;
83 *p2 ^= *p1;
84 *p1 ^= *p2;
87 return str;
90 /*********************************************************************
91 * _strset (MSVCRT.@)
93 char* _strset(char* str, int value)
95 char *ptr = str;
96 while (*ptr)
97 *ptr++ = value;
99 return str;
102 /*********************************************************************
103 * _swab (MSVCRT.@)
105 void _swab(char* src, char* dst, int len)
107 if (len > 1)
109 len = (unsigned)len >> 1;
111 while (len--) {
112 *dst++ = src[1];
113 *dst++ = *src++;
114 src++;