2 * CRTDLL 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 * Implementation Notes:
16 DEFAULT_DEBUG_CHANNEL(crtdll);
18 /* INTERNAL: CRTDLL_malloc() based strndup */
19 LPSTR __CRTDLL__strndup(LPSTR buf, INT size);
20 LPSTR __CRTDLL__strndup(LPSTR buf, INT size)
23 int len = strlen(buf);
26 max_len = size <= len? size : len + 1;
28 ret = CRTDLL_malloc(max_len);
31 memcpy(ret,buf,max_len);
38 /*********************************************************************
39 * _strdec (CRTDLL.282)
41 * Return the byte before str2 while it is >= to str1.
44 * str1 [in] Terminating string
46 * sre2 [in] string to start searching from
49 * The byte before str2, or str1, whichever is greater
52 * This function is implemented as tested with windows, which means
53 * it does not have a terminating condition. It always returns
54 * the byte before str2. Use with extreme caution!
56 LPSTR __cdecl CRTDLL__strdec(LPSTR str1, LPSTR str2)
58 /* Hmm. While the docs suggest that the following should work... */
59 /* return (str2<=str1?0:str2-1); */
60 /* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
61 str1 = str1; /* remove warning */
66 /*********************************************************************
67 * _strdup (CRTDLL.285)
71 LPSTR __cdecl CRTDLL__strdup(LPCSTR ptr)
73 LPSTR ret = CRTDLL_malloc(strlen(ptr)+1);
74 if (ret) strcpy( ret, ptr );
79 /*********************************************************************
80 * _strinc (CRTDLL.287)
82 * Return a pointer to the next character in a string
84 LPSTR __cdecl CRTDLL__strinc(LPSTR str)
90 /*********************************************************************
91 * _strnextc (CRTDLL.290)
93 * Return an unsigned int from a string.
95 UINT __cdecl CRTDLL__strnextc(LPCSTR str)
101 /*********************************************************************
102 * _strninc (CRTDLL.292)
104 * Return a pointer to the 'n'th character in a string
106 LPSTR __cdecl CRTDLL__strninc(LPSTR str, INT n)
112 /*********************************************************************
113 * _strnset (CRTDLL.293)
115 * Fill a string with a character up to a certain length
117 LPSTR __cdecl CRTDLL__strnset(LPSTR str, INT c, INT len)
120 while (*str && len--)
126 /*********************************************************************
127 * _strrev (CRTDLL.294)
129 * Reverse a string in place
131 LPSTR __cdecl CRTDLL__strrev (LPSTR str)
137 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
147 /*********************************************************************
148 * _strset (CRTDLL.295)
150 * Fill a string with a value.
152 LPSTR __cdecl CRTDLL__strset (LPSTR str, INT set)
163 /*********************************************************************
164 * _strncnt (CRTDLL.289)
166 * Return the length of a string or the maximum given length.
168 LONG __cdecl CRTDLL__strncnt(LPSTR str, LONG max)
170 LONG len = strlen(str);
171 return (len > max? max : len);
175 /*********************************************************************
176 * _strspnp (CRTDLL.296)
179 LPSTR __cdecl CRTDLL__strspnp(LPSTR str1, LPSTR str2)
181 str1 += strspn(str1,str2);
182 return *str1? str1 : 0;
186 /*********************************************************************
189 * Copy from source to dest alternating bytes (i.e 16 bit big-to-little
190 * endian or vice versa).
192 void __cdecl CRTDLL__swab(LPSTR src, LPSTR dst, INT len)
196 len = (unsigned)len >> 1;