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
12 DEFAULT_DEBUG_CHANNEL(msvcrt
);
14 /* INTERNAL: MSVCRT_malloc() based strndup */
15 char * MSVCRT__strndup(const char * buf
, unsigned int size
)
18 unsigned int len
= strlen(buf
), max_len
;
20 max_len
= size
<= len
? size
: len
+ 1;
22 ret
= MSVCRT_malloc(max_len
);
25 memcpy(ret
,buf
,max_len
);
31 /*********************************************************************
34 char * __cdecl
MSVCRT__strdec(const char * str1
, const char * str2
)
36 /* Hmm. While the docs suggest that the following should work... */
37 /* return (str2<=str1?0:str2-1); */
38 /* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
39 str1
= str1
; /* remove warning */
40 return (char *)str2
-1;
43 /*********************************************************************
46 char * __cdecl
MSVCRT__strdup(const char * str
)
48 char * ret
= MSVCRT_malloc(strlen(str
)+1);
49 if (ret
) strcpy( ret
, str
);
53 /*********************************************************************
56 char * __cdecl
MSVCRT__strinc(const char * str
)
61 /*********************************************************************
62 * _strnextc (MSVCRT.@)
64 unsigned int __cdecl
MSVCRT__strnextc(const char * str
)
66 return (unsigned int)*str
;
69 /*********************************************************************
72 * Return a pointer to the 'n'th character in a string
74 char * __cdecl
MSVCRT__strninc(char * str
, unsigned int n
)
79 /*********************************************************************
82 char * __cdecl
MSVCRT__strnset(char * str
, int value
, unsigned int len
)
90 /*********************************************************************
93 char * __cdecl
MSVCRT__strrev (char * str
)
99 for (p1
= str
, p2
= str
+ strlen(str
) - 1; p2
> p1
; ++p1
, --p2
)
109 /*********************************************************************
112 char * __cdecl
MSVCRT__strset (char * str
, int value
)
121 /*********************************************************************
122 * _strncnt (MSVCRT.@)
124 unsigned int __cdecl
MSVCRT__strncnt(char * str
, unsigned int max
)
126 unsigned int len
= strlen(str
);
127 return (len
> max
? max
: len
);
130 /*********************************************************************
131 * _strspnp (MSVCRT.@)
133 char * __cdecl
MSVCRT__strspnp(char * str1
, char * str2
)
135 str1
+= strspn(str1
,str2
);
136 return *str1
? str1
: 0;
139 /*********************************************************************
142 void __cdecl
MSVCRT__swab(char * src
, char * dst
, int len
)
146 len
= (unsigned)len
>> 1;