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
11 #include "msvcrt/stdlib.h"
12 #include "msvcrt/string.h"
14 DEFAULT_DEBUG_CHANNEL(msvcrt
);
16 /* INTERNAL: MSVCRT_malloc() based strndup */
17 char* msvcrt_strndup(const char* buf
, unsigned int size
)
20 unsigned int len
= strlen(buf
), max_len
;
22 max_len
= size
<= len
? size
: len
+ 1;
24 ret
= MSVCRT_malloc(max_len
);
27 memcpy(ret
,buf
,max_len
);
33 /*********************************************************************
36 char* _strdec(const char* str1
, const char* str2
)
38 /* Hmm. While the docs suggest that the following should work... */
39 /* return (str2<=str1?0:str2-1); */
40 /* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
41 str1
= str1
; /* remove warning */
42 return (char *)str2
-1;
45 /*********************************************************************
48 char* _strdup(const char* str
)
50 char * ret
= MSVCRT_malloc(strlen(str
)+1);
51 if (ret
) strcpy( ret
, str
);
55 /*********************************************************************
58 char* _strinc(const char* str
)
63 /*********************************************************************
64 * _strnextc (MSVCRT.@)
66 unsigned int _strnextc(const char* str
)
68 return (unsigned int)*str
;
71 /*********************************************************************
74 * Return a pointer to the 'n'th character in a string
76 char* _strninc(char* str
, unsigned int n
)
81 /*********************************************************************
84 char* _strnset(char* str
, int value
, unsigned int len
)
92 /*********************************************************************
95 char* _strrev(char* str
)
101 for (p1
= str
, p2
= str
+ strlen(str
) - 1; p2
> p1
; ++p1
, --p2
)
111 /*********************************************************************
114 char* _strset(char* str
, int value
)
123 /*********************************************************************
124 * _strncnt (MSVCRT.@)
126 unsigned int _strncnt(char* str
, unsigned int max
)
128 unsigned int len
= strlen(str
);
129 return (len
> max
? max
: len
);
132 /*********************************************************************
133 * _strspnp (MSVCRT.@)
135 char* _strspnp(char* str1
, char* str2
)
137 str1
+= strspn(str1
,str2
);
138 return *str1
? str1
: 0;
141 /*********************************************************************
144 void _swab(char* src
, char* dst
, int len
)
148 len
= (unsigned)len
>> 1;