2 * NTDLL string functions
4 * Copyright 2000 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
6 * Copyright 2003 Thomas Mertes
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 /*********************************************************************
39 INT __cdecl NTDLL__memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
44 if ((ret = tolower(*s1) - tolower(*s2))) break;
52 /*********************************************************************
55 LPSTR __cdecl _strupr( LPSTR str )
58 for ( ; *str; str++) *str = toupper(*str);
63 /*********************************************************************
66 * convert a string in place to lowercase
68 LPSTR __cdecl _strlwr( LPSTR str )
71 for ( ; *str; str++) *str = tolower(*str);
76 /*********************************************************************
79 * Converts an unsigned long integer to a string.
85 * Converts value to a '\0' terminated string which is copied to str.
86 * The maximum length of the copied str is 33 bytes.
87 * Does not check if radix is in the range of 2 to 36.
88 * If str is NULL it crashes, as the native function does.
90 char * __cdecl _ultoa(
91 unsigned long value, /* [I] Value to be converted */
92 char *str, /* [O] Destination for the converted value */
93 int radix) /* [I] Number base for conversion */
103 digit = value % radix;
104 value = value / radix;
106 *--pos = '0' + digit;
108 *--pos = 'a' + digit - 10;
110 } while (value != 0L);
112 memcpy(str, pos, &buffer[32] - pos + 1);
117 /*********************************************************************
120 * Converts a long integer to a string.
123 * Always returns str.
126 * Converts value to a '\0' terminated string which is copied to str.
127 * The maximum length of the copied str is 33 bytes. If radix
128 * is 10 and value is negative, the value is converted with sign.
129 * Does not check if radix is in the range of 2 to 36.
130 * If str is NULL it crashes, as the native function does.
132 char * __cdecl _ltoa(
133 long value, /* [I] Value to be converted */
134 char *str, /* [O] Destination for the converted value */
135 int radix) /* [I] Number base for conversion */
143 if (value < 0 && radix == 10) {
158 *--pos = '0' + digit;
160 *--pos = 'a' + digit - 10;
168 memcpy(str, pos, &buffer[32] - pos + 1);
173 /*********************************************************************
176 * Converts an integer to a string.
179 * Always returns str.
182 * Converts value to a '\0' terminated string which is copied to str.
183 * The maximum length of the copied str is 33 bytes. If radix
184 * is 10 and value is negative, the value is converted with sign.
185 * Does not check if radix is in the range of 2 to 36.
186 * If str is NULL it crashes, as the native function does.
188 char * __cdecl _itoa(
189 int value, /* [I] Value to be converted */
190 char *str, /* [O] Destination for the converted value */
191 int radix) /* [I] Number base for conversion */
193 return _ltoa(value, str, radix);
197 /*********************************************************************
200 * Converts a large unsigned integer to a string.
203 * Always returns str.
206 * Converts value to a '\0' terminated string which is copied to str.
207 * The maximum length of the copied str is 65 bytes.
208 * Does not check if radix is in the range of 2 to 36.
209 * If str is NULL it crashes, as the native function does.
211 char * __cdecl _ui64toa(
212 ULONGLONG value, /* [I] Value to be converted */
213 char *str, /* [O] Destination for the converted value */
214 int radix) /* [I] Number base for conversion */
224 digit = value % radix;
225 value = value / radix;
227 *--pos = '0' + digit;
229 *--pos = 'a' + digit - 10;
231 } while (value != 0L);
233 memcpy(str, pos, &buffer[64] - pos + 1);
238 /*********************************************************************
241 * Converts a large integer to a string.
244 * Always returns str.
247 * Converts value to a '\0' terminated string which is copied to str.
248 * The maximum length of the copied str is 65 bytes. If radix
249 * is 10 and value is negative, the value is converted with sign.
250 * Does not check if radix is in the range of 2 to 36.
251 * If str is NULL it crashes, as the native function does.
254 * - The native DLL converts negative values (for base 10) wrong:
255 * -1 is converted to -18446744073709551615
256 * -2 is converted to -18446744073709551614
257 * -9223372036854775807 is converted to -9223372036854775809
258 * -9223372036854775808 is converted to -9223372036854775808
259 * The native msvcrt _i64toa function and our ntdll _i64toa function
260 * do not have this bug.
262 char * __cdecl _i64toa(
263 LONGLONG value, /* [I] Value to be converted */
264 char *str, /* [O] Destination for the converted value */
265 int radix) /* [I] Number base for conversion */
273 if (value < 0 && radix == 10) {
288 *--pos = '0' + digit;
290 *--pos = 'a' + digit - 10;
298 memcpy(str, pos, &buffer[64] - pos + 1);
303 /*********************************************************************
306 * Converts a string to a large integer.
309 * str [I] Wstring to be converted
312 * On success it returns the integer value otherwise it returns 0.
315 * Accepts: {whitespace} [+|-] {digits}
316 * No check is made for value overflow, only the lower 64 bits are assigned.
317 * If str is NULL it crashes, as the native function does.
319 LONGLONG __cdecl _atoi64( char *str )
321 ULONGLONG RunningTotal = 0;
324 while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
330 } else if (*str == '-') {
335 while (*str >= '0' && *str <= '9') {
336 RunningTotal = RunningTotal * 10 + *str - '0';
340 return bMinus ? -RunningTotal : RunningTotal;
344 /*********************************************************************
345 * _splitpath (NTDLL.@)
347 void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
348 char* fname, char * ext )
352 if (inpath[0] && inpath[1] == ':')
362 else if (drv) drv[0] = 0;
364 /* look for end of directory part */
366 for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
368 if (end) /* got a directory */
372 memcpy( dir, inpath, end - inpath );
373 dir[end - inpath] = 0;
377 else if (dir) dir[0] = 0;
379 /* look for extension: what's after the last dot */
381 for (p = inpath; *p; p++) if (*p == '.') end = p;
383 if (!end) end = p; /* there's no extension */
387 memcpy( fname, inpath, end - inpath );
388 fname[end - inpath] = 0;
390 if (ext) strcpy( ext, end );