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
32 /*********************************************************************
35 INT __cdecl NTDLL__memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
40 if ((ret = tolower(*s1) - tolower(*s2))) break;
48 /*********************************************************************
51 LPSTR __cdecl _strupr( LPSTR str )
54 for ( ; *str; str++) *str = toupper(*str);
59 /*********************************************************************
62 * convert a string in place to lowercase
64 LPSTR __cdecl _strlwr( LPSTR str )
67 for ( ; *str; str++) *str = tolower(*str);
72 /*********************************************************************
75 * Converts an unsigned long integer to a string.
81 * Converts value to a '\0' terminated string which is copied to str.
82 * The maximum length of the copied str is 33 bytes.
83 * Does not check if radix is in the range of 2 to 36.
84 * If str is NULL it crashes, as the native function does.
86 char * __cdecl _ultoa(
87 unsigned long value, /* [I] Value to be converted */
88 char *str, /* [O] Destination for the converted value */
89 int radix) /* [I] Number base for conversion */
99 digit = value % radix;
100 value = value / radix;
102 *--pos = '0' + digit;
104 *--pos = 'a' + digit - 10;
106 } while (value != 0L);
108 memcpy(str, pos, &buffer[32] - pos + 1);
113 /*********************************************************************
116 * Converts a long integer to a string.
119 * Always returns str.
122 * Converts value to a '\0' terminated string which is copied to str.
123 * The maximum length of the copied str is 33 bytes. If radix
124 * is 10 and value is negative, the value is converted with sign.
125 * Does not check if radix is in the range of 2 to 36.
126 * If str is NULL it crashes, as the native function does.
128 char * __cdecl _ltoa(
129 long value, /* [I] Value to be converted */
130 char *str, /* [O] Destination for the converted value */
131 int radix) /* [I] Number base for conversion */
139 if (value < 0 && radix == 10) {
154 *--pos = '0' + digit;
156 *--pos = 'a' + digit - 10;
164 memcpy(str, pos, &buffer[32] - pos + 1);
169 /*********************************************************************
172 * Converts an integer to a string.
175 * Always returns str.
178 * Converts value to a '\0' terminated string which is copied to str.
179 * The maximum length of the copied str is 33 bytes. If radix
180 * is 10 and value is negative, the value is converted with sign.
181 * Does not check if radix is in the range of 2 to 36.
182 * If str is NULL it crashes, as the native function does.
184 char * __cdecl _itoa(
185 int value, /* [I] Value to be converted */
186 char *str, /* [O] Destination for the converted value */
187 int radix) /* [I] Number base for conversion */
189 return _ltoa(value, str, radix);
193 /*********************************************************************
196 * Converts a large unsigned integer to a string.
199 * Always returns str.
202 * Converts value to a '\0' terminated string which is copied to str.
203 * The maximum length of the copied str is 65 bytes.
204 * Does not check if radix is in the range of 2 to 36.
205 * If str is NULL it crashes, as the native function does.
207 char * __cdecl _ui64toa(
208 ULONGLONG value, /* [I] Value to be converted */
209 char *str, /* [O] Destination for the converted value */
210 int radix) /* [I] Number base for conversion */
220 digit = value % radix;
221 value = value / radix;
223 *--pos = '0' + digit;
225 *--pos = 'a' + digit - 10;
227 } while (value != 0L);
229 memcpy(str, pos, &buffer[64] - pos + 1);
234 /*********************************************************************
237 * Converts a large integer to a string.
240 * Always returns str.
243 * Converts value to a '\0' terminated string which is copied to str.
244 * The maximum length of the copied str is 65 bytes. If radix
245 * is 10 and value is negative, the value is converted with sign.
246 * Does not check if radix is in the range of 2 to 36.
247 * If str is NULL it crashes, as the native function does.
250 * - The native DLL converts negative values (for base 10) wrong:
251 * -1 is converted to -18446744073709551615
252 * -2 is converted to -18446744073709551614
253 * -9223372036854775807 is converted to -9223372036854775809
254 * -9223372036854775808 is converted to -9223372036854775808
255 * The native msvcrt _i64toa function and our ntdll _i64toa function
256 * do not have this bug.
258 char * __cdecl _i64toa(
259 LONGLONG value, /* [I] Value to be converted */
260 char *str, /* [O] Destination for the converted value */
261 int radix) /* [I] Number base for conversion */
269 if (value < 0 && radix == 10) {
284 *--pos = '0' + digit;
286 *--pos = 'a' + digit - 10;
294 memcpy(str, pos, &buffer[64] - pos + 1);
299 /*********************************************************************
302 * Converts a string to a large integer.
305 * str [I] Wstring to be converted
308 * On success it returns the integer value otherwise it returns 0.
311 * Accepts: {whitespace} [+|-] {digits}
312 * No check is made for value overflow, only the lower 64 bits are assigned.
313 * If str is NULL it crashes, as the native function does.
315 LONGLONG __cdecl _atoi64( char *str )
317 ULONGLONG RunningTotal = 0;
320 while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
326 } else if (*str == '-') {
331 while (*str >= '0' && *str <= '9') {
332 RunningTotal = RunningTotal * 10 + *str - '0';
336 return bMinus ? -RunningTotal : RunningTotal;
340 /*********************************************************************
341 * _splitpath (NTDLL.@)
343 void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
344 char* fname, char * ext )
346 /* Modified PD code from 'snippets' collection. */
348 char pathbuff[MAX_PATH], *path=pathbuff;
350 strcpy(pathbuff, inpath);
352 /* convert slashes to backslashes for searching */
353 for (ptr = (char*)path; *ptr; ++ptr)
357 /* look for drive spec */
358 if ('\0' != (ptr = strchr(path, ':')))
363 strncpy(drv, path, ptr - path);
364 drv[ptr - path] = '\0';
371 /* find rightmost backslash or leftmost colon */
372 if (NULL == (ptr = strrchr(path, '\\')))
373 ptr = (strchr(path, ':'));
377 ptr = (char *)path; /* no path */
383 ++ptr; /* skip the delimiter */
393 if (NULL == (p = strrchr(ptr, '.')))
410 /* Fix pathological case - Win returns ':' as part of the
411 * directory when no drive letter is given.
413 if (drv && drv[0] == ':')
420 strcat(pathbuff,dir);
421 strcpy(dir,pathbuff);