[9633] | 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"
|
---|
[10005] | 27 | #include <string.h>
|
---|
[9633] | 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 | * _mbsdup (MSVCRT.@)
|
---|
| 51 | * _strdup (MSVCRT.@)
|
---|
| 52 | */
|
---|
[10005] | 53 | char* MSVCRT__strdup(const char* str)
|
---|
[9633] | 54 | {
|
---|
| 55 | char * ret = MSVCRT_malloc(strlen(str)+1);
|
---|
| 56 | if (ret) strcpy( ret, str );
|
---|
| 57 | return ret;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /*********************************************************************
|
---|
| 61 | * _strnset (MSVCRT.@)
|
---|
| 62 | */
|
---|
[10005] | 63 | char* MSVCRT__strnset(char* str, int value, unsigned int len)
|
---|
[9633] | 64 | {
|
---|
[10005] | 65 | dprintf(("MSVCRT: _strnset %s %d %d",str, value, len));
|
---|
[9633] | 66 | if (len > 0 && str)
|
---|
| 67 | while (*str && len--)
|
---|
| 68 | *str++ = value;
|
---|
| 69 | return str;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /*********************************************************************
|
---|
| 73 | * _strrev (MSVCRT.@)
|
---|
| 74 | */
|
---|
[10005] | 75 | char* MSVCRT__strrev(char* str)
|
---|
[9633] | 76 | {
|
---|
| 77 | char * p1;
|
---|
| 78 | char * p2;
|
---|
| 79 |
|
---|
[10005] | 80 | dprintf(("MSVCRT: _strrev %s",str));
|
---|
| 81 |
|
---|
[9633] | 82 | if (str && *str)
|
---|
| 83 | for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
|
---|
| 84 | {
|
---|
| 85 | *p1 ^= *p2;
|
---|
| 86 | *p2 ^= *p1;
|
---|
| 87 | *p1 ^= *p2;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return str;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /*********************************************************************
|
---|
| 94 | * _strset (MSVCRT.@)
|
---|
| 95 | */
|
---|
[10005] | 96 | char* MSVCRT__strset(char* str, int value)
|
---|
[9633] | 97 | {
|
---|
| 98 | char *ptr = str;
|
---|
[10005] | 99 |
|
---|
| 100 | dprintf(("MSVCRT: _strset %s %d",str, value));
|
---|
| 101 |
|
---|
[9633] | 102 | while (*ptr)
|
---|
| 103 | *ptr++ = value;
|
---|
| 104 |
|
---|
| 105 | return str;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /*********************************************************************
|
---|
| 109 | * _swab (MSVCRT.@)
|
---|
| 110 | */
|
---|
[10005] | 111 | void MSVCRT__swab(char* src, char* dst, int len)
|
---|
[9633] | 112 | {
|
---|
[10005] | 113 | dprintf(("MSVCRT: _swab %s %s %d",src, dst, len));
|
---|
| 114 |
|
---|
[9633] | 115 | if (len > 1)
|
---|
| 116 | {
|
---|
| 117 | len = (unsigned)len >> 1;
|
---|
| 118 |
|
---|
| 119 | while (len--) {
|
---|
| 120 | *dst++ = src[1];
|
---|
| 121 | *dst++ = *src++;
|
---|
| 122 | src++;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
[10005] | 126 |
|
---|
| 127 | int MSVCRT_strncmp (const char* a,const char* b,MSVCRT(size_t) c)
|
---|
| 128 | {
|
---|
| 129 | dprintf(("MSVCRT: strncmp %s,%s (%d)",a,b,c));
|
---|
| 130 | return strncmp(a,b,c);
|
---|
| 131 | }
|
---|
| 132 |
|
---|